Beispiel #1
0
def test_save_load_guess_format_invalid(tmp_path):
    xdc = _build_xdc(ts=[2019, 2020, 2021],
                     bands=["a", "b"],
                     xs=[2, 3, 4, 5],
                     ys=[5, 6, 7, 8, 9])
    assert xdc.array.shape == (3, 2, 4, 5)
    path = tmp_path / "cube.foobar"
    with pytest.raises(ValueError, match="Can not guess format"):
        xdc.save_to_file(path)
    xdc.save_to_file(path, fmt="netcdf")
    with pytest.raises(ValueError, match="Can not guess format"):
        result = XarrayDataCube.from_file(path)
    result = XarrayDataCube.from_file(path, fmt="netcdf")
    xarray.testing.assert_equal(xdc.array, result.array)
Beispiel #2
0
def test_save_load_guess_format(filename, save_format, load_format, tmp_path):
    xdc = _build_xdc(ts=[2019, 2020, 2021],
                     bands=["a", "b"],
                     xs=[2, 3, 4, 5],
                     ys=[5, 6, 7, 8, 9])
    assert xdc.array.shape == (3, 2, 4, 5)
    path = tmp_path / filename
    xdc.save_to_file(path, fmt=save_format)
    result = XarrayDataCube.from_file(path, fmt=load_format)
    xarray.testing.assert_equal(xdc.array, result.array)
def test_debug_udf_direct_invoke():
    """
    Shows how to run your UDF locally for testing, by invoking the function directly, breakpoints work.
    https://open-eo.github.io/openeo-python-client/udf.html#example-downloading-a-datacube-and-executing-an-udf-locally
    depends on composite.nc file created in earlier function!
    """
    from openeo.udf import XarrayDataCube
    udf_cube = XarrayDataCube.from_file('masked.nc', fmt='netcdf')

    apply_datacube(udf_cube,context={})
def datacube_from_file(filename, fmt='netcdf') -> "XarrayDataCube":
    from openeo.udf.xarraydatacube import XarrayDataCube
    return XarrayDataCube.from_file(path=filename, fmt=fmt)
Beispiel #5
0
def _assert_equal_after_save_and_load(xdc, tmp_path, format) -> XarrayDataCube:
    path = tmp_path / ("cube." + format)
    xdc.save_to_file(path=path, fmt=format)
    result = XarrayDataCube.from_file(path=path, fmt=format)
    xarray.testing.assert_equal(xdc.array, result.array)
    return result