Skip to content

Commit 2ae7a62

Browse files
authored
Merge pull request #1 from openclimatefix/pre-commit-ci-update-config
[pre-commit.ci] pre-commit autoupdate
2 parents 3f9c563 + 32b33c7 commit 2ae7a62

7 files changed

Lines changed: 84 additions & 31 deletions

File tree

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.1.0
3+
rev: v4.3.0
44
hooks:
55
# list of supported hooks: https://pre-commit.com/hooks.html
66
- id: trailing-whitespace
@@ -12,7 +12,7 @@ repos:
1212

1313
# python code formatting
1414
- repo: https://github.com/psf/black
15-
rev: 22.1.0
15+
rev: 22.6.0
1616
hooks:
1717
- id: black
1818
args: [--line-length, "99"]
@@ -33,19 +33,19 @@ repos:
3333

3434
# yaml formatting
3535
- repo: https://github.com/pre-commit/mirrors-prettier
36-
rev: v2.5.1
36+
rev: v2.7.1
3737
hooks:
3838
- id: prettier
3939
types: [yaml]
4040

4141
# python code analysis
4242
- repo: https://github.com/PyCQA/flake8
43-
rev: 4.0.1
43+
rev: 5.0.4
4444
hooks:
4545
- id: flake8
4646

4747
# jupyter notebook cell output clearing
4848
- repo: https://github.com/kynan/nbstripout
49-
rev: 0.5.0
49+
rev: 0.6.0
5050
hooks:
5151
- id: nbstripout

configs/datamodule/xresunet.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,18 @@ _target_: src.datamodules.xresunet_datamodule.SatDataModule
33
data_dir: ${data_dir} # data_dir is specified in config.yaml
44
batch_size: 32
55
num_workers: 8
6-
channels: ["IR_016", "IR_039", "IR_087", "IR_097", "IR_108", "IR_120", "IR_134", "VIS006", "VIS008", "WV_062", "WV_073"]
6+
channels:
7+
[
8+
"IR_016",
9+
"IR_039",
10+
"IR_087",
11+
"IR_097",
12+
"IR_108",
13+
"IR_120",
14+
"IR_134",
15+
"VIS006",
16+
"VIS008",
17+
"WV_062",
18+
"WV_073",
19+
]
720
pin_memory: True

configs/model/xresunet.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ weight_decay: 0.0005
44

55
net:
66
_target_: src.models.components.xresnet_unet.XResUNet
7-
input_size: [64,64]
7+
input_size: [64, 64]
88
forecast_steps: 24
99
history_steps: 9
1010
pretrained: False

src/datamodules/components/sat_dataloader.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import numpy as np
2-
import xarray as xr
3-
import fsspec
41
import glob
52
import os
63

4+
import fsspec
5+
import numpy as np
6+
import xarray as xr
77
from torch.utils.data import ConcatDataset, DataLoader, Dataset, random_split
88

