(self, use_cftime: bool, calendar: str)
| 1156 | ], |
| 1157 | ) |
| 1158 | def test_chunk_by_season_resampler(self, use_cftime: bool, calendar: str) -> None: |
| 1159 | import dask.array |
| 1160 | |
| 1161 | N = 365 + 365 # 2 years - 1 day |
| 1162 | time = xr.date_range( |
| 1163 | "2000-01-01", periods=N, freq="D", use_cftime=use_cftime, calendar=calendar |
| 1164 | ) |
| 1165 | |
| 1166 | ds = Dataset( |
| 1167 | { |
| 1168 | "pr": ("time", dask.array.random.random((N), chunks=(20))), |
| 1169 | "pr2d": (("x", "time"), dask.array.random.random((10, N), chunks=(20))), |
| 1170 | "ones": ("time", np.ones((N,))), |
| 1171 | }, |
| 1172 | coords={"time": time}, |
| 1173 | ) |
| 1174 | |
| 1175 | # Standard seasons |
| 1176 | rechunked = ds.chunk( |
| 1177 | {"x": 2, "time": SeasonResampler(["DJF", "MAM", "JJA", "SON"])} |
| 1178 | ) |
| 1179 | assert rechunked.chunksizes["x"] == (2,) * 5 |
| 1180 | assert len(rechunked.chunksizes["time"]) == 9 |
| 1181 | assert rechunked.chunksizes["x"] == (2,) * 5 |
| 1182 | assert sum(rechunked.chunksizes["time"]) == ds.sizes["time"] |
| 1183 | |
| 1184 | if calendar == "standard": |
| 1185 | assert rechunked.chunksizes["time"] == (60, 92, 92, 91, 90, 92, 92, 91, 30) |
| 1186 | elif calendar == "noleap": |
| 1187 | assert rechunked.chunksizes["time"] == (59, 92, 92, 91, 90, 92, 92, 91, 31) |
| 1188 | elif calendar == "360_day": |
| 1189 | assert rechunked.chunksizes["time"] == (60, 90, 90, 90, 90, 90, 90, 90, 40) |
| 1190 | else: |
| 1191 | raise AssertionError("unreachable") |
| 1192 | |
| 1193 | # Custom seasons |
| 1194 | rechunked = ds.chunk( |
| 1195 | {"x": 2, "time": SeasonResampler(["DJFM", "AM", "JJA", "SON"])} |
| 1196 | ) |
| 1197 | assert len(rechunked.chunksizes["time"]) == 9 |
| 1198 | assert sum(rechunked.chunksizes["time"]) == ds.sizes["time"] |
| 1199 | assert rechunked.chunksizes["x"] == (2,) * 5 |
| 1200 | |
| 1201 | if calendar == "standard": |
| 1202 | assert rechunked.chunksizes["time"] == (91, 61, 92, 91, 121, 61, 92, 91, 30) |
| 1203 | elif calendar == "noleap": |
| 1204 | assert rechunked.chunksizes["time"] == (90, 61, 92, 91, 121, 61, 92, 91, 31) |
| 1205 | elif calendar == "360_day": |
| 1206 | assert rechunked.chunksizes["time"] == (90, 60, 90, 90, 120, 60, 90, 90, 40) |
| 1207 | else: |
| 1208 | raise AssertionError("unreachable") |
| 1209 | |
| 1210 | # Test that drop_incomplete doesn't affect chunking |
| 1211 | rechunked_drop_true = ds.chunk( |
| 1212 | time=SeasonResampler(["DJF", "MAM", "JJA", "SON"], drop_incomplete=True) |
| 1213 | ) |
| 1214 | rechunked_drop_false = ds.chunk( |
| 1215 | time=SeasonResampler(["DJF", "MAM", "JJA", "SON"], drop_incomplete=False) |
nothing calls this directly
no test coverage detected