Пример #1
0
def test_alignment(tmpdir, extent, from_files):
    datapath = tmpdir.mkdir('data')
    path = tmpdir.mkdir('aligned')
    bounds = [
        (-10.0, 50.0, 0.0, 60.0),
        (-12.0, 40.0, -2.0, 52.0),
        (-13.0, 50.0, -3.0, 60.0),
        (-9.0, 51.0, 1.0, 61.0)
    ]
    datasets = [generate_test_dataset(extent=ext) for ext in bounds]
    if extent is None:
        common_bounds = warp.get_common_bounds(datasets)
    else:
        common_bounds = extent
    files = [str(datapath.join('data_%d.nc' % i))
             for i in range(len(datasets))]
    if from_files:
        for ds, f in zip(datasets, files):
            to_netcdf(ds, f)
        datasets = files
    warp.Alignment(extent=extent).apply(datasets, path=str(path))
    aligned = [open_dataset(str(f)) for f in path.listdir()]
    for ds in aligned:
        assert_equal(warp.get_bounds(ds), common_bounds)
        assert_equal(
            warp.get_transform(ds),
            warp.get_transform(aligned[0])
        )
        xr_assert_equal(ds['x'], aligned[0]['x'])
        xr_assert_equal(ds['y'], aligned[0]['y'])
Пример #2
0
def test_get_common_bounds():
    bounds = [
        (-10.0, 50.0, 0.0, 60.0),
        (-12.0, 40.0, -2.0, 52.0),
        (-13.0, 50.0, -3.0, 60.0),
        (-9.0, 51.0, 1.0, 61.0)
    ]
    datasets = [generate_test_dataset(extent=ext) for ext in bounds]
    assert_equal(
        warp.get_common_bounds(datasets),
        (-13.0, 40.0, 1.0, 61.0)
    )
Пример #3
0
def test_get_common_extent():
    bounds = [(-10.0, 50.0, 0.0, 60.0), (-12.0, 40.0, -2.0, 52.0),
              (-13.0, 50.0, -3.0, 60.0), (-9.0, 51.0, 1.0, 61.0)]
    common_extent = (-13.0, 40.0, 1.0, 61.0)
    datasets = [generate_test_dataset(extent=ext) for ext in bounds]

    # Reproject such that the projected bounds change,
    # but the extent remains the same:
    proj = Reprojection(crs=sinusoidal)
    datasets_sinu = [proj.apply(ds) for ds in datasets]

    common_bounds = get_common_bounds(datasets_sinu)
    expected_result = BoundingBox(*rasterio.warp.transform_bounds(
        sinusoidal, epsg4326, **common_bounds._asdict()))

    assert_raises(AssertionError, assert_equal, common_bounds, common_extent)
    assert_almost_equal(get_common_extent(datasets_sinu), expected_result)