PySDM_examples.Pyrcel.profile_plotter
1import numpy as np 2from matplotlib import pyplot 3from open_atmos_jupyter_utils import show_plot 4 5from PySDM.physics.constants import si 6 7 8class ProfilePlotter: 9 def __init__(self, settings, legend=True, log_base=10): 10 self.settings = settings 11 self.format = "pdf" 12 self.legend = legend 13 self.log_base = log_base 14 self.ax = pyplot 15 self.fig = pyplot 16 17 def show(self): 18 pyplot.tight_layout() 19 show_plot() 20 21 def save(self, file): 22 # self.finish() 23 pyplot.savefig(file, format=self.format) 24 25 def plot(self, output): 26 self.plot_data(self.settings, output) 27 28 def plot_data(self, settings, output): 29 _, axs = pyplot.subplots(1, 2, sharey=True, figsize=(10, 5)) 30 axS = axs[0] 31 if output["products"].get("S_max"): 32 SS_percent = (np.asarray(output["products"]["S_max"]) - 1) * 100 33 else: 34 SS_percent = np.asarray(output["products"]["S_max_percent"]) - 100 35 axS.plot( 36 SS_percent, 37 output["products"]["z"], 38 color="black", 39 ) 40 axS.set_ylabel("Displacement [m]") 41 axS.set_xlabel("Supersaturation [%]") 42 axS.set_xlim(0, 0.7) 43 axS.set_ylim(0, 250) 44 axS.text(0.3, 52, f"max SS = {np.nanmax(SS_percent):.2f}%") 45 axS.grid() 46 47 axT = axS.twiny() 48 axT.xaxis.label.set_color("red") 49 axT.tick_params(axis="x", colors="red") 50 axT.plot(output["products"]["T"], output["products"]["z"], color="red") 51 rng = (272, 274) 52 axT.set_xlim(*rng) 53 axT.set_xticks(np.linspace(*rng, num=5)) 54 axT.set_xlabel("Temperature [K]") 55 56 axR = axs[1] 57 axR.set_xscale("log") 58 axR.set_xlim(1e-2, 1e2) 59 for drop_id, volume in enumerate(output["attributes"]["volume"]): 60 axR.plot( 61 settings.formulae.trivia.radius(volume=np.asarray(volume)) / si.um, 62 output["products"]["z"], 63 color="magenta" if drop_id < settings.n_sd_per_mode[0] else "blue", 64 label=( 65 "mode 1" 66 if drop_id == 0 67 else "mode 2" if drop_id == settings.n_sd_per_mode[0] else "" 68 ), 69 ) 70 axR.legend(loc="upper right") 71 axR.set_xlabel("Droplet radius [μm]")
class
ProfilePlotter:
9class ProfilePlotter: 10 def __init__(self, settings, legend=True, log_base=10): 11 self.settings = settings 12 self.format = "pdf" 13 self.legend = legend 14 self.log_base = log_base 15 self.ax = pyplot 16 self.fig = pyplot 17 18 def show(self): 19 pyplot.tight_layout() 20 show_plot() 21 22 def save(self, file): 23 # self.finish() 24 pyplot.savefig(file, format=self.format) 25 26 def plot(self, output): 27 self.plot_data(self.settings, output) 28 29 def plot_data(self, settings, output): 30 _, axs = pyplot.subplots(1, 2, sharey=True, figsize=(10, 5)) 31 axS = axs[0] 32 if output["products"].get("S_max"): 33 SS_percent = (np.asarray(output["products"]["S_max"]) - 1) * 100 34 else: 35 SS_percent = np.asarray(output["products"]["S_max_percent"]) - 100 36 axS.plot( 37 SS_percent, 38 output["products"]["z"], 39 color="black", 40 ) 41 axS.set_ylabel("Displacement [m]") 42 axS.set_xlabel("Supersaturation [%]") 43 axS.set_xlim(0, 0.7) 44 axS.set_ylim(0, 250) 45 axS.text(0.3, 52, f"max SS = {np.nanmax(SS_percent):.2f}%") 46 axS.grid() 47 48 axT = axS.twiny() 49 axT.xaxis.label.set_color("red") 50 axT.tick_params(axis="x", colors="red") 51 axT.plot(output["products"]["T"], output["products"]["z"], color="red") 52 rng = (272, 274) 53 axT.set_xlim(*rng) 54 axT.set_xticks(np.linspace(*rng, num=5)) 55 axT.set_xlabel("Temperature [K]") 56 57 axR = axs[1] 58 axR.set_xscale("log") 59 axR.set_xlim(1e-2, 1e2) 60 for drop_id, volume in enumerate(output["attributes"]["volume"]): 61 axR.plot( 62 settings.formulae.trivia.radius(volume=np.asarray(volume)) / si.um, 63 output["products"]["z"], 64 color="magenta" if drop_id < settings.n_sd_per_mode[0] else "blue", 65 label=( 66 "mode 1" 67 if drop_id == 0 68 else "mode 2" if drop_id == settings.n_sd_per_mode[0] else "" 69 ), 70 ) 71 axR.legend(loc="upper right") 72 axR.set_xlabel("Droplet radius [μm]")
def
plot_data(self, settings, output):
29 def plot_data(self, settings, output): 30 _, axs = pyplot.subplots(1, 2, sharey=True, figsize=(10, 5)) 31 axS = axs[0] 32 if output["products"].get("S_max"): 33 SS_percent = (np.asarray(output["products"]["S_max"]) - 1) * 100 34 else: 35 SS_percent = np.asarray(output["products"]["S_max_percent"]) - 100 36 axS.plot( 37 SS_percent, 38 output["products"]["z"], 39 color="black", 40 ) 41 axS.set_ylabel("Displacement [m]") 42 axS.set_xlabel("Supersaturation [%]") 43 axS.set_xlim(0, 0.7) 44 axS.set_ylim(0, 250) 45 axS.text(0.3, 52, f"max SS = {np.nanmax(SS_percent):.2f}%") 46 axS.grid() 47 48 axT = axS.twiny() 49 axT.xaxis.label.set_color("red") 50 axT.tick_params(axis="x", colors="red") 51 axT.plot(output["products"]["T"], output["products"]["z"], color="red") 52 rng = (272, 274) 53 axT.set_xlim(*rng) 54 axT.set_xticks(np.linspace(*rng, num=5)) 55 axT.set_xlabel("Temperature [K]") 56 57 axR = axs[1] 58 axR.set_xscale("log") 59 axR.set_xlim(1e-2, 1e2) 60 for drop_id, volume in enumerate(output["attributes"]["volume"]): 61 axR.plot( 62 settings.formulae.trivia.radius(volume=np.asarray(volume)) / si.um, 63 output["products"]["z"], 64 color="magenta" if drop_id < settings.n_sd_per_mode[0] else "blue", 65 label=( 66 "mode 1" 67 if drop_id == 0 68 else "mode 2" if drop_id == settings.n_sd_per_mode[0] else "" 69 ), 70 ) 71 axR.legend(loc="upper right") 72 axR.set_xlabel("Droplet radius [μm]")