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

very first interim_l3 dataset #121

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
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
Next Next commit
fix theta and q calculation
hgloeckner committed Aug 19, 2024
commit 21d2827d58bde5bf7ef805ce8aff0304d010bc82
32 changes: 23 additions & 9 deletions src/halodrops/helper/__init__.py
Original file line number Diff line number Diff line change
@@ -219,16 +219,25 @@ def calc_q_from_rh(ds):
Function to estimate specific humidity from the relative humidity, temperature and pressure in the given dataset.
"""
e_s = calc_saturation_pressure(ds.ta.values)
w_s = mpcalc.mixing_ratio(e_s * units.Pa, ds.p.values * units.Pa).magnitude
w = ds.rh.values * w_s
q = w / (1 + w)
ds["q"] = (ds.rh.dims, q)

vmr = mpcalc.mixing_ratio_from_relative_humidity(
ds["p"].values * units.Pa,
ds.ta.values * units.kelvin,
(ds.rh * 100) * units.percent,
)
q = mpcalc.specific_humidity_from_mixing_ratio(vmr)

ds["q"] = (ds.rh.dims, q.magnitude)
ds["q"].attrs = dict(
standard_name="specific humidity",
long_name="specific humidity",
units=str(q.units),
)

return ds


def calc_theta_from_T(dataset):
def calc_theta_from_T(ds):
"""
Input :
@@ -241,8 +250,13 @@ def calc_theta_from_T(dataset):
Function to estimate potential temperature from the temperature and pressure in the given dataset.
"""
theta = mpcalc.potential_temperature(
dataset.p.values * units.Pa, dataset.ta.values * units.kelvin
).magnitude
ds["theta"] = (ds.ta.dims, theta)
ds.p.values * units.Pa, ds.ta.values * units.kelvin
)
ds["theta"] = (ds.ta.dims, theta.magnitude)
ds["theta"].attrs = dict(
standard_name="potential temperature",
long_name="potential temperature",
units=str(theta.units),
)

return ds