Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions sarxarray/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
META_ARRAY_KEYS,
META_FLOAT_KEYS,
META_INT_KEYS,
META_UNIT_CONVERSION_MULTIPLICATION_KEYS_DORIS4,
META_UNIT_CONVERSION_MULTIPLICATION_KEYS_DORIS5,
RE_PATTERNS_DORIS4,
RE_PATTERNS_DORIS5,
RE_PATTERNS_DORIS5_IFG,
Expand Down Expand Up @@ -441,8 +443,16 @@
# Convert time metadata from string to datetime
if driver == "doris5":
time_format = TIME_FORMAT_DORIS5
unit_conversions = META_UNIT_CONVERSION_MULTIPLICATION_KEYS_DORIS5
elif driver == "doris4":
time_format = TIME_FORMAT_DORIS4
unit_conversions = META_UNIT_CONVERSION_MULTIPLICATION_KEYS_DORIS4
else:
raise NotImplementedError(
f"Driver '{driver}' is not implemented. "
"Supported drivers are: 'doris4', 'doris5'."
)

list_time = []
# If the time is a single string, convert it to a list
if isinstance(metadata[TIME_STAMP_KEY], str):
Expand Down Expand Up @@ -473,6 +483,8 @@
for row in range(len(arr)):
for col in range(len(arr[row])):
regulated_array[row, col] = META_ARRAY_KEYS[key](arr[row][col])
if key in unit_conversions.keys():
regulated_array *= unit_conversions[key]
regulated_arrays.append(np.copy(regulated_array))

metadata[key] = [
Expand All @@ -481,7 +493,6 @@
if len(metadata[key]) == 1:
metadata[key] = metadata[key][0]


else:
# Only keep the unique values
if isinstance(metadata[key], list):
Expand All @@ -502,12 +513,20 @@
f"Inconsistency found in metadata key: {key}. "
"Standard deviation is larger than 1% of the mean."
)
if key in unit_conversions.keys():
metadata[key] *= unit_conversions[key]
if key in META_INT_KEYS:
if isinstance(metadata[key], str):
metadata[key] = int(metadata[key])
if key in unit_conversions.keys():
metadata[key] *= unit_conversions[key]
elif len(metadata[key]) > 1: # set with multiple values
metadata[key] = set([int(v) for v in metadata[key]])

if key in unit_conversions.keys():
metadata[key] = set(

Check warning on line 525 in sarxarray/_io.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this set constructor call by a set literal.

See more on https://sonarcloud.io/project/issues?id=TUDelftGeodesy_sarxarray&issues=AZsNOSh_EPrYlvRt_Zlg&open=AZsNOSh_EPrYlvRt_Zlg&pullRequest=75
[int(v) * unit_conversions[key] for v in metadata[key]]
)
else:
metadata[key] = set([int(v) for v in metadata[key]])
if key in ["number_of_lines", "number_of_pixels"]:
if isinstance(metadata[key], set):
warning_msg = f"Multiple values found in {key}: {metadata[key]}."
Expand Down
15 changes: 14 additions & 1 deletion sarxarray/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"weighting_range": r"Weighting_range:\s+(.+)",
"first_azimuth_time": r"First_pixel_azimuth_time \(UTC\):\s+(.+)",
}
# Regular expressions for reading metadata from DORIS4 files
# Regular expressions for reading metadata from DORIS5 files
RE_PATTERNS_DORIS5 = {
"sar_processor": r"SAR_PROCESSOR:\s+(.+)",
"product_type": r"Product type specifier:\s+(.+)",
Expand Down Expand Up @@ -107,6 +107,19 @@
META_ARRAY_KEYS = {
"orbit_txyz": float # DORIS5 only
}
# Some keys are not read in in SI units. The following dictionary specifies those
# keys, and the factor they should be multiplied by to restore them to SI units
META_UNIT_CONVERSION_MULTIPLICATION_KEYS_DORIS4 = {
"range_sampling_rate": 1_000_000, # originally MHz
"total_range_bandwidth": 1_000_000, # originally MHz
"first_range_time": 0.001, # originally ms
}

META_UNIT_CONVERSION_MULTIPLICATION_KEYS_DORIS5 = {
"range_sampling_rate": 1_000_000, # originally MHz
"total_range_bandwidth": 1_000_000, # originally MHz
"first_range_time": 0.001, # originally ms
}
# Time formats for DORIS metadata
TIME_FORMAT_DORIS4 = "%d-%b-%Y %H:%M:%S.%f"
TIME_FORMAT_DORIS5 = "%Y-%b-%d %H:%M:%S.%f"
Expand Down
Loading