Skip to content

Commit

Permalink
calcs test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
allibco committed Oct 4, 2024
1 parent cee8fe7 commit b3fa398
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 15 deletions.
7 changes: 3 additions & 4 deletions ldcpy/calcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def min_agg(ds):

# avoid divde by zero warning
# log_ds = np.log10(abs(self._ds)).where(np.log10(abs(self._ds)) != -np.inf)
a_d = abs(self._ds)
a_d = abs(self._ds.copy())
log_ds = np.log10(a_d, where=a_d.data > 0)

if len(self._not_agg_dims) == 0:
Expand All @@ -364,7 +364,6 @@ def min_agg(ds):
stack = log_ds.stack(multi_index=tuple(self._not_agg_dims))
my_max = stack.groupby('multi_index').map(max_agg)
my_min = stack.groupby('multi_index').map(min_agg)

if (
np.isinf(my_max).any()
or np.isinf(my_min).any()
Expand All @@ -375,8 +374,8 @@ def min_agg(ds):
return self._magnitude_range
else:
self._magnitude_range = my_max - my_min
# print(self._magnitude_range)
return self._magnitude_range

return self._magnitude_range

@property
def magnitude_diff_ew(self) -> xr.DataArray:
Expand Down
13 changes: 4 additions & 9 deletions tests/test_calcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
],
dims=['lat', 'lon', 'time'],
)


d = ds['TS'].sel(collection='orig')

ds_pointwise_calcs = ldcpy.Datasetcalcs(d, 'cam-fv', [], weighted=False)
ds_spatial_calcs = ldcpy.Datasetcalcs(d, 'cam-fv', ['time'], weighted=False)

Expand Down Expand Up @@ -97,12 +100,6 @@ def setUpClass(cls) -> None:
}
]

# def test_fftsum(self):
# f = ds_spatial_calcs.get_calc('fft2')
# t = ldcpy.Datasetcalcs(f, 'cam-fv', [], weighted=False)
# t.get_single_calc('fftsum')
# self.assertTrue(True)

def test_creation_01(self):
Diffcalcs(
xr.DataArray(self._samples[0]['observed']),
Expand Down Expand Up @@ -152,7 +149,6 @@ def test_TS_02(self):
import xarray as xr

# import zfpy

ds = xr.open_dataset('data/cam-fv/orig.TS.100days.nc')

TS = ds.TS
Expand All @@ -166,8 +162,7 @@ def test_mean(self):
self.assertTrue(test_overall_calcs.mean == -0.5)

def test_magnitude_range(self):
# check if the sum of the magnitude range is 2 with a tolerance of 1e-09
value = test_overall_calcs.magnitude_range.values.sum()
value = float(test_overall_calcs.magnitude_range.values)
self.assertTrue(np.isclose(value, 2, rtol=1e-04))

def test_mean_abs(self):
Expand Down
1 change: 1 addition & 0 deletions tests/test_calcs_pop.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def test_creation_01(self):
Diffcalcs(
xr.DataArray(self._samples[0]['observed']),
xr.DataArray(self._samples[0]['measured']),
'pop',
[],
)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def test_mean_abs_diff_time_series(self):
)
self.assertTrue(True is True)

@pytest.mark.nonsequential
# @pytest.mark.nonsequential
def test_mean_diff_time_series_subset(self):
ldcpy.plot(
ds2,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_plot_pop.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_mean_abs_diff_time_series(self):
)
self.assertTrue(True is True)

@pytest.mark.nonsequential
# @pytest.mark.nonsequential
def test_mean_diff_time_series_subset(self):
ldcpy.plot(
ds,
Expand Down

0 comments on commit b3fa398

Please sign in to comment.