def test_time_resampling(od, timeFreq, sampMethod): # Warning due to tiset(['1, 20'])me_midp with pytest.warns(UserWarning): new_od = od.subsample.cutout(timeFreq=timeFreq, sampMethod=sampMethod) if timeFreq == '12H': assert (len(new_od.dataset['time']) == np.ceil( len(od.dataset['time']) / 2)) elif timeFreq == '6H': assert (len(new_od.dataset['time']) == len(od.dataset['time'])) elif timeFreq == '1D' and sampMethod == 'mean': with pytest.warns(RuntimeWarning): # Test time only new_ds = new_od.dataset new_ds = new_ds.drop('time_midp') new_od = OceanDataset(new_ds) new_od.subsample.cutout(timeFreq='2D', sampMethod=sampMethod)
# Directory Datadir = './oceanspy/tests/Data/' # Test oceandataset MITgcm_curv_nc = open_oceandataset.from_netcdf('{}MITgcm_curv_nc.nc' ''.format(Datadir)) MITgcm_rect_bin = open_oceandataset.from_netcdf('{}MITgcm_rect_bin.nc' ''.format(Datadir)) MITgcm_rect_nc = open_oceandataset.from_netcdf('{}MITgcm_rect_nc.nc' ''.format(Datadir)) # ======= # CUTOUT # ======= od = MITgcm_curv_nc moor_od = OceanDataset(od.dataset.expand_dims('mooring')) Ywarn = od.dataset['YG'].min() - 1 Xwarn = od.dataset['XG'].min() - 1 Zwarn = od.dataset['Zp1'].min() - 1 Twarn = od.dataset['time'].min() - 1 YRange = [od.dataset['YG'].min(), od.dataset['YG'].max()] XRange = [od.dataset['XG'].min(), od.dataset['XG'].max()] ZRange = [od.dataset['Zp1'].min(), od.dataset['Zp1'].max()] timeRange = [od.dataset['time'].values[0], od.dataset['time'].values[-1]] dropAxes = ['Y', 'X', 'Z', 'time'] dropwarn = 'mooring' @pytest.mark.parametrize("od, YRange, XRange, ZRange, timeRange, dropAxes", [(od, YRange, XRange, ZRange, timeRange, dropwarn), (od, Ywarn, XRange, ZRange, timeRange, ['time']),