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 axS.plot( 32 np.asarray(output["products"]["S_max"]) - 100, 33 output["products"]["z"], 34 color="black", 35 ) 36 axS.set_ylabel("Displacement [m]") 37 axS.set_xlabel("Supersaturation [%]") 38 axS.set_xlim(0, 0.7) 39 axS.set_ylim(0, 250) 40 axS.text(0.3, 52, f"max S = {np.nanmax(output['products']['S_max'])-100:.2f}%") 41 axS.grid() 42 43 axT = axS.twiny() 44 axT.xaxis.label.set_color("red") 45 axT.tick_params(axis="x", colors="red") 46 axT.plot(output["products"]["T"], output["products"]["z"], color="red") 47 rng = (272, 274) 48 axT.set_xlim(*rng) 49 axT.set_xticks(np.linspace(*rng, num=5)) 50 axT.set_xlabel("Temperature [K]") 51 52 axR = axs[1] 53 axR.set_xscale("log") 54 axR.set_xlim(1e-2, 1e2) 55 for drop_id, volume in enumerate(output["attributes"]["volume"]): 56 axR.plot( 57 settings.formulae.trivia.radius(volume=np.asarray(volume)) / si.um, 58 output["products"]["z"], 59 color="magenta" if drop_id < settings.n_sd_per_mode[0] else "blue", 60 label=( 61 "mode 1" 62 if drop_id == 0 63 else "mode 2" if drop_id == settings.n_sd_per_mode[0] else "" 64 ), 65 ) 66 axR.legend(loc="upper right") 67 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 axS.plot( 33 np.asarray(output["products"]["S_max"]) - 100, 34 output["products"]["z"], 35 color="black", 36 ) 37 axS.set_ylabel("Displacement [m]") 38 axS.set_xlabel("Supersaturation [%]") 39 axS.set_xlim(0, 0.7) 40 axS.set_ylim(0, 250) 41 axS.text(0.3, 52, f"max S = {np.nanmax(output['products']['S_max'])-100:.2f}%") 42 axS.grid() 43 44 axT = axS.twiny() 45 axT.xaxis.label.set_color("red") 46 axT.tick_params(axis="x", colors="red") 47 axT.plot(output["products"]["T"], output["products"]["z"], color="red") 48 rng = (272, 274) 49 axT.set_xlim(*rng) 50 axT.set_xticks(np.linspace(*rng, num=5)) 51 axT.set_xlabel("Temperature [K]") 52 53 axR = axs[1] 54 axR.set_xscale("log") 55 axR.set_xlim(1e-2, 1e2) 56 for drop_id, volume in enumerate(output["attributes"]["volume"]): 57 axR.plot( 58 settings.formulae.trivia.radius(volume=np.asarray(volume)) / si.um, 59 output["products"]["z"], 60 color="magenta" if drop_id < settings.n_sd_per_mode[0] else "blue", 61 label=( 62 "mode 1" 63 if drop_id == 0 64 else "mode 2" if drop_id == settings.n_sd_per_mode[0] else "" 65 ), 66 ) 67 axR.legend(loc="upper right") 68 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 axS.plot( 33 np.asarray(output["products"]["S_max"]) - 100, 34 output["products"]["z"], 35 color="black", 36 ) 37 axS.set_ylabel("Displacement [m]") 38 axS.set_xlabel("Supersaturation [%]") 39 axS.set_xlim(0, 0.7) 40 axS.set_ylim(0, 250) 41 axS.text(0.3, 52, f"max S = {np.nanmax(output['products']['S_max'])-100:.2f}%") 42 axS.grid() 43 44 axT = axS.twiny() 45 axT.xaxis.label.set_color("red") 46 axT.tick_params(axis="x", colors="red") 47 axT.plot(output["products"]["T"], output["products"]["z"], color="red") 48 rng = (272, 274) 49 axT.set_xlim(*rng) 50 axT.set_xticks(np.linspace(*rng, num=5)) 51 axT.set_xlabel("Temperature [K]") 52 53 axR = axs[1] 54 axR.set_xscale("log") 55 axR.set_xlim(1e-2, 1e2) 56 for drop_id, volume in enumerate(output["attributes"]["volume"]): 57 axR.plot( 58 settings.formulae.trivia.radius(volume=np.asarray(volume)) / si.um, 59 output["products"]["z"], 60 color="magenta" if drop_id < settings.n_sd_per_mode[0] else "blue", 61 label=( 62 "mode 1" 63 if drop_id == 0 64 else "mode 2" if drop_id == settings.n_sd_per_mode[0] else "" 65 ), 66 ) 67 axR.legend(loc="upper right") 68 axR.set_xlabel("Droplet radius [μm]")