Ejemplo n.º 1
0
def test_open_dataset() -> None:
    expected_groups = {
        "IW1",
        "IW1/VV",
        "IW1/VV/gcp",
        "IW1/VV/attitude",
        "IW1/VV/orbit",
        "IW1/VV/calibration",
        "IW1/VV/noise_range",
        "IW1/VV/noise_azimuth",
    }

    res = sentinel1.open_sentinel1_dataset(SLC_IW)

    assert isinstance(res, xr.Dataset)
    assert len(res.data_vars) == 0
    assert set(res.attrs["subgroups"]) >= expected_groups

    res = sentinel1.open_sentinel1_dataset(SLC_IW, group="IW1")

    assert isinstance(res, xr.Dataset)
    assert len(res.data_vars) == 0

    res = sentinel1.open_sentinel1_dataset(SLC_IW, group="IW1/VV/orbit")

    assert isinstance(res, xr.Dataset)
    assert res.dims == {"axis": 3, "azimuth_time": 17}

    with pytest.raises(ValueError):
        sentinel1.open_sentinel1_dataset(SLC_IW, group="IW1/VV/non-existent")
Ejemplo n.º 2
0
def test_calibrate_intensity() -> None:
    swath_ds = sentinel1.open_sentinel1_dataset(SLC_IW, group="IW1/VH")
    burst_ds = sentinel1.crop_burst_dataset(swath_ds, burst_index=8)
    cal_ds = sentinel1.open_sentinel1_dataset(SLC_IW,
                                              group="IW1/VH/calibration")

    res = sentinel1.calibrate_intensity(burst_ds.measurement,
                                        cal_ds["betaNought"])

    assert set(res.dims) == {"azimuth_time", "slant_range_time"}
    assert np.issubdtype(res.dtype, np.float32)

    cal_ds["betaNought"].attrs.pop("long_name")

    res = sentinel1.calibrate_intensity(burst_ds.measurement,
                                        cal_ds["betaNought"],
                                        as_db=True)

    assert set(res.dims) == {"azimuth_time", "slant_range_time"}
    assert np.issubdtype(res.dtype, np.float32)

    res = sentinel1.calibrate_intensity(
        burst_ds.measurement,
        cal_ds["betaNought"],
        as_db=True,
        min_db=None,
    )

    assert np.issubdtype(res.dtype, np.float32)
Ejemplo n.º 3
0
def test_ground_range_to_slant_range_time() -> None:
    swath_ds = sentinel1.open_sentinel1_dataset(GRD_IW, group="IW/VV")
    swath = swath_ds.measurement[:1000, :1000]
    cc_ds = sentinel1.open_sentinel1_dataset(
        GRD_IW, group="IW/VV/coordinate_conversion")

    res = sentinel1.ground_range_to_slant_range_time(swath.azimuth_time,
                                                     swath.ground_range, cc_ds)

    assert isinstance(res, xr.DataArray)
Ejemplo n.º 4
0
def test_crop_burst_dataset() -> None:
    swath_ds = sentinel1.open_sentinel1_dataset(SLC_IW_V340, group="IW1/HH")

    res1 = sentinel1.crop_burst_dataset(swath_ds, 8)

    assert set(res1.dims) == {"azimuth_time", "slant_range_time"}
    assert res1.dims["azimuth_time"] == swath_ds.attrs["lines_per_burst"]

    res2 = sentinel1.crop_burst_dataset(swath_ds, azimuth_anx_time=2210)

    assert res2.equals(res1)

    res3 = sentinel1.crop_burst_dataset(swath_ds,
                                        azimuth_anx_time=2213,
                                        use_center=True)

    assert res3.equals(res1)

    res4 = sentinel1.crop_burst_dataset(swath_ds, burst_id=365923)

    assert res4.equals(res1)

    with pytest.raises(TypeError):
        sentinel1.crop_burst_dataset(swath_ds)

    with pytest.raises(TypeError):
        sentinel1.crop_burst_dataset(swath_ds,
                                     burst_index=8,
                                     azimuth_anx_time=2213)

    with pytest.raises(TypeError):
        sentinel1.crop_burst_dataset(swath_ds, burst_index=8, burst_id=365923)

    with pytest.raises(TypeError):
        sentinel1.crop_burst_dataset(swath_ds,
                                     azimuth_anx_time=2213,
                                     burst_id=365923)

    with pytest.raises(IndexError):
        sentinel1.crop_burst_dataset(swath_ds, burst_index=-1)

    with pytest.raises(KeyError):
        sentinel1.crop_burst_dataset(swath_ds, burst_id=1)

    swath_ds = sentinel1.open_sentinel1_dataset(SLC_IW, group="IW1/VH")

    with pytest.raises(TypeError):
        sentinel1.crop_burst_dataset(swath_ds, burst_id=1)
