Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates to the Grabowski & Pawlowska 2023 example #1129

Merged
merged 40 commits into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5062e1f
we added a new example folder
AgnieszkaMakulska Jun 30, 2023
d58b68b
fixed new line
AgnieszkaMakulska Jun 30, 2023
6274a0e
one more newline fix
slayoo Jun 30, 2023
4781745
we changed the list of examples
AgnieszkaMakulska Jun 30, 2023
e19f8bb
added equilibrium supersaturation attribute and a draft of example no…
AgnieszkaMakulska Jul 19, 2023
4d0c532
added equilibrium saturation and colors indicating whether droplet is…
AgnieszkaMakulska Jul 19, 2023
33968ac
added figure 2
AgnieszkaMakulska Jul 21, 2023
69f8388
add AA to .zenodo.json credits file
slayoo Jul 24, 2023
c4ae69f
added standard deviation and rel. dispersion
AgnieszkaMakulska Jul 29, 2023
2c391f6
added figure 4
AgnieszkaMakulska Jul 31, 2023
3d1113c
changed sampling to ConstantMultiplicity and corrected the mean volum…
AgnieszkaMakulska Jul 31, 2023
1c47be1
added new products: activation_filtered_product, particle_concentrati…
AgnieszkaMakulska Aug 11, 2023
33a5420
added a new product for mean volume radius and updated the example "Y…
AgnieszkaMakulska Aug 17, 2023
33fba74
added a new product and a new test for particle size standard deviation
AgnieszkaMakulska Aug 21, 2023
ea7fdb0
used new standard deviation product in figure 4
AgnieszkaMakulska Aug 21, 2023
d2a6229
added a new test for particle size product
AgnieszkaMakulska Aug 24, 2023
be759c8
added a test for figure 4 and rearranged code in example notebooks
AgnieszkaMakulska Aug 24, 2023
91f5b38
changed the test for figure 4
AgnieszkaMakulska Aug 28, 2023
195d332
dt and n_sd no longer have default values
AgnieszkaMakulska Aug 28, 2023
9dbb646
run pre-commit
AgnieszkaMakulska Aug 28, 2023
7b4ea86
fixed problems with pylint
AgnieszkaMakulska Aug 28, 2023
80ae2c1
fixed problems with tests
AgnieszkaMakulska Aug 28, 2023
5fd691a
fixed problems with notebooks and changed tests for figures 3,4
AgnieszkaMakulska Aug 28, 2023
d73b82c
fixed problems with notebooks
AgnieszkaMakulska Aug 28, 2023
9023a7b
Merge branch 'New_exmple' of github.com:AgnieszkaMakulska/PySDM into …
slayoo Aug 28, 2023
f07cf4e
switch CI timestep lengths in notebooks to integer fractions of the w…
slayoo Aug 28, 2023
e206320
refactors in new smoke tests
slayoo Aug 29, 2023
0c1fdd1
fix fixture name issue
slayoo Aug 29, 2023
e2958df
added test for figures 1,2
AgnieszkaMakulska Aug 31, 2023
22f08af
changes tests for figures 1,2,3
AgnieszkaMakulska Aug 31, 2023
375b98d
fix "n" -> "multiplicity" in test
slayoo Aug 31, 2023
9c1ff4e
fix typos, try with default condensation tolerances
slayoo Aug 31, 2023
f898fcb
Merge pull request #1 from open-atmos/main
AgnieszkaMakulska Sep 3, 2023
79eb217
added figure with ripening rate
AgnieszkaMakulska Sep 3, 2023
03c7fae
changed "n" to "multiplicity". there is an issue with results (see fi…
AgnieszkaMakulska Sep 3, 2023
9e82919
added relative tolerances for condensation
AgnieszkaMakulska Sep 5, 2023
c58c8e2
added test for condensation tolerance
AgnieszkaMakulska Sep 5, 2023
a58ed37
fixed problem with pylint
AgnieszkaMakulska Sep 8, 2023
d1c1ff3
added a variable for the default condensation tolerance and a test f…
AgnieszkaMakulska Sep 9, 2023
1553461
imported condensation tolerance instead of defining if in test
AgnieszkaMakulska Sep 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions examples/PySDM_examples/Grabowski_and_Pawlowska_2023/figure_1.ipynb

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions examples/PySDM_examples/Grabowski_and_Pawlowska_2023/figure_2.ipynb

Large diffs are not rendered by default.

32 changes: 14 additions & 18 deletions examples/PySDM_examples/Grabowski_and_Pawlowska_2023/figure_3.ipynb

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions examples/PySDM_examples/Grabowski_and_Pawlowska_2023/figure_4.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
from pystrict import strict

from PySDM import Formulae
from PySDM.dynamics import condensation
from PySDM.initialisation.spectra import Lognormal, Sum
from PySDM.physics import si

condensation_tolerance = condensation.DEFAULTS.rtol_thd / 100


@strict
class Settings:
Expand All @@ -20,6 +23,8 @@ def __init__(
initial_relative_humidity: float = 0.97,
displacement: float = 1000 * si.m,
mass_accommodation_coefficient: float = 0.3,
rtol_thd: float = condensation_tolerance,
rtol_x: float = condensation_tolerance
):
self.formulae = Formulae(constants={"MAC": mass_accommodation_coefficient})
self.n_sd = n_sd
Expand Down Expand Up @@ -64,6 +69,8 @@ def __init__(
self.t_max = displacement / vertical_velocity
self.timestep = dt
self.output_interval = self.timestep
self.rtol_thd = rtol_thd
self.rtol_x = rtol_x

@property
def initial_air_density(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def __init__(
builder = Builder(n_sd=settings.n_sd, backend=CPU(formulae=settings.formulae))
builder.set_environment(env)
builder.add_dynamic(AmbientThermodynamics())
builder.add_dynamic(Condensation())
builder.add_dynamic(
Condensation(rtol_thd=settings.rtol_thd, rtol_x=settings.rtol_x)
)
for attribute in (
"critical supersaturation",
"equilibrium supersaturation",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""
test for condensation tolerance parameters: rtol_thd and rtol_x,
checking if supersaturation has more than one local maximum
"""

import numpy as np
import pytest
from PySDM_examples.Grabowski_and_Pawlowska_2023 import Settings, Simulation
from PySDM_examples.Grabowski_and_Pawlowska_2023.settings import condensation_tolerance
from scipy import signal

from PySDM.dynamics import condensation
from PySDM.physics import si
from PySDM.products import AmbientRelativeHumidity

PRODUCTS = [
AmbientRelativeHumidity(name="S_max", var="RH"),
]

N_SD = 25
DZ = 10 * si.m
VELOCITIES_CM_PER_S = (25, 100, 400)
AEROSOLS = ("polluted",)


@pytest.mark.parametrize(
"rtol_cond",
(
condensation_tolerance,
pytest.param(
condensation.DEFAULTS.rtol_thd, marks=pytest.mark.xfail(strict=True)
),
),
)
@pytest.mark.parametrize("aerosol", AEROSOLS)
@pytest.mark.parametrize("w_cm_per_s", VELOCITIES_CM_PER_S)
def test_condensation_tolerance(
rtol_cond: float,
w_cm_per_s: int,
aerosol: str,
):
# arrange
output = Simulation(
Settings(
n_sd=25,
dt=10 * si.s,
vertical_velocity=w_cm_per_s * si.cm / si.s,
aerosol=aerosol,
rtol_thd=rtol_cond,
rtol_x=rtol_cond,
),
products=PRODUCTS,
).run()

assert (
signal.find_peaks(
np.asarray(output["products"]["S_max"]),
height=(1, None),
prominence=(1e-5, None),
)[0].shape[0]
== 1
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
test for values of the ripening rate
"""

import numpy as np
import pytest
from PySDM_examples.Grabowski_and_Pawlowska_2023 import Settings, Simulation

from PySDM.physics import si
from PySDM.products import RipeningRate

PRODUCTS = [
RipeningRate(
name="ripening",
)
]

N_SD = 200

VELOCITIES_CM_PER_S = (25, 100)

AEROSOLS = ("pristine", "polluted")

DT = 1 * si.s

RTOL = 0.1


@pytest.fixture(scope="session", name="outputs")
def outputs_fixture():
outputs = {}
for aerosol in AEROSOLS:
outputs[aerosol] = {}
for w_cm_per_s in VELOCITIES_CM_PER_S:
vertical_velocity = w_cm_per_s * si.cm / si.s
outputs[aerosol][w_cm_per_s] = Simulation(
Settings(
n_sd=N_SD,
dt=DT,
vertical_velocity=vertical_velocity,
aerosol=aerosol,
),
products=PRODUCTS,
).run()
return outputs


@pytest.mark.parametrize("aerosol", AEROSOLS)
@pytest.mark.parametrize("w_cm_per_s", VELOCITIES_CM_PER_S)
def test_ripening_rate(
outputs: dict,
w_cm_per_s: int,
aerosol: str,
):
# arrange
expected = {
"pristine": {
25: 0,
100: 0,
},
"polluted": {
25: 2.8 * 1e8,
100: 4 * 1e8,
},
}[aerosol][w_cm_per_s]
output = outputs[aerosol][w_cm_per_s]["products"]["ripening"]

# assert
assert np.isclose(
np.max(output),
expected,
rtol=RTOL,
).all()
Loading