Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_merge_arrays__res():
dem_test = os.path.join(TEST_INPUT_DATA_DIR, "MODIS_ARRAY.nc")
with open_rasterio(dem_test, masked=True) as rds:
rds.attrs = {
"_FillValue": rds.rio.nodata,
"grid_mapping": "spatial_ref",
"crs": rds.attrs["crs"],
}
arrays = [
rds.isel(x=slice(100), y=slice(100)),
rds.isel(x=slice(100, 200), y=slice(100, 200)),
rds.isel(x=slice(100), y=slice(100, 200)),
rds.isel(x=slice(100, 200), y=slice(100)),
]
merged = merge_arrays(arrays, res=(300, 300))
assert_almost_equal(
merged.rio.bounds(),
(-7274009.649486291, 5003608.61015275, -7227509.649486291, 5050108.61015275),
)
assert_almost_equal(
tuple(merged.rio.transform()),
(300.0, 0.0, -7274009.649486291, 0.0, -300.0, 5050108.61015275, 0.0, 0.0, 1.0),
)
assert merged.rio._cached_transform() == merged.rio.transform()
assert merged.rio.shape == (155, 155)
assert merged.coords["band"].values == [1]
assert sorted(merged.coords) == ["band", "spatial_ref", "x", "y"]
assert merged.rio.crs == rds.rio.crs
assert merged.attrs == rds.attrs
assert_almost_equal(nansum(merged), 13556564)
def test_merge_arrays():
dem_test = os.path.join(TEST_INPUT_DATA_DIR, "MODIS_ARRAY.nc")
with open_rasterio(dem_test) as rds:
rds.attrs = {
"_FillValue": rds.rio.nodata,
"grid_mapping": "spatial_ref",
"crs": rds.attrs["crs"],
}
arrays = [
rds.isel(x=slice(100), y=slice(100)),
rds.isel(x=slice(100, 200), y=slice(100, 200)),
rds.isel(x=slice(100), y=slice(100, 200)),
rds.isel(x=slice(100, 200), y=slice(100)),
]
merged = merge_arrays(arrays)
assert_almost_equal(
merged.rio.bounds(),
(-7274009.649486291, 5003545.682141737, -7227446.721475236, 5050108.61015275),
)
assert_almost_equal(
tuple(merged.rio.transform()),
(
231.6563582639536,
0.0,
-7274009.649486291,
0.0,
-231.65635826374404,
5050108.61015275,
0.0,
0.0,