Skip to content

Commit 34987ec

Browse files
authored
Merge pull request #104 from bopen/declare-typed
Declare package typed
2 parents 09af28d + 346c807 commit 34987ec

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

tests/test_20_sentinel1.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,16 @@ def test_crop_burst_dataset() -> None:
295295

296296

297297
def test_mosaic_slc_iw() -> None:
298-
da = sentinel1.open_sentinel1_dataset(SLC_IW_V340, group="IW1/HH")
298+
ds = sentinel1.open_sentinel1_dataset(SLC_IW_V340, group="IW1/HH")
299299

300-
res = sentinel1.mosaic_slc_iw(da)
300+
res = sentinel1.mosaic_slc_iw(ds)
301301

302302
assert isinstance(res, xr.Dataset)
303303

304+
res = sentinel1.mosaic_slc_iw(ds.measurement)
305+
306+
assert isinstance(res, xr.DataArray)
307+
304308

305309
def test_calibrate_amplitude() -> None:
306310
swath_ds = sentinel1.open_sentinel1_dataset(SLC_IW, group="IW1/VH")

xarray_sentinel/conventions.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
"""CF representation of metadata according to
2-
Sentinel-1 Product Specification: S1-RS-MDA-52-7441, DI-MPC-PB, MPC-0240, 3/7, 27/02/2020 See:
1+
"""CF representation of metadata according to Sentinel-1 Product Specification.
2+
3+
See: S1-RS-MDA-52-7441, DI-MPC-PB, MPC-0240, 3/7, 27/02/2020
34
https://sentinel.esa.int/documents/247904/1877131/Sentinel-1-Product-Specification
45
"""
56

xarray_sentinel/py.typed

Whitespace-only changes.

xarray_sentinel/sentinel1.py

+19-13
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
ONE_SECOND = np.timedelta64(1, "s")
2525

2626

27+
DataArrayOrDataset = T.TypeVar("DataArrayOrDataset", xr.DataArray, xr.Dataset)
28+
29+
2730
def get_fs_path(
2831
urlpath_or_path: esa_safe.PathType,
2932
fs: T.Optional[fsspec.AbstractFileSystem] = None,
@@ -551,7 +554,7 @@ def open_pol_dataset(
551554

552555

553556
def find_bursts_index(
554-
pol_dataset: xr.Dataset,
557+
pol_dataset: DataArrayOrDataset,
555558
azimuth_anx_time: float,
556559
use_center: bool = False,
557560
) -> int:
@@ -573,15 +576,16 @@ def find_bursts_index(
573576

574577

575578
def crop_burst_dataset(
576-
pol_dataset: xr.Dataset,
579+
pol_dataset: DataArrayOrDataset,
577580
burst_index: T.Optional[int] = None,
578581
azimuth_anx_time: T.Optional[float] = None,
579582
use_center: bool = False,
580583
burst_id: T.Optional[int] = None,
581-
) -> xr.Dataset:
582-
"""
583-
Returns the measurement dataset cropped to the selected burst.
584+
) -> DataArrayOrDataset:
585+
"""Return the measurement dataset cropped to the selected burst.
586+
584587
Only one keyword between 'burst_index' and 'azimuth_anx_time' and 'burst_id' must be defined.
588+
585589
:param xr.Dataset pol_dataset: measurement dataset
586590
:param int burst_index: burst index can take values from 1 to the number of bursts
587591
:param float azimuth_anx_time: azimuth anx time of first line of the bursts
@@ -643,7 +647,9 @@ def crop_burst_dataset(
643647
return ds
644648

645649

646-
def mosaic_slc_iw(slc_iw_image: xr.Dataset, crop: int = 90) -> xr.Dataset:
650+
def mosaic_slc_iw(
651+
slc_iw_image: DataArrayOrDataset, crop: int = 90
652+
) -> DataArrayOrDataset:
647653
bursts = []
648654
for i in range(slc_iw_image.attrs["number_of_bursts"]):
649655
burst = crop_burst_dataset(slc_iw_image, burst_index=i)
@@ -654,9 +660,11 @@ def mosaic_slc_iw(slc_iw_image: xr.Dataset, crop: int = 90) -> xr.Dataset:
654660
def calibrate_amplitude(
655661
digital_number: xr.DataArray, calibration_lut: xr.DataArray
656662
) -> xr.DataArray:
657-
"""Returns the calibrated amplitude. The calibration is done using the calibration LUT in the product metadata.
663+
"""Return the calibrated amplitude. The calibration is done using the calibration LUT in the product metadata.
664+
658665
:param digital_number: digital numbers to be calibrated
659666
:param calibration_lut: calibration LUT (sigmaNought, betaNought or gamma).
667+
660668
The LUT can be opened using the measurement sub-group `calibration`
661669
"""
662670
calibration = calibration_lut.interp(
@@ -680,8 +688,8 @@ def calibrate_intensity(
680688
as_db: bool = False,
681689
min_db: T.Optional[float] = -40.0,
682690
) -> xr.DataArray:
683-
"""
684-
Returns the calibrated intensity. The calibration is done using the calibration LUT in the product metadata.
691+
"""Return the calibrated intensity. The calibration is done using the calibration LUT in the product metadata.
692+
685693
:param digital_number: digital numbers to be calibrated
686694
:param calibration_lut: calibration LUT (sigmaNought, betaNought or gamma).
687695
The LUT can be opened using the measurement sub-group `calibration`.
@@ -712,14 +720,12 @@ def slant_range_time_to_ground_range(
712720
slant_range_time: xr.DataArray,
713721
coordinate_conversion: xr.Dataset,
714722
) -> xr.DataArray:
715-
"""
716-
Convert the slant range time coordinates to ground range coordinates using the coordinate conversion `sr0`
717-
and `srgrCoefficients` product metadata
723+
"""Convert slant range time to ground range using the coordinate conversion metadata.
724+
718725
:param azimuth_time: azimuth time coordinates
719726
:param slant_range_time: slant range time
720727
:param coordinate_conversion: coordinate conversion dataset.
721728
The coordinate conversion dataset can be opened using the measurement sub-groub `coordinate_conversion`
722-
:return:
723729
"""
724730
slant_range = SPEED_OF_LIGHT / 2.0 * slant_range_time
725731
cc = coordinate_conversion.interp(azimuth_time=azimuth_time)

0 commit comments

Comments
 (0)