def setup_nc_single_test_data(): """ Creates test data as a multi-time and multi-variable NetCDF file. Returns ------- str NetCDF test data filepath. list of datetime List of timestamps as datetime objects. """ root_dirpath = os.path.join(dirpath_test(), 'data', 'Sentinel-1_CSAR') # create target folders dirpath = os.path.join(root_dirpath, 'IWGRDH', 'products', 'datasets', 'resampled', 'T0101', 'EQUI7_EU500M', 'E048N012T6', 'data') timestamps = [datetime(2016, 1, 1), datetime(2016, 2, 1), datetime(2017, 1, 1), datetime(2017, 2, 1)] var_names = ["SIG0", "GMR-"] directions = ["A", "D"] combs = itertools.product(var_names, directions, timestamps) rows, cols = np.meshgrid(np.arange(0, 1200), np.arange(0, 1200)) data = rows + cols equi7 = Equi7Grid(500) tile_oi = equi7.EU.tilesys.create_tile(name="E042N012T6") xr_dss = [] filepath = os.path.join(dirpath, "D20160101_20170201_PREPRO---_S1AIWGRDH1VV-_146_T0101_EU500M_E048N012T6.nc") if not os.path.exists(dirpath): os.makedirs(dirpath) if not os.path.exists(filepath): for comb in combs: var_name = comb[0] direction = comb[1] timestamp = comb[2] tags = {'direction': direction} data_i = data + timestamps.index(timestamp) xr_ar = xr.DataArray(data=data_i[None, :, :], coords={'time': [timestamp]}, dims=['time', 'y', 'x'], attrs=tags) xr_dss.append(xr.Dataset(data_vars={var_name.strip('-'): xr_ar})) nc_file = NcFile(filepath, mode='w', geotransform=tile_oi.geotransform(), spatialref=tile_oi.get_geotags()['spatialreference']) xr_ds = xr.merge(xr_dss) nc_file.write(xr_ds) nc_file.close() timestamps = [pd.Timestamp(timestamp.strftime("%Y%m%d")) for timestamp in timestamps] return filepath, timestamps
def setup_nc_multi_test_data(): """ Creates test data as single-time and single-variable NetCDF files. Returns ------- list of str List of NetCDF test data filepaths. list of datetime List of timestamps as datetime objects. """ root_dirpath = os.path.join(dirpath_test(), 'data', 'Sentinel-1_CSAR') # create target folders dirpath = os.path.join(root_dirpath, 'IWGRDH', 'parameters', 'datasets', 'resampled', 'T0101', 'EQUI7_EU500M', 'E042N012T6', 'sig0') timestamps = [datetime(2016, 1, 1), datetime(2016, 2, 1), datetime(2017, 1, 1), datetime(2017, 2, 1)] pols = ["VV", "VH"] directions = ["A", "D"] filename_fmt = "D{}_000000--_SIG0-----_S1AIWGRDH1{}{}_146_T0101_EU500M_E042N012T6.nc" combs = itertools.product(pols, directions, timestamps) rows, cols = np.meshgrid(np.arange(0, 1200), np.arange(0, 1200)) data = (rows + cols).astype(float) equi7 = Equi7Grid(500) tile_oi = equi7.EU.tilesys.create_tile(name="E042N012T6") if not os.path.exists(dirpath): os.makedirs(dirpath) filepaths = [] for comb in combs: pol = comb[0] direction = comb[1] timestamp = comb[2] filename = filename_fmt.format(timestamp.strftime("%Y%m%d"), pol, direction) filepath = os.path.join(dirpath, filename) filepaths.append(filepath) if not os.path.exists(filepath): tags = {'direction': direction} nc_file = NcFile(filepath, mode='w', geotransform=tile_oi.geotransform(), spatialref=tile_oi.get_geotags()['spatialreference']) data_i = data + timestamps.index(timestamp) xr_ar = xr.DataArray(data=data_i[None, :, :], coords={'time': [timestamp]}, dims=['time', 'y', 'x']) xr_ds = xr.Dataset(data_vars={'1': xr_ar}, attrs=tags) nc_file.write(xr_ds) nc_file.close() timestamps = [pd.Timestamp(timestamp.strftime("%Y%m%d")) for timestamp in timestamps] return filepaths, timestamps