Skip to content

Commit d8a9897

Browse files
authored
using ocf_datapipes in Open-Source-Quartz-Solar-Forecast (#76)
* accessing ocf_datapipes in quartz project * refactoring of code * moved datapipes to scripts
1 parent 0cda6fa commit d8a9897

File tree

4 files changed

+83
-1
lines changed

4 files changed

+83
-1
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
.env
1+
.env
2+
scripts/datapipes/test.nc
3+
scripts/datapipes/UK_PV_metadata.csv
4+
scripts/datapipes/nwp_data

scripts/datapipes/__init__.py

Whitespace-only changes.

scripts/datapipes/ocf_datapipe.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import ocf_datapipes # noqa
2+
from ocf_datapipes.training.example.simple_pv import simple_pv_datapipe
3+
from ocf_datapipes.training.example.pv_nwp import pv_nwp_datapipe
4+
from ocf_datapipes.batch import BatchKey
5+
from datetime import datetime
6+
import os
7+
import certifi
8+
import ssl
9+
import warnings
10+
11+
# Suppress warnings and configure SSL certificate for secure connections
12+
warnings.filterwarnings("ignore")
13+
os.environ['SSL_CERT_FILE'] = certifi.where()
14+
ssl._create_default_https_context = ssl._create_unverified_context
15+
16+
def process_ocf_datapipes(config_file):
17+
18+
"""
19+
This function demonstrates the use of Open Climate Fix's datapipes with the Open Source Quartz Solar Forecast Project.
20+
It is an exploratory integration and not currently utilized in the Quartz Solar Forecast production pipeline.
21+
22+
It processes solar power (PV) and numerical weather prediction (NWP) data to prepare it for forecasting tasks.
23+
24+
:param config_file: The config file that specifies the paths to the data files, data preprocessing parameters, and other configurations necessary for the datapipes to function correctly.
25+
- 'pv_and_nwp_config.yaml' specifes the paths to necessary data files (e.g., PV output data, NWP data).
26+
- The YAML file needs to be edited to reflect the correct paths to your data files and any specific preprocessing requirements for your project.
27+
28+
This script is meant as a starting point for integrating Open Climate Fix datapipes into the Quartz Solar Forecast Project, serving as an example of how to preprocess and load data for solar power forecasting.
29+
"""
30+
31+
pv_data_pipe = simple_pv_datapipe(configuration_filename=config_file)
32+
pv_nwp_data_pipe = pv_nwp_datapipe(configuration_filename=config_file)
33+
34+
## Pv datapipe: store the first batch of processed data for inspection
35+
pv_batch = next(iter(pv_data_pipe))
36+
37+
# Access the batch elements through batch keys: Convert the first set of timestamps to readable dates
38+
pv_times_readable = [datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') for ts in pv_batch[BatchKey.pv_time_utc][0]]
39+
print("Readable PV Times:", pv_times_readable)
40+
41+
# Check Observed Capacity (Wp), and Nominal Capacity (Wp) of the PV system
42+
observed_capacity = pv_batch[BatchKey.pv_observed_capacity_wp]
43+
nominal_capacity = pv_batch[BatchKey.pv_nominal_capacity_wp]
44+
45+
print("Observed Capacity (Wp):", observed_capacity)
46+
print("Nominal Capacity (Wp):", nominal_capacity)
47+
48+
# NWP_PV DataPipe: Retrieve and print NWP data from the batch
49+
pv_nwp_batch = next(iter(pv_nwp_data_pipe))
50+
nwp_data = pv_nwp_batch[BatchKey.nwp]
51+
print("NWP data", nwp_data)
52+
53+
54+
# Load configuration from YAML specifying data sources and processing parameters for datapipes
55+
config_file = 'pv_and_nwp_config.yaml'
56+
process_ocf_datapipes(config_file)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
input_data:
2+
pv:
3+
pv_files_groups:
4+
- label: solar_sheffield_passiv
5+
pv_filename: 'test.nc' # Available at https://github.com/openclimatefix/ocf_datapipes/blob/main/tests/data/pv/passiv/test.nc
6+
pv_metadata_filename: 'UK_PV_metadata.csv' # Available at https://github.com/openclimatefix/ocf_datapipes/blob/main/tests/data/pv/passiv/UK_PV_metadata.csv
7+
get_center: false
8+
pv_image_size_meters_height: 10000000
9+
pv_image_size_meters_width: 10000000
10+
nwp:
11+
ukv:
12+
nwp_channels:
13+
- t
14+
nwp_image_size_pixels_height: 2
15+
nwp_image_size_pixels_width: 2
16+
nwp_zarr_path: nwp_data/test.zarr # Available at https://github.com/openclimatefix/ocf_datapipes/tree/main/tests/data/nwp_data/test.zarr
17+
nwp_provider: "ukv"
18+
history_minutes: 60
19+
forecast_minutes: 120
20+
time_resolution_minutes: 60
21+
index_by_id: True
22+
dropout_timedeltas_minutes: [-180]
23+
dropout_fraction: 1.0

0 commit comments

Comments
 (0)