upload cloud_s3olci dataset
Browse files
cloud_s3olci/cloud_s3olci.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1ce5697ab3c60e43e92a24968d6dcb1b7080da0a8c9016782e8926a88a4733d8
|
| 3 |
+
size 6991634480
|
cloud_s3olci/dataset_cloud_s3olci.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from torch.utils.data import Dataset, DataLoader
|
| 3 |
+
import os
|
| 4 |
+
import rasterio
|
| 5 |
+
import numpy as np
|
| 6 |
+
from datetime import date
|
| 7 |
+
from pyproj import Transformer
|
| 8 |
+
|
| 9 |
+
S3_OLCI_SCALE = [0.0139465,0.0133873,0.0121481,0.0115198,0.0100953,0.0123538,0.00879161,0.00876539,
|
| 10 |
+
0.0095103,0.00773378,0.00675523,0.0071996,0.00749684,0.0086512,0.00526779,0.00530267,
|
| 11 |
+
0.00493004,0.00549962,0.00502847,0.00326378,0.00324118]
|
| 12 |
+
|
| 13 |
+
Cls_index_binary = {
|
| 14 |
+
'invalid': 0,
|
| 15 |
+
'clear': 1,
|
| 16 |
+
'cloud': 2,
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
Cls_index_multi = {
|
| 20 |
+
'invalid': 0,
|
| 21 |
+
'clear': 1,
|
| 22 |
+
'cloud-sure': 2,
|
| 23 |
+
'cloud-ambiguous': 3,
|
| 24 |
+
'cloud shadow': 4,
|
| 25 |
+
'snow and ice': 5,
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class S3OLCI_CloudDataset(Dataset):
|
| 31 |
+
'''
|
| 32 |
+
1596/399 train/test images 256x256
|
| 33 |
+
21 bands
|
| 34 |
+
nodata: nan
|
| 35 |
+
|
| 36 |
+
'''
|
| 37 |
+
def __init__(self, root_dir, split='train', mode='multi', meta=True):
|
| 38 |
+
self.root_dir = root_dir
|
| 39 |
+
self.meta = meta
|
| 40 |
+
|
| 41 |
+
self.img_dir = os.path.join(root_dir, split, 's3_olci')
|
| 42 |
+
self.fpaths = os.listdir(self.img_dir)
|
| 43 |
+
self.fpaths = [f for f in self.fpaths if f.endswith('.tif')]
|
| 44 |
+
|
| 45 |
+
if mode == 'multi':
|
| 46 |
+
self.cloud_dir = os.path.join(root_dir, split, 'cloud_multi')
|
| 47 |
+
elif mode == 'binary':
|
| 48 |
+
self.cloud_dir = os.path.join(root_dir, split, 'cloud_binary')
|
| 49 |
+
|
| 50 |
+
if self.meta:
|
| 51 |
+
self.reference_date = date(1970, 1, 1)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def __len__(self):
|
| 55 |
+
return len(self.fpaths)
|
| 56 |
+
|
| 57 |
+
def __getitem__(self, idx):
|
| 58 |
+
fpath = self.fpaths[idx]
|
| 59 |
+
fpath_img = os.path.join(self.img_dir, fpath)
|
| 60 |
+
fpath_cloud = os.path.join(self.cloud_dir, fpath)
|
| 61 |
+
|
| 62 |
+
with rasterio.open(fpath_img) as src:
|
| 63 |
+
img = src.read()
|
| 64 |
+
# convert nan pixels to 0
|
| 65 |
+
img[np.isnan(img)] = 0
|
| 66 |
+
|
| 67 |
+
for b in range(21):
|
| 68 |
+
img[b] = img[b] * S3_OLCI_SCALE[b]
|
| 69 |
+
|
| 70 |
+
if self.meta:
|
| 71 |
+
cx,cy = src.xy(src.height // 2, src.width // 2)
|
| 72 |
+
crs_transformer = Transformer.from_crs(src.crs, 'epsg:4326')
|
| 73 |
+
lon, lat = crs_transformer.transform(cx,cy)
|
| 74 |
+
img_fname = os.path.basename(fpath_img)
|
| 75 |
+
date_str = img_fname.split('____')[1][:8]
|
| 76 |
+
date_obj = date(int(date_str[:4]), int(date_str[4:6]), int(date_str[6:8]))
|
| 77 |
+
delta = (date_obj - self.reference_date).days
|
| 78 |
+
meta_info = np.array([lon, lat, delta, np.nan]).astype(np.float32)
|
| 79 |
+
else:
|
| 80 |
+
meta_info = np.array([np.nan,np.nan,np.nan,np.nan]).astype(np.float32)
|
| 81 |
+
|
| 82 |
+
img = torch.from_numpy(img).float()
|
| 83 |
+
|
| 84 |
+
with rasterio.open(fpath_cloud) as src:
|
| 85 |
+
cloud = src.read(1)
|
| 86 |
+
cloud = torch.from_numpy(cloud).long()
|
| 87 |
+
|
| 88 |
+
return img, cloud, meta_info
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
if __name__ == '__main__':
|
| 93 |
+
dataset = S3OLCI_CloudDataset(root_dir='./cloud_s3olci', split='train', mode='multi')
|
| 94 |
+
dataloader = DataLoader(dataset, batch_size=2, shuffle=False)
|
| 95 |
+
for img, cloud, meta in dataloader:
|
| 96 |
+
print(img.shape, cloud.shape, meta.shape)
|
| 97 |
+
break
|