15 from dateutil
import parser
16 from datetime
import tzinfo, timedelta, datetime
30 l = glob.glob(fdbdir +
'/*.*.*')
33 filenameSplitted = os.path.split(i)[1].split(
'.')
34 if len(filenameSplitted[2]) < 10:
36 if i.find(
".obt") != -1:
38 file[
"expe"] = filenameSplitted[0]
39 file[
"type"] = filenameSplitted[1]
40 file[
"referenceTime"] = filenameSplitted[2]
41 file[
"refTime"] = parser.parse(filenameSplitted[2])
43 term = self.
getTerm(filenameSplitted[3])
44 file[
"term"] = filenameSplitted[3]
45 file[
"intTerm"] = term
46 file[
"validTime"] = file[
"refTime"] + term
49 file[
"intTerm"] = timedelta(seconds=0)
50 file[
"validTime"] = file[
"refTime"]
52 file[
"filename"] = os.path.split(i)[1]
53 self.
map[os.path.split(i)[1]] = file
60 for file
in self.
map.values():
61 if file[
"validTime"] == date :
69 date = parser.parse(stringdate)
80 infile = open(self.
fdbdir +
"/" + file[
"filename"],
"r") 82 [nx, ny, nl, nf, ns] = [int(i) for i
in infile.readline().split()]
83 validity_date = infile.readline()
84 psi = np.fromfile(file=infile,dtype=
"float64", \
85 count=(2*ny*nx),sep=
" ").reshape((2,ny,nx))
86 pv = np.fromfile(file=infile,dtype=
"float64", \
87 count=(2*ny*nx),sep=
" ").reshape((2,ny,nx))
103 for f
in self.
map.values():
104 key = f[
"expe"] +
"." + f[
"type"]
110 if f[
"referenceTime"]
in arr:
111 terms = arr[f[
"referenceTime"]]
114 arr[f[
"referenceTime"]] = terms
115 terms[f[
"intTerm"]] = f[
"term"]
116 for expe
in lst.keys():
117 for date
in lst[expe].keys():
124 lst[expe][date] = newT
134 for f
in self.
map.values():
135 key = f[
"expe"] +
"." + f[
"type"]
137 items[f[
'refTime']] = f[
'referenceTime']
149 for f
in self.
map.values():
150 key = f[
"expe"] +
"." + f[
"type"]
151 if expe == key
and refTime == f[
'refTime']
and validTime == f[
'validTime'] :
160 for expe
in lst.keys():
162 for date
in lst[expe].keys():
164 if len(lst[expe][date]) > 1:
165 for ech
in lst[expe][date]:
174 regex = re.compile(
'(?P<sign>-?)P(?:(?P<years>\d+)Y)?(?:(?P<months>\d+)M)?(?:(?P<days>\d+)D)?(?:T(?:(?P<hours>\d+)H)?(?:(?P<minutes>\d+)M)?(?:(?P<seconds>\d+)S)?)?')
175 duration = regex.match(term).groupdict(0)
176 delta = timedelta(days=int(duration[
'days']) + (int(duration[
'months']) * 30) + (int(duration[
'years']) * 365),
177 hours=int(duration[
'hours']),
178 minutes=int(duration[
'minutes']),
179 seconds=int(duration[
'seconds']))
def getAtValidTime(self, date)
def ggetAtValidTime(self, stringdate)
def getTimeList(self, expe)
def __init__(self, fdbdir)
def getExpeAt(self, expe, refTime, validTime)