PVNet 2.5.0__tar.gz → 2.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. PVNet-2.6.0/PKG-INFO +377 -0
  2. PVNet-2.6.0/PVNet.egg-info/PKG-INFO +377 -0
  3. {PVNet-2.5.0 → PVNet-2.6.0}/PVNet.egg-info/requires.txt +1 -1
  4. PVNet-2.6.0/README.md +339 -0
  5. PVNet-2.6.0/pvnet/__init__.py +2 -0
  6. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/data/utils.py +1 -2
  7. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/base_model.py +1 -1
  8. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/baseline/last_value.py +1 -1
  9. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/baseline/single_value.py +1 -1
  10. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/multimodal/deep_supervision.py +1 -1
  11. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/multimodal/multimodal.py +1 -1
  12. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/multimodal/nwp_weighting.py +1 -1
  13. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/multimodal/site_encoders/encoders.py +1 -1
  14. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/multimodal/weather_residual.py +1 -1
  15. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/utils.py +1 -1
  16. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/utils.py +2 -1
  17. {PVNet-2.5.0 → PVNet-2.6.0}/requirements.txt +1 -1
  18. {PVNet-2.5.0 → PVNet-2.6.0}/tests/conftest.py +1 -1
  19. PVNet-2.5.0/PKG-INFO +0 -81
  20. PVNet-2.5.0/PVNet.egg-info/PKG-INFO +0 -81
  21. PVNet-2.5.0/README.md +0 -43
  22. PVNet-2.5.0/pvnet/__init__.py +0 -2
  23. {PVNet-2.5.0 → PVNet-2.6.0}/LICENSE +0 -0
  24. {PVNet-2.5.0 → PVNet-2.6.0}/MANIFEST.in +0 -0
  25. {PVNet-2.5.0 → PVNet-2.6.0}/PVNet.egg-info/SOURCES.txt +0 -0
  26. {PVNet-2.5.0 → PVNet-2.6.0}/PVNet.egg-info/dependency_links.txt +0 -0
  27. {PVNet-2.5.0 → PVNet-2.6.0}/PVNet.egg-info/top_level.txt +0 -0
  28. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/callbacks.py +0 -0
  29. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/data/__init__.py +0 -0
  30. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/data/datamodule.py +0 -0
  31. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/data/wind_datamodule.py +0 -0
  32. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/__init__.py +0 -0
  33. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/baseline/__init__.py +0 -0
  34. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/multimodal/__init__.py +0 -0
  35. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/multimodal/basic_blocks.py +0 -0
  36. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/multimodal/encoders/__init__.py +0 -0
  37. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/multimodal/encoders/basic_blocks.py +0 -0
  38. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/multimodal/encoders/encoders2d.py +0 -0
  39. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/multimodal/encoders/encoders3d.py +0 -0
  40. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/multimodal/encoders/encodersRNN.py +0 -0
  41. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/multimodal/linear_networks/__init__.py +0 -0
  42. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/multimodal/linear_networks/basic_blocks.py +0 -0
  43. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/multimodal/linear_networks/networks.py +0 -0
  44. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/multimodal/site_encoders/__init__.py +0 -0
  45. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/models/multimodal/site_encoders/basic_blocks.py +0 -0
  46. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/optimizers.py +0 -0
  47. {PVNet-2.5.0 → PVNet-2.6.0}/pvnet/training.py +0 -0
  48. {PVNet-2.5.0 → PVNet-2.6.0}/pyproject.toml +0 -0
  49. {PVNet-2.5.0 → PVNet-2.6.0}/requirements-dev.txt +0 -0
  50. {PVNet-2.5.0 → PVNet-2.6.0}/setup.cfg +0 -0
  51. {PVNet-2.5.0 → PVNet-2.6.0}/setup.py +0 -0
  52. {PVNet-2.5.0 → PVNet-2.6.0}/tests/__init__.py +0 -0