99
SAT_MEAN = {
@@ -41,11 +41,12 @@
4141

4242

4343
def _set_sat_coords(dataset: xr.Dataset) -> xr.Dataset:
44-
"""Set variables as coordinates"""
44+
"""Set variables as coordinates."""
4545
return dataset.set_coords(
4646
["time_utc", "channel_name", "y_osgb", "x_osgb", "y_geostationary", "x_geostationary"]
4747
)
4848

49+
4950
def load_netcdf(filename, engine="h5netcdf", *args, **kwargs) -> xr.Dataset:
5051
"""Load a NetCDF dataset from local file system or cloud bucket."""
5152
with fsspec.open(filename, mode="rb") as file:
@@ -54,7 +55,23 @@ def load_netcdf(filename, engine="h5netcdf", *args, **kwargs) -> xr.Dataset:
5455

5556

5657
class Satellite(DataLoader):
57-
def __init__(self, channels=["IR_016", "IR_039", "IR_087", "IR_097", "IR_108", "IR_120", "IR_134", "VIS006", "VIS008", "WV_062", "WV_073"], data_dir="./"):
58+
def __init__(
59+
self,
60+
channels=[
61+
"IR_016",
62+
"IR_039",
63+
"IR_087",
64+
"IR_097",
65+
"IR_108",
66+
"IR_120",
67+
"IR_134",
68+
"VIS006",
69+
"VIS008",
70+
"WV_062",
71+
"WV_073",
72+
],
73+
data_dir="./",
74+
):
5875
self.channels = channels
5976
self.data_dir = data_dir
6077
if "HRV" in self.channels:
@@ -114,9 +131,14 @@ def __getitem__(self, item):
114131
std = np.expand_dims(std, axis=[1, 2, 3])
115132
hrvsatellite = hrvsatellite - mean
116133
hrvsatellite = hrvsatellite / std
117-
input_data = hrvsatellite.values[:,:7]
118-
target_data = hrvsatellite.values[:,7:]
119-
merged_data = (
120-
np.concatenate((input_data, np.expand_dims(dataset["y_osgb"].values, axis=[1,2]),np.expand_dims(dataset["x_osgb"].values, axis=[1,2])), 1)
121-
) # Now in Batch, Time+Coord, Channel, W, H orderk
134+
input_data = hrvsatellite.values[:, :7]
135+
target_data = hrvsatellite.values[:, 7:]
136+
merged_data = np.concatenate(
137+
(
138+
input_data,
139+
np.expand_dims(dataset["y_osgb"].values, axis=[1, 2]),
140+
np.expand_dims(dataset["x_osgb"].values, axis=[1, 2]),
141+
),
142+
1,
143+
) # Now in Batch, Time+Coord, Channel, W, H orderk
122144
return np.squeeze(merged_data), np.squeeze(target_data)

src/datamodules/xresunet_datamodule.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import torch
44
from pytorch_lightning import LightningDataModule
55
from torch.utils.data import ConcatDataset, DataLoader, Dataset, random_split
6+
67
from src.datamodules.components.sat_dataloader import Satellite
78

89

@@ -27,7 +28,19 @@ def __init__(
2728
self,
2829
data_dir: str = "data/",
2930
batch_size: int = 64,
30-
channels: list = ["IR_016", "IR_039", "IR_087", "IR_097", "IR_108", "IR_120", "IR_134", "VIS006", "VIS008", "WV_062", "WV_073"],
31+
channels: list = [
32+
"IR_016",
33+
"IR_039",
34+
"IR_087",
35+
"IR_097",
36+
"IR_108",
37+
"IR_120",
38+
"IR_134",
39+
"VIS006",
40+
"VIS008",
41+
"WV_062",
42+
"WV_073",
43+
],
3144
num_workers: int = 0,
3245
pin_memory: bool = False,
3346
):
@@ -51,9 +64,15 @@ def setup(self, stage: Optional[str] = None):
5164

5265
# load datasets only if they're not loaded already
5366
if not self.data_train and not self.data_val and not self.data_test:
54-
self.data_train = Satellite(channels=self.channels, data_dir=self.hparams.data_dir + "/train/")
55-
self.data_val = Satellite(channels=self.channels, data_dir=self.hparams.data_dir + "/test/")
56-
self.data_test = Satellite(channels=self.channels, data_dir=self.hparams.data_dir + "/test/")
67+
self.data_train = Satellite(
68+
channels=self.channels, data_dir=self.hparams.data_dir + "/train/"
69+
)
70+
self.data_val = Satellite(
71+
channels=self.channels, data_dir=self.hparams.data_dir + "/test/"
72+
)
73+
self.data_test = Satellite(
74+
channels=self.channels, data_dir=self.hparams.data_dir + "/test/"
75+
)
5776

5877
def train_dataloader(self):
5978
return DataLoader(

src/models/components/xresnet_unet.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
from fastai.vision.all import *
2-
from fastai.callback.wandb import *
31
from fastai.callback.tracker import *
2+
from fastai.callback.wandb import *
43
from fastai.distributed import *
5-
from fastai.vision.models.xresnet import *
64
from fastai.layers import Mish
7-
8-
9-
5+
from fastai.vision.all import *
6+
from fastai.vision.models.xresnet import *
107
from torch import nn
118

129

src/models/xresunet_module.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from typing import Any, List
22

33
import torch
4-
from torch.optim.lr_scheduler import CosineAnnealingLR
5-
from torch.optim import AdamW
64
from pytorch_lightning import LightningModule
5+
from torch.optim import AdamW
6+
from torch.optim.lr_scheduler import CosineAnnealingLR
77

88
from src.models.components.xresnet_unet import XResUNet
99

@@ -32,7 +32,7 @@ def __init__(
3232

3333
# this line allows to access init params with 'self.hparams' attribute
3434
# it also ensures init params will be stored in ckpt
35-
#self.save_hyperparameters(logger=False)
35+
# self.save_hyperparameters(logger=False)
3636

3737
self.net = net
3838
self.lr = lr
@@ -85,7 +85,9 @@ def test_step(self, batch: Any, batch_idx: int):
8585
# log test metrics
8686
self.log("test/loss", loss, on_step=False, on_epoch=True)
8787

88-
return {"loss": loss, }
88+
return {
89+
"loss": loss,
90+
}
8991

9092
def test_epoch_end(self, outputs: List[Any]):
9193
pass

0 commit comments

Comments
 (0)