Skip to content

Commit

Permalink
refactor coe
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdudfield committed Aug 2, 2024
1 parent da09475 commit 0f59e54
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions ocf_data_sampler/select/select_time_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@
from typing import Optional


def _sel_fillnan(ds, start_dt, end_dt, sample_period_duration: timedelta):
requested_times = pd.date_range(
start_dt,
end_dt,
freq=sample_period_duration,
)
# Missing time indexes are returned with all NaN values
return ds.reindex(time_utc=requested_times)


def _sel_default(ds, start_dt, end_dt):
return ds.sel(time_utc=slice(start_dt, end_dt))


# TODO either implement this or remove it, which would tidy up the code
def _sel_fillinterp(ds, start_dt, end_dt):
return NotImplemented


def select_time_slice(
ds: xr.Dataset | xr.DataArray,
Expand All @@ -30,30 +48,13 @@ def select_time_slice(
interval_start = np.timedelta64(interval_start)
interval_end = np.timedelta64(interval_end)

def _sel_fillnan(ds, start_dt, end_dt):
requested_times = pd.date_range(
start_dt,
end_dt,
freq=sample_period_duration,
)
# Missing time indexes are returned with all NaN values
return ds.reindex(time_utc=requested_times)

def _sel_default(ds, start_dt, end_dt):
return ds.sel(time_utc=slice(start_dt, end_dt))

def _sel_fillinterp(ds, start_dt, end_dt):
return NotImplemented


if fill_selection and max_steps_gap == 0:
_sel = _sel_fillnan
elif fill_selection and max_steps_gap > 0:
_sel = _sel_fillinterp
else:
_sel = _sel_default


t0_datetime_utc = pd.Timestamp(t0)
start_dt = t0_datetime_utc + interval_start
end_dt = t0_datetime_utc + interval_end
Expand Down

0 comments on commit 0f59e54

Please sign in to comment.