Ejemplo n.º 5
0
def test_calibrate_amplitude() -> None:
    swath_ds = sentinel1.open_sentinel1_dataset(SLC_IW, group="IW1/VH")
    burst_ds = sentinel1.crop_burst_dataset(swath_ds, burst_index=8)
    cal_ds = sentinel1.open_sentinel1_dataset(SLC_IW,
                                              group="IW1/VH/calibration")

    res = sentinel1.calibrate_amplitude(burst_ds.measurement,
                                        cal_ds["betaNought"])

    assert set(res.dims) == {"azimuth_time", "slant_range_time"}
    assert np.issubdtype(res.dtype, np.complex64)

    res = sentinel1.calibrate_amplitude(burst_ds.measurement, cal_ds["gamma"])

    assert set(res.dims) == {"azimuth_time", "slant_range_time"}
    assert np.issubdtype(res.dtype, np.complex64)
Ejemplo n.º 6
0
def test_calibrate_intensity() -> None:
    swath_ds = sentinel1.open_sentinel1_dataset(SLC_IW, group="IW1/VH")
    burst_ds = sentinel1.crop_burst_dataset(swath_ds, burst_index=8)
    calibration_ds = sentinel1.open_calibration_dataset(SLC_IW1_VV_calibration)

    res = sentinel1.calibrate_intensity(burst_ds.measurement,
                                        calibration_ds["betaNought"])

    assert set(res.dims) == {"azimuth_time", "slant_range_time"}
    assert np.issubdtype(res.dtype, np.float32)
Ejemplo n.º 7
0
def test_mosaic_slc_iw() -> None:
    ds = sentinel1.open_sentinel1_dataset(SLC_IW_V340, group="IW1/HH")

    res = sentinel1.mosaic_slc_iw(ds)

    assert isinstance(res, xr.Dataset)

    res = sentinel1.mosaic_slc_iw(ds.measurement)

    assert isinstance(res, xr.DataArray)
def test_open_dataset_zip_data() -> None:
    zip_path = (
        DATA_FOLDER /
        "S1B_IW_SLC__1SDV_20210401T052622_20210401T052650_026269_032297_EFA4.zip"
    )
    zip_urlpath = f"zip://*/manifest.safe::{zip_path}"

    res = sentinel1.open_sentinel1_dataset(zip_urlpath, group="IW1/VV/0")

    assert isinstance(res, xr.Dataset)
    assert res.dims == {"slant_range_time": 21632, "azimuth_time": 1501}
    assert abs(res.measurement[:40, :40]).mean() >= 0
def test_open_dataset_zip_metadata() -> None:
    zip_path = (
        DATA_FOLDER /
        "S1B_IW_SLC__1SDV_20210401T052622_20210401T052650_026269_032297_EFA4.zip"
    )
    zip_urlpath = f"zip://*/manifest.safe::{zip_path}"
    expected_groups = {
        "IW1",
        "IW1/VV",
        "IW1/VV/gcp",
        "IW1/VV/attitude",
        "IW1/VV/orbit",
        "IW1/VV/calibration",
    }

    res = sentinel1.open_sentinel1_dataset(zip_urlpath)

    assert isinstance(res, xr.Dataset)
    assert set(res.attrs["subgroups"]) >= expected_groups

    res = sentinel1.open_sentinel1_dataset(zip_urlpath, group="IW1/VV/orbit")

    assert isinstance(res, xr.Dataset)
    assert res.dims == {"axis": 3, "azimuth_time": 17}
Ejemplo n.º 10
0
def test_open_dataset_virtual_groups() -> None:
    res = sentinel1.open_sentinel1_dataset(SLC_IW, group="IW1/VV/0")

    assert isinstance(res, xr.Dataset)
    assert len(res.data_vars) == 1
    assert res.attrs["burst_index"] == 0