Skip to content

[Refactor] Improve the performance of temporal group averaging #689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/xcdat.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
Expand Down
62 changes: 31 additions & 31 deletions tests/test_temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_averages_for_yearly_time_series(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

# Test unweighted averages
result = ds.temporal.average("ts", weighted=False)
Expand All @@ -139,7 +139,7 @@ def test_averages_for_yearly_time_series(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_averages_for_monthly_time_series(self):
# Set up dataset
Expand Down Expand Up @@ -293,7 +293,7 @@ def test_averages_for_daily_time_series(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

# Test unweighted averages
result = ds.temporal.average("ts", weighted=False)
Expand All @@ -310,7 +310,7 @@ def test_averages_for_daily_time_series(self):
"weighted": "False",
},
)
assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_averages_for_hourly_time_series(self):
ds = xr.Dataset(
Expand Down Expand Up @@ -378,7 +378,7 @@ def test_averages_for_hourly_time_series(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

# Test unweighted averages
result = ds.temporal.average("ts", weighted=False)
Expand All @@ -396,7 +396,7 @@ def test_averages_for_hourly_time_series(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)


class TestGroupAverage:
Expand Down Expand Up @@ -619,7 +619,7 @@ def test_weighted_seasonal_averages_with_DJF_and_drop_incomplete_seasons(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_seasonal_averages_with_DJF_without_dropping_incomplete_seasons(
self,
Expand Down Expand Up @@ -670,7 +670,7 @@ def test_weighted_seasonal_averages_with_DJF_without_dropping_incomplete_seasons
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_seasonal_averages_with_JFD(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -729,7 +729,7 @@ def test_weighted_seasonal_averages_with_JFD(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_custom_seasonal_averages(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -787,7 +787,7 @@ def test_weighted_custom_seasonal_averages(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_raises_error_with_incorrect_custom_seasons_argument(self):
# Test raises error with non-3 letter strings
Expand Down Expand Up @@ -873,7 +873,7 @@ def test_weighted_monthly_averages(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_monthly_averages_with_masked_data(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -924,7 +924,7 @@ def test_weighted_monthly_averages_with_masked_data(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_daily_averages(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -967,7 +967,7 @@ def test_weighted_daily_averages(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_hourly_averages(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -1011,7 +1011,7 @@ def test_weighted_hourly_averages(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)


class TestClimatology:
Expand Down Expand Up @@ -1105,7 +1105,7 @@ def test_subsets_climatology_based_on_reference_period(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_seasonal_climatology_with_DJF(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -1159,7 +1159,7 @@ def test_weighted_seasonal_climatology_with_DJF(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

@requires_dask
def test_chunked_weighted_seasonal_climatology_with_DJF(self):
Expand Down Expand Up @@ -1214,7 +1214,7 @@ def test_chunked_weighted_seasonal_climatology_with_DJF(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_seasonal_climatology_with_JFD(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -1265,7 +1265,7 @@ def test_weighted_seasonal_climatology_with_JFD(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_custom_seasonal_climatology(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -1328,7 +1328,7 @@ def test_weighted_custom_seasonal_climatology(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_monthly_climatology(self):
result = self.ds.temporal.climatology("ts", "month")
Expand Down Expand Up @@ -1391,7 +1391,7 @@ def test_weighted_monthly_climatology(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_unweighted_monthly_climatology(self):
result = self.ds.temporal.climatology("ts", "month", weighted=False)
Expand Down Expand Up @@ -1453,7 +1453,7 @@ def test_unweighted_monthly_climatology(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_daily_climatology(self):
result = self.ds.temporal.climatology("ts", "day", weighted=True)
Expand Down Expand Up @@ -1515,7 +1515,7 @@ def test_weighted_daily_climatology(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_daily_climatology_drops_leap_days_with_matching_calendar(self):
time = xr.DataArray(
Expand Down Expand Up @@ -1606,7 +1606,7 @@ def test_weighted_daily_climatology_drops_leap_days_with_matching_calendar(self)
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_unweighted_daily_climatology(self):
result = self.ds.temporal.climatology("ts", "day", weighted=False)
Expand Down Expand Up @@ -1668,7 +1668,7 @@ def test_unweighted_daily_climatology(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)


class TestDepartures:
Expand Down Expand Up @@ -1810,7 +1810,7 @@ def test_seasonal_departures_relative_to_climatology_reference_period(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_monthly_departures_relative_to_climatology_reference_period_with_same_output_freq(
self,
Expand Down Expand Up @@ -1895,7 +1895,7 @@ def test_monthly_departures_relative_to_climatology_reference_period_with_same_o
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_seasonal_departures_with_DJF(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -1945,7 +1945,7 @@ def test_weighted_seasonal_departures_with_DJF(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_seasonal_departures_with_DJF_and_keep_weights(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -2021,7 +2021,7 @@ def test_weighted_seasonal_departures_with_DJF_and_keep_weights(self):
dims=["time_original"],
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_unweighted_seasonal_departures_with_DJF(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -2071,7 +2071,7 @@ def test_unweighted_seasonal_departures_with_DJF(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_unweighted_seasonal_departures_with_JFD(self):
ds = self.ds.copy()
Expand Down Expand Up @@ -2121,7 +2121,7 @@ def test_unweighted_seasonal_departures_with_JFD(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)

def test_weighted_daily_departures_drops_leap_days_with_matching_calendar(self):
time = xr.DataArray(
Expand Down Expand Up @@ -2214,7 +2214,7 @@ def test_weighted_daily_departures_drops_leap_days_with_matching_calendar(self):
},
)

assert result.identical(expected)
xr.testing.assert_identical(result, expected)


class Test_GetWeights:
Expand Down
Loading
Loading