PySDM_examples.Lowe_et_al_2019.plot_helper

  1import numpy as np
  2from matplotlib import pyplot
  3from open_atmos_jupyter_utils import show_plot
  4
  5
  6def plot_profiles(subplot_list, updraft_list, forg_list, output, save=False):
  7    _, axes = pyplot.subplots(
  8        len(subplot_list),
  9        len(updraft_list),
 10        sharex=False,
 11        sharey=True,
 12        figsize=(3 * len(updraft_list), 4 * len(subplot_list)),
 13    )
 14
 15    for k, subplot in enumerate(subplot_list):
 16        for i, w in enumerate(updraft_list):
 17            for _, Forg in enumerate(forg_list):
 18                key = subplot + f"_w{w:.2f}_f{Forg:.2f}_"
 19                var = "CDNC_cm3"
 20                z = np.array(output[key + "CompressedFilmOvadnevaite"]["z"])
 21                CDNC_film = np.array(output[key + "CompressedFilmOvadnevaite"][var])
 22                CDNC_bulk = np.array(output[key + "Constant"][var])
 23
 24                cmap = pyplot.get_cmap("Spectral")
 25                if len(subplot_list) > 1:
 26                    ax = axes[k, i]
 27                else:
 28                    ax = axes[i]
 29
 30                ax.plot(CDNC_film, z, "--", color=cmap(Forg))
 31                ax.plot(CDNC_bulk, z, "-", color=cmap(Forg), label=f"{Forg:.2f}")
 32
 33                if i == 0:
 34                    ax.set_ylabel("Parcel displacement [m]")
 35                    ax.set_title(subplot, loc="left", weight="bold")
 36                if i == len(updraft_list) - 1 and k == 0:
 37                    ax.legend(title="Forg", loc=2)
 38                if k == 0:
 39                    ax.set_title(f"w = {w:.2f} m/s")
 40                if k == len(subplot_list) - 1:
 41                    ax.set_xlabel("CDNC [cm$^{-3}$]")
 42    if save:
 43        show_plot("fig3_parcel_profiles.pdf")
 44
 45
 46def plot_contours(
 47    subplot_list, updraft_list, forg_list, output, actfrac=False, save=False
 48):
 49    _, axes = pyplot.subplots(2, 2, sharex=True, sharey=True, figsize=(14, 10))
 50
 51    for subplot in subplot_list:
 52        dCDNC = np.zeros((len(updraft_list), len(forg_list)))
 53        for i, w in enumerate(updraft_list):
 54            for j, Forg in enumerate(forg_list):
 55                key = subplot + f"_w{w:.2f}_f{Forg:.2f}_"
 56                if actfrac:
 57                    var = "Activated Fraction"
 58                    Naer = 1.0
 59                    CDNC_film = output[key + "CompressedFilmOvadnevaite"][var][0] * Naer
 60                    CDNC_bulk = output[key + "Constant"][var][0] * Naer
 61                else:
 62                    var = "CDNC_cm3"
 63                    z = np.array(output[key + "CompressedFilmOvadnevaite"]["z"])
 64                    wz = np.where(z == z[-1])[0][0]
 65                    CDNC_film = np.array(
 66                        output[key + "CompressedFilmOvadnevaite"][var]
 67                    )[wz]
 68                    CDNC_bulk = np.array(output[key + "Constant"][var])[wz]
 69                dCDNC[i, j] = (CDNC_film - CDNC_bulk) / CDNC_bulk * 100.0
 70
 71        if subplot == "a":
 72            ax = axes[0, 0]
 73            ax.set_title(
 74                "MA Accum. mode conc. N$_2 = 30$ cm$^{-3}$", fontsize=13, loc="right"
 75            )
 76            ax.contour(
 77                forg_list,
 78                updraft_list,
 79                dCDNC,
 80                levels=[10, 25],
 81                colors=["#1fa8f2", "#4287f5"],
 82                linestyles=[":", "--"],
 83                linewidths=4,
 84            )
 85            p = ax.contourf(
 86                forg_list,
 87                updraft_list,
 88                dCDNC,
 89                cmap="Blues",
 90                levels=np.linspace(0, 90, 11),
 91                extend="both",
 92            )
 93        if subplot == "b":
 94            ax = axes[0, 1]
 95            ax.set_title(
 96                "MA Accum. mode conc. N$_2 = 135$ cm$^{-3}$", fontsize=13, loc="right"
 97            )
 98            ax.contour(
 99                forg_list,
100                updraft_list,
101                dCDNC,
102                levels=[10, 25],
103                colors=["#1fa8f2", "#4287f5"],
104                linestyles=[":", "--"],
105                linewidths=4,
106            )
107            p = ax.contourf(
108                forg_list,
109                updraft_list,
110                dCDNC,
111                cmap="Blues",
112                levels=np.linspace(0, 90, 11),
113                extend="both",
114            )
115        if subplot == "c":
116            ax = axes[1, 0]
117            ax.set_title(
118                "HYY Accum. mode conc. N$_2 = 160$ cm$^{-3}$", fontsize=13, loc="right"
119            )
120            ax.contour(
121                forg_list,
122                updraft_list,
123                dCDNC,
124                levels=[10, 25],
125                colors=["#04c753", "#157d3f"],
126                linestyles=[":", "--"],
127                linewidths=4,
128            )
129            p = ax.contourf(
130                forg_list,
131                updraft_list,
132                dCDNC,
133                cmap="Greens",
134                levels=np.linspace(0, 75, 11),
135                extend="both",
136            )
137        if subplot == "d":
138            ax = axes[1, 1]
139            ax.set_title(
140                "HYY Accum. mode conc. N$_2 = 540$ cm$^{-3}$", fontsize=13, loc="right"
141            )
142            ax.contour(
143                forg_list,
144                updraft_list,
145                dCDNC,
146                levels=[10, 25],
147                colors=["#04c753", "#157d3f"],
148                linestyles=[":", "--"],
149                linewidths=4,
150            )
151            p = ax.contourf(
152                forg_list,
153                updraft_list,
154                dCDNC,
155                cmap="Greens",
156                levels=np.linspace(0, 75, 11),
157                extend="both",
158            )
159
160        ax.set_title(subplot, weight="bold", loc="left")
161        if subplot in ("c", "d"):
162            ax.set_xlabel("Organic mass fraction")
163        ax.set_yscale("log")
164        ax.set_yticks([0.1, 1, 10])
165        ax.set_yticklabels(["0.1", "1", "10"])
166        ax.set_xlim([0, 1])
167        if subplot in ("a", "c"):
168            ax.set_ylabel("Updraft [ms$^{-1}$]")
169        pyplot.colorbar(p, ax=ax, label=r"$\Delta_{CDNC}$ [%]")
170
171    pyplot.rcParams.update({"font.size": 15})
172    if save:
173        if actfrac:
174            pyplot.savefig(
175                "fig_3_Scrit.png", dpi=200, facecolor="w", bbox_inches="tight"
176            )
177            show_plot("fig_3_Scrit.pdf")
178        else:
179            pyplot.savefig(
180                "fig_3_rcrit.png", dpi=200, facecolor="w", bbox_inches="tight"
181            )
182            show_plot("fig_3_rcrit.pdf")
def plot_profiles(subplot_list, updraft_list, forg_list, output, save=False):
 7def plot_profiles(subplot_list, updraft_list, forg_list, output, save=False):
 8    _, axes = pyplot.subplots(
 9        len(subplot_list),
10        len(updraft_list),
11        sharex=False,
12        sharey=True,
13        figsize=(3 * len(updraft_list), 4 * len(subplot_list)),
14    )
15
16    for k, subplot in enumerate(subplot_list):
17        for i, w in enumerate(updraft_list):
18            for _, Forg in enumerate(forg_list):
19                key = subplot + f"_w{w:.2f}_f{Forg:.2f}_"
20                var = "CDNC_cm3"
21                z = np.array(output[key + "CompressedFilmOvadnevaite"]["z"])
22                CDNC_film = np.array(output[key + "CompressedFilmOvadnevaite"][var])
23                CDNC_bulk = np.array(output[key + "Constant"][var])
24
25                cmap = pyplot.get_cmap("Spectral")
26                if len(subplot_list) > 1:
27                    ax = axes[k, i]
28                else:
29                    ax = axes[i]
30
31                ax.plot(CDNC_film, z, "--", color=cmap(Forg))
32                ax.plot(CDNC_bulk, z, "-", color=cmap(Forg), label=f"{Forg:.2f}")
33
34                if i == 0:
35                    ax.set_ylabel("Parcel displacement [m]")
36                    ax.set_title(subplot, loc="left", weight="bold")
37                if i == len(updraft_list) - 1 and k == 0:
38                    ax.legend(title="Forg", loc=2)
39                if k == 0:
40                    ax.set_title(f"w = {w:.2f} m/s")
41                if k == len(subplot_list) - 1:
42                    ax.set_xlabel("CDNC [cm$^{-3}$]")
43    if save:
44        show_plot("fig3_parcel_profiles.pdf")
def plot_contours( subplot_list, updraft_list, forg_list, output, actfrac=False, save=False):
 47def plot_contours(
 48    subplot_list, updraft_list, forg_list, output, actfrac=False, save=False
 49):
 50    _, axes = pyplot.subplots(2, 2, sharex=True, sharey=True, figsize=(14, 10))
 51
 52    for subplot in subplot_list:
 53        dCDNC = np.zeros((len(updraft_list), len(forg_list)))
 54        for i, w in enumerate(updraft_list):
 55            for j, Forg in enumerate(forg_list):
 56                key = subplot + f"_w{w:.2f}_f{Forg:.2f}_"
 57                if actfrac:
 58                    var = "Activated Fraction"
 59                    Naer = 1.0
 60                    CDNC_film = output[key + "CompressedFilmOvadnevaite"][var][0] * Naer
 61                    CDNC_bulk = output[key + "Constant"][var][0] * Naer
 62                else:
 63                    var = "CDNC_cm3"
 64                    z = np.array(output[key + "CompressedFilmOvadnevaite"]["z"])
 65                    wz = np.where(z == z[-1])[0][0]
 66                    CDNC_film = np.array(
 67                        output[key + "CompressedFilmOvadnevaite"][var]
 68                    )[wz]
 69                    CDNC_bulk = np.array(output[key + "Constant"][var])[wz]
 70                dCDNC[i, j] = (CDNC_film - CDNC_bulk) / CDNC_bulk * 100.0
 71
 72        if subplot == "a":
 73            ax = axes[0, 0]
 74            ax.set_title(
 75                "MA Accum. mode conc. N$_2 = 30$ cm$^{-3}$", fontsize=13, loc="right"
 76            )
 77            ax.contour(
 78                forg_list,
 79                updraft_list,
 80                dCDNC,
 81                levels=[10, 25],
 82                colors=["#1fa8f2", "#4287f5"],
 83                linestyles=[":", "--"],
 84                linewidths=4,
 85            )
 86            p = ax.contourf(
 87                forg_list,
 88                updraft_list,
 89                dCDNC,
 90                cmap="Blues",
 91                levels=np.linspace(0, 90, 11),
 92                extend="both",
 93            )
 94        if subplot == "b":
 95            ax = axes[0, 1]
 96            ax.set_title(
 97                "MA Accum. mode conc. N$_2 = 135$ cm$^{-3}$", fontsize=13, loc="right"
 98            )
 99            ax.contour(
100                forg_list,
101                updraft_list,
102                dCDNC,
103                levels=[10, 25],
104                colors=["#1fa8f2", "#4287f5"],
105                linestyles=[":", "--"],
106                linewidths=4,
107            )
108            p = ax.contourf(
109                forg_list,
110                updraft_list,
111                dCDNC,
112                cmap="Blues",
113                levels=np.linspace(0, 90, 11),
114                extend="both",
115            )
116        if subplot == "c":
117            ax = axes[1, 0]
118            ax.set_title(
119                "HYY Accum. mode conc. N$_2 = 160$ cm$^{-3}$", fontsize=13, loc="right"
120            )
121            ax.contour(
122                forg_list,
123                updraft_list,
124                dCDNC,
125                levels=[10, 25],
126                colors=["#04c753", "#157d3f"],
127                linestyles=[":", "--"],
128                linewidths=4,
129            )
130            p = ax.contourf(
131                forg_list,
132                updraft_list,
133                dCDNC,
134                cmap="Greens",
135                levels=np.linspace(0, 75, 11),
136                extend="both",
137            )
138        if subplot == "d":
139            ax = axes[1, 1]
140            ax.set_title(
141                "HYY Accum. mode conc. N$_2 = 540$ cm$^{-3}$", fontsize=13, loc="right"
142            )
143            ax.contour(
144                forg_list,
145                updraft_list,
146                dCDNC,
147                levels=[10, 25],
148                colors=["#04c753", "#157d3f"],
149                linestyles=[":", "--"],
150                linewidths=4,
151            )
152            p = ax.contourf(
153                forg_list,
154                updraft_list,
155                dCDNC,
156                cmap="Greens",
157                levels=np.linspace(0, 75, 11),
158                extend="both",
159            )
160
161        ax.set_title(subplot, weight="bold", loc="left")
162        if subplot in ("c", "d"):
163            ax.set_xlabel("Organic mass fraction")
164        ax.set_yscale("log")
165        ax.set_yticks([0.1, 1, 10])
166        ax.set_yticklabels(["0.1", "1", "10"])
167        ax.set_xlim([0, 1])
168        if subplot in ("a", "c"):
169            ax.set_ylabel("Updraft [ms$^{-1}$]")
170        pyplot.colorbar(p, ax=ax, label=r"$\Delta_{CDNC}$ [%]")
171
172    pyplot.rcParams.update({"font.size": 15})
173    if save:
174        if actfrac:
175            pyplot.savefig(
176                "fig_3_Scrit.png", dpi=200, facecolor="w", bbox_inches="tight"
177            )
178            show_plot("fig_3_Scrit.pdf")
179        else:
180            pyplot.savefig(
181                "fig_3_rcrit.png", dpi=200, facecolor="w", bbox_inches="tight"
182            )
183            show_plot("fig_3_rcrit.pdf")