PVNet 3.0.55__tar.gz → 3.0.56__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-3.0.55 → pvnet-3.0.56}/PKG-INFO +1 -1
- {pvnet-3.0.55 → pvnet-3.0.56}/PVNet.egg-info/PKG-INFO +1 -1
- pvnet-3.0.56/pvnet/__init__.py +2 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/base_model.py +70 -2
- pvnet-3.0.55/pvnet/__init__.py +0 -2
- {pvnet-3.0.55 → pvnet-3.0.56}/LICENSE +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/MANIFEST.in +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/PVNet.egg-info/SOURCES.txt +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/PVNet.egg-info/dependency_links.txt +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/PVNet.egg-info/requires.txt +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/PVNet.egg-info/top_level.txt +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/README.md +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/callbacks.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/data/__init__.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/data/base.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/data/datamodule.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/data/pv_site_datamodule.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/data/utils.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/data/wind_datamodule.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/load_model.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/__init__.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/baseline/__init__.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/baseline/last_value.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/baseline/single_value.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/ensemble.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/multimodal/__init__.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/multimodal/basic_blocks.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/multimodal/encoders/__init__.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/multimodal/encoders/basic_blocks.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/multimodal/encoders/encoders2d.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/multimodal/encoders/encoders3d.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/multimodal/encoders/encodersRNN.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/multimodal/linear_networks/__init__.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/multimodal/linear_networks/basic_blocks.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/multimodal/linear_networks/networks.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/multimodal/multimodal.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/multimodal/multimodal_base.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/multimodal/site_encoders/__init__.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/multimodal/site_encoders/basic_blocks.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/multimodal/site_encoders/encoders.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/multimodal/unimodal_teacher.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/models/utils.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/optimizers.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/training.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pvnet/utils.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/pyproject.toml +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/setup.cfg +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/tests/test_end2end.py +0 -0
- {pvnet-3.0.55 → pvnet-3.0.56}/tests/test_utils.py +0 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import json
|
|
3
3
|
import logging
|
|
4
4
|
import os
|
|
5
|
+
import tempfile
|
|
5
6
|
from pathlib import Path
|
|
6
7
|
from typing import Dict, Optional, Union
|
|
7
8
|
|
|
@@ -410,6 +411,9 @@ class BaseModel(pl.LightningModule, PVNetModelHubMixin):
|
|
|
410
411
|
else:
|
|
411
412
|
self.num_output_features = self.forecast_len
|
|
412
413
|
|
|
414
|
+
# save all validation results to array, so we can save these to weights n biases
|
|
415
|
+
self.validation_epoch_results = []
|
|
416
|
+
|
|
413
417
|
def _quantiles_to_prediction(self, y_quantiles):
|
|
414
418
|
"""
|
|
415
419
|
Convert network prediction into a point prediction.
|
|
@@ -609,12 +613,61 @@ class BaseModel(pl.LightningModule, PVNetModelHubMixin):
|
|
|
609
613
|
print(e)
|
|
610
614
|
plt.close(fig)
|
|
611
615
|
|
|
616
|
+
def _log_validation_results(self, batch, y_hat, accum_batch_num):
|
|
617
|
+
"""Append validation results to self.validation_epoch_results"""
|
|
618
|
+
|
|
619
|
+
# get truth values, shape (b, forecast_len)
|
|
620
|
+
y = batch[self._target_key][:, -self.forecast_len :, 0]
|
|
621
|
+
y = y.detach().cpu().numpy()
|
|
622
|
+
batch_size = y.shape[0]
|
|
623
|
+
|
|
624
|
+
# get prediction values, shape (b, forecast_len, quantiles?)
|
|
625
|
+
y_hat = y_hat.detach().cpu().numpy()
|
|
626
|
+
|
|
627
|
+
# get time_utc, shape (b, forecast_len)
|
|
628
|
+
time_utc_key = BatchKey[f"{self._target_key_name}_time_utc"]
|
|
629
|
+
time_utc = batch[time_utc_key][:, -self.forecast_len :].detach().cpu().numpy()
|
|
630
|
+
|
|
631
|
+
# get target id and change from (b,1) to (b,)
|
|
632
|
+
id_key = BatchKey[f"{self._target_key_name}_id"]
|
|
633
|
+
target_id = batch[id_key].detach().cpu().numpy()
|
|
634
|
+
target_id = target_id.squeeze()
|
|
635
|
+
|
|
636
|
+
for i in range(batch_size):
|
|
637
|
+
y_i = y[i]
|
|
638
|
+
y_hat_i = y_hat[i]
|
|
639
|
+
time_utc_i = time_utc[i]
|
|
640
|
+
target_id_i = target_id[i]
|
|
641
|
+
|
|
642
|
+
results_dict = {
|
|
643
|
+
"y": y_i,
|
|
644
|
+
"time_utc": time_utc_i,
|
|
645
|
+
}
|
|
646
|
+
if self.use_quantile_regression:
|
|
647
|
+
results_dict.update(
|
|
648
|
+
{f"y_quantile_{q}": y_hat_i[:, i] for i, q in enumerate(self.output_quantiles)}
|
|
649
|
+
)
|
|
650
|
+
else:
|
|
651
|
+
results_dict["y_hat"] = y_hat_i
|
|
652
|
+
|
|
653
|
+
results_df = pd.DataFrame(results_dict)
|
|
654
|
+
results_df["id"] = target_id_i
|
|
655
|
+
results_df["batch_idx"] = accum_batch_num
|
|
656
|
+
results_df["example_idx"] = i
|
|
657
|
+
|
|
658
|
+
self.validation_epoch_results.append(results_df)
|
|
659
|
+
|
|
612
660
|
def validation_step(self, batch: dict, batch_idx):
|
|
613
661
|
"""Run validation step"""
|
|
662
|
+
|
|
663
|
+
accum_batch_num = batch_idx // self.trainer.accumulate_grad_batches
|
|
664
|
+
|
|
614
665
|
y_hat = self(batch)
|
|
615
666
|
# Sensor seems to be in batch, station, time order
|
|
616
667
|
y = batch[self._target_key][:, -self.forecast_len :, 0]
|
|
617
668
|
|
|
669
|
+
self._log_validation_results(batch, y_hat, accum_batch_num)
|
|
670
|
+
|
|
618
671
|
# Expand persistence to be the same shape as y
|
|
619
672
|
losses = self._calculate_common_losses(y, y_hat)
|
|
620
673
|
losses.update(self._calculate_val_losses(y, y_hat))
|
|
@@ -632,8 +685,6 @@ class BaseModel(pl.LightningModule, PVNetModelHubMixin):
|
|
|
632
685
|
on_epoch=True,
|
|
633
686
|
)
|
|
634
687
|
|
|
635
|
-
accum_batch_num = batch_idx // self.trainer.accumulate_grad_batches
|
|
636
|
-
|
|
637
688
|
# Make plots only if using wandb logger
|
|
638
689
|
if isinstance(self.logger, pl.loggers.WandbLogger) and accum_batch_num in [0, 1]:
|
|
639
690
|
# Store these temporarily under self
|
|
@@ -675,6 +726,23 @@ class BaseModel(pl.LightningModule, PVNetModelHubMixin):
|
|
|
675
726
|
def on_validation_epoch_end(self):
|
|
676
727
|
"""Run on epoch end"""
|
|
677
728
|
|
|
729
|
+
try:
|
|
730
|
+
# join together validation results, and save to wandb
|
|
731
|
+
validation_results_df = pd.concat(self.validation_epoch_results)
|
|
732
|
+
with tempfile.TemporaryDirectory() as tempdir:
|
|
733
|
+
filename = os.path.join(tempdir, f"validation_results_{self.current_epoch}.csv")
|
|
734
|
+
validation_results_df.to_csv(filename, index=False)
|
|
735
|
+
|
|
736
|
+
# make and log wand artifact
|
|
737
|
+
validation_artifact = wandb.Artifact(
|
|
738
|
+
f"validation_results_epoch={self.current_epoch}", type="dataset"
|
|
739
|
+
)
|
|
740
|
+
validation_artifact.add_file(filename)
|
|
741
|
+
wandb.log_artifact(validation_artifact)
|
|
742
|
+
except Exception as e:
|
|
743
|
+
print("Failed to log validation results to wandb")
|
|
744
|
+
print(e)
|
|
745
|
+
|
|
678
746
|
horizon_maes_dict = self._horizon_maes.flush()
|
|
679
747
|
|
|
680
748
|
# Create the horizon accuracy curve
|
pvnet-3.0.55/pvnet/__init__.py
DELETED
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|