Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
Reimplementing edits from Mads that have been removed during the merge of `develop` into this branch

some frequency and iloc updated to remove deprecation warning
  • Loading branch information
BaptisteVandecrux committed Aug 15, 2024
1 parent 885fae3 commit 03b7546
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/pypromice/postprocess/create_bufr_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def create_bufr_files(
Suffix for the compiled output file
"""
periods = pd.date_range(period_start, period_end, freq="H")
periods = pd.date_range(period_start, period_end, freq="h")
output_individual_root = output_root / "individual"
output_compiled_root = output_root / "compiled"
output_individual_root.mkdir(parents=True, exist_ok=True)
Expand Down
4 changes: 2 additions & 2 deletions src/pypromice/postprocess/real_time_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ 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, 3)
# limit to single most recent valid row (convert to series)
s_current = df_limited.loc[last_valid_index]

Expand Down
5 changes: 3 additions & 2 deletions src/pypromice/process/L2toL3.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def toL3(L2, station_config={}, T_0=273.15):

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))
Expand Down Expand Up @@ -193,7 +194,7 @@ def process_surface_height(ds, station_config={}):
ts_interpolated = np.minimum(
xr.where(ds.z_ice_surf.notnull(),
ds.z_ice_surf,ds.z_surf_combined),
ds.z_surf_combined).to_series().resample('H').interpolate(limit=72)
ds.z_surf_combined).to_series().resample('h').interpolate(limit=72)

if len(ts_interpolated)>24*7:
# Apply the rolling window with median calculation
Expand Down Expand Up @@ -337,7 +338,7 @@ def combine_surface_height(df, site_type, threshold_ablation = -0.0002):
# meaning when smoothed_z_pt.diff() < threshold_ablation
# first smoothing
smoothed_PT = (df['z_ice_surf']
.resample('H')
.resample('h')
.interpolate(limit=72)
.rolling('14D',center=True, min_periods=1)
.mean())
Expand Down
2 changes: 1 addition & 1 deletion src/pypromice/process/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def addMeta(ds, meta):
time_diff = pd.Timedelta((ds['time'][1] - ds['time'][0]).values)
if time_diff == pd.Timedelta('10min'):
sample_rate = "10min"
elif time_diff == pd.Timedelta('1H'):
elif time_diff == pd.Timedelta('1h'):
sample_rate = "hourly"
elif time_diff == pd.Timedelta('1D'):
sample_rate = "daily"
Expand Down
1 change: 1 addition & 0 deletions tests/data/test_config1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ station_id = 'TEST1'
logger_type = 'CR1000X'
nodata = ['-999', 'NAN'] # if one is a string, all must be strings
number_of_booms = 1 #1-boom = promice, 2-boom = gc-net
site_type = 'ablation'
latitude = 79.91
longitude = 24.09

Expand Down
1 change: 1 addition & 0 deletions tests/data/test_config2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ station_id = 'TEST2'
logger_type = 'CR1000X'
nodata = ['-999', 'NAN'] # if one is a string, all must be strings
number_of_booms = 2
site_type = 'accumulation'

['test_raw_transmitted2.txt']
format = 'TX'
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/qc/test_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_persistent_period_longer_than_period_threshold(self):
input_series = pd.Series(index=time_range, data=np.arange(0, len(time_range)))
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
expected_output.iloc[expected_filter_start:expected_filter_end] = True

persistent_mask = find_persistent_regions(
input_series, min_repeats=min_repeats, max_diff=0.001
Expand Down Expand Up @@ -175,19 +175,19 @@ def test_get_duration_consecutive_true(self):
np.isnan(duration_consecutive_true[0]), "The first index should be ignored"
)
np.testing.assert_almost_equal(
duration_consecutive_true[1],
duration_consecutive_true.iloc[1],
delta_time_hours[1],
)
np.testing.assert_almost_equal(
duration_consecutive_true[6],
duration_consecutive_true.iloc[6],
delta_time_hours[6],
)
np.testing.assert_almost_equal(
duration_consecutive_true[10:14],
duration_consecutive_true.iloc[10:14],
delta_time_hours[10:14].cumsum(),
)
np.testing.assert_almost_equal(
duration_consecutive_true[-3:],
duration_consecutive_true.iloc[-3:],
delta_time_hours[-3:].cumsum(),
)

Expand Down

0 comments on commit 03b7546

Please sign in to comment.