Skip to content

Commit

Permalink
Merge pull request #34 from hgloeckner/add_p_units
Browse files Browse the repository at this point in the history
fix p unit
  • Loading branch information
hgloeckner authored Sep 3, 2024
2 parents 092d384 + 803f5f2 commit 0510d81
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pydropsonde/helper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ def calc_theta_from_T(ds):
Function to estimate potential temperature from the temperature and pressure in the given dataset.
"""
theta = mpcalc.potential_temperature(
ds.p.values * units.Pa, ds.ta.values * units.kelvin
ds.p.values * units(ds.p.attrs["units"]),
ds.ta.values * units(ds.ta.attrs["units"]),
)
ds = ds.assign(theta=(ds.ta.dims, theta.magnitude))
ds["theta"].attrs = dict(
Expand Down
6 changes: 3 additions & 3 deletions pydropsonde/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,7 @@ def add_l2_ds(self, l2_dir: str = None):
object.__setattr__(
self, "l2_ds", xr.open_dataset(os.path.join(l2_dir, self.l2_filename))
)

return self
except FileNotFoundError:
return None
Expand Down Expand Up @@ -1094,7 +1095,7 @@ def interpolate_alt(
)
ds = self._prep_l3_ds.swap_dims({"time": alt_var}).load()
if p_log:
ds = ds.assign(p=(ds.p.dims, np.log(ds.p.values)))
ds = ds.assign(p=(ds.p.dims, np.log(ds.p.values), ds.p.attrs))
if method == "linear_interpolate":
interp_ds = ds.interp({alt_var: interpolation_grid})
elif method == "bin":
Expand Down Expand Up @@ -1134,10 +1135,9 @@ def interpolate_alt(
)

if p_log:
interp_ds = ds.assign(p=(ds.p.dims, np.exp(ds.p.values)))
interp_ds = ds.assign(p=(ds.p.dims, np.exp(ds.p.values), ds.p.attrs))

object.__setattr__(self, "_prep_l3_ds", interp_ds)

return self

def add_attributes_as_var(self):
Expand Down

0 comments on commit 0510d81

Please sign in to comment.