From 76c4ad0e33fb753e50b87172352c9f88ee5995d5 Mon Sep 17 00:00:00 2001 From: AgnieszkaMakulska Date: Thu, 4 Jun 2026 10:27:09 +0200 Subject: [PATCH 1/6] spectrum test - larger tolerance --- unit_test_debug/test_spectrum.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unit_test_debug/test_spectrum.py b/unit_test_debug/test_spectrum.py index aed8aa6..1a81aa6 100644 --- a/unit_test_debug/test_spectrum.py +++ b/unit_test_debug/test_spectrum.py @@ -52,7 +52,7 @@ def test_bin_checker(data, name_spect, eps_d=1.e-14): @pytest.mark.parametrize("var", ["wradii_r_wet", "wradii_dr_wet", "linwradii_r_wet", "linwradii_dr_wet", "dradii_r_dry", "dradii_dr_dry", "lindradii_r_dry", "lindradii_dr_dry"]) -def test_spectrum_diff(data, var, eps_d = 1e-15): +def test_spectrum_diff(data, var, eps_d = 1e-14): """ Compare the results with the referential simulation (stored in refdata folder) @@ -61,7 +61,7 @@ def test_spectrum_diff(data, var, eps_d = 1e-15): f_ref = netcdf.netcdf_file("unit_test/refdata/test_spectrum.nc", "r") # ... the bin edges and bin sizes ... - assert np.isclose(f_ref.variables[var][:], data.variables[var][:],atol=0, rtol=eps_d).all() + assert np.isclose(f_ref.variables[var][:], data.variables[var][:],atol=1e-20, rtol=eps_d).all() # ... and 0th, 1st, 3rd moment of wet and dry radius size distribution @pytest.mark.parametrize("mom, eps", [("wradii_m0", 1e-15), ("dradii_m0", 1e-15), From 9762943d9c166c784e3d1271fc9b819ffd2d54c2 Mon Sep 17 00:00:00 2001 From: AgnieszkaMakulska Date: Fri, 12 Jun 2026 16:06:45 +0200 Subject: [PATCH 2/6] change plot for ice SD test --- long_test/test_plot_ice_SD.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/long_test/test_plot_ice_SD.py b/long_test/test_plot_ice_SD.py index 5625595..98e1dd0 100644 --- a/long_test/test_plot_ice_SD.py +++ b/long_test/test_plot_ice_SD.py @@ -20,11 +20,12 @@ def plot_profiles(fnc, output_name): plt.rcParams.update({'font.size': 14}) fig, plots = plt.subplots(1, 2, figsize=(15, 5)) plots[0].set_xlabel('mixing ratio [g/kg]') - plots[1].set_xlabel('T [K]') + plots[1].set_xlabel('T [C]') for ax in plots: - ax.set_ylabel('z [m]') + ax.set_ylabel('z [km]') + ax.grid() - z = fnc.variables["z"][:] + z = fnc.variables["z"][:] / 1000 #km r_v = fnc.variables["r_v"][:] * 1000 #g/kg r_liq = np.array([i[0] for i in fnc.variables['liq_m3'][:]]) *4/3 * np.pi * common.rho_w * 1000 #g/kg r_ice = fnc.variables["ice_mix_ratio"][:] * 1000 #g/kg @@ -34,7 +35,8 @@ def plot_profiles(fnc, output_name): plots[0].plot(r_liq, z) plots[0].plot(r_ice, z) plots[0].legend(['$r_{tot}$', '$r_v$', '$r_{liq}$', '$r_{ice}$'], loc='best') - plots[1].plot(fnc.variables["T"][:], z) + plots[1].plot(fnc.variables["T"][:] - 273.15, z) + plt.suptitle("Homogeneous ice nucleation" if output_name == "ice_SD_plot_hom.svg" else "Heterogeneous ice nucleation") if not os.path.exists("plots/outputs/"): subprocess.call(["mkdir", "plots/outputs/"]) From a7a9c275e814d15fcc46b5d5656c54c1f46af6e9 Mon Sep 17 00:00:00 2001 From: AgnieszkaMakulska Date: Tue, 23 Jun 2026 11:27:01 +0200 Subject: [PATCH 3/6] sol_frac and mean_r for large dust INP --- long_test/test_ice_SD.py | 2 +- long_test/test_plot_ice_SD.py | 4 ++-- long_test/test_plot_schemes_ice.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/long_test/test_ice_SD.py b/long_test/test_ice_SD.py index ce34ba1..701a2fa 100644 --- a/long_test/test_ice_SD.py +++ b/long_test/test_ice_SD.py @@ -27,7 +27,7 @@ def test_ice_SD(): depo = True, ice_nucl = True, time_dep_ice_nucl = time_dep, - aerosol = '{"ammonium_sulfate": {"kappa": 0.61, "sol_frac": 0.1, "mean_r": [0.02e-6], "gstdev": [1.4], "n_tot": [60.0e6]}}', + aerosol = '{"ammonium_sulfate": {"kappa": 0.61, "sol_frac": 6.4e-5, "mean_r": [0.5e-6], "gstdev": [1.4], "n_tot": [60.0e6]}}', outfreq = 4000, out_bin = '{"liq": {"rght": 1, "moms": [0,3], "drwt": "wet", "nbin": 1, "lnli": "lin", "left": 5e-20}}', outfile = outfile, diff --git a/long_test/test_plot_ice_SD.py b/long_test/test_plot_ice_SD.py index 580da9a..a8b9185 100644 --- a/long_test/test_plot_ice_SD.py +++ b/long_test/test_plot_ice_SD.py @@ -43,7 +43,7 @@ def plot_profiles(fnc, output_name): plt.savefig(os.path.join("plots/outputs/", output_name)) def test_plot_ice_SD(): - for (sol_frac, output_name) in [("0.1", "ice_SD_plot_het.svg"), ("1.0", "ice_SD_plot_hom.svg")]: + for (mean_r, sol_frac, output_name) in [("0.5e-6", "6.4e-5", "ice_SD_plot_het.svg"), ("0.02e-6", "1.0", "ice_SD_plot_hom.svg")]: outfile = "onesim_plot.nc" parcel(dt=1.,w=1.,sd_conc=100, z_max = 5000.0, @@ -54,7 +54,7 @@ def test_plot_ice_SD(): depo = True, ice_nucl=True, time_dep_ice_nucl=True, - aerosol = f'{{"ammonium_sulfate": {{"kappa": 0.61, "sol_frac": {sol_frac}, "mean_r": [0.02e-6], "gstdev": [1.4], "n_tot": [60.0e6]}}}}', + aerosol = f'{{"ammonium_sulfate": {{"kappa": 0.61, "sol_frac": {sol_frac}, "mean_r": [{mean_r}], "gstdev": [1.4], "n_tot": [60.0e6]}}}}', outfreq = 100, out_bin= '{"liq": {"rght": 1, "moms": [0,3], "drwt": "wet", "nbin": 1, "lnli": "lin", "left": 5e-20}}', outfile=outfile) diff --git a/long_test/test_plot_schemes_ice.py b/long_test/test_plot_schemes_ice.py index f687dc1..f66411b 100644 --- a/long_test/test_plot_schemes_ice.py +++ b/long_test/test_plot_schemes_ice.py @@ -29,7 +29,7 @@ def run_scheme(scheme, time_dep, outfile): depo = True, ice_nucl=True, time_dep_ice_nucl=time_dep, - aerosol = f'{{"ammonium_sulfate": {{"kappa": 0.61, "sol_frac": 0.1, "mean_r": [0.02e-6], "gstdev": [1.4], "n_tot": [60.0e6]}}}}', + aerosol = f'{{"ammonium_sulfate": {{"kappa": 0.61, "sol_frac": 6.4e-5, "mean_r": [0.5e-6], "gstdev": [1.4], "n_tot": [60.0e6]}}}}', outfreq = 100, out_bin= '{"liq": {"rght": 1, "moms": [3], "drwt": "wet", "nbin": 1, "lnli": "lin", "left": 5e-20}}', outfile=outfile) From 04024334d8717722980ad59eaf321950621fa1c8 Mon Sep 17 00:00:00 2001 From: AgnieszkaMakulska Date: Wed, 24 Jun 2026 15:27:35 +0200 Subject: [PATCH 4/6] Revert "spectrum test - larger tolerance" This reverts commit 76c4ad0e33fb753e50b87172352c9f88ee5995d5. --- unit_test_debug/test_spectrum.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unit_test_debug/test_spectrum.py b/unit_test_debug/test_spectrum.py index 1a81aa6..aed8aa6 100644 --- a/unit_test_debug/test_spectrum.py +++ b/unit_test_debug/test_spectrum.py @@ -52,7 +52,7 @@ def test_bin_checker(data, name_spect, eps_d=1.e-14): @pytest.mark.parametrize("var", ["wradii_r_wet", "wradii_dr_wet", "linwradii_r_wet", "linwradii_dr_wet", "dradii_r_dry", "dradii_dr_dry", "lindradii_r_dry", "lindradii_dr_dry"]) -def test_spectrum_diff(data, var, eps_d = 1e-14): +def test_spectrum_diff(data, var, eps_d = 1e-15): """ Compare the results with the referential simulation (stored in refdata folder) @@ -61,7 +61,7 @@ def test_spectrum_diff(data, var, eps_d = 1e-14): f_ref = netcdf.netcdf_file("unit_test/refdata/test_spectrum.nc", "r") # ... the bin edges and bin sizes ... - assert np.isclose(f_ref.variables[var][:], data.variables[var][:],atol=1e-20, rtol=eps_d).all() + assert np.isclose(f_ref.variables[var][:], data.variables[var][:],atol=0, rtol=eps_d).all() # ... and 0th, 1st, 3rd moment of wet and dry radius size distribution @pytest.mark.parametrize("mom, eps", [("wradii_m0", 1e-15), ("dradii_m0", 1e-15), From f104ceaab341c212648ca37136de289a62cbb12c Mon Sep 17 00:00:00 2001 From: AgnieszkaMakulska Date: Wed, 24 Jun 2026 16:02:05 +0200 Subject: [PATCH 5/6] improving test plot --- long_test/test_plot_ice_SD.py | 8 +++--- long_test/test_plot_schemes_ice.py | 43 +++++++++++++++--------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/long_test/test_plot_ice_SD.py b/long_test/test_plot_ice_SD.py index a8b9185..aff35e7 100644 --- a/long_test/test_plot_ice_SD.py +++ b/long_test/test_plot_ice_SD.py @@ -17,7 +17,7 @@ def plot_profiles(fnc, output_name): plt.clf() - plt.rcParams.update({'font.size': 14}) + plt.rcParams.update({'font.size': 13}) fig, plots = plt.subplots(1, 2, figsize=(15, 5)) plots[0].set_xlabel('mixing ratio [g/kg]') plots[1].set_xlabel('T [C]') @@ -34,7 +34,7 @@ def plot_profiles(fnc, output_name): plots[0].plot(r_v, z) plots[0].plot(r_liq, z) plots[0].plot(r_ice, z) - plots[0].legend(['$r_{tot}$', '$r_v$', '$r_{liq}$', '$r_{ice}$'], loc='best') + plots[0].legend(['total', 'water vapor', 'liquid', 'ice'], loc='best', fontsize=12) plots[1].plot(fnc.variables["T"][:] - 273.15, z) plt.suptitle("Homogeneous ice nucleation" if output_name == "ice_SD_plot_hom.svg" else "Heterogeneous ice nucleation") @@ -43,11 +43,11 @@ def plot_profiles(fnc, output_name): plt.savefig(os.path.join("plots/outputs/", output_name)) def test_plot_ice_SD(): - for (mean_r, sol_frac, output_name) in [("0.5e-6", "6.4e-5", "ice_SD_plot_het.svg"), ("0.02e-6", "1.0", "ice_SD_plot_hom.svg")]: + for (mean_r, sol_frac, output_name) in [("0.5e-6", "6.4e-5", "ice_SD_plot_het.pdf"), ("0.02e-6", "1.0", "ice_SD_plot_hom.pdf")]: outfile = "onesim_plot.nc" parcel(dt=1.,w=1.,sd_conc=100, z_max = 5000.0, - T_0 = 263.0, + T_0 = 265.0, RH_0 = 1., scheme = "lgrngn", ice_switch=True, diff --git a/long_test/test_plot_schemes_ice.py b/long_test/test_plot_schemes_ice.py index f66411b..44bb081 100644 --- a/long_test/test_plot_schemes_ice.py +++ b/long_test/test_plot_schemes_ice.py @@ -4,7 +4,7 @@ - lgrngn with time-dependent freezing (as in Arabas et al., 2025) - 1-moment bulk (Grabowski, 1999) -It plots the evolution of ice, liquid and vapor mixing ratios for different schemes. +It plots the evolution of ice and liquid mixing ratios for different schemes. """ import sys, os @@ -21,7 +21,7 @@ def run_scheme(scheme, time_dep, outfile): args = dict(dt=1., w=1., sd_conc=100, - z_max = 6000.0, + z_max = 5000.0, T_0 = 265.0, RH_0 = 1., scheme = scheme, @@ -35,40 +35,41 @@ def run_scheme(scheme, time_dep, outfile): outfile=outfile) parcel(**args) with netcdf.netcdf_file(outfile, 'r') as f: - rv = np.array(f.variables['r_v'][:]).squeeze() z = np.array(f.variables['z'][:]).squeeze() - T = np.array(f.variables['T'][:]).squeeze() if scheme.startswith("blk"): r_liq = np.array(f.variables['rc'][:]) + np.array(f.variables['rr'][:]).squeeze() r_ice = np.array(f.variables['ria'][:]) + np.array(f.variables['rib'][:]).squeeze() - else: + else: r_liq = np.array(f.variables['liq_m3'][:]).squeeze() *4/3 * np.pi * common.rho_w r_ice = np.array(f.variables['ice_mix_ratio'][:]).squeeze() - return z, rv, r_liq, r_ice, T + return z, r_liq, r_ice def test_plot_schemes(): schemes = [("lgrngn", False), ("lgrngn", True), ("blk_1m", None)] plt.rcParams.update({'font.size': 14}) - fig, ax = plt.subplots(1,4, figsize=(16, 6)) + fig, ax = plt.subplots(1,2, figsize=(9,6)) for (scheme, time_dep) in schemes: - z, rv, r_liq, r_ice, T = run_scheme(scheme, time_dep, f"test_{scheme}.nc") + z, r_liq, r_ice = run_scheme(scheme, time_dep, f"test_{scheme}.nc") if scheme == "lgrngn" and time_dep == True: - l = "Lagrangian time dependent" + l = "Lagrangian time-dependent" elif time_dep == False: l = "Lagrangian singular" else: l = "1-moment bulk" - ax[0].plot(rv*1e3, z, label=l, linestyle ='--' if scheme=='blk_1m' else '-') - ax[1].plot(r_liq*1e3, z, label=l, linestyle ='--' if scheme=='blk_1m' else '-') - ax[2].plot(r_ice*1e3, z, label=l, linestyle ='--' if scheme=='blk_1m' else '-') - ax[3].plot(T, z, label=l, linestyle ='--' if scheme=='blk_1m' else '-') + ax[0].plot(r_liq*1e3, z*1e-3, label=l, linestyle ='--' if scheme=='blk_1m' else '-') + ax[1].plot(r_ice*1e3, z*1e-3, label=l, linestyle ='--' if scheme=='blk_1m' else '-') os.remove(f"test_{scheme}.nc") - ax[0].set_ylabel("z [m]") - ax[0].set_xlabel("$r_v$ [g/kg]") - ax[1].set_xlabel("$r_{liq} [g/kg]$") - ax[2].set_xlabel("$r_{ice} [g/kg]$") - ax[3].set_xlabel("T [K]") - ax[0].legend() - plt.tight_layout() - plt.savefig("plots/outputs/plot_schemes_ice.svg") \ No newline at end of file + ax[0].set_ylabel("z [km]") + ax[0].set_xlabel("liquid mix. ratio [g/kg]") + ax[1].set_xlabel("ice mix. ratio [g/kg]") + handles, labels = ax[0].get_legend_handles_labels() + fig.legend( + handles, labels, + loc="upper center", + bbox_to_anchor=(0.5, 1.0), + ncol=len(labels), + frameon=False, + ) + fig.tight_layout(rect=[0, 0, 1, 0.9]) + plt.savefig("plots/outputs/plot_schemes_ice.pdf", bbox_inches="tight") \ No newline at end of file From adb1e233ed3b8823ff18eed58928587b7819ea67 Mon Sep 17 00:00:00 2001 From: AgnieszkaMakulska Date: Wed, 24 Jun 2026 16:13:15 +0200 Subject: [PATCH 6/6] correct plot title --- long_test/test_plot_ice_SD.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/long_test/test_plot_ice_SD.py b/long_test/test_plot_ice_SD.py index aff35e7..213d276 100644 --- a/long_test/test_plot_ice_SD.py +++ b/long_test/test_plot_ice_SD.py @@ -36,7 +36,7 @@ def plot_profiles(fnc, output_name): plots[0].plot(r_ice, z) plots[0].legend(['total', 'water vapor', 'liquid', 'ice'], loc='best', fontsize=12) plots[1].plot(fnc.variables["T"][:] - 273.15, z) - plt.suptitle("Homogeneous ice nucleation" if output_name == "ice_SD_plot_hom.svg" else "Heterogeneous ice nucleation") + plt.suptitle("Homogeneous ice nucleation" if output_name.startswith("ice_SD_plot_hom") else "Heterogeneous ice nucleation") if not os.path.exists("plots/outputs/"): subprocess.call(["mkdir", "plots/outputs/"])