Skip to content

Commit

Permalink
Merge pull request #20 from hgloeckner/minor_l3_changes
Browse files Browse the repository at this point in the history
Minor l3 changes
  • Loading branch information
hgloeckner authored Aug 30, 2024
2 parents 854be4e + 4642562 commit 1ea0ba2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
13 changes: 11 additions & 2 deletions pydropsonde/helper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@
"positive": "up",
}
},
"alt": {
"attributes": {
"standard_name": "altitude",
"long_name": "altitude above MSL",
"units": "m",
"axis": "Z",
"positive": "up",
}
},
}

encoding_variables = {
Expand Down Expand Up @@ -176,7 +185,7 @@ def calc_q_from_rh(ds):
)
q = mpcalc.specific_humidity_from_mixing_ratio(vmr)

ds["q"] = (ds.rh.dims, q.magnitude)
ds = ds.assign(q=(ds.rh.dims, q.magnitude))
ds["q"].attrs = dict(
standard_name="specific humidity",
long_name="specific humidity",
Expand All @@ -201,7 +210,7 @@ def calc_theta_from_T(ds):
theta = mpcalc.potential_temperature(
ds.p.values * units.Pa, ds.ta.values * units.kelvin
)
ds["theta"] = (ds.ta.dims, theta.magnitude)
ds = ds.assign(theta=(ds.ta.dims, theta.magnitude))
ds["theta"].attrs = dict(
standard_name="potential temperature",
long_name="potential temperature",
Expand Down
9 changes: 4 additions & 5 deletions pydropsonde/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,14 @@ def iterate_Sonde_method_over_dict_of_Sondes_objects(
result = function(value, **get_args_for_function(config, function))
if result is not None:
new_dict[key] = result
my_dict = new_dict

my_dict = new_dict

return my_dict


def sondes_to_gridded(sondes: dict, config: configparser.ConfigParser):
flight_id = list(sondes.values())[0].flight_id
platform_id = list(sondes.values())[0].platform_id
gridded = Gridded(sondes, flight_id, platform_id)
gridded = Gridded(sondes)
gridded.concat_sondes()
return gridded

Expand Down Expand Up @@ -449,7 +448,7 @@ def run_pipeline(pipeline: dict, config: configparser.ConfigParser):
"add_q_and_theta_to_l2_ds",
"remove_non_mono_incr_alt",
"interpolate_alt",
"prepare_l2_for_gridded",
"add_attributes_as_var",
],
"output": "sondes",
"comment": "This step reads from the saved L2 files and prepares individual sonde datasets before they can be concatenated to create L3.",
Expand Down
6 changes: 2 additions & 4 deletions pydropsonde/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ def add_q_and_theta_to_l2_ds(self):
ds = hh.calc_q_from_rh(ds)
ds = hh.calc_theta_from_T(ds)

object.__setattr__(self, "_interim_l3_ds", ds)
object.__setattr__(self, "_prep_l3_ds", ds)

return self

Expand Down Expand Up @@ -1096,7 +1096,7 @@ def interpolate_alt(

return self

def prepare_l2_for_gridded(self):
def add_attributes_as_var(self):
"""
Prepares l2 datasets to be concatenated to gridded.
adds all attributes as variables to avoid conflicts when concatenating because attributes are different
Expand All @@ -1114,8 +1114,6 @@ def prepare_l2_for_gridded(self):
@dataclass(order=True)
class Gridded:
sondes: dict
flight_id: str
platform_id: str

def concat_sondes(self):
"""
Expand Down
27 changes: 27 additions & 0 deletions tests/test_gridded.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pytest
import os
import xarray as xr
from pydropsonde.processor import Gridded

sondes = None
l3_default = f"Level_3.nc"


@pytest.fixture
def gridded():
return Gridded(sondes)


def test_l3_dir(gridded):
with pytest.raises(ValueError):
gridded.get_l3_dir()


def test_l3_dir_name(gridded):
gridded.get_l3_dir(l3_dir="test")
assert gridded.l3_dir == "test"


def test_l3_default(gridded):
gridded.get_l3_filename()
assert gridded.l3_filename == l3_default

0 comments on commit 1ea0ba2

Please sign in to comment.