PVNet 2.1.14__tar.gz → 2.1.16__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-2.1.14 → PVNet-2.1.16}/PKG-INFO +1 -1
- {PVNet-2.1.14 → PVNet-2.1.16}/PVNet.egg-info/PKG-INFO +1 -1
- PVNet-2.1.16/PVNet.egg-info/SOURCES.txt +43 -0
- PVNet-2.1.16/pvnet/__init__.py +2 -0
- {PVNet-2.1.14 → PVNet-2.1.16}/pvnet/app.py +1 -1
- PVNet-2.1.16/pvnet/data/__init__.py +1 -0
- PVNet-2.1.16/pvnet/data/datamodule.py +194 -0
- PVNet-2.1.16/pvnet/models/__init__.py +1 -0
- PVNet-2.1.16/pvnet/models/base_model.py +439 -0
- PVNet-2.1.16/pvnet/models/baseline/__init__.py +1 -0
- PVNet-2.1.16/pvnet/models/baseline/last_value.py +43 -0
- PVNet-2.1.16/pvnet/models/baseline/single_value.py +37 -0
- PVNet-2.1.16/pvnet/models/multimodal/__init__.py +1 -0
- PVNet-2.1.16/pvnet/models/multimodal/basic_blocks.py +104 -0
- PVNet-2.1.16/pvnet/models/multimodal/deep_supervision.py +286 -0
- PVNet-2.1.16/pvnet/models/multimodal/encoders/basic_blocks.py +158 -0
- PVNet-2.1.16/pvnet/models/multimodal/encoders/encoders2d.py +413 -0
- PVNet-2.1.16/pvnet/models/multimodal/encoders/encoders3d.py +306 -0
- PVNet-2.1.16/pvnet/models/multimodal/encoders/encodersRNN.py +141 -0
- PVNet-2.1.16/pvnet/models/multimodal/linear_networks/__init__.py +0 -0
- PVNet-2.1.16/pvnet/models/multimodal/linear_networks/basic_blocks.py +121 -0
- PVNet-2.1.16/pvnet/models/multimodal/linear_networks/networks.py +331 -0
- PVNet-2.1.16/pvnet/models/multimodal/multimodal.py +242 -0
- PVNet-2.1.16/pvnet/models/multimodal/nwp_weighting.py +103 -0
- PVNet-2.1.16/pvnet/models/multimodal/weather_residual.py +316 -0
- PVNet-2.1.16/pvnet/models/utils.py +112 -0
- PVNet-2.1.16/tests/__init__.py +0 -0
- PVNet-2.1.14/PVNet.egg-info/SOURCES.txt +0 -21
- PVNet-2.1.14/pvnet/__init__.py +0 -2
- {PVNet-2.1.14 → PVNet-2.1.16}/LICENSE +0 -0
- {PVNet-2.1.14 → PVNet-2.1.16}/MANIFEST.in +0 -0
- {PVNet-2.1.14 → PVNet-2.1.16}/PVNet.egg-info/dependency_links.txt +0 -0
- {PVNet-2.1.14 → PVNet-2.1.16}/PVNet.egg-info/requires.txt +0 -0
- {PVNet-2.1.14 → PVNet-2.1.16}/PVNet.egg-info/top_level.txt +0 -0
- {PVNet-2.1.14 → PVNet-2.1.16}/README.md +0 -0
- {PVNet-2.1.14 → PVNet-2.1.16}/pvnet/callbacks.py +0 -0
- {PVNet-2.1.14/tests → PVNet-2.1.16/pvnet/models/multimodal/encoders}/__init__.py +0 -0
- {PVNet-2.1.14 → PVNet-2.1.16}/pvnet/optimizers.py +0 -0
- {PVNet-2.1.14 → PVNet-2.1.16}/pvnet/training.py +0 -0
- {PVNet-2.1.14 → PVNet-2.1.16}/pvnet/utils.py +0 -0
- {PVNet-2.1.14 → PVNet-2.1.16}/pyproject.toml +0 -0
- {PVNet-2.1.14 → PVNet-2.1.16}/requirements-dev.txt +0 -0
- {PVNet-2.1.14 → PVNet-2.1.16}/requirements.txt +0 -0
- {PVNet-2.1.14 → PVNet-2.1.16}/setup.cfg +0 -0
- {PVNet-2.1.14 → PVNet-2.1.16}/setup.py +0 -0
- {PVNet-2.1.14 → PVNet-2.1.16}/tests/conftest.py +0 -0
- {PVNet-2.1.14 → PVNet-2.1.16}/tests/test_app.py +0 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
requirements-dev.txt
|
|
6
|
+
requirements.txt
|
|
7
|
+
setup.py
|
|
8
|
+
PVNet.egg-info/PKG-INFO
|
|
9
|
+
PVNet.egg-info/SOURCES.txt
|
|
10
|
+
PVNet.egg-info/dependency_links.txt
|
|
11
|
+
PVNet.egg-info/requires.txt
|
|
12
|
+
PVNet.egg-info/top_level.txt
|
|
13
|
+
pvnet/__init__.py
|
|
14
|
+
pvnet/app.py
|
|
15
|
+
pvnet/callbacks.py
|
|
16
|
+
pvnet/optimizers.py
|
|
17
|
+
pvnet/training.py
|
|
18
|
+
pvnet/utils.py
|
|
19
|
+
pvnet/data/__init__.py
|
|
20
|
+
pvnet/data/datamodule.py
|
|
21
|
+
pvnet/models/__init__.py
|
|
22
|
+
pvnet/models/base_model.py
|
|
23
|
+
pvnet/models/utils.py
|
|
24
|
+
pvnet/models/baseline/__init__.py
|
|
25
|
+
pvnet/models/baseline/last_value.py
|
|
26
|
+
pvnet/models/baseline/single_value.py
|
|
27
|
+
pvnet/models/multimodal/__init__.py
|
|
28
|
+
pvnet/models/multimodal/basic_blocks.py
|
|
29
|
+
pvnet/models/multimodal/deep_supervision.py
|
|
30
|
+
pvnet/models/multimodal/multimodal.py
|
|
31
|
+
pvnet/models/multimodal/nwp_weighting.py
|
|
32
|
+
pvnet/models/multimodal/weather_residual.py
|
|
33
|
+
pvnet/models/multimodal/encoders/__init__.py
|
|
34
|
+
pvnet/models/multimodal/encoders/basic_blocks.py
|
|
35
|
+
pvnet/models/multimodal/encoders/encoders2d.py
|
|
36
|
+
pvnet/models/multimodal/encoders/encoders3d.py
|
|
37
|
+
pvnet/models/multimodal/encoders/encodersRNN.py
|
|
38
|
+
pvnet/models/multimodal/linear_networks/__init__.py
|
|
39
|
+
pvnet/models/multimodal/linear_networks/basic_blocks.py
|
|
40
|
+
pvnet/models/multimodal/linear_networks/networks.py
|
|
41
|
+
tests/__init__.py
|
|
42
|
+
tests/conftest.py
|
|
43
|
+
tests/test_app.py
|
|
@@ -62,7 +62,7 @@ batch_size = 10
|
|
|
62
62
|
|
|
63
63
|
# Huggingfacehub model repo and commit
|
|
64
64
|
model_name = "openclimatefix/pvnet_v2"
|
|
65
|
-
model_version = "
|
|
65
|
+
model_version = "898630f3f8cd4e8506525d813dd61c6d8de86144"
|
|
66
66
|
|
|
67
67
|
model_name_ocf_db = "pvnet_v2"
|
|
68
68
|
use_adjuster = os.getenv("USE_ADJUSTER", "True").lower() == "true"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Data parts"""
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
""" Data module for pytorch lightning """
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
import torch
|
|
6
|
+
from lightning.pytorch import LightningDataModule
|
|
7
|
+
from ocf_datapipes.training.pvnet import pvnet_datapipe
|
|
8
|
+
from ocf_datapipes.utils.consts import BatchKey
|
|
9
|
+
from ocf_datapipes.utils.utils import stack_np_examples_into_batch
|
|
10
|
+
from torchdata.dataloader2 import DataLoader2, MultiProcessingReadingService
|
|
11
|
+
from torchdata.datapipes import functional_datapipe
|
|
12
|
+
from torchdata.datapipes.iter import FileLister, IterDataPipe
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def copy_batch_to_device(batch, device):
|
|
16
|
+
"""Moves a dict-batch of tensors to new device."""
|
|
17
|
+
batch_copy = {}
|
|
18
|
+
for k in list(batch.keys()):
|
|
19
|
+
if isinstance(batch[k], torch.Tensor):
|
|
20
|
+
batch_copy[k] = batch[k].to(device)
|
|
21
|
+
else:
|
|
22
|
+
batch_copy[k] = batch[k]
|
|
23
|
+
return batch_copy
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def batch_to_tensor(batch):
|
|
27
|
+
"""Moves numpy batch to a tensor"""
|
|
28
|
+
for k in list(batch.keys()):
|
|
29
|
+
if isinstance(batch[k], np.ndarray) and np.issubdtype(batch[k].dtype, np.number):
|
|
30
|
+
batch[k] = torch.as_tensor(batch[k])
|
|
31
|
+
return batch
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def split_batches(batch):
|
|
35
|
+
"""Splits a single batch of data."""
|
|
36
|
+
n_samples = batch[BatchKey.gsp].shape[0]
|
|
37
|
+
keys = list(batch.keys())
|
|
38
|
+
examples = [{} for _ in range(n_samples)]
|
|
39
|
+
for i in range(n_samples):
|
|
40
|
+
b = examples[i]
|
|
41
|
+
for k in keys:
|
|
42
|
+
if ("idx" in k.name) or ("channel_names" in k.name):
|
|
43
|
+
b[k] = batch[k]
|
|
44
|
+
else:
|
|
45
|
+
b[k] = batch[k][i]
|
|
46
|
+
return examples
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@functional_datapipe("split_batches")
|
|
50
|
+
class BatchSplitter(IterDataPipe):
|
|
51
|
+
"""Pipeline step to split batches of data and yield single examples"""
|
|
52
|
+
|
|
53
|
+
def __init__(self, source_datapipe: IterDataPipe):
|
|
54
|
+
"""Pipeline step to split batches of data and yield single examples"""
|
|
55
|
+
self.source_datapipe = source_datapipe
|
|
56
|
+
|
|
57
|
+
def __iter__(self):
|
|
58
|
+
"""Opens the NWP data"""
|
|
59
|
+
for batch in self.source_datapipe:
|
|
60
|
+
for example in split_batches(batch):
|
|
61
|
+
yield example
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class DataModule(LightningDataModule):
|
|
65
|
+
"""Datamodule for training pvnet and using pvnet pipeline in `ocf_datapipes`."""
|
|
66
|
+
|
|
67
|
+
def __init__(
|
|
68
|
+
self,
|
|
69
|
+
configuration=None,
|
|
70
|
+
batch_size=16,
|
|
71
|
+
num_workers=0,
|
|
72
|
+
prefetch_factor=2,
|
|
73
|
+
train_period=[None, None],
|
|
74
|
+
val_period=[None, None],
|
|
75
|
+
test_period=[None, None],
|
|
76
|
+
block_nwp_and_sat=False,
|
|
77
|
+
batch_dir=None,
|
|
78
|
+
):
|
|
79
|
+
"""Datamodule for training pvnet and using pvnet pipeline in `ocf_datapipes`.
|
|
80
|
+
|
|
81
|
+
Can also be used with pre-made batches if `batch_dir` is set.
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
configuration: Path to datapipe configuration file.
|
|
86
|
+
batch_size: Batch size.
|
|
87
|
+
num_workers: Number of workers to use in multiprocess batch loading.
|
|
88
|
+
prefetch_factor: Number of data will be prefetched at the end of each worker process.
|
|
89
|
+
train_period: Date range filter for train dataloader.
|
|
90
|
+
val_period: Date range filter for val dataloader.
|
|
91
|
+
test_period: Date range filter for test dataloader.
|
|
92
|
+
block_nwp_and_sat: If True, the dataloader does not load the requested NWP and sat data.
|
|
93
|
+
It instead returns an zero-array of the required shape. Useful for pretraining.
|
|
94
|
+
batch_dir: Path to the directory of pre-saved batches. Cannot be used together with
|
|
95
|
+
`configuration` or 'train/val/test_period'.
|
|
96
|
+
|
|
97
|
+
"""
|
|
98
|
+
super().__init__()
|
|
99
|
+
self.configuration = configuration
|
|
100
|
+
self.batch_size = batch_size
|
|
101
|
+
self.block_nwp_and_sat = block_nwp_and_sat
|
|
102
|
+
self.batch_dir = batch_dir
|
|
103
|
+
|
|
104
|
+
if not ((batch_dir is not None) ^ (configuration is not None)):
|
|
105
|
+
raise ValueError("Exactly one of `batch_dir` or `configuration` must be set.")
|
|
106
|
+
|
|
107
|
+
if batch_dir is not None:
|
|
108
|
+
if any([period != [None, None] for period in [train_period, val_period, test_period]]):
|
|
109
|
+
raise ValueError("Cannot set `(train/val/test)_period` with presaved batches")
|
|
110
|
+
|
|
111
|
+
self.train_period = [
|
|
112
|
+
None if d is None else datetime.strptime(d, "%Y-%m-%d") for d in train_period
|
|
113
|
+
]
|
|
114
|
+
self.val_period = [
|
|
115
|
+
None if d is None else datetime.strptime(d, "%Y-%m-%d") for d in val_period
|
|
116
|
+
]
|
|
117
|
+
self.test_period = [
|
|
118
|
+
None if d is None else datetime.strptime(d, "%Y-%m-%d") for d in test_period
|
|
119
|
+
]
|
|
120
|
+
|
|
121
|
+
self.readingservice_config = dict(
|
|
122
|
+
num_workers=num_workers,
|
|
123
|
+
multiprocessing_context="spawn",
|
|
124
|
+
worker_prefetch_cnt=prefetch_factor,
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
def _get_datapipe(self, start_time, end_time):
|
|
128
|
+
data_pipeline = pvnet_datapipe(
|
|
129
|
+
self.configuration,
|
|
130
|
+
start_time=start_time,
|
|
131
|
+
end_time=end_time,
|
|
132
|
+
block_sat=self.block_nwp_and_sat,
|
|
133
|
+
block_nwp=self.block_nwp_and_sat,
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
data_pipeline = (
|
|
137
|
+
data_pipeline.batch(self.batch_size)
|
|
138
|
+
.map(stack_np_examples_into_batch)
|
|
139
|
+
.map(batch_to_tensor)
|
|
140
|
+
)
|
|
141
|
+
return data_pipeline
|
|
142
|
+
|
|
143
|
+
def _get_premade_batches_datapipe(self, subdir, shuffle=False):
|
|
144
|
+
data_pipeline = FileLister(f"{self.batch_dir}/{subdir}", masks="*.pt", recursive=False)
|
|
145
|
+
if shuffle:
|
|
146
|
+
data_pipeline = (
|
|
147
|
+
data_pipeline.shuffle(buffer_size=10_000)
|
|
148
|
+
.sharding_filter()
|
|
149
|
+
.map(torch.load)
|
|
150
|
+
# Split the batches and reshuffle them to be combined into new batches
|
|
151
|
+
.split_batches()
|
|
152
|
+
.shuffle(buffer_size=100 * self.batch_size)
|
|
153
|
+
)
|
|
154
|
+
else:
|
|
155
|
+
data_pipeline = (
|
|
156
|
+
data_pipeline.sharding_filter().map(torch.load)
|
|
157
|
+
# Split the batches so we can use any batch-size
|
|
158
|
+
.split_batches()
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
data_pipeline = (
|
|
162
|
+
data_pipeline.batch(self.batch_size)
|
|
163
|
+
.map(stack_np_examples_into_batch)
|
|
164
|
+
.map(batch_to_tensor)
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
return data_pipeline
|
|
168
|
+
|
|
169
|
+
def train_dataloader(self):
|
|
170
|
+
"""Construct train dataloader"""
|
|
171
|
+
if self.batch_dir is not None:
|
|
172
|
+
datapipe = self._get_premade_batches_datapipe("train", shuffle=True)
|
|
173
|
+
else:
|
|
174
|
+
datapipe = self._get_datapipe(*self.train_period)
|
|
175
|
+
rs = MultiProcessingReadingService(**self.readingservice_config)
|
|
176
|
+
return DataLoader2(datapipe, reading_service=rs)
|
|
177
|
+
|
|
178
|
+
def val_dataloader(self):
|
|
179
|
+
"""Construct val dataloader"""
|
|
180
|
+
if self.batch_dir is not None:
|
|
181
|
+
datapipe = self._get_premade_batches_datapipe("val")
|
|
182
|
+
else:
|
|
183
|
+
datapipe = self._get_datapipe(*self.val_period)
|
|
184
|
+
rs = MultiProcessingReadingService(**self.readingservice_config)
|
|
185
|
+
return DataLoader2(datapipe, reading_service=rs)
|
|
186
|
+
|
|
187
|
+
def test_dataloader(self):
|
|
188
|
+
"""Construct test dataloader"""
|
|
189
|
+
if self.batch_dir is not None:
|
|
190
|
+
datapipe = self._get_premade_batches_datapipe("test")
|
|
191
|
+
else:
|
|
192
|
+
datapipe = self._get_datapipe(*self.test_period)
|
|
193
|
+
rs = MultiProcessingReadingService(**self.readingservice_config)
|
|
194
|
+
return DataLoader2(datapipe, reading_service=rs)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Models for PVNet"""
|