def test_cog_no_crs(tmpdir, with_dask): pp = Path(str(tmpdir)) xx, ds = gen_test_data(pp, dask=with_dask) xx = remove_crs(xx) with pytest.raises(ValueError): write_cog(xx, ":mem:") with pytest.raises(ValueError): to_cog(xx)
def test_assign_crs(odc_style_xr_dataset): xx = odc_style_xr_dataset assert xx.geobox is not None xx_nocrs = remove_crs(xx) assert xx_nocrs.geobox is None yy = assign_crs(xx_nocrs, 'epsg:4326') assert xx_nocrs.geobox is None # verify source is not modified in place assert yy.geobox.crs == 'epsg:4326' yy = assign_crs(xx_nocrs.B10, 'epsg:4326') assert yy.geobox.crs == 'epsg:4326' xx_xr_style_crs = xx_nocrs.copy() xx_xr_style_crs.attrs.update(crs='epsg:3857') yy = assign_crs(xx_xr_style_crs) assert yy.geobox.crs == 'epsg:3857' with pytest.raises(ValueError): assign_crs(xx_nocrs)
def test_write_geotiff_str_crs(tmpdir, odc_style_xr_dataset): """Ensure the geotiff helper writer works, and supports crs as a string.""" filename = tmpdir + '/test.tif' original_crs = odc_style_xr_dataset.crs odc_style_xr_dataset.attrs['crs'] = str(original_crs) with pytest.warns(DeprecationWarning): write_geotiff(filename, odc_style_xr_dataset) assert filename.exists() with rasterio.open(str(filename)) as src: written_data = src.read(1) assert (written_data == odc_style_xr_dataset['B10']).all() odc_style_xr_dataset = remove_crs(odc_style_xr_dataset) with pytest.raises(ValueError): with pytest.warns(DeprecationWarning): write_geotiff(filename, odc_style_xr_dataset)
def test_xr_extension(odc_style_xr_dataset): xx = odc_style_xr_dataset assert _norm_crs(None) is None assert _norm_crs(epsg4326) is epsg4326 assert _norm_crs(str(epsg4326)) == epsg4326 with pytest.raises(ValueError): _norm_crs([]) assert xx.geobox.shape == xx.B10.shape (sx, zz0, tx, zz1, sy, ty) = xx.affine[:6] assert (zz0, zz1) == (0, 0) xx = remove_crs(xx) assert _xarray_geobox(xx) is None assert _xarray_extent(xx) is None # affine should still be valid A = _xarray_affine(xx) assert A is not None assert A * (0.5, 0.5) == (xx.longitude[0], xx.latitude[0]) assert A * (0.5, 1.5) == (xx.longitude[0], xx.latitude[1])