Skip to content

Commit

Permalink
more instructive error messages + some deprecation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BaptisteVandecrux committed Aug 15, 2024
1 parent 3897140 commit 2818bcb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/pypromice/postprocess/real_time_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get_latest_data(

# Apply smoothing to z_boom_u
# require at least 2 hourly obs? Sometimes seeing once/day data for z_boom_u
df_limited = rolling_window(df_limited, "z_boom_u", "72H", 2, 1)
df_limited = rolling_window(df_limited, "z_boom_u", "72h", 2, 1)

# limit to single most recent valid row (convert to series)
s_current = df_limited.loc[last_valid_index]
Expand Down
19 changes: 15 additions & 4 deletions src/pypromice/process/L2toL3.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,31 @@ def toL3(L2, station_config={}, T_0=273.15):
else:
logger.info('t_l, p_l or rh_l_cor missing, cannot calulate tubrulent heat fluxes')

# Smoothing and inter/extrapolation of GPS coordinates
if len(station_config)==0:
logger.warning('\n***\nThe station configuration file is missing or improperly passed to pypromice. Some processing steps might fail.\n***\n')
# Smoothing and inter/extrapolation of GPS coordinates
for var in ['gps_lat', 'gps_lon', 'gps_alt']:
ds[var.replace('gps_','')] = ('time', gps_coordinate_postprocessing(ds, var, station_config))

# processing continuous surface height, ice surface height, snow height
try:
ds = process_surface_height(ds, station_config)
except Exception as e:
logger.error("Error processing surface height at %s"%station_config['stid'])
logger.error("Error processing surface height at %s"%L2.attrs['station_id'])
logging.error(e, exc_info=True)

# making sure dataset has the attributes contained in the config files
ds.attrs['project'] = station_config['project']
ds.attrs['location_type'] = station_config['location_type']
if 'project' in station_config.keys():
ds.attrs['project'] = station_config['project']
else:
logger.error('No project info in station_config. Using \"PROMICE\".')
ds.attrs['project'] = "PROMICE"

if 'location_type' in station_config.keys():
ds.attrs['location_type'] = station_config['location_type']
else:
logger.error('No project info in station_config. Using \"ice sheet\".')
ds.attrs['location_type'] = "ice sheet"

return ds

Expand Down
18 changes: 9 additions & 9 deletions tests/unit/qc/test_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def _test_1_hour_repeat(self, index: int):
start="2023-01-26", end="2023-01-27", freq="h", tz="utc", inclusive="left"
)
input_series = pd.Series(index=time_range, data=np.arange(0, len(time_range)))
input_series[index + 1] = input_series[index]
input_series.iloc[index + 1] = input_series.iloc[index]
min_repeats = 1
expected_output = input_series.map(lambda _: False)
expected_output[index + 1] = True
expected_output.iloc[index + 1] = True

persistent_mask = find_persistent_regions(
input_series, min_repeats=min_repeats, max_diff=0.001
Expand Down Expand Up @@ -62,7 +62,7 @@ def test_persistent_period_longer_than_period_threshold(self):
expected_filter_start = 27
expected_filter_end = 33
input_series = pd.Series(index=time_range, data=np.arange(0, len(time_range)))
input_series[index_start:index_end] = input_series[index_start]
input_series.iloc[index_start:index_end] = input_series.iloc[index_start]
expected_output = input_series.map(lambda _: False)
expected_output[expected_filter_start:expected_filter_end] = True

Expand All @@ -82,7 +82,7 @@ def test_period_threshold_longer_than_persistent_period(self):
index_end = 27
min_repeats = 10
input_series = pd.Series(index=time_range, data=np.arange(0, len(time_range)))
input_series[index_start:index_end] = input_series[index_start]
input_series.iloc[index_start:index_end] = input_series.iloc[index_start]
expected_output = input_series.map(lambda _: False)

persistent_mask = find_persistent_regions(
Expand All @@ -101,7 +101,7 @@ def test_persistent_period_at_the_end(self):
min_repeats = 4
expected_filter_start = 27
input_series = pd.Series(index=time_range, data=np.arange(0, len(time_range)))
input_series[index_start:] = input_series[index_start]
input_series.iloc[index_start:] = input_series.iloc[index_start]
expected_output = input_series.map(lambda _: False)
expected_output[expected_filter_start:] = True

Expand All @@ -121,10 +121,10 @@ def test_dont_filter_nan_values(self):
index=time_range, data=np.zeros_like(time_range, dtype="float")
)
min_repeats = 4
input_series[:] = np.nan
input_series[9] = -11
input_series[10:12] = -10
input_series[15] = -9
input_series.iloc[:] = np.nan
input_series.iloc[9] = -11
input_series.iloc[10:12] = -10
input_series.iloc[15] = -9
# There are >=4 repeats if the nan values are forward filled. [10:15] == -10
# The output mask shouldn't filter nan values.
expected_output = input_series.map(lambda _: False)
Expand Down

0 comments on commit 2818bcb

Please sign in to comment.