-
Notifications
You must be signed in to change notification settings - Fork 2
/
S3_OLCI_L1b.py
70 lines (55 loc) · 2.37 KB
/
S3_OLCI_L1b.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
"""A class to operate with the OLCI re-gridded product
"""
import datetime
import glob
import re
import os
from collections import namedtuple
import numpy as np
import gdal
OLCI_granule = namedtuple("OLCI_granule", "mask sza saa vza vaa " +
"b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 "+
"b13 b14 b15 b16 b17 b18 b19 b20 b21")
class OLCI_L1b_reader(object):
def __init__ (self, tile, olci_path):
"A class to read out OLCI data"""
if os.path.exists (olci_path):
self.olci_path = olci_path
else:
raise IOError("The given olci_path (%s)" + \
"does not exist!")
if re.match ("h\d\dv\d\d", tile):
self.tile = tile
else:
raise ValueError("tile has to be hxxvxx (%s)" % tile)
self._find_olci_granules()
def _process_fname(self, granule_path):
granule = os.path.basename(granule_path)
date = granule.split("____")[1].split("_")[0]
date = datetime.datetime.strptime(date,
"%Y%m%dT%H%M%S")
bands = ["Oa%02d_reflectance.%s.masked.tif" %(band, self.tile)
for band in xrange(1, 22)]
metadata = ["%s.%s.tif" % ( meta, self.tile)
for meta in ["quality_flags", "SZA",
"SAA", "OZA", "OAA"]]
ll = []
for layer in (metadata + bands):
if not os.path.exists(os.path.join(granule_path,
layer)):
raise IOError
ll.append(os.path.join(granule_path,
layer))
return date, OLCI_granule( *ll)
def _find_olci_granules(self):
granules = glob.glob (os.path.join(self.olci_path,
"S3A_OL_1_EFR*.%s" % self.tile))
if len(granules) == 0:
raise ValueError("No OLCI granules found")
self.granules = {}
for granule in granules:
this_date, this_data = self._process_fname(granule)
self.granules[this_date] = this_data
if __name__ == "__main__":
OLCI = OLCI_L1b_reader("h17v05", "/storage/ucfajlg/Ujia/S3_test/OLCI")