Skip to content

Commit

Permalink
Add processing info to the general attributes (bopen#140).
Browse files Browse the repository at this point in the history
  • Loading branch information
mdbmdb74 committed Mar 29, 2024
1 parent c544713 commit 7751c06
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions xarray_sentinel/sentinel1.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from __future__ import annotations

import os
import re
import warnings
from typing import Any, Dict, List, Optional, Sequence, Tuple, TypeVar

Expand All @@ -26,6 +27,25 @@

SPEED_OF_LIGHT = 299_792_458 # m / s
ONE_SECOND = np.timedelta64(1, "s")
PROCESSING_INFO_PARAMS = [
"rawDataAnalysisUsed",
"orbitDataFileUsed",
"attitudeDataFileUsed",
"rxVariationCorrectionApplied",
"antennaElevationPatternApplied",
"antennaAzimuthPatternApplied",
"antennaAzimuthElementPatternApplied",
"dcMethod",
"dcInputData",
"rangeSpreadingLossCompensationApplied",
"srgrConversionApplied",
"detectionPerformed",
"thermalNoiseCorrectionPerformed",
"chirpSource",
"pgSource",
"rrfSpectrum",
"applicationLutId",
]


DataArrayOrDataset = TypeVar("DataArrayOrDataset", xr.DataArray, xr.Dataset)
Expand Down Expand Up @@ -547,17 +567,33 @@ def make_azimuth_time(
return azimuth_time.values


def camel_to_snake(string: str) -> str:
"""Convert camel-case into snake_case.
:param str string: the input string in camel case
:return str:
"""
s1 = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", string)
snake_case_str = re.sub("([a-z0-9])([A-Z])", r"\1_\2", s1).lower()
return snake_case_str


def open_pol_dataset(
measurement: esa_safe.PathOrFileType,
annotation: esa_safe.PathOrFileType,
fs: Optional[fsspec.AbstractFileSystem] = None,
attrs: Dict[str, Any] = {},
gcp: Optional[xr.Dataset] = None,
) -> xr.Dataset:
processing_information = esa_safe.parse_tag(annotation, ".//processingInformation")
product_information = esa_safe.parse_tag(annotation, ".//productInformation")
image_information = esa_safe.parse_tag(annotation, ".//imageInformation")
swath_timing = esa_safe.parse_tag(annotation, ".//swathTiming")

processing_info_attrs = {
camel_to_snake(k): str(processing_information[k]).lower()
for k in PROCESSING_INFO_PARAMS
}
number_of_samples = image_information["numberOfSamples"]
range_sampling_rate = product_information["rangeSamplingRate"]

Expand All @@ -570,6 +606,7 @@ def open_pol_dataset(
range_pixel_spacing = image_information["rangePixelSpacing"]

attrs = attrs.copy()
attrs.update(processing_info_attrs)
attrs.update(
{
"radar_frequency": product_information["radarFrequency"] / 10**9,
Expand Down

0 comments on commit 7751c06

Please sign in to comment.