-
Notifications
You must be signed in to change notification settings - Fork 0
/
wildfirebestfeatures.py
37 lines (26 loc) · 1.48 KB
/
wildfirebestfeatures.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import torch
from torch.utils.data import Dataset
from preprocessdata import clip_and_normalize, random_crop_input_and_output_images
from constants import OUTPUT_FEATURES, BEST_INPUT_FEATURES
class WildfireBestFeaturesDataset(Dataset):
def __init__(self, dataset, transform=None):
self.dataset = dataset
self.transform = transform
def __len__(self):
return len(self.dataset['FireMask'])
def __getitem__(self, index):
# clip all data to avoid extreme values, (unreasonable, spanning an extensive dynamic range).
# The clipping values are either based on physical knowledge or set to the 0.1% and 99.9% percentiles.
# Means and standard deviations are calculated after clipping.
x = [clip_and_normalize(self.dataset.get(key), key) for key in BEST_INPUT_FEATURES]
x = [feature[index] for feature in x] # 3 x 64 x 64, list of tensors
inputs_stacked = torch.stack(x, dim = 0) # num_channels x H x W, Tensor
y = [clip_and_normalize(self.dataset.get(key).reshape(-1, 64, 64), key) for key in OUTPUT_FEATURES]
y = y[0][index].reshape((-1, 64,64)) #1 x H x W, Tensor
y = y.type(torch.int32)
y[y < 0] = 0
if self.transform:
# random crops (crop all data to 32x32km regions)
input_img, output_img = random_crop_input_and_output_images(inputs_stacked, y, sample_size, num_in_channels, 1)
return input_img, output_img
return inputs_stacked, y