Skip to content

Commit

Permalink
Add site backtest script (#192)
Browse files Browse the repository at this point in the history
Add site PVNet backtest functionality
  • Loading branch information
Sukh-P authored May 16, 2024
1 parent 9e6bc2e commit ef0c4e1
Show file tree
Hide file tree
Showing 6 changed files with 519 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ val data batches, you can now train PVNet by running:
python run.py
```

## Backtest

If you have succesfully trained a PVNet model and have a saved model checkpoint you can create a backtest using this, e.g. forecasts on historical data to evaluate forecast accuracy/skill. This can be done by running one of the scripts in this repo such as [the UK gsp backtest script](scripts/backtest_uk_gsp.py) or the [the pv site backtest script](scripts/backtest_sites.py), further info on how to run these are in each backtest file.


## Testing

You can use `python -m pytest tests` to run tests
2 changes: 1 addition & 1 deletion pvnet/data/pv_site_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _get_datapipe(self, start_time, end_time):
def _get_premade_batches_datapipe(self, subdir, shuffle=False):
filenames = list(glob.glob(f"{self.batch_dir}/{subdir}/*.nc"))
data_pipeline = pvnet_site_netcdf_datapipe(
keys=["pv", "nwp"],
keys=["pv", "nwp"], # add other keys e.g. sat if used as input in site model
filenames=filenames,
)
data_pipeline = (
Expand Down
28 changes: 28 additions & 0 deletions pvnet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,34 @@ def __call__(self, gsp_id: int) -> Location:
)


class SiteLocationLookup:
"""Query object for site location from site ID"""

def __init__(self, long: xr.DataArray, lat: xr.DataArray):
"""Query object for site location from site ID
Args:
long: DataArray of the longitude coordinates for any given site ID
lat: DataArray of the latitude coordinates for any given site ID
"""
self.longitude = long
self.latitude = lat

def __call__(self, site_id: int) -> Location:
"""Returns the locations for the input site IDs.
Args:
site_id: Integer ID of the site
"""
return Location(
coordinate_system="lon_lat",
x=self.longitude.sel(pv_system_id=site_id).item(),
y=self.latitude.sel(pv_system_id=site_id).item(),
id=site_id,
)


def extras(config: DictConfig) -> None:
"""A couple of optional utilities.
Expand Down
Loading

0 comments on commit ef0c4e1

Please sign in to comment.