-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreproject_s3.py
More file actions
60 lines (46 loc) · 1.37 KB
/
reproject_s3.py
File metadata and controls
60 lines (46 loc) · 1.37 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
import sys
import satpy
from glob import glob
from cartopy import crs as ccrs
class S3OLCIReproject(object):
"""
Crude class to resample a sentinel3 OLCI image
to the mercator projection. Intended to be run in
parallel across a directory (e.g. via gnu parallel)
"""
def __init__(self, sen3_dir, reader='olci_l2'):
self.scene = satpy.Scene(
glob(sen3_dir+"/*"),
reader=reader
)
self._dir = sen3_dir
def reproject(self):
dss_outfiles = []
dss = ['chl_oc4me', 'chl_nn']
try:
self.scene.load(dss)
except Exception as e:
print(e)
return
rs_sc = self.scene.resample(
self.scene['chl_nn'].area.compute_optimal_bb_area(
ccrs.Mercator().proj4_params
)
)
for i in dss:
outpath = os.path.join(
self._dir,
f"{i}-{self.scene.attrs['start_time']:%Y%m%d}.tif"
)
rs_sc.save_dataset(
i,
outpath,
writer='geotiff',
compute=True
)
dss_outfiles.append(outpath)
return(dss_outfiles)
if __name__ == "__main__":
_rp = S3OLCIReproject(sys.argv[1])
print(_rp.reproject())