def test_rm_poly_validity_dask(gridded_da_float, order): """Tests that grid cells are different and equal to doing it manually with dask arrays.""" data = gridded_da_float().chunk() x = data['time'] y = data actual = rm_poly(x, y, order) for i in range(3): for j in range(3): single_grid_cell = y.isel(lon=i, lat=j) expected = _np_rm_poly(x.values, single_grid_cell.values, order) assert (actual.isel(lon=i, lat=j).values == expected).all()
def test_polyfit_against_time_dask( gridded_da_datetime, gridded_da_cftime, gridded_da_float, time_type, gridded, single_arg, ): """Tests that ``polyfit`` plus ``rm_poly`` equals the original time series when fitting against time with dask arrays.""" data = eval(f"gridded_da_{time_type}")().chunk() x = data["time"] y = data if gridded else data.isel(lat=0, lon=0) if single_arg: dt = rm_poly(y, order=2) fit = polyfit(y, order=2) else: dt = rm_poly(x, y, 2) fit = polyfit(x, y, 2) diff = np.abs((dt + fit) - y) assert (diff.compute() < 1e-15).all()
def test_polyfit_against_time( gridded_da_datetime, gridded_da_cftime, gridded_da_float, time_type, gridded, order, single_arg, ): """Tests that ``polyfit`` plus ``rm_poly`` equals the original time series when fitting against time.""" data = eval(f'gridded_da_{time_type}')() x = data['time'] y = data if gridded else data.isel(lat=0, lon=0) if single_arg: dt = rm_poly(y, order=order) fit = polyfit(y, order=order) else: dt = rm_poly(x, y, order) fit = polyfit(x, y, order) diff = np.abs((dt + fit) - y) assert (diff < 1e-15).all()