PVNet-2.6.0/PKG-INFO ADDED
@@ -0,0 +1,377 @@
1
+ Metadata-Version: 2.1
2
+ Name: PVNet
3
+ Version: 2.6.0
4
+ Summary: PVNet
5
+ Author: Peter Dudfield
6
+ Author-email: info@openclimatefix.org
7
+ License: MIT
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: ocf_datapipes>=3.0.0
11
+ Requires-Dist: ocf_ml_metrics
12
+ Requires-Dist: numpy
13
+ Requires-Dist: pandas
14
+ Requires-Dist: matplotlib
15
+ Requires-Dist: xarray
16
+ Requires-Dist: ipykernel
17
+ Requires-Dist: h5netcdf
18
+ Requires-Dist: torch>=2.0.0
19
+ Requires-Dist: lightning>=2.0.1
20
+ Requires-Dist: torchvision
21
+ Requires-Dist: pytest
22
+ Requires-Dist: pytest-cov
23
+ Requires-Dist: typer
24
+ Requires-Dist: sqlalchemy
25
+ Requires-Dist: fsspec[s3]
26
+ Requires-Dist: wandb
27
+ Requires-Dist: huggingface-hub
28
+ Requires-Dist: tensorboard
29
+ Requires-Dist: tqdm
30
+ Requires-Dist: omegaconf
31
+ Requires-Dist: hydra-core
32
+ Requires-Dist: python-dotenv
33
+ Requires-Dist: hydra-optuna-sweeper
34
+ Requires-Dist: rich
35
+ Provides-Extra: all-models
36
+ Requires-Dist: pytorch-tabnet; extra == "all-models"
37
+ Requires-Dist: efficientnet_pytorch; extra == "all-models"
38
+
39
+ # PVNet 2.1
40
+
41
+ [![test-release](https://github.com/openclimatefix/PVNet/actions/workflows/test-release.yml/badge.svg)](https://github.com/openclimatefix/PVNet/actions/workflows/test-release.yml)
42
+
43
+ This project is used for training PVNet and running PVnet on live data.
44
+
45
+ PVNet2 largely inherits the same architecture from
46
+ [PVNet1.0](https://github.com/openclimatefix/predict_pv_yield). The NWP and
47
+ satellite data are sent through some neural network which encodes them down to
48
+ 1D intermediate representations. These are concatenated together with the GSP
49
+ output history, the calculated solar coordinates (azimuth and elevation) and the
50
+ GSP ID which has been put through an embedding layer. This 1D concatenated
51
+ feature vector is put through an output network which outputs predictions of the
52
+ future GSP yield. National forecasts are made by adding all the GSP forecasts
53
+ together.
54
+
55
+ ## Setup / Installation
56
+
57
+ ```bash
58
+ git clone https://github.com/openclimatefix/PVNet.git
59
+ cd PVNet
60
+ pip install -r requirements.txt
61
+ ```
62
+
63
+ ### Additional development dependencies
64
+
65
+ ```bash
66
+ pip install -r requirements-dev.txt
67
+ ```
68
+
69
+ ## Getting started with running PVNet
70
+
71
+ Before running any code in within PVNet, copy the example configuration to a
72
+ configs directory:
73
+
74
+ ```
75
+ cp -r configs.example configs
76
+ ```
77
+
78
+ You will be making local amendments to these configs
79
+
80
+ ### Datasets
81
+
82
+ As a minimum, in order to create batches of data/run PVNet, you will need to
83
+ supply paths to NWP and GSP data. PV data can also be used. We list some
84
+ suggested locations for downloading such datasets below:
85
+
86
+ **GSP (Grid Supply Point)** - Regional PV generation data\
87
+ The University of Sheffield provides API access to download this data:
88
+ https://www.solar.sheffield.ac.uk/pvlive/api/
89
+
90
+ Documentation for querying generation data aggregated by GSP region can be found
91
+ here:
92
+ https://docs.google.com/document/d/e/2PACX-1vSDFb-6dJ2kIFZnsl-pBQvcH4inNQCA4lYL9cwo80bEHQeTK8fONLOgDf6Wm4ze_fxonqK3EVBVoAIz/pub#h.9d97iox3wzmd
93
+
94
+ **NWP (Numerical weather predictions)**\
95
+ OCF maintains a Zarr formatted version the German Weather Service's (DWD)
96
+ ICON-EU NWP model here:
97
+ https://huggingface.co/datasets/openclimatefix/dwd-icon-eu which includes the UK
98
+
99
+ **PV**\
100
+ OCF maintains a dataset of PV generation from 1311 private PV installations
101
+ here: https://huggingface.co/datasets/openclimatefix/uk_pv
102
+
103
+ ### Generating pre-made batches of data for training/validation of PVNet
104
+
105
+ PVNet contains a script for generating batches of data suitable for training the
106
+ PVNet models.
107
+
108
+ To run the script you will need to make some modifications to the datamodule
109
+ configuration.
110
+
111
+ 1. First, create your new configuration file in
112
+ `./configs/datamodule/configiration/local_configuration.yaml` and paste the
113
+ sample config (shown below)
114
+ 2. Duplicate the `./configs/datamodule/ocf_datapipes.yaml` to
115
+ `./configs/datamodule/_local_ocf_datapipes.yaml` and ensure the
116
+ `configuration` key points to your newly created configuration file in
117
+ step 1.
118
+ 3. Also in this file, update the train, val & test periods to cover the data you
119
+ have access to.
120
+ 4. To get you started with your own configuration file, see the sample config
121
+ below. Update the data paths to the location of your local GSP, NWP and PV
122
+ datasets:
123
+
124
+ ```yaml
125
+ general:
126
+ description: Demo config
127
+ name: demo_datamodule_config
128
+
129
+ input_data:
130
+ default_history_minutes: 60
131
+ default_forecast_minutes: 120
132
+
133
+ gsp:
134
+ gsp_zarr_path: /path/to/gsp-data.zarr
135
+ history_minutes: 60
136
+ forecast_minutes: 120
137
+ time_resolution_minutes: 30
138
+ start_datetime: "2019-01-01T00:00:00"
139
+ end_datetime: "2019-01-08T00:00:00"
140
+ metadata_only: false
141
+
142
+ nwp:
143
+ ukv:
144
+ nwp_zarr_path: /path/to/nwp-data.zarr
145
+ history_minutes: 60
146
+ forecast_minutes: 120
147
+ time_resolution_minutes: 60
148
+ nwp_channels: # comment out channels as appropriate
149
+ - t # live = t2m
150
+ - dswrf
151
+ - dlwrf
152
+ - hcc
153
+ - MCC
154
+ - lcc
155
+ - vis
156
+ - r # live = r2
157
+ - prate # live ~= rprate
158
+ - si10 # 10-metre wind speed | live = unknown
159
+ nwp_image_size_pixels_height: 24
160
+ nwp_image_size_pixels_width: 24
161
+ nwp_provider: ukv
162
+
163
+ pv:
164
+ pv_files_groups:
165
+ - label: pvoutput.org
166
+ pv_filename: /path/to/pv-data/pv.netcdf
167
+ pv_metadata_filename: /path/to/pv-data/metadata.csv
168
+ history_minutes: 60
169
+ forecast_minutes: 0 # PVNet assumes no future PV generation
170
+ time_resolution_minutes: 5
171
+ start_datetime: "2019-01-01T00:00:00"
172
+ end_datetime: "2019-01-08T00:00:00"
173
+ pv_image_size_meters_height: 24
174
+ pv_image_size_meters_width: 24
175
+ pv_ml_ids: [154,155,156,158,159,160,162,164,165,166,167,168,169,171,173,177,178,179,181,182,185,186,187,188,189,190,191,192,193,197,198,199,200,202,204,205,206,208,209,211,214,215,216,217,218,219,220,221,225,229,230,232,233,234,236,242,243,245,252,254,255,256,257,258,260,261,262,265,267,268,272,273,275,276,277,280,281,282,283,287,289,291,292,293,294,295,296,297,298,301,302,303,304,306,307,309,310,311,317,318,319,320,321,322,323,325,326,329,332,333,335,336,338,340,342,344,345,346,348,349,352,354,355,356,357,360,362,363,368,369,370,371,372,374,375,376,378,380,382,384,385,388,390,391,393,396,397,398,399,400,401,403,404,405,406,407,409,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,429,431,435,437,438,440,441,444,447,450,451,453,456,457,458,459,464,465,466,467,468,470,471,473,474,476,477,479,480,481,482,485,486,488,490,491,492,493,496,498,501,503,506,507,508,509,510,511,512,513,515,516,517,519,520,521,522,524,526,527,528,531,532,536,537,538,540,541,542,543,544,545,549,550,551,552,553,554,556,557,560,561,563,566,568,571,572,575,576,577,579,580,581,582,584,585,588,590,594,595,597,600,602,603,604,606,611,613,614,616,618,620,622,623,624,625,626,628,629,630,631,636,637,638,640,641,642,644,645,646,650,651,652,653,654,655,657,660,661,662,663,666,667,668,670,675,676,679,681,683,684,685,687,696,698,701,702,703,704,706,710,722,723,724,725,727,728,729,730,732,733,734,735,736,737,]
176
+ n_pv_systems_per_example: 128
177
+ get_center: false
178
+ is_live: false
179
+
180
+ satellite:
181
+ satellite_zarr_path: "" # Left empty to avoid using satellite data
182
+ history_minutes: 60
183
+ forecast_minutes: 0
184
+ live_delay_minutes: 30
185
+ time_resolution_minutes: 5
186
+ satellite_channels:
187
+ - IR_016
188
+ - IR_039
189
+ - IR_087
190
+ - IR_097
191
+ - IR_108
192
+ - IR_120
193
+ - IR_134
194
+ - VIS006
195
+ - VIS008
196
+ - WV_062
197
+ - WV_073
198
+ satellite_image_size_pixels_height: 24
199
+ satellite_image_size_pixels_width: 24
200
+ ```
201
+
202
+ With your configuration in place, you can proceed to create batches. PVNet uses
203
+ [hydra](https://hydra.cc/) which enables us to pass variables via the command
204
+ line that will override the configuration defined in the `./configs` directory.
205
+
206
+ Run the save_batches.py script to create batches with the following arguments as
207
+ a minimum:
208
+
209
+ ```
210
+ python scripts/save_batches.py datamodule=local_ocf_datapipes +batch_output_dir="./output" +num_train_batches=10 +num_val_batches=5
211
+ ```
212
+
213
+ ### Training PVNet
214
+
215
+ How PVNet is run is determined by the extensive configuration in the config
216
+ files. The following configs have been tested to work using batches of data
217
+ created using the steps and batch creation config mentioned above.
218
+
219
+ You should create the following configs before trying to train a model locally,
220
+ as so:
221
+
222
+ In `configs/datamodule/local_premade_batches.yaml`:
223
+
224
+ ```yaml
225
+ _target_: pvnet.data.datamodule.DataModule
226
+ configuration: null
227
+ batch_dir: "./output" # where the batches are saved
228
+ num_workers: 20
229
+ prefetch_factor: 2
230
+ batch_size: 8
231
+ ```
232
+
233
+ In `configs/model/local_multimodal.yaml`:
234
+
235
+ ```yaml
236
+ _target_: pvnet.models.multimodal.multimodal.Model
237
+
238
+ output_quantiles: [0.02, 0.1, 0.25, 0.5, 0.75, 0.9, 0.98]
239
+
240
+ #--------------------------------------------
241
+ # NWP encoder
242
+ #--------------------------------------------
243
+
244
+ nwp_encoders_dict:
245
+ ukv:
246
+ _target_: pvnet.models.multimodal.encoders.encoders3d.DefaultPVNet
247
+ _partial_: True
248
+ in_channels: 10
249
+ out_features: 256
250
+ number_of_conv3d_layers: 6
251
+ conv3d_channels: 32
252
+ image_size_pixels: 24
253
+
254
+ #--------------------------------------------
255
+ # Sat encoder settings
256
+ #--------------------------------------------
257
+
258
+ # Ignored as premade batches were created without satellite data
259
+ # sat_encoder:
260
+ # _target_: pvnet.models.multimodal.encoders.encoders3d.DefaultPVNet
261
+ # _partial_: True
262
+ # in_channels: 11
263
+ # out_features: 256
264
+ # number_of_conv3d_layers: 6
265
+ # conv3d_channels: 32
266
+ # image_size_pixels: 24
267
+
268
+ add_image_embedding_channel: False
269
+
270
+ #--------------------------------------------
271
+ # PV encoder settings
272
+ #--------------------------------------------
273
+
274
+ pv_encoder:
275
+ _target_: pvnet.models.multimodal.site_encoders.encoders.SingleAttentionNetwork
276
+ _partial_: True
277
+ num_sites: 349
278
+ out_features: 40
279
+ num_heads: 4
280
+ kdim: 40
281
+ pv_id_embed_dim: 20
282
+
283
+ #--------------------------------------------
284
+ # Tabular network settings
285
+ #--------------------------------------------
286
+
287
+ output_network:
288
+ _target_: pvnet.models.multimodal.linear_networks.networks.ResFCNet2
289
+ _partial_: True
290
+ fc_hidden_features: 128
291
+ n_res_blocks: 6
292
+ res_block_layers: 2
293
+ dropout_frac: 0.0
294
+
295
+ embedding_dim: 16
296
+ include_sun: True
297
+ include_gsp_yield_history: False
298
+
299
+ #--------------------------------------------
300
+ # Times
301
+ #--------------------------------------------
302
+
303
+ # Foreast and time settings
304
+ history_minutes: 60
305
+ forecast_minutes: 120
306
+
307
+ min_sat_delay_minutes: 60
308
+
309
+ sat_history_minutes: 90
310
+ pv_history_minutes: 60
311
+
312
+ # These must be set for each NWP encoder
313
+ nwp_history_minutes:
314
+ ukv: 60
315
+ nwp_forecast_minutes:
316
+ ukv: 120
317
+
318
+ # ----------------------------------------------
319
+ # Optimizer
320
+ # ----------------------------------------------
321
+ optimizer:
322
+ _target_: pvnet.optimizers.EmbAdamWReduceLROnPlateau
323
+ lr: 0.0001
324
+ weight_decay: 0.01
325
+ amsgrad: True
326
+ patience: 5
327
+ factor: 0.1
328
+ threshold: 0.002
329
+ ```
330
+
331
+ In `configs/local_trainer.yaml`:
332
+
333
+ ```yaml
334
+ _target_: lightning.pytorch.trainer.trainer.Trainer
335
+
336
+ accelerator: cpu # Important if running on a system without a supported GPU
337
+ devices: auto
338
+
339
+ min_epochs: null
340
+ max_epochs: null
341
+ reload_dataloaders_every_n_epochs: 0
342
+ num_sanity_val_steps: 8
343
+ fast_dev_run: false
344
+ accumulate_grad_batches: 4
345
+ log_every_n_steps: 50
346
+ ```
347
+
348
+ And finally update `defaults` in the main `./configs/config.yaml` file to use
349
+ your customised config files:
350
+
351
+ ```yaml
352
+ defaults:
353
+ - trainer: local_trainer.yaml
354
+ - model: local_multimodal.yaml
355
+ - datamodule: local_premade_batches.yaml
356
+ - callbacks: null
357
+ - logger: csv.yaml
358
+ - experiment: null
359
+ - hparams_search: null
360
+ - hydra: default.yaml
361
+ ```
362
+
363
+ Assuming you ran the `save_batches.py` script to generate some premade train and
364
+ val data batches, you can now train PVNet by running:
365
+
366
+ ```
367
+ python run.py
368
+ ```
369
+
370
+ ## Testing
371
+
372
+ You can use `python -m pytest tests` to run tests
373
+
374
+ ## Experiments
375
+
376
+ Notes on these experiments are
377
+ [here](https://docs.google.com/document/d/1fbkfkBzp16WbnCg7RDuRDvgzInA6XQu3xh4NCjV-WDA/edit?usp=sharing).