wangyi111 commited on
Commit
61d7a28
·
verified ·
1 Parent(s): 1d6262c

upload biomass-s3olci dataset

Browse files
biomass_s3olci/biomass_dataset_5k.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5103c9e4caa2b9ca8dec0170abcbbfee8e6a0bb89e0b188447b285ee1309cc20
3
+ size 1158553387
biomass_s3olci/dataset_biomass_s3olci.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from torch.utils.data import DataLoader, Dataset
2
+ import cv2
3
+ import os
4
+ import rasterio
5
+ import torch
6
+ import numpy as np
7
+
8
+ S3_OLCI_SCALE = [0.0139465,0.0133873,0.0121481,0.0115198,0.0100953,0.0123538,0.00879161,0.00876539,
9
+ 0.0095103,0.00773378,0.00675523,0.0071996,0.00749684,0.0086512,0.00526779,0.00530267,
10
+ 0.00493004,0.00549962,0.00502847,0.00326378,0.00324118]
11
+
12
+ BIOMASS_MEAN = 93.8317
13
+ BIOMASS_STD = 110.5369
14
+
15
+
16
+ class S3OLCI_BiomassDataset(Dataset):
17
+ '''
18
+ 4000/1000 train/test images 94x94x21 (full dataset is 25K)
19
+ CCI biomass 282x282
20
+ nodata: -inf
21
+ time series: 1-4 images / location
22
+
23
+ '''
24
+
25
+
26
+ def __init__(self, root_dir, split='train', mode='static'):
27
+ self.root_dir = root_dir
28
+ self.split = split
29
+ self.mode = mode
30
+ self.img_dir = os.path.join(root_dir, split, 's3_olci')
31
+ self.biomass_dir = os.path.join(root_dir, split, 'biomass')
32
+
33
+ self.fnames = os.listdir(self.biomass_dir)
34
+
35
+ def __len__(self):
36
+ return len(self.fnames)
37
+
38
+ def __getitem__(self, idx):
39
+ fname = self.fnames[idx]
40
+ biomass_path = os.path.join(self.biomass_dir, fname)
41
+ s3_path = os.path.join(self.img_dir, fname.replace('.tif',''))
42
+ img_fnames = os.listdir(s3_path)
43
+ s3_paths = []
44
+ for img_fname in img_fnames:
45
+ s3_paths.append(os.path.join(s3_path, img_fname))
46
+
47
+ imgs = []
48
+ img_paths = []
49
+ for img_path in s3_paths:
50
+ with rasterio.open(img_path) as src:
51
+ img = src.read()
52
+ chs = []
53
+ for b in range(21):
54
+ #ch = cv2.resize(img[b], (94,94), interpolation=cv2.INTER_CUBIC)
55
+ ch = cv2.resize(img[b], (282,282), interpolation=cv2.INTER_CUBIC)
56
+ chs.append(ch)
57
+ img = np.stack(chs)
58
+ img[np.isnan(img)] = 0
59
+ for b in range(21):
60
+ img[b] = img[b]*S3_OLCI_SCALE[b]
61
+ img = torch.from_numpy(img).float()
62
+ imgs.append(img)
63
+ img_paths.append(img_path)
64
+ # pad to 4 images if less than 4
65
+ while len(imgs) < 4:
66
+ imgs.append(img)
67
+ img_paths.append(img_path)
68
+
69
+ with rasterio.open(biomass_path) as src:
70
+ biomass = src.read(1)
71
+ biomass = cv2.resize(biomass, (282,282), interpolation=cv2.INTER_CUBIC) # 0-650
72
+ biomass = torch.from_numpy(biomass.astype('float32'))
73
+ biomass = (biomass - BIOMASS_MEAN) / BIOMASS_STD # 0-center normalized
74
+ if self.mode == 'static':
75
+ return imgs[0], biomass # 94x94x21, 282x282
76
+ elif self.mode == 'series':
77
+ return imgs[0], imgs[1], imgs[2], imgs[3], biomass # 94x94x21, 94x94x21, 94x94x21, 94x94x21, 282x282