Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better gestion of error for recalibration #230

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
14 changes: 1 addition & 13 deletions src/xsar/config.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
# default data dir for tests and examples
data_dir: /tmp
auxiliary_dir:
path_auxiliary_df:

auxiliary_names:
S1B:
v_IPF_36:
AUX_PP1: 'S1B_AUX_PP1_V20160422T000000_G20220323T140710.SAFE'
AUX_CAL: 'S1B_AUX_CAL_V20160422T000000_G20210104T140113.SAFE'
#AUX_INS: 'S1B_AUX_INS_V20160422T000000_G20211027T134314.SAFE'
S1A:
v_IPF_36:
AUX_PP1: 'S1A_AUX_PP1_V20190228T092500_G20220323T153041.SAFE'
AUX_CAL: 'S1A_AUX_CAL_V20190228T092500_G20210104T141310.SAFE'
#AUX_INS: 'S1A_AUX_INS_V20190228T092500_G20211103T111906.SAFE'}
path_auxiliary_df:
7 changes: 4 additions & 3 deletions src/xsar/raster_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def ecmwf_0100_1h(fname, **kwargs):
xarray.Dataset
"""
ecmwf_ds = xr.open_dataset(
fname, chunks={'Longitude': 1000, 'Latitude': 1000}).isel(time=0)
fname, chunks={'time': 1, 'latitude': 901, 'longitude': 1800}).isel(time=0)
ecmwf_ds.attrs['time'] = datetime.datetime.fromtimestamp(
ecmwf_ds.time.item() // 1000000000)
if 'time' in ecmwf_ds:
Expand Down Expand Up @@ -149,7 +149,7 @@ def hwrf_0015_3h(fname, **kwargs):
-------
xarray.Dataset
"""
hwrf_ds = xr.open_dataset(fname)
hwrf_ds = xr.open_dataset(fname, chunks={'t': 1, 'LAT': 700, 'LON': 700})
try:
hwrf_ds = hwrf_ds[['U', 'V', 'LON', 'LAT']]
hwrf_ds = hwrf_ds.squeeze('t', drop=True)
Expand Down Expand Up @@ -191,7 +191,8 @@ def era5_0250_1h(fname, **kwargs):
xarray.Dataset
"""

ds_era5 = xr.open_dataset(fname, chunks={'time': 1})
ds_era5 = xr.open_dataset(
fname, chunks={'time': 6, 'latitude025': 721, 'longitude025': 1440})
ds_era5 = ds_era5[['u10', 'v10', 'latitude025', 'longitude025']]
ds_era5 = ds_era5.sel(time=str(kwargs['date']), method="nearest")
ds_era5 = ds_era5.drop('time')
Expand Down
28 changes: 27 additions & 1 deletion src/xsar/sentinel1_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def __init__(self, dataset_id, resolution=None,
if self.apply_recalibration and np.all(np.isnan(self.datatree.antenna_pattern['roll'].values)):
self.apply_recalibration = False
raise ValueError(
f"Recalibration can't be done without roll angle. You probably work with an old file for which roll angle is not auxiliary file.")
f"Recalibration can't be done without roll angle. You probably work with an old file for which roll angle is not in auxiliary file.")

# self.datatree['measurement'].ds = .from_dict({'measurement':self._load_digital_number(resolution=resolution, resampling=resampling, chunks=chunks)
# self._dataset = self.datatree['measurement'].ds #the two variables should be linked then.
Expand Down Expand Up @@ -528,14 +528,40 @@ def add_high_resolution_variables(self, luts=False, patch_variable=True, skip_va
(dataframe_aux.aux_type == "CAL") &
(dataframe_aux.icid == int(self.sar_meta.manifest_attrs['icid'])) &
(dataframe_aux.validation_date <= self.sar_meta.start_date)]
# Check if sel_cal is empty
if sel_cal.empty:
sel_ = dataframe_aux.loc[(dataframe_aux.sat_name == self.sar_meta.manifest_attrs['satellite']) &
(dataframe_aux.aux_type == "CAL") &
(dataframe_aux.icid == int(self.sar_meta.manifest_attrs['icid']))]
if sel_.empty:
raise ValueError(
f"Cannot recalibrate - No matching CAL data found for your data : start_date : {self.sar_meta.start_date}.")
else:
raise ValueError(f"Cannot recalibrate - No matching CAL data found for your data: start_date: {self.sar_meta.start_date} & \
miniumum validation date in active aux files: {sel_.sort_values(by=['validation_date'], ascending=False).validation_date.values[0]}.")

sel_cal = sel_cal.sort_values(
by=["validation_date", "generation_date"], ascending=False)

path_new_cal = sel_cal.iloc[0].aux_path

sel_pp1 = dataframe_aux.loc[(dataframe_aux.sat_name == self.sar_meta.manifest_attrs['satellite']) &
(dataframe_aux.aux_type == "PP1") &
(dataframe_aux.icid == int(self.sar_meta.manifest_attrs['icid'])) &
(dataframe_aux.validation_date <= self.sar_meta.start_date)]

# Check if sel_pp1 is empty
if sel_pp1.empty:
sel_ = dataframe_aux.loc[(dataframe_aux.sat_name == self.sar_meta.manifest_attrs['satellite']) &
(dataframe_aux.aux_type == "PP1") &
(dataframe_aux.icid == int(self.sar_meta.manifest_attrs['icid']))]
if sel_.empty:
raise ValueError(
f"Cannot recalibrate - No matching PP1 data found for your data : start_date : {self.sar_meta.start_date}.")
else:
raise ValueError(f"Cannot recalibrate - No matching PP1 data found for your data: start_date: {self.sar_meta.start_date} & \
miniumum validation date in active aux files: {sel_.sort_values(by=['validation_date'], ascending=False).validation_date.values[0]}.")

sel_pp1 = sel_pp1.sort_values(
by=["validation_date", "generation_date"], ascending=False)
path_new_pp1 = sel_pp1.iloc[0].aux_path
Expand Down
Loading