def test_polyfit_against_data_dask(gridded_da_float, gridded): """Tests that ``polyfit`` plus ``rm_poly`` equals the original time series when fitting against data series and gridded data with dask arrays.""" x = gridded_da_float() if gridded else gridded_da_float().isel(lat=0, lon=0).chunk() y = gridded_da_float() 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_data(gridded_da_float, gridded, order): """Tests that ``polyfit`` plus ``rm_poly`` equals the original time series when fitting against data series and gridded data.""" x = gridded_da_float() if gridded else gridded_da_float().isel(lat=0, lon=0) y = gridded_da_float() dt = rm_poly(x, y, order) fit = polyfit(x, y, order) diff = np.abs((dt + fit) - y) assert (diff < 1e-15).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()