Skip to content

Commit

Permalink
fix time filtering for NWP dropout (#217)
Browse files Browse the repository at this point in the history
* fix time filtering for NWP dropout

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
dfulu and pre-commit-ci[bot] authored Aug 7, 2023
1 parent 92e09ae commit e9cdcb4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
21 changes: 10 additions & 11 deletions ocf_datapipes/training/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def create_t0_and_loc_datapipes(
configuration: Configuration,
key_for_t0: str = "gsp",
shuffle: bool = True,
nwp_max_t0_offset: timedelta = timedelta(minutes=0),
nwp_max_dropout_minutes: int = 0,
):
"""
Takes source datapipes and returns datapipes of appropriate sample pairs of locations and times.
Expand All @@ -336,9 +336,9 @@ def create_t0_and_loc_datapipes(
key_for_t0: Key to use for the t0 datapipe. Must be "gsp" or "pv".
shuffle: Whether to use the internal shuffle function when yielding location times. Else
location times will be heavily ordered.
nwp_max_t0_offset: If using dropout on NWP, sometimes we have to go back to previous NWP
init time. In order to accomodat for this possibility in selecting times, set
`nwp_max_t0_offset` as the max NWP dropout delay you plan to use.
nwp_max_dropout_minutes: If using dropout on NWP, sometimes we have to go back to previous
NWP init time. In order to accomodate for this possibility in selecting times, set
`nwp_max_dropout_minutes` as the max NWP dropout delay you plan to use.
Returns:
location datapipe, t0 datapipe
Expand All @@ -357,38 +357,38 @@ def create_t0_and_loc_datapipes(

elif key == "nwp":
sample_frequency = 180 # Init times are 3 hours apart
history_duration = configuration.input_data.nwp.history_minutes

# If using NWP dropout we need to make sure the previous forecast is available
# Setting the history to larger here will do the required filtering
history_duration = max(
configuration.input_data.nwp.history_minutes, nwp_max_dropout_minutes
)
forecast_duration = configuration.input_data.nwp.forecast_minutes
time_dim = "init_time_utc"
max_t0_offset = nwp_max_t0_offset

elif key == "sat":
sample_frequency = 5
history_duration = configuration.input_data.satellite.history_minutes
forecast_duration = 0
time_dim = "time_utc"
max_t0_offset = timedelta(minutes=0)

elif key == "hrv":
sample_frequency = 5
history_duration = configuration.input_data.hrvsatellite.history_minutes
forecast_duration = 0
time_dim = "time_utc"
max_t0_offset = timedelta(minutes=0)

elif key == "pv":
sample_frequency = 5
history_duration = configuration.input_data.pv.history_minutes
forecast_duration = configuration.input_data.pv.forecast_minutes
time_dim = "time_utc"
max_t0_offset = timedelta(minutes=0)

elif key == "gsp":
sample_frequency = 30
history_duration = configuration.input_data.gsp.history_minutes
forecast_duration = configuration.input_data.gsp.forecast_minutes
time_dim = "time_utc"
max_t0_offset = timedelta(minutes=0)

else:
raise ValueError(f"Unexpected key: {key}")
Expand All @@ -400,7 +400,6 @@ def create_t0_and_loc_datapipes(
history_duration=timedelta(minutes=history_duration),
forecast_duration=timedelta(minutes=forecast_duration),
time_dim=time_dim,
max_t0_offset=max_t0_offset,
)

contiguous_time_datapipes.append(time_periods)
Expand Down
2 changes: 1 addition & 1 deletion ocf_datapipes/training/pvnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def construct_loctime_pipelines(
configuration=config,
key_for_t0="gsp",
shuffle=True,
nwp_max_t0_offset=minutes(180),
nwp_max_dropout_minutes=180,
)

return location_pipe, t0_datapipe
Expand Down

0 comments on commit e9cdcb4

Please sign in to comment.