3 import logging, os, sys, re
7 def hrd_multistorm_sorter(a,b):
8 """A drop-in replacement for "cmp" that can be used for sorting or
9 comparison. Returns -1 if a<b, 1 if a>b or 0 if a=b. Decision is
12 User priority (a.userprio): lower (priority 1) is "more
13 important" than higher numbers (priority 9999 is fill value).
15 Invest vs. non-invest: invest is less important
17 wind: stronger wind is more important than weaker wind
19 North Atlantic (L) storms: farther west is more important
21 North East Pacific (E) storms: farther East is more important
23 If all of the above values are equal, 0 is returned."""
24 a_userprio=getattr(a,
'userprio',9999)
25 b_userprio=getattr(b,
'userprio',9999)
26 a_invest=1
if (a.stormname==
'INVEST')
else 0
27 b_invest=1
if (b.stormname==
'INVEST')
else 0
29 c = cmp(a_userprio,b_userprio)
or cmp(a_invest,b_invest)
or\
30 -cmp(a.wmax,b.wmax)
or\
31 (a.basin1==
'L' and b.basin1==
'L' and cmp(a.lon,b.lon))
or \
32 (a.basin1==
'E' and b.basin1==
'E' and -cmp(a.lon,b.lon))
36 '/com/arch/prod/syndat/syndat_tcvitals.%Y',
37 '/lfs3/projects/hwrf-data/hwrf-input/SYNDAT-PLUS/syndat_tcvitals.%Y',
38 '/scratch1/portfolios/NCEPDEV/hwrf/noscrub/input/SYNDAT-PLUS/syndat_tcvitals.%Y']
43 eloglevel=logging.INFO)
44 logger=logging.getLogger(__file__)
47 YMDH=cyc.strftime(
'%Y%m%d%H')
53 if 'LECWPQSAB'.find(arg.upper())<0:
54 logger.error(
'Invalid basin %s'%(arg,))
56 basins=basins+arg.upper()
58 m=re.match(
'(\d\d[LECWPQSAB])=(\d+)',arg.upper())
60 logger.error(
'Unrecognized argument: '+arg)
62 (storm,userprio)=m.groups()
63 userprios[storm]=int(userprio)
66 rv.readfiles([ cyc.strftime(v)
for v
in vitfiles ],
70 rv.delete_invest_duplicates()
72 rv.discard_except(
lambda v: v.YMDH==YMDH)
74 logger.info(
'Only keep basins: <%s>'%(basins,))
75 rv.discard_except(
lambda v: v.basin1
in basins)
78 if v.stormid3
in userprios:
79 userprio=int(userprios[v.stormid3])
80 logger.info(
'User priority for %s is %d'%(v.stormid3,userprio))
81 setattr(v,
'userprio',userprio)
83 rv.sort_by_function(hrd_multistorm_sorter)
87 if __name__==
'__main__': main(sys.argv)
Contains setup(), which initializes the produtil package.
Defines the Revital class which manipulates tcvitals files.
def setup(ignore_hup=False, dbnalert_logger=None, jobname=None, cluster=None, send_dbn=None, thread_logger=False, thread_stack=2 **24, kwargs)
Initializes the produtil package.
def to_datetime(d)
Converts the argument to a datetime.
Time manipulation and other numerical routines.
This class reads one or more tcvitals files and rewrites them as requested.