13 __all__ = [
'get_vitals' ]
17 from util
import counter
21 def get_vitals(vitalfile, centerid, stormid, yyyy, trackfile):
23 @param vitalfile File to parse
24 @param centerid Forecast center: NHC or JTWC
25 @param stormid three character storm ID (ie.: 12L, 19W)
27 @param trackfile Output file."""
31 with open(vitalfile,
"rt")
as f:
33 fields = re.split(
'[\s]\s*', line)
34 if fields[0] == centerid.upper()
and \
35 fields[1] == stormid.upper():
37 dates.append(int(
''.join([fields[3],fields[4]])))
40 if int(
''.join([fields[3],fields[4]]))
in dates:
41 n=dates.index(int(
''.join([fields[3],fields[4]])))
42 if len(line) >= len(vitals[n]):
43 dates[n] = int(
''.join([fields[3],fields[4]]))
46 dates.append(int(
''.join([fields[3],fields[4]])))
48 vitals = [y
for (x,y)
in sorted(zip(dates,vitals))]
51 with open(trackfile,
"wt")
as f:
54 r1s =
qck(line[69:73], line[73:78])
55 r2s =
qck(line[69:73], line[78:83])
56 r3s =
qck(line[69:73], line[83:88])
57 r4s =
qck(line[69:73], line[88:93])
59 f.write(
"%s%s%s%s%s%s%s%s \n"%(line[:19],line[21:36],line[37:42], \
60 line[43:73],r1s,r2s,r3s,r4s))
62 r5s =
qck(line[69:73], line[95:100])
63 r6s =
qck(line[69:73], line[100:105])
64 r7s =
qck(line[69:73], line[105:110])
65 r8s =
qck(line[69:73], line[110:115])
66 f.write(
"%s%s%s%s%s%s%s%s%s%s%s%s \n"%(line[:19],line[21:36],line[37:42], \
67 line[43:73],r1s,r2s,r3s,r4s,r5s,r6s,r7s,r8s))
68 f.write(
"%s\n"%(
"000 000 00000 000000 0000 000 0000 000 000 0000 0000"))
70 except IOError
as err:
73 """!Quality check function: if a>b or b is 999, returns -999, otherwise returns b
74 @param astr,bstr string values containing integers a and b"""
75 if int(astr) > int(bstr)
or int(bstr) == 999:
82 """!Removes unwanted parts of the track file from get_vitals()
83 @param fin,fout input and output files
84 @param ymdh date and hour of interest as a ten digit number in a string
85 @param logger a logging.Logger for log messages
86 @returns 0 on error, or the number of lines kept in fin otherwise"""
87 if logger
is None: logger=logging.getLogger(
'pom')
88 if not os.path.exists(fin)
or not isnonempty(fin):
89 logger.error(
"%s does not exists " %(fin))
90 print(
"%s does not exists " %(fin))
92 with open(fin)
as fid:
93 with open(fout,
'wt')
as fo:
99 if l[19:25] == ymdh[2:8]
and l[26:28] == ymdh[8:10]:
102 fo.write(
"%s\n"%(
"000 000 00000 000000 0000 000 0000 000 000 0000 0000"))
104 logger.error(
"%s does not Found in %s"%(ymdh,fin))
105 print(
"%s does not Found in %s"%(ymdh,fin))
This module provides a set of utility functions to do filesystem operations.
def track_shorten
Removes unwanted parts of the track file from get_vitals()
def get_vitals(vitalfile, centerid, stormid, yyyy, trackfile)
Reads tcvitals.
def qck(astr, bstr)
Quality check function: if a>b or b is 999, returns -999, otherwise returns b.