Skip to content

Commit

Permalink
Restoring to original grouping logic to resolve `reindex along dimens…
Browse files Browse the repository at this point in the history
…ion 'ping_time' because the (pandas) index has duplicate values`
  • Loading branch information
Sohambutala committed Sep 18, 2024
1 parent fb69f47 commit 085ba4c
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions echodataflow/utils/xr_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@ def fetch_slice_from_store(edf_group: Group, config: Dataset, options: Dict[str,
if ed.data is not None:
store = ed.data
else:
store = xr.open_mfdataset(paths=[ed.out_path for ed in edf_group.data], **default_options).compute()

store_slice = store.sel(ping_time=slice(pd.to_datetime(start_time, unit="ns"), pd.to_datetime(end_time, unit="ns")))

if store_slice["ping_time"].size == 0:
del store
del store_slice
raise ValueError(f"No data available between {start_time} and {end_time}")
store = xr.open_mfdataset(paths=[ed.out_path for ed in edf_group.data], **default_options)

if group:

store_slice_grouped = store_slice.sortby('ping_time')
store_slice_grouped = store.groupby('ping_time').mean()

for var in store_slice.data_vars:
if 'ping_time' in store_slice[var].dims:
store_slice_grouped[var] = store_slice[var].groupby('ping_time').mean()
# for var in store.data_vars:
# if 'ping_time' in store[var].dims:
# store_slice_grouped[var] = store[var].groupby('ping_time').mean()

store_slice = store_slice_grouped
store = store_slice_grouped
del store_slice_grouped

store_slice = store.sel(ping_time=slice(pd.to_datetime(start_time, unit="ns"), pd.to_datetime(end_time, unit="ns"))).compute()

if store_slice["ping_time"].size == 0:
del store
del store_slice
raise ValueError(f"No data available between {start_time} and {end_time}")

del store

return store_slice
Expand Down

0 comments on commit 085ba4c

Please sign in to comment.