3 import logging, os, sys, re
21 def hrd_multistorm_sorter(a,b):
22 """!A drop-in replacement for "cmp" that can be used for sorting or
23 comparison. Returns -1 if a<b, 1 if a>b or 0 if a=b. Decision is
26 User priority (a.userprio): lower (priority 1) is "more
27 important" than higher numbers (priority 9999 is fill value).
29 Invest vs. non-invest: invest is less important
31 wind: stronger wind is more important than weaker wind
33 North Atlantic (L) storms: farther west is more important
35 North East Pacific (E) storms: farther East is more important
37 If all of the above values are equal, 0 is returned."""
38 a_userprio=getattr(a,
'userprio',9999)
39 b_userprio=getattr(b,
'userprio',9999)
40 a_invest=1
if (a.stormname==
'INVEST')
else 0
41 b_invest=1
if (b.stormname==
'INVEST')
else 0
43 c = cmp(a_userprio,b_userprio)
or cmp(a_invest,b_invest)
or\
44 -cmp(a.wmax,b.wmax)
or\
45 (a.basin1==
'L' and b.basin1==
'L' and cmp(a.lon,b.lon))
or \
46 (a.basin1==
'E' and b.basin1==
'E' and -cmp(a.lon,b.lon))
53 '/com/arch/prod/syndat/syndat_tcvitals.%Y',
54 '/lfs3/projects/hwrf-data/hwrf-input/SYNDAT-PLUS/syndat_tcvitals.%Y',
55 '/scratch3/NCEPDEV/hwrf/noscrub/input/SYNDAT-PLUS/syndat_tcvitals.%Y',
56 '/scratch1/portfolios/NCEPDEV/hwrf/noscrub/input/SYNDAT-PLUS/syndat_tcvitals.%Y']
59 """!Set up logging, reads vitals, outputs storm list."""
63 eloglevel=logging.INFO)
64 logger=logging.getLogger(
'hwrf_multistorm_sort_test.py')
67 YMDH=cyc.strftime(
'%Y%m%d%H')
73 if 'LECWPQSAB'.find(arg.upper())<0:
74 logger.error(
'Invalid basin %s'%(arg,))
76 basins=basins+arg.upper()
78 m=re.match(
'(\d\d[LECWPQSAB])=(\d+)',arg.upper())
80 logger.error(
'Unrecognized argument: '+arg)
82 (storm,userprio)=m.groups()
83 userprios[storm]=int(userprio)
86 rv.readfiles([ cyc.strftime(v)
for v
in vitfiles ],
90 rv.delete_invest_duplicates()
92 rv.discard_except(
lambda v: v.YMDH==YMDH)
94 logger.info(
'Only keep basins: <%s>'%(basins,))
95 rv.discard_except(
lambda v: v.basin1
in basins)
98 if v.stormid3
in userprios:
99 userprio=int(userprios[v.stormid3])
100 logger.info(
'User priority for %s is %d'%(v.stormid3,userprio))
101 setattr(v,
'userprio',userprio)
103 rv.sort_by_function(hrd_multistorm_sorter)
105 print v.as_tcvitals()
107 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.