Skip to content

Commit

Permalink
fix bug for get dates (#284)
Browse files Browse the repository at this point in the history
* fix bug for get dates

* add comments to clarify

---------

Co-authored-by: mirzaees <smirzaee@aurora.jpl.nasa.gov>
  • Loading branch information
mirzaees and mirzaees authored May 1, 2024
1 parent d6556a9 commit 23204ad
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
20 changes: 15 additions & 5 deletions src/dolphin/atmosphere/ionosphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,21 @@ def estimate_ionospheric_delay(
)
continue

reference_date = (ref_date,)
secondary_date = (sec_date,)
# The keys in slc_files do not necessarily have one date,
# it means with the production file naming convention,
# there will be multiple dates stored in the keys from get_dates
# function. So in the following if we set reference_date = (ref_date, ),
# there will be an error that it does not find the key.
# Examples of the file naming convention for CSLC and compressed cslc is:
# OPERA_L2_CSLC-S1_T042-088905-IW1\
# _20221119T000000Z_20221120T000000Z_S1A_VV_v1.0.h5
# OPERA_L2_COMPRESSED-CSLC-S1_T042-088905-IW1_20221107T000000Z_\
# 20221107T000000Z_20230506T000000Z_20230507T000000Z_VV_v1.0.h5
reference_date = next(key for key in slc_files if ref_date in key)
secondary_date = next(key for key in slc_files if sec_date in key)

secondary_time = oput.get_zero_doppler_time(slc_files[secondary_date][0])
if len(slc_files[reference_date]) == 0:
if "compressed" in str(slc_files[reference_date][0]).lower():
# this is for when we have compressed slcs but the actual
# reference date does not exist in the input data
reference_time = secondary_time
Expand All @@ -130,14 +140,14 @@ def estimate_ionospheric_delay(

reference_vtec = read_zenith_tec(
time=reference_time,
tec_file=tec_files[reference_date][0],
tec_file=tec_files[(ref_date,)][0],
lat=latc,
lon=lonc,
)

secondary_vtec = read_zenith_tec(
time=secondary_time,
tec_file=tec_files[secondary_date][0],
tec_file=tec_files[(sec_date,)][0],
lat=latc,
lon=lonc,
)
Expand Down
24 changes: 11 additions & 13 deletions src/dolphin/atmosphere/troposphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ def estimate_tropospheric_delay(
tropo_height_levels = np.concatenate(([-100], np.arange(0, 9000, 500)))

for key in slc_files:
if len(key) == 1:
first_date = key
if "compressed" not in str(slc_files[key][0]).lower():
one_of_slcs = slc_files[key][0]
break
wavelength = oput.get_radar_wavelength(slc_files[first_date][0])

wavelength = oput.get_radar_wavelength(one_of_slcs)

tropo_run = compute_pyaps if tropo_package.lower() == "pyaps" else compute_raider

Expand All @@ -154,7 +155,7 @@ def estimate_tropospheric_delay(
output_tropo_dir.mkdir(exist_ok=True)
output_paths: list[Path] = []
for ifg in ifg_file_list:
ref_date, sec_date = get_dates(ifg)
ref_date, sec_date = get_dates(ifg)[0:2]

date_str = format_date_pair(ref_date, sec_date)
name = f"{date_str}_tropoDelay_pyaps_{tropo_model.value}_LOS_{delay_type}.tif"
Expand All @@ -165,18 +166,15 @@ def estimate_tropospheric_delay(
logger.info(f"{tropo_delay_product_path} exists, skipping")
continue

reference_date = (ref_date,)
secondary_date = (sec_date,)
reference_date = next(key for key in slc_files if ref_date in key)
secondary_date = next(key for key in slc_files if sec_date in key)

if (
reference_date not in troposphere_files
or secondary_date not in troposphere_files
):
if (ref_date,) not in troposphere_files or (sec_date,) not in troposphere_files:
logger.warning(f"Weather-model files do not exist for {date_str}, skipping")
continue

secondary_time = oput.get_zero_doppler_time(slc_files[secondary_date][0])
if len(slc_files[reference_date]) == 0:
if "compressed" in str(slc_files[reference_date][0]).lower():
# this is for when we have compressed slcs but the actual
# reference date does not exist in the input data
reference_time = datetime.datetime.combine(
Expand All @@ -196,8 +194,8 @@ def estimate_tropospheric_delay(
wavelength=wavelength,
shape=(ysize, xsize),
geotransform=gt,
reference_file=troposphere_files[reference_date],
secondary_file=troposphere_files[secondary_date],
reference_file=troposphere_files[(ref_date,)],
secondary_file=troposphere_files[(sec_date,)],
reference_time=reference_time,
secondary_time=secondary_time,
interferogram=format_date_pair(ref_date, sec_date),
Expand Down
2 changes: 1 addition & 1 deletion src/dolphin/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def from_filename(
) -> CompressedSlcInfo:
"""Parse just the dates from a compressed SLC filename."""
try:
ref, start, end = get_dates(filename, fmt=date_fmt)
ref, start, end = get_dates(filename, fmt=date_fmt)[0:3]
except IndexError as e:
msg = f"{filename} does not have 3 dates like {date_fmt}"
raise ValueError(msg) from e
Expand Down

0 comments on commit 23204ad

Please sign in to comment.