PVNet 4.1.8__tar.gz → 4.1.10__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.
- {pvnet-4.1.8 → pvnet-4.1.10}/PKG-INFO +1 -1
- {pvnet-4.1.8 → pvnet-4.1.10}/PVNet.egg-info/PKG-INFO +1 -1
- {pvnet-4.1.8 → pvnet-4.1.10}/PVNet.egg-info/SOURCES.txt +0 -1
- pvnet-4.1.10/pvnet/__init__.py +2 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/base_model.py +53 -1
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/multimodal/multimodal.py +3 -3
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/multimodal/unimodal_teacher.py +3 -3
- pvnet-4.1.8/pvnet/__init__.py +0 -2
- pvnet-4.1.8/pvnet/models/multimodal/multimodal_base.py +0 -55
- {pvnet-4.1.8 → pvnet-4.1.10}/LICENSE +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/MANIFEST.in +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/PVNet.egg-info/dependency_links.txt +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/PVNet.egg-info/requires.txt +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/PVNet.egg-info/top_level.txt +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/README.md +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/callbacks.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/data/__init__.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/data/base_datamodule.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/data/site_datamodule.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/data/uk_regional_datamodule.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/load_model.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/__init__.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/baseline/__init__.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/baseline/last_value.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/baseline/single_value.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/ensemble.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/model_cards/pv_india_model_card_template.md +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/model_cards/pv_uk_regional_model_card_template.md +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/model_cards/wind_india_model_card_template.md +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/multimodal/__init__.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/multimodal/basic_blocks.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/multimodal/encoders/__init__.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/multimodal/encoders/basic_blocks.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/multimodal/encoders/encoders2d.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/multimodal/encoders/encoders3d.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/multimodal/encoders/encodersRNN.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/multimodal/linear_networks/__init__.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/multimodal/linear_networks/basic_blocks.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/multimodal/linear_networks/networks.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/multimodal/site_encoders/__init__.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/multimodal/site_encoders/basic_blocks.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/multimodal/site_encoders/encoders.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/models/utils.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/optimizers.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/training.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pvnet/utils.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/pyproject.toml +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/setup.cfg +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/tests/test_end2end.py +0 -0
- {pvnet-4.1.8 → pvnet-4.1.10}/tests/test_utils.py +0 -0
|
@@ -30,7 +30,6 @@ pvnet/models/model_cards/wind_india_model_card_template.md
|
|
|
30
30
|
pvnet/models/multimodal/__init__.py
|
|
31
31
|
pvnet/models/multimodal/basic_blocks.py
|
|
32
32
|
pvnet/models/multimodal/multimodal.py
|
|
33
|
-
pvnet/models/multimodal/multimodal_base.py
|
|
34
33
|
pvnet/models/multimodal/unimodal_teacher.py
|
|
35
34
|
pvnet/models/multimodal/encoders/__init__.py
|
|
36
35
|
pvnet/models/multimodal/encoders/basic_blocks.py
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"""Base model for all PVNet submodels"""
|
|
2
|
-
|
|
2
|
+
import copy
|
|
3
3
|
import json
|
|
4
4
|
import logging
|
|
5
5
|
import os
|
|
@@ -22,6 +22,7 @@ from huggingface_hub.constants import CONFIG_NAME, PYTORCH_WEIGHTS_NAME
|
|
|
22
22
|
from huggingface_hub.file_download import hf_hub_download
|
|
23
23
|
from huggingface_hub.hf_api import HfApi
|
|
24
24
|
from ocf_data_sampler.torch_datasets.sample.base import copy_batch_to_device
|
|
25
|
+
from torchvision.transforms.functional import center_crop
|
|
25
26
|
|
|
26
27
|
from pvnet.models.utils import (
|
|
27
28
|
BatchAccumulator,
|
|
@@ -535,6 +536,51 @@ class BaseModel(pl.LightningModule, PVNetModelHubMixin):
|
|
|
535
536
|
# save all validation results to array, so we can save these to weights n biases
|
|
536
537
|
self.validation_epoch_results = []
|
|
537
538
|
|
|
539
|
+
def _adapt_batch(self, batch):
|
|
540
|
+
"""Slice batches into appropriate shapes for model.
|
|
541
|
+
|
|
542
|
+
Returns a new batch dictionary with adapted data, leaving the original batch unchanged.
|
|
543
|
+
We make some specific assumptions about the original batch and the derived sliced batch:
|
|
544
|
+
- We are only limiting the future projections. I.e. we are never shrinking the batch from
|
|
545
|
+
the left hand side of the time axis, only slicing it from the right
|
|
546
|
+
- We are only shrinking the spatial crop of the satellite and NWP data
|
|
547
|
+
|
|
548
|
+
"""
|
|
549
|
+
# Create a copy of the batch to avoid modifying the original
|
|
550
|
+
new_batch = {key: copy.deepcopy(value) for key, value in batch.items()}
|
|
551
|
+
|
|
552
|
+
if "gsp" in new_batch.keys():
|
|
553
|
+
# Slice off the end of the GSP data
|
|
554
|
+
gsp_len = self.forecast_len + self.history_len + 1
|
|
555
|
+
new_batch["gsp"] = new_batch["gsp"][:, :gsp_len]
|
|
556
|
+
new_batch["gsp_time_utc"] = new_batch["gsp_time_utc"][:, :gsp_len]
|
|
557
|
+
|
|
558
|
+
if self.include_sat:
|
|
559
|
+
# Slice off the end of the satellite data and spatially crop
|
|
560
|
+
# Shape: batch_size, seq_length, channel, height, width
|
|
561
|
+
new_batch["satellite_actual"] = center_crop(
|
|
562
|
+
new_batch["satellite_actual"][:, : self.sat_sequence_len],
|
|
563
|
+
output_size=self.sat_encoder.image_size_pixels,
|
|
564
|
+
)
|
|
565
|
+
|
|
566
|
+
if self.include_nwp:
|
|
567
|
+
# Slice off the end of the NWP data and spatially crop
|
|
568
|
+
for nwp_source in self.nwp_encoders_dict:
|
|
569
|
+
# shape: batch_size, seq_len, n_chans, height, width
|
|
570
|
+
new_batch["nwp"][nwp_source]["nwp"] = center_crop(
|
|
571
|
+
new_batch["nwp"][nwp_source]["nwp"],
|
|
572
|
+
output_size=self.nwp_encoders_dict[nwp_source].image_size_pixels,
|
|
573
|
+
)[:, : self.nwp_encoders_dict[nwp_source].sequence_length]
|
|
574
|
+
|
|
575
|
+
if self.include_sun:
|
|
576
|
+
sun_len = self.forecast_len + self.history_len + 1
|
|
577
|
+
# Slice off end of solar coords
|
|
578
|
+
for s in ["solar_azimuth", "solar_elevation"]:
|
|
579
|
+
if s in new_batch.keys():
|
|
580
|
+
new_batch[s] = new_batch[s][:, :sun_len]
|
|
581
|
+
|
|
582
|
+
return new_batch
|
|
583
|
+
|
|
538
584
|
def transfer_batch_to_device(self, batch, device, dataloader_idx):
|
|
539
585
|
"""Method to move custom batches to a given device"""
|
|
540
586
|
return copy_batch_to_device(batch, device)
|
|
@@ -693,6 +739,10 @@ class BaseModel(pl.LightningModule, PVNetModelHubMixin):
|
|
|
693
739
|
def training_step(self, batch, batch_idx):
|
|
694
740
|
"""Run training step"""
|
|
695
741
|
y_hat = self(batch)
|
|
742
|
+
|
|
743
|
+
# Batch is adapted in the model forward method, but needs to be adapted here too
|
|
744
|
+
batch = self._adapt_batch(batch)
|
|
745
|
+
|
|
696
746
|
y = batch[self._target_key][:, -self.forecast_len :]
|
|
697
747
|
|
|
698
748
|
losses = self._calculate_common_losses(y, y_hat)
|
|
@@ -774,6 +824,8 @@ class BaseModel(pl.LightningModule, PVNetModelHubMixin):
|
|
|
774
824
|
accum_batch_num = batch_idx // self.trainer.accumulate_grad_batches
|
|
775
825
|
|
|
776
826
|
y_hat = self(batch)
|
|
827
|
+
# Batch is adapted in the model forward method, but needs to be adapted here too
|
|
828
|
+
batch = self._adapt_batch(batch)
|
|
777
829
|
|
|
778
830
|
y = batch[self._target_key][:, -self.forecast_len :]
|
|
779
831
|
|
|
@@ -8,15 +8,15 @@ from omegaconf import DictConfig
|
|
|
8
8
|
from torch import nn
|
|
9
9
|
|
|
10
10
|
import pvnet
|
|
11
|
+
from pvnet.models.base_model import BaseModel
|
|
11
12
|
from pvnet.models.multimodal.basic_blocks import ImageEmbedding
|
|
12
13
|
from pvnet.models.multimodal.encoders.basic_blocks import AbstractNWPSatelliteEncoder
|
|
13
14
|
from pvnet.models.multimodal.linear_networks.basic_blocks import AbstractLinearNetwork
|
|
14
|
-
from pvnet.models.multimodal.multimodal_base import MultimodalBaseModel
|
|
15
15
|
from pvnet.models.multimodal.site_encoders.basic_blocks import AbstractSitesEncoder
|
|
16
16
|
from pvnet.optimizers import AbstractOptimizer
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
class Model(
|
|
19
|
+
class Model(BaseModel):
|
|
20
20
|
"""Neural network which combines information from different sources
|
|
21
21
|
|
|
22
22
|
Architecture is roughly as follows:
|
|
@@ -152,7 +152,7 @@ class Model(MultimodalBaseModel):
|
|
|
152
152
|
self.use_id_embedding = location_id_mapping is not None
|
|
153
153
|
|
|
154
154
|
if self.use_id_embedding:
|
|
155
|
-
num_embeddings = max(location_id_mapping.values())
|
|
155
|
+
num_embeddings = max(location_id_mapping.values()) + 1
|
|
156
156
|
|
|
157
157
|
super().__init__(
|
|
158
158
|
history_minutes=history_minutes,
|
|
@@ -11,12 +11,12 @@ from pyaml_env import parse_config
|
|
|
11
11
|
from torch import nn
|
|
12
12
|
|
|
13
13
|
import pvnet
|
|
14
|
+
from pvnet.models.base_model import BaseModel
|
|
14
15
|
from pvnet.models.multimodal.linear_networks.basic_blocks import AbstractLinearNetwork
|
|
15
|
-
from pvnet.models.multimodal.multimodal_base import MultimodalBaseModel
|
|
16
16
|
from pvnet.optimizers import AbstractOptimizer
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
class Model(
|
|
19
|
+
class Model(BaseModel):
|
|
20
20
|
"""Neural network which combines information from different sources
|
|
21
21
|
|
|
22
22
|
The network is trained via unimodal teachers [1].
|
|
@@ -106,7 +106,7 @@ class Model(MultimodalBaseModel):
|
|
|
106
106
|
self.use_id_embedding = location_id_mapping is not None
|
|
107
107
|
|
|
108
108
|
if self.use_id_embedding:
|
|
109
|
-
num_embeddings = max(location_id_mapping.values())
|
|
109
|
+
num_embeddings = max(location_id_mapping.values()) + 1
|
|
110
110
|
|
|
111
111
|
# This is set but modified later based on the teachers
|
|
112
112
|
self.add_image_embedding_channel = False
|
pvnet-4.1.8/pvnet/__init__.py
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"""Base model class for multimodal model and unimodal teacher"""
|
|
2
|
-
import copy
|
|
3
|
-
|
|
4
|
-
from torchvision.transforms.functional import center_crop
|
|
5
|
-
|
|
6
|
-
from pvnet.models.base_model import BaseModel
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class MultimodalBaseModel(BaseModel):
|
|
10
|
-
"""Base model class for multimodal model and unimodal teacher"""
|
|
11
|
-
|
|
12
|
-
def _adapt_batch(self, batch):
|
|
13
|
-
"""Slice batches into appropriate shapes for model.
|
|
14
|
-
|
|
15
|
-
Returns a new batch dictionary with adapted data, leaving the original batch unchanged.
|
|
16
|
-
We make some specific assumptions about the original batch and the derived sliced batch:
|
|
17
|
-
- We are only limiting the future projections. I.e. we are never shrinking the batch from
|
|
18
|
-
the left hand side of the time axis, only slicing it from the right
|
|
19
|
-
- We are only shrinking the spatial crop of the satellite and NWP data
|
|
20
|
-
|
|
21
|
-
"""
|
|
22
|
-
# Create a copy of the batch to avoid modifying the original
|
|
23
|
-
new_batch = {key: copy.deepcopy(value) for key, value in batch.items()}
|
|
24
|
-
|
|
25
|
-
if "gsp" in new_batch.keys():
|
|
26
|
-
# Slice off the end of the GSP data
|
|
27
|
-
gsp_len = self.forecast_len + self.history_len + 1
|
|
28
|
-
new_batch["gsp"] = new_batch["gsp"][:, :gsp_len]
|
|
29
|
-
new_batch["gsp_time_utc"] = new_batch["gsp_time_utc"][:, :gsp_len]
|
|
30
|
-
|
|
31
|
-
if self.include_sat:
|
|
32
|
-
# Slice off the end of the satellite data and spatially crop
|
|
33
|
-
# Shape: batch_size, seq_length, channel, height, width
|
|
34
|
-
new_batch["satellite_actual"] = center_crop(
|
|
35
|
-
new_batch["satellite_actual"][:, : self.sat_sequence_len],
|
|
36
|
-
output_size=self.sat_encoder.image_size_pixels,
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
if self.include_nwp:
|
|
40
|
-
# Slice off the end of the NWP data and spatially crop
|
|
41
|
-
for nwp_source in self.nwp_encoders_dict:
|
|
42
|
-
# shape: batch_size, seq_len, n_chans, height, width
|
|
43
|
-
new_batch["nwp"][nwp_source]["nwp"] = center_crop(
|
|
44
|
-
new_batch["nwp"][nwp_source]["nwp"],
|
|
45
|
-
output_size=self.nwp_encoders_dict[nwp_source].image_size_pixels,
|
|
46
|
-
)[:, : self.nwp_encoders_dict[nwp_source].sequence_length]
|
|
47
|
-
|
|
48
|
-
if self.include_sun:
|
|
49
|
-
sun_len = self.forecast_len + self.history_len + 1
|
|
50
|
-
# Slice off end of solar coords
|
|
51
|
-
for s in ["solar_azimuth", "solar_elevation"]:
|
|
52
|
-
if s in new_batch.keys():
|
|
53
|
-
new_batch[s] = new_batch[s][:, :sun_len]
|
|
54
|
-
|
|
55
|
-
return new_batch
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|