-
Notifications
You must be signed in to change notification settings - Fork 11
Bulk_1m ice test #83
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
Open
AgnieszkaMakulska
wants to merge
13
commits into
igfuw:master
Choose a base branch
from
AgnieszkaMakulska:ice
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Bulk_1m ice test #83
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2bf51ba
blk_1m functions
AgnieszkaMakulska f4379b9
ice
AgnieszkaMakulska 55d294e
no collisions
AgnieszkaMakulska 4e57009
tests
AgnieszkaMakulska 6e00d5a
tests description
AgnieszkaMakulska c1fb4b2
test compare schemes
AgnieszkaMakulska a908bed
separate test for plotting
AgnieszkaMakulska 7cb4244
renaming to opts_init for blk
AgnieszkaMakulska ab156e0
renaming micro_opts and code cleanup
AgnieszkaMakulska 61dbdd9
use new libcloudph++ API: opts.th_dry and opts_const_p
pdziekan c9634ba
Merge branch 'ice' into ice
AgnieszkaMakulska 8123010
Merge pull request #1 from pdziekan/ice
AgnieszkaMakulska 639557e
updating ice test values
AgnieszkaMakulska File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
""" | ||
This test runs the parcel model using three different microphysics schemes: | ||
- lgrngn (Lagrangian particle-based) | ||
- blk_1m (bulk warm) | ||
- blk_1m_ice (bulk ice) | ||
|
||
It compares the evolution of rv, th_d, and total condensed water in different schemes. | ||
""" | ||
|
||
import sys | ||
sys.path.insert(0, "../") | ||
sys.path.insert(0, "./") | ||
|
||
import numpy as np | ||
from parcel import parcel | ||
from scipy.io import netcdf | ||
import matplotlib.pyplot as plt | ||
|
||
def run_scheme(scheme, outfile): | ||
args = dict( | ||
dt=0.1, | ||
z_max=800, | ||
w=1.0, | ||
T_0=300, | ||
r_0=0.022, | ||
outfile=outfile, | ||
outfreq=50, | ||
scheme=scheme, | ||
out_bin='{"radius": {"rght": 1, "moms": [3], "drwt": "wet", "nbin": 1, "lnli": "lin", "left": 1e-15}}' | ||
) | ||
parcel(**args) | ||
with netcdf.netcdf_file(outfile, 'r') as f: | ||
rv = np.array(f.variables['r_v'][:]) | ||
th_d = np.array(f.variables['th_d'][:]) | ||
z = np.array(f.variables['z'][:]) | ||
if scheme.startswith("blk"): | ||
r_tot = np.array(f.variables['rc'][:]) + np.array(f.variables['rr'][:]) | ||
else: | ||
moment_3 = np.array(f.variables['radius_m3'][:]) | ||
r_tot = moment_3 *4/3 * np.pi * 997 #multiply by density of water | ||
return rv, th_d, z, r_tot | ||
|
||
def test_compare_schemes(): | ||
schemes = ["lgrngn", "blk_1m", "blk_1m_ice"] | ||
results = {} | ||
for scheme in schemes: | ||
rv, th_d, z, r_tot = run_scheme(scheme, f"test_{scheme}.nc") | ||
results[scheme] = (rv, th_d, z, r_tot) | ||
# Compare final values | ||
rv_vals = [results[s][0][-1] for s in schemes] | ||
th_d_vals = [results[s][1][-1] for s in schemes] | ||
r_tot_vals = [results[s][2][-1] for s in schemes] | ||
|
||
fig, ax = plt.subplots(1,3, figsize=(12, 6)) | ||
for scheme in schemes: | ||
rv, th_d, z, r_tot = results[scheme] | ||
ax[0].plot(rv, z, label=f"{scheme}") | ||
ax[1].plot(th_d, z, label=f"{scheme}") | ||
ax[2].plot(r_tot, z, label=f"{scheme}") | ||
ax[0].set_ylabel("Height [m]") | ||
ax[0].set_xlabel("Water vapor mixing ratio") | ||
ax[1].set_xlabel("Dry potential temperature") | ||
ax[2].set_xlabel("Total condensed water mixing ratio") | ||
ax[0].legend() | ||
ax[1].legend() | ||
ax[2].legend() | ||
plt.tight_layout() | ||
plt.savefig("plots/outputs/scheme_comparison.svg") | ||
|
||
# Check closeness | ||
for i in range(1, len(schemes)): | ||
assert np.isclose(rv_vals[0], rv_vals[i], rtol=5e-2), f"r_v differs: {rv_vals[0]} vs {rv_vals[i]}" | ||
assert np.isclose(th_d_vals[0], th_d_vals[i], rtol=5e-2), f"th_d differs: {th_d_vals[0]} vs {th_d_vals[i]}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
""" | ||
This test runs the parcel model using blk_1m_ice microphysics scheme. | ||
It checks that the final values of ria and rc match their reference values (are consistent in each run). | ||
""" | ||
|
||
import sys | ||
sys.path.insert(0, "../") | ||
sys.path.insert(0, "./") | ||
from parcel import parcel | ||
from scipy.io import netcdf | ||
import numpy as np | ||
|
||
def test_bulk_ice(): | ||
args = dict( | ||
dt=0.1, | ||
z_max=500, | ||
w=1.0, | ||
T_0=273, | ||
RH_0 = 1, | ||
outfile="test_bulk_ice.nc", | ||
outfreq=100, | ||
scheme="blk_1m_ice" | ||
) | ||
parcel(**args) | ||
with netcdf.netcdf_file("test_bulk_ice.nc", 'r') as f: | ||
ria = np.array(f.variables['ria'][:]) | ||
rc = np.array(f.variables['rc'][:]) | ||
assert np.isclose(ria[-1], 7.843e-11, rtol=1e-3) | ||
assert np.isclose(rc[-1], 5.522e-4, rtol=1e-3) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.