Skip to content

Commit

Permalink
modification to enable WW3 spectra from CCI sea state runs to be co-l…
Browse files Browse the repository at this point in the history
…ocated
  • Loading branch information
agrouaze committed Jan 28, 2025
1 parent f575d1c commit 27f0ffd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
20 changes: 15 additions & 5 deletions slcl1butils/coloc/coloc_IW_WW3spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,13 @@ def check_colocation(cartesianspWW3, lon, lat, time):
return coloc_ds


def resampleWW3spectra_on_TOPS_SAR_cartesian_grid(dsar, xspeckind):
def resampleWW3spectra_on_TOPS_SAR_cartesian_grid(dsar, xspeckind, nameWW3sp_product):
"""
Args:
dsar: xarray.core.Dataset IW Level-1B IFREMER dataset
xspeckind: str inter or intra
nameWW3sp_product: str example "ww3CCIseastate_spectra"
Returns:
"""
Expand All @@ -149,7 +150,7 @@ def resampleWW3spectra_on_TOPS_SAR_cartesian_grid(dsar, xspeckind):
start_date_dt = datetime.datetime.strptime(
dsar.attrs["start_date"], "%Y-%m-%d %H:%M:%S.%f"
)
pathww3sp = get_ww3HINDCAST_TRCKspectra_path_from_date(sar_date=start_date_dt)
pathww3sp = get_ww3_path_from_date(sar_date=start_date_dt,nameWW3sp_product=nameWW3sp_product)
gridsar = {
d: k
for d, k in dsar.sizes.items()
Expand Down Expand Up @@ -296,11 +297,13 @@ def resampleWW3spectra_on_TOPS_SAR_cartesian_grid(dsar, xspeckind):
return dsar, flag_ww3spectra_added, flag_ww3spectra_found


def get_ww3HINDCAST_TRCKspectra_path_from_date(sar_date):
def get_ww3_path_from_date(sar_date,nameWW3sp_product):
"""
Args:
sar_date: (datetime)
nameWW3sp_product : (str) eg ww3CCIseastate_spectra
Returns:
filename (str): path of the TRCK WW3 HINDCAST corresponding to the
Expand All @@ -309,10 +312,17 @@ def get_ww3HINDCAST_TRCKspectra_path_from_date(sar_date):

filename = None
conf = get_conf()
pattern = conf["ww3hindcast_track_pattern"].replace(
if 'ww3handcast_track_pattern' in nameWW3sp_product:
pattern = conf["ww3hindcast_track_pattern"].replace(
"LOPS_WW3-GLOB-30M_*_trck.nc",
"LOPS_WW3-GLOB-30M_" + sar_date.strftime("%Y%m") + "_trck.nc",
)
)
elif 'ww3CCIseastate_spectra' in nameWW3sp_product:
pattern = conf['auxilliary_dataset'][nameWW3sp_product]['pattern'].replace('%Y/',sar_date.strftime("%Y/")).replace('%Y%m',sar_date.strftime("%Y%m"))

else:
raise ValueError('nameWW3sp_product: not handled : %s'%nameWW3sp_product)
logging.info('pattern for spectra : %s',pattern)
datefound, pattern2 = resource_strftime(pattern, step=0.5, date=sar_date)
filenames = glob.glob(pattern2)

Expand Down
21 changes: 14 additions & 7 deletions slcl1butils/scripts/do_IW_L1C_SAFE_from_L1B_SAFE.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,21 +213,27 @@ def enrich_onesubswath_l1b(
ancillary_list[ancillary_name], ds_intra, ds_inter
)
flag_ancillaries[ancillary_name] = ancillary_fields_added
if "ww3hindcast_spectra" in ancillary_list:
if "ww3hindcast_spectra" in ancillary_list or 'ww3CCIseastate_spectra' in ancillary_list:
idx = None
for uui,uu in enumerate(ancillary_list):
if 'spectra' in uu:
idx = uu
ww3spectra_matching_name = ancillary_list[idx]['name']
logging.info('the product used to add wave spectra is: %s',ww3spectra_matching_name)
(
ds_intra,
flag_ww3spectra_added,
flag_ww3spectra_found,
) = resampleWW3spectra_on_TOPS_SAR_cartesian_grid(
dsar=ds_intra, xspeckind="intra"
dsar=ds_intra, xspeckind="intra",nameWW3sp_product=ww3spectra_matching_name
)
flag_ancillaries["ww3spectra_intra"] = flag_ww3spectra_added
(
ds_inter,
flag_ww3spectra_added,
flag_ww3spectra_found,
) = resampleWW3spectra_on_TOPS_SAR_cartesian_grid(
dsar=ds_inter, xspeckind="inter"
dsar=ds_inter, xspeckind="inter",nameWW3sp_product=ww3spectra_matching_name
)
flag_ancillaries["ww3spectra_inter"] = flag_ww3spectra_added
return ds_intra, ds_inter, flag_ancillaries
Expand Down Expand Up @@ -271,7 +277,7 @@ def append_ancillary_field(ancillary, ds_intra, ds_inter):
raster_ds = ww3_global_yearly_3h(filename, closest_date)
elif ancillary["name"] == "ww3hindcast_field":
raster_ds = ww3_IWL1Btrack_hindcasts_30min(glob(filename)[0], closest_date)
elif ancillary["name"] == "ww3hindcast_spectra":
elif ancillary["name"] in ["ww3hindcast_spectra","ww3CCIseastate_spectra"]:
pass # nothing to do here, there is a specific method called later in the code.
return ds_intra, ds_inter, ancillary_fields_added
else:
Expand Down Expand Up @@ -428,9 +434,10 @@ def main():
"ww3hindcast_field": conf["auxilliary_dataset"]["ww3hindcast_field"],
}
if args.ww3spectra:
ancillary_list["ww3hindcast_spectra"] = conf["auxilliary_dataset"][
"ww3hindcast_spectra"
]
#ancillary_list["ww3hindcast_spectra"] = conf["auxilliary_dataset"][
# "ww3hindcast_spectra"
#]
ancillary_list["ww3CCIseastate_spectra"] = conf["auxilliary_dataset"]["ww3CCIseastate_spectra"]
final_L1C_path = do_L1C_SAFE_from_L1B_SAFE(
args.l1bsafe,
version=args.version,
Expand Down

0 comments on commit 27f0ffd

Please sign in to comment.