Skip to content

Commit

Permalink
fix data step pytests
Browse files Browse the repository at this point in the history
  • Loading branch information
raehik committed Sep 20, 2023
1 parent eafd869 commit 6a9f2d2
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions tests/data/test_coarse.py → tests/step/test_data.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Unit tests for the data/coarse.py module"""
"""Unit tests for the data step."""

import pytest
import xarray as xr
import numpy as np
from numpy import ma
import matplotlib.pyplot as plt
from gz21_ocean_momentum.data.coarse import spatial_filter_dataset, spatial_filter, eddy_forcing

import gz21_ocean_momentum.step.data.lib as lib

class TestEddyForcing:
"Class to test eddy forcing routines."
Expand All @@ -18,7 +17,7 @@ def test_spatial_filter(self):
Check that number of dimensions stay the same through spatial_filter().
"""
a = np.random.randn(10, 4, 4)
filtered_a = spatial_filter(a, 5)
filtered_a = lib._spatial_filter(a, 5)
assert a.ndim == filtered_a.ndim

def test_spatial_filter_of_constant(self):
Expand Down Expand Up @@ -49,7 +48,7 @@ def test_spatial_filter_of_constant(self):
}
)

filtered_data = spatial_filter_dataset(data, grid_info, (5, 5))
filtered_data = lib._spatial_filter_dataset(data, grid_info, (5, 5))

assert data["a"].values == pytest.approx(filtered_data["a"].values)

Expand Down Expand Up @@ -88,7 +87,7 @@ def test_eddy_forcing_chunks(self):
),
}
)
forcing = eddy_forcing(data, grid_info, 4)
forcing = lib.compute_forcings_cm2_6(data, grid_info, 4)
usurf_0, usurf_1 = forcing.usurf.isel(time=0), forcing.usurf.isel(time=1)
# remove nan values at the boundaries from the test
usurf_0 = usurf_0.data[~np.isnan(usurf_0)]
Expand Down Expand Up @@ -144,9 +143,7 @@ def test_eddy_forcing_chunking(self):
)

# new forcing: apply
forcing_new = eddy_forcing(
data, grid_info, scale=scale_m,
method='mean', scale_mode='factor')
forcing_new = lib.compute_forcings_cm2_6(data, grid_info, scale=scale_m)

# new forcing: post-chunk
for var in forcing_new:
Expand All @@ -172,7 +169,7 @@ def f(block):
- S_x and S_y, the two components of the diagnosed subgrid momentum
forcing
"""
return eddy_forcing(block, grid_info, scale=scale_m)
return lib.compute_forcings_cm2_6(block, grid_info, scale=scale_m)

# old forcing: apply
template = data.coarsen(
Expand Down

0 comments on commit 6a9f2d2

Please sign in to comment.