def download_no_args(self, tmp_path, format, format_options={}): input = self.create_spacetime_layer() imagecollection = GeopysparkDataCube(pyramid=gps.Pyramid({0: input})) imagecollection.metadata=imagecollection.metadata.add_dimension('band_one', 'band_one', 'bands') imagecollection.metadata=imagecollection.metadata.append_band(Band('band_two','','')) res = imagecollection.save_result(str(tmp_path / "test_download_result.") + format, format=format, format_options=format_options) print(res) return res
def download_no_args_single_byte_band(self, tmp_path, format, format_options={}): input = self.create_spacetime_layer().convert_data_type(gps.CellType.UINT8) imagecollection = GeopysparkDataCube(pyramid=gps.Pyramid({0: input})) imagecollection.metadata=imagecollection.metadata.add_dimension('band_one', 'band_one', 'bands') imagecollection.metadata=imagecollection.metadata.append_band(Band('band_two','','')) imagecollection.filter_bands(['band_one']) res = imagecollection.save_result(str(tmp_path / "test_download_result_single_band.") + format, format=format, format_options=format_options) print(res) return res
def download_masked(self, tmp_path, format): input = self.create_spacetime_layer() imagecollection = GeopysparkDataCube(pyramid=gps.Pyramid({0: input})) imagecollection.metadata=imagecollection.metadata.add_dimension('band_one', 'band_one', 'bands') imagecollection.metadata=imagecollection.metadata.append_band(Band('band_two','','')) polygon = geometry.Polygon([[0, 0], [1.9, 0], [1.9, 1.9], [0, 1.9]]) imagecollection = imagecollection.mask_polygon(mask=polygon) filename = str(tmp_path / "test_download_masked_result.") + format res = imagecollection.save_result(filename, format=format) print(res)
def test_write_assets(self, tmp_path): input = self.create_spacetime_layer() imagecollection = GeopysparkDataCube(pyramid=gps.Pyramid({0: input})) imagecollection.metadata = imagecollection.metadata.add_dimension('band_one', 'band_one', 'bands') imagecollection.metadata = imagecollection.metadata.append_band(Band('band_two', '', '')) format = 'GTiff' res = imagecollection.write_assets(str(tmp_path / "test_download_result.") + format, format=format,format_options={ "multidate":True, "batch_mode":True }) assert 1 == len(res) name, asset = res.popitem() assert Path(asset['href']).parent == tmp_path assert asset['nodata'] == -1 assert asset['roles'] == ['data'] assert 2 == len(asset['bands']) assert 'image/tiff; application=geotiff' == asset['type'] assert asset['datetime'] == "2017-09-25T11:37:00Z"
def test_write_assets_samples_netcdf(self, tmp_path): input = self.create_spacetime_layer() imagecollection = GeopysparkDataCube(pyramid=gps.Pyramid({0: input})) imagecollection.metadata = imagecollection.metadata.add_dimension('band_one', 'band_one', 'bands') imagecollection.metadata = imagecollection.metadata.append_band(Band('band_two', '', '')) format = 'netCDF' res = imagecollection.write_assets(str(tmp_path / "test_download_result.") + format, format=format,format_options={ "batch_mode":True, "geometries":geojson_to_geometry(self.features), "sample_by_feature": True, "feature_id_property": 'id' }) assert len(res) == 3 name,asset = res.popitem() file = asset['href'] assert asset['nodata'] == -1 assert asset['roles'] == ['data'] assert 2 == len(asset['bands']) assert 'application/x-netcdf' == asset['type']
def download_masked_reproject(self, tmp_path, format): input = self.create_spacetime_layer() imagecollection = GeopysparkDataCube(pyramid=gps.Pyramid({0: input})) imagecollection.metadata=imagecollection.metadata.add_dimension('band_one', 'band_one', 'bands') imagecollection.metadata=imagecollection.metadata.append_band(Band('band_two','','')) polygon = geometry.Polygon([[0, 0], [1.9, 0], [1.9, 1.9], [0, 1.9]]) import pyproj from shapely.ops import transform from functools import partial project = partial( pyproj.transform, pyproj.Proj(init="EPSG:4326"), # source coordinate system pyproj.Proj(init="EPSG:3857")) # destination coordinate system reprojected = transform(project, polygon) imagecollection = imagecollection.mask_polygon(mask=reprojected, srs="EPSG:3857") filename = str(tmp_path / "test_download_masked_result.3857.") + format res = imagecollection.save_result(filename, format=format) print(res)