Skip to content

Commit

Permalink
fix tests, examples and missing use of lat/lon function
Browse files Browse the repository at this point in the history
  • Loading branch information
leifdenby committed Dec 16, 2024
1 parent 972186d commit ba46718
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 33 deletions.
24 changes: 3 additions & 21 deletions example.era5_cropped.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,13 @@ inputs:
time:
method: rename
dim: time
x:
method: rename
dim: longitude
y:
method: rename
dim: latitude
forcing_feature:
method: stack_variables_by_var_name
dims: [level]
name_format: "{var_name}{level}hPa"
grid_index:
method: stack
dims: [x, y]
dims: [longitude, latitude]
target_output_variable: forcing

era5_surface:
Expand All @@ -68,18 +62,12 @@ inputs:
time:
method: rename
dim: time
x:
method: rename
dim: longitude
y:
method: rename
dim: latitude
forcing_feature:
method: stack_variables_by_var_name
name_format: "{var_name}"
grid_index:
method: stack
dims: [x, y]
dims: [longitude, latitude]
target_output_variable: forcing

era5_static:
Expand All @@ -88,18 +76,12 @@ inputs:
variables:
- land_sea_mask
dim_mapping:
x:
method: rename
dim: longitude
y:
method: rename
dim: latitude
static_feature:
method: stack_variables_by_var_name
name_format: "{var_name}"
grid_index:
method: stack
dims: [x, y]
dims: [longitude, latitude]
target_output_variable: static

extra:
Expand Down
7 changes: 2 additions & 5 deletions mllam_data_prep/ops/cropping.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ def _get_latlon_coords(da: xr.DataArray) -> tuple:
elif "lat" in da.coords and "lon" in da.coords:
return (da.lat, da.lon)
else:
import ipdb

ipdb.set_trace()
raise Exception("Could not find lat/lon coordinates in DataArray.")


Expand Down Expand Up @@ -132,9 +129,9 @@ def distance_to_convex_hull_boundary(
# only consider points that are external to the convex hull
ds_exterior = ds.where(~da_ch_mask, drop=True)

da_xyz = _latlon_to_unit_sphere_xyz(ds_exterior.lat, ds_exterior.lon)
da_xyz = _latlon_to_unit_sphere_xyz(*_get_latlon_coords(ds_exterior))
da_xyz_ref = _latlon_to_unit_sphere_xyz(
ds_reference_separate_gridindex.lat, ds_reference_separate_gridindex.lon
*_get_latlon_coords(ds_reference_separate_gridindex)
)

def calc_dist(da_pt_xyz):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_convex_hull_cropping.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ def test_create_convex_hull_mask():
)

# check that there are fewer points in this margin region
n_points_margin_region = da_convex_hull_margin_crop.count().values
n_points_margin_region = da_convex_hull_margin_crop.count()
assert n_points_margin_region < n_outside
22 changes: 16 additions & 6 deletions tests/test_from_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@
import tests.data as testdata


def _find_example_config_files():
fps = Path(__file__).parent.parent.glob("example.*.yaml")
examples = {fp.name.split(".")[1]: fp for fp in fps}
return examples


EXAMPLE_YAML_FILES = _find_example_config_files()


@pytest.mark.parametrize("example_name", EXAMPLE_YAML_FILES.keys())
def test_yaml_example(example_name):
fp_config = EXAMPLE_YAML_FILES[example_name]
with tempfile.TemporaryDirectory(suffix=".zarr") as tmpdir:
mdp.create_dataset_zarr(fp_config=fp_config, fp_zarr=tmpdir)


def test_gen_data():
tmpdir = tempfile.TemporaryDirectory()
testdata.create_data_collection(
Expand Down Expand Up @@ -277,12 +293,6 @@ def test_feature_collision(use_common_feature_var_name):
mdp.create_dataset_zarr(fp_config=fp_config)


def test_danra_example():
fp_config = Path(__file__).parent.parent / "example.danra.yaml"
with tempfile.TemporaryDirectory(suffix=".zarr") as tmpdir:
mdp.create_dataset_zarr(fp_config=fp_config, fp_zarr=tmpdir)


@pytest.mark.parametrize("extra_content", [None, {"foobar": {"baz": 42}}])
def test_optional_extra_section(extra_content):
"""
Expand Down

0 comments on commit ba46718

Please sign in to comment.