1 """!Combines Tasks from multiple modules into a single initialization object.
3 This class combines Tasks from several hwrf modules to make two
4 different initialization systems: the InitBeforeGSI and the HWRFInit.
5 Also, the FGATInit is provided, which is an array of InitBeforeGSI,
10 __all__=[
'HWRFInit',
'InitBeforeGSI',
'FGATInit']
12 import os, datetime, pdb
20 from hwrf.numerics import to_datetime_rel, to_timedelta, to_datetime, \
21 TimeMapping, to_fraction
27 """!Runs the deterministic model initialization.
29 This class runs the WPS, real, prep_hybrid (if enabled), WRF
30 wrfanl and ghost jobs, and runs the tracker to find the parent
31 vortex. Passes that into the relocation (if enabled) to produce
32 the final vortex. It encapsulates that logic within one top-level
33 wrapper object, and provides a way to run several parts of the
34 initialization from a single function call."""
58 def _subworkdir(self,childname):
59 """!Helper function for constructor workdir arguments.
61 Generates a workdir location for input to an HWRFTask
62 constructor by appending the child name as a new directory
63 path component after self.workdir.
64 @param childname the child task name"""
65 dir=os.path.join(self.
workdir,childname)
68 def _suboutdir(self,childname):
69 """!Helper function for constructor outdir arguments.
71 Generates a outdir location for input to an HWRFTask
72 constructor by appending the child name as a new directory
73 path component after self.outdir.
74 @param childname the child task name"""
75 dir=os.path.join(self.
outdir,childname)
78 def __init__(self,ds,conf,section, wrf,initlen,fcstlen,outdir=None,
79 realfcst=
False,wrfghost=
None,prep=
True,track=
True,
80 in_ftime=
None,in_atime=
None,geogrid=
None,
81 prep_one_time=
None,relocate=
True,modin=
None,
82 ibdystep=
None,fgat_times=
None,prepfcst=
None,**kwargs):
83 """!HWRFInit constructor.
85 Creates the deterministic HWRF initialization. Which pieces
86 are selected, and how they are plugged in to one another, is
87 dependent on the input arguments.
89 @param ds passed to Datum: the Datastore object for this Task
90 @param conf the conf object for this task
91 @param section the conf section for this task
92 @param wrf (required) the WRFSimulation representing the full WRF
94 @param initlen (required) the length of the real_nmm run for the
96 @param fcstlen (required) the length of the real_nmm run for the
98 @param outdir The directory in intercom to receive output.
99 Default: intercom/{taskname}. Individual initialization
100 components will be in subdirectories.
101 @param realfcst Flag: do we need to run real for the full forecast
103 @param wrfghost hwrf.wrf.WRFSimulation object for the wrfghost
104 files. If absent, no wrfghost-related jobs will be run
105 @param prep if True, use prep_hybrid input. This changes the way
106 in which real_nmm, ungrib and metgrid are run.
107 @param prepfcst If True AND prep=True, use prep_hybrid for
108 boundary conditions. This changes how realfcst, ungribfcst
109 and metgridfcst are run.
110 @param track Run a post, regribber and tracker on the wrfanl
111 history file for domain 1, to find the location of the
113 @param in_ftime parent model forecast hour to treat as "time 0."
114 This is used for the FGAT to use GDAS forecasts as input
115 @param in_atime parent model analysis time. Default: start time
117 @param geogrid Should be an hwrf.wps.Geogrid, or None. This is
118 used to avoid running expensive geogrid jobs multiple times
119 for multiple FGAT hours. (This is especially important for
120 hourly FGAT.) If None or missing, a Geogrid is created.
121 @param prep_one_time Flag. If True, pretend hour 0 is also
122 hour 1, 2, 3, and so on. This is only used by prep_hybrid,
123 and is intended to prevent expensive spectral to grid
124 transformations of hour 3 when only the analysis time is
126 @param relocate If True, vortex relocation is performed.
127 @param modin The modin argument to hwrf.relocate task constructors.
128 Default: in_dataset.upper()
129 @param ibdystep Optional: the boundary input frequency for the
130 ~1 minute forecasts. Default: bdystep.
131 @param fgat_times: the times at which FGAT is run.
132 @param kwargs Passed to hwrf.hwrftask.HWRFTask.__init__
134 @note If "in_dataset" is in kwargs, it is the option sent to
135 hwrf.input.DataCatalog.locate used for obtaining input files
136 for Ungrib and PrepHybrid.
138 ----------------------------------------------------------
140 This constructor creates the following public member variables
141 or accessors. These are intended to be used to query various
142 components of the initialization. The scripting layer can run
143 the sub-objects via their run methods, or it can simply call
144 the self.run_* subroutines to run them in groups.
147 initlen -- timedelta for length of initialization
148 fcstlen -- timedelta for length of forecast
149 wrffcst -- Task for running or monitoring the WRF forecast
150 wrfdoms -- WRFDomain objects from that wrffcst object
151 wrfinit -- Task for running the wrfanl run of WRF
152 bdytimes -- an array of boundary times needed by the forecast run
153 ibdytimes -- an array of boundary times needed by the init
156 Initialization-Length WRF Init:
157 geogrid -- the hwrf.wps.Geogrid object for running geogrid.exe
158 external_geogrid -- if a geogrid argument was sent to the
159 constructor, it is stored here
160 ungrib -- the hwrf.wps.Ungrib object for running ungrib
161 metgrid -- the hwrf.metgrid.Metgrid object for running metgrid
162 realinit -- the hwrf.fcsttask.RealNMM object for running real
163 for the WRF init jobs
164 runwrfanl -- the hwrf.fcsttask.WRFAnl4Trak object used to run
165 the WRF for to produce the wrfanl files and outer domain
167 wrfghost -- the WRFSimulation representing the ghost if
168 requested. This is the same as the wrfghost argument to
170 runghost -- the hwrf.fcsttask.WRFGhost to run the ghost
174 prep -- the hwrf.prep.PrepHybrid object to run prep_hybrid.
175 The same prep object is used for both the init-length and
176 fcst-length initialization.
178 Forecast-Length WRF Init:
179 ungribfcst -- the hwrf.wps.Ungrib object for running ungrib for
180 the full WRF forecast job, if prep=False
181 metgridfcst -- the hwrf.wps.Metgrid object for running metgrid
182 for the full WRF forecast job if prep=False
183 realfcst -- the hwrf.fcsttask.RealNMM object
185 Parent domain vortex detection:
186 post -- if track=True, this is the hwrf.post.PostOneWRF
187 object used to post-process the wrfanl job's time 0 outer
189 gribber -- the hwrf.gribtask.GRIBTask object used to
190 regrib the output of self.post
191 tracker -- the hwrf.tracker.TrackerTask object used to
192 run the tracker on the gribber
194 super(HWRFInit,self).
__init__(ds,conf,section,**kwargs)
196 if prepfcst
and not prep:
197 raise NotImplementedError(
198 'When running prep_hybrid for boundary conditions, you '
199 'must also run it for initial conditions.')
200 if prep_one_time
is None: prep_one_time=
not prepfcst
213 self.
initlen=to_datetime_rel(initlen,wrf.simstart())
214 self.
fcstlen=to_datetime_rel(fcstlen,wrf.simstart())
215 assert(ibdystep
is not None)
217 ibdystep=self.
confint(
'ibdystep',0)
218 if ibdystep<1: ibdystep=
None
222 self.wrffcst.set_timing(end=self.
fcstlen)
227 self.wrfinit.set_timing(end=self.
initlen)
231 if ibdystep
is not None:
232 self.wrfinit.set_bdystep(ibdystep)
234 bdytimes=[x
for x
in fwrf.bdytimes()]
238 if fwrf.bdystep() != iwrf.bdystep()
and prep
and realfcst:
239 raise NotImplementedError(
240 'You have asked me to run prep_hybrid to produce full '
241 'simulation length inputs AND you specified different '
242 'boundary input timesteps for the initialization-length '
243 'and forecast-length jobs. I cannot do that. You need '
244 'to either disable realfcst or disable prep_hybrid, or '
245 'use the same boundary input timesteps for forecast-length'
246 ' and initialization-length jobs.')
248 starttime=iwrf.simstart()
255 def c(s):
return self.
confstr(s,s)
256 def t(s):
return '%s/%s'%(self.
taskname,s)
261 if 'in_dataset' in kwargs:
262 dst=kwargs[
'in_dataset']
263 ungrib_opts[
'in_dataset']=dst
264 prep_opts[
'in_dataset']=dst
265 if modin
is None: modin=dst.upper()
266 if 'ungrib_one_time' in kwargs:
267 ungrib_opts[
'one_time']=bool(kwargs[
'ungrib_one_time'])
268 if modin
is None: modin=
'GFS'
270 if geogrid
is not None:
274 self.
wrfdoms,taskname=t(
'geogrid'),location=wpsloc,
275 workdir=wpsloc,outdir=so(
'wps'))
279 if fwrf.bdystep() != iwrf.bdystep():
284 geogrid.geodat(moad), times=pbdytimes, taskname=t(
'prep_hybrid'),
285 ftime=in_ftime,atime=in_atime,one_time=prep_one_time,
286 workdir=sw(
'prep_hybrid'),outdir=so(
'prep_hybrid'),**prep_opts)
290 if section ==
'gfsinit':
295 self.
_make_realinit(prep,ds,conf,fwrf,iwrf,endtime,wpsloc,in_atime,
296 in_ftime,ungrib_opts,geogrid,c,t,so,sw)
300 in_atime,in_ftime,ungrib_opts,geogrid,
304 taskname=t(
'wrfanl'), workdir=sw(
'wrfanl'), outdir=so(
'wrfanl')) \
305 .add_metgrid(self.
metgrid).add_geogrid(geogrid).add_real(self.
realinit)
308 if wrfghost
is not None:
309 self.
_make_ghost(ds,conf,wrfghost,geogrid,c,t,so,sw)
313 def _make_realinit(self,prep,ds,conf,fwrf,iwrf,endtime,wpsloc,in_atime,
314 in_ftime,ungrib_opts,geogrid,c,t,so,sw):
315 """!Makes the ungrib, metgrid and realinit member variables.
316 @param prep True if prep_hybrid is in use
317 @param ds the produtil.datastore.Datastore object
318 @param conf the hwrf.config.HWRFConfig
319 @param fwrf the hwrf.wrf.WRFSimulation for the forecast-length run
320 @param iwrf the hwrf.wrf.WRFSimulation for the init-length run
321 @param endtime the end time of the iwrf
322 @param wpsloc directory in which to run WPS
323 @param in_atime the analysis time for the parent model
324 @param in_ftime the forecast time for the parent model that
325 corresponds to the analysis time of this HWRFInit
326 @param ungrib_opts - dict of keyword arguments to send to the hwrf.wps.Ungrib.__init__
327 @param geogrid the hwrf.wps.Geogrid
328 @param c - function to generate config section names for subtasks
329 @param t - function to generate task names for subtasks
330 @param so - function to generate outdirs for subtasks
331 @param sw - function to generate workdirs for subtasks"""
333 self.
wrfdoms,endtime=endtime, taskname=t(
'ungrib'),
334 location=wpsloc,in_atime=in_atime,in_ftime=in_ftime,
335 workdir=wpsloc,outdir=so(
'wps'),**ungrib_opts)
337 self.
wrfdoms,increment=self.
ibdystep,endtime=endtime,taskname=t(
'metgrid'),
338 workdir=wpsloc,outdir=so(
'wps'),location=wpsloc)
340 iwrf, taskname=t(
'realinit'),workdir=sw(
'realinit'),
341 outdir=so(
'realinit')) \
342 .add_metgrid(self.
metgrid).add_geogrid(geogrid)
344 self.realinit.add_prep_hybrid(self.
prep)
346 def _make_realfcst(self,prep,prepfcst,ds,conf,fwrf,fcstlen,wpsloc,
347 in_atime,in_ftime,ungrib_opts,geogrid,c,t,so,sw):
348 """!Makes the ungribfcst, metgridfcst and realfcst member variables:
349 @param prep True if prep_hybrid is in use
350 @param prepfcst True if prep_hybrid is in use for boundary conditions
351 @param ds the produtil.datastore.Datastore object
352 @param conf the hwrf.config.HWRFConfig
353 @param fwrf the WRFSimulation for the forecast-length run
354 @param fcstlen the length of the forecast as a datetime.time_delta
355 @param wpsloc directory in which to run WPS
356 @param in_atime the analysis time for the parent model
357 @param in_ftime the forecast time for the parent model that
358 corresponds to the analysis time of this HWRFInit
359 @param ungrib_opts dict of keyword arguments to send to
360 hwrf.wps.Ungrib.__init__
361 @param geogrid the hwrf.wps.Geogrid
362 @param c function to generate config section names for subtasks
363 @param t function to generate task names for subtasks
364 @param so function to generate outdirs for subtasks
365 @param sw function to generate workdirs for subtasks"""
368 self.
wrfdoms,endtime=fcstlen, taskname=t(
'ungribfcst'),
369 location=wpsloc,in_atime=in_atime,in_ftime=in_ftime,
370 outdir=so(
'wpsfcst'),workdir=wpsloc,**ungrib_opts)
372 self.
wrfdoms,endtime=fcstlen, taskname=t(
'metgridfcst'),
373 outdir=so(
'wpsfcst'),workdir=wpsloc,location=wpsloc,
376 outdir=so(
'realfcst'),workdir=sw(
'realfcst'),
377 taskname=t(
'realfcst')).add_geogrid(geogrid)
380 self.realfcst.add_prep_hybrid(self.
prep) \
386 def _make_track(self,ds,conf,moad,starttime,c,t,so,sw):
387 """!Makes the gribber and tracker member variables.
388 @param ds the produtil.datastore.Datastore object
389 @param conf the hwrf.config.HWRFConfig
390 @param moad the hwrf.wrf.WRFDomain for the outermost domain
391 @param starttime the start time of this HWRFInit's WRF simulations
392 @param c function to generate config section names for subtasks
393 @param t function to generate task names for subtasks
394 @param so function to generate outdirs for subtasks
395 @param sw function to generate workdirs for subtasks"""
398 self.
runwrfanl,[moad],conf,c(
'post'),time=starttime,
399 needcrtm=
False,taskname=t(
'post'),outdir=so(
'post'),
405 'part',hwrf.tracker.tracker_subset,
None)
407 lon=conf[
'config',
'domlon'])
409 lon=self.storminfo.lon)
410 basin=self.storminfo.pubbasin2
411 if ((basin.upper()==
'AL' or basin.upper()==
'EP') \
412 and domloc.ewcenter<360.0):
413 domloc.ewcenter+=360.0
415 wgrib=alias(exe(conf.getexe(
'wgrib'))))
416 r.sync_frequently=self.
confbool(
'sync_frequently',
True)
417 r.add(
'p25grid',clatlon(domloc,res=[0.25,0.25],size=[90.,110.],
418 scan=136,n=[441,361]))
419 r.add(
'trkgrid',clatlon(stormloc,res=[0.25,0.25],size=[20.,20.],
421 r.add(
'quarter_degree',grid1*r.grid(
'p25grid'))
422 r.add(
'subset',r.GRIB(
'quarter_degree')/trksub)
424 r.GRIB(
'subset')*r.grid(
'trkgrid')))
425 basedir=os.path.join(self.
getdir(
'intercom'),t(
'regribber'))
426 r.to_intercom(basedir+
'/quarter_degree.grb',
'quarter_degree')
427 r.to_intercom(basedir+
'/subset.grb',
'subset')
428 r.to_intercom(basedir+
'/{out_prefix}.hwrftrk.grbf{fahr:02d}',
'hwrftrk')
430 ds,conf,c(
'regribber'),r,start=starttime,step=3600,end=starttime,
431 taskname=t(
'regribber'),atime=starttime,workdir=sw(
'regribber'))
433 ds,conf,c(
'tracker'),taskname=t(
'tracker'),start=starttime,
434 step=3600, end=starttime,outdir=so(
'tracker'),
435 workdir=sw(
'tracker'))
437 self.tracker.send_atcfunix(
438 'track0',self.
outdir+
'/gfs.track0.atcfunix')
439 def _make_ghost(self,ds,conf,wrfghost,geogrid,c,t,so,sw):
440 """!Makes the wrfghost, runghost and ghost_domains member variables.
441 @param ds the produtil.datastore.Datastore object
442 @param conf the hwrf.config.HWRFConfig
443 @param wrfghost the WRFSimulation for the ghost run of wrf
444 @param geogrid the hwrf.wps.Geogrid
445 @param c function to generate config section names for subtasks
446 @param t function to generate task names for subtasks
447 @param so function to generate outdirs for subtasks
448 @param sw function to generate workdirs for subtasks"""
451 ds, conf, c(
'wrfghost'), self.
wrfghost, taskname=t(
'wrfghost'),
452 workdir=sw(
'ghost'),outdir=so(
'ghost'))\
453 .add_metgrid(self.
metgrid).add_geogrid(geogrid)\
457 def _make_relocate_kwargs(self,ds,conf,wrfghost,track,modin,dest_dir,so,sw):
458 """!Makes a dict containing the keyword arguments to send in to
459 the constructor for the hwrf.relocate task(s).
460 @param ds the produtil.datastore.Datastore object
461 @param conf the hwrf.config.HWRFConfig
462 @param wrfghost the wrfghost argument to the constructor
463 @param track the track argument to the constructor
464 @param modin the modin argument to the constructor
465 @param dest_dir the directory in which to run the relocate
466 @param so function to generate outdirs for subtasks
467 @param sw function to generate workdirs for subtasks"""
471 modin=modin,dest_dir=dest_dir,workdir=sw(
'relocate'),
472 outdir=so(
'relocate'))
474 if wrfghost
is not None: kwargs.update(wrfghost=self.
runghost)
475 if track: kwargs.update(parentTrack=self.
tracker,trackName=
'track0')
478 def _make_relocate(self,ds,conf,wrfghost,track,modin,c,t,so,sw):
479 """!Makes the relocation, rstage1, rstage2 and rstage3 member
481 @param ds the produtil.datastore.Datastore object
482 @param conf the hwrf.config.HWRFConfig
483 @param wrfghost the wrfghost argument to the constructor
484 @param track the track argument to the constructor
485 @param modin the modin argument to the constructor
486 @param c function to generate config section names for subtasks
487 @param t function to generate task names for subtasks
488 @param so function to generate outdirs for subtasks
489 @param sw function to generate workdirs for subtasks"""
491 raise ArgumentError(
'When in HWRFInit.__init__, when '
492 'relocate=True, wrfghost must not be None')
493 dest_dir=os.path.join(self.
workdir,
'relocate')
498 taskname_pattern=t(
'relocate.stage')+
'%d',**kwargs)
505 """!Iterates over all fgat times, if known."""
511 """!Runs the relocate jobs, if present."""
512 if 'rstage1' in self.__dict__:
513 self.rstage1.delete_temp()
515 if 'rstage2' in self.__dict__:
517 if 'rstage3' in self.__dict__:
519 if self.rstage1.scrub
and self.rstage2.scrub
and \
521 self.rstage3.delete_temp()
523 """!Returns the parent model forecast hour treated as this
524 HWRFInit object's analysis time."""
525 return self._in_ftime
527 """!Returns the parent model analysis time. The value of that
528 may differ from this HWRFInit object's analysis time."""
529 return self._in_atime
533 ftime=property(get_ftime,
None,
None,
534 """!Forecast time of parent model used for initializing HWRF.""")
537 atime=property(get_atime,
None,
None,
"""Analysis time of parent model.""")
540 """!Runs all steps of the initialization in sequence."""
547 """!Runs the following jobs, if they are enabled: geogrid,
548 ungrib, metgrid, init-length prep_hybrid, init-length real_nmm
550 self.
log().warning(
'run_through_anl')
551 if 'geogrid' in self.__dict__:
555 if 'prep' in self.__dict__:
559 self.prep.run_ipiece(i)
563 """!Runs the following jobs if they are enabled: ghost, post,
566 logger.warning(
'run_init_after_anl')
567 if 'runghost' in self.__dict__:
571 if 'post' in self.__dict__:
572 with self.dstore.transaction()
as t:
575 self.post.run(raiseall=
True)
577 if self.gribber.is_completed():
580 msg=
'Error regridding inputs to tracker. See earlier log messages for details.'
584 """!Runs boundary processing jobs.
586 Runs the forecast-length versions of the following jobs if
587 they are enabled: ungribfcst, metgridfcst, prep_hybrid and
588 real. Note that ungribfcst and metgridfcst should be disabled
589 if prep_hybrid is enabled. That is done in the constructor
590 though; the run_real_bdy will happily run all four jobs if
592 self.
log().warning(
'run_real_bdy')
593 if 'ungribfcst' in self.__dict__:
594 self.ungribfcst.run()
595 if 'metgridfcst' in self.__dict__:
596 self.metgridfcst.run()
597 if 'realfcst' in self.__dict__:
598 if 'prep' in self.__dict__
and self.
_prepfcst:
599 for i
in xrange(len(self.
bdytimes)):
603 '%s: skipping: is an initial bdy time (should '
604 'already be done)'%(t.strftime(
'%Y%m%d%H'),))
606 self.prep.run_ipiece(i)
609 """!Iterates over all needed input data
611 Calls the inputiter for the ungrib, ungribfcst and prep
612 members, iterating over all data they need to run the
614 if 'ungrib' in self.__dict__:
615 for d
in self.ungrib.inputiter():
yield d
616 if 'ungribfcst' in self.__dict__:
617 for d
in self.ungribfcst.inputiter():
yield d
618 if 'prep' in self.__dict__:
619 for d
in self.prep.inputiter():
yield d
699 """!Runs the FGAT initialization for one FGAT member
701 This class serves a similar purpose to its superclass, HWRFInit,
702 but is intended for initialization that runs before the GSI. It
703 has a modified list of arguments to the hwrf.relocate classes."""
704 def __init__(self,ds,conf,section,gsi_d01=None,gsi_d02=None,gsi_d03=None,
705 fgat_times=
None, **kwargs):
706 """!Creates a new InitBeforeGSI object. See the
707 HWRFInit.__init__ for details.
708 @param ds passed to Datum: the Datastore object for this Task
709 @param conf the conf object for this task
710 @param section the conf section for this task
711 @param gsi_d01 passed to the hwrf.relocate constructors'
713 @param gsi_d02 passed to the hwrf.relocate constructors'
715 @param gsi_d03 passed to the hwrf.relocate constructors'
717 @param fgat_times array of FGAT times
718 @param kwargs All other keyword arguments are passed to
721 assert(fgat_times
is not None)
722 if not isinstance(fgat_times,list):
723 raise TypeError(
'In InitBeforeGSI.__init__, fgat_times must be a list or tuple, not a %s %s.'
724 %(type(fgat_times).__name__,repr(fgat_times)))
729 ds,conf,section,fgat_times=fgat_times,**kwargs)
738 def _make_relocate_kwargs(self,ds,conf,wrfghost,track,modin,dest_dir,
740 """!Makes the FGAT relocation.
742 This serves the same purpose as the
743 HWRFInit._make_relocate_kwargs(), but it adds to those
744 arguments the gsi_d01, d02 and d03 sent to the constructor,
745 plus the fgat_times."""
747 kwargs=super(InitBeforeGSI,self)._make_relocate_kwargs(
748 ds,conf,wrfghost,track,modin,dest_dir,so,sw)
752 def _make_ghost(self,ds,conf,wrfghost,geogrid,c,t,so,sw):
753 """!Makes the wrfghost, runghost and ghost_domains member
756 Overrides the HWRFInit._make_ghost() to use the
757 WRFGhostForPost class instead of WRFGhost in order to get the
758 wrfout "ghout_d0X" files for each domain for post-processing.
760 @param ds the produtil.datastore.Datastore object
761 @param conf the hwrf.config.HWRFConfig
762 @param wrfghost the WRFSimulation for the ghost run of wrf
763 @param geogrid the hwrf.wps.Geogrid
764 @param c function to generate config section names for subtasks
765 @param t function to generate task names for subtasks
766 @param so function to generate outdirs for subtasks
767 @param sw function to generate workdirs for subtasks"""
770 ds, conf, c(
'wrfghost'), self.
wrfghost, taskname=t(
'wrfghost'),
771 workdir=sw(
'ghost'),outdir=so(
'ghost'))\
772 .add_metgrid(self.
metgrid).add_geogrid(geogrid)\
780 """!The FGATInit represents an array of InitBeforeGSI objects, each run
781 for one forecast hour of some parent model (usually GDAS)."""
793 def __init__(self,ds,conf,section, wrf,initlen,fcstlen,outdir=None,
794 realfcst=
False,wrfghost=
None,prep=
True,track=
True,
795 in_ftimes=
None,in_atime=
None,cycling_interval=6*3600,
796 gsi_d01=
None,gsi_d02=
None,gsi_d03=
None,ibdystep=
None,
797 prepfcst=
True,**kwargs):
798 """!Creates an FGATInit, passing most arguments to the child
799 InitBeforeGSI objects' constructors. The cycling_interval is the
800 time to subtract from this model's analysis time to get the
801 parent model's analysis time. The default of six hours
802 (6*3600 as an int) is correct for the operational HWRF and
805 @param ds passed to Datum: the Datastore object for this Task
806 @param conf the conf object for this task
807 @param section the conf section for this task
808 @param wrf (required) the WRFSimulation representing the full WRF
810 @param initlen (required) the length of the real_nmm run for the
812 @param fcstlen (required) the length of the real_nmm run for the
814 @param outdir The directory in intercom to receive output.
815 Default: intercom/{taskname}. Individual initialization
816 components will be in subdirectories.
817 @param outdir The directory in intercom to receive output.
818 Default: intercom/{taskname}. Individual initialization
819 components will be in subdirectories.
820 @param realfcst Flag: do we need to run real for the full forecast
822 @param wrfghost hwrf.wrf.WRFSimulation object for the wrfghost
823 files. If absent, no wrfghost-related jobs will be run
824 @param prep if True, use prep_hybrid input. This changes the way
825 in which real_nmm, ungrib and metgrid are run.
826 @param track Run a post, regribber and tracker on the wrfanl
827 history file for domain 1, to find the location of the
829 @param in_ftimes array of parent model forecast hours to treat
830 as "time 0" for each FGAT time. This is used for the FGAT to
831 use GDAS forecasts as input
832 @param in_atime parent model analysis time. Default: start time
834 @param cycling_interval HWRF cycling interval in seconds.
835 @param gsi_d01 passed to the hwrf.relocate constructors'
837 @param gsi_d02 passed to the hwrf.relocate constructors'
839 @param gsi_d03 passed to the hwrf.relocate constructors'
841 @param ibdystep Optional: the boundary input frequency for the
842 ~1 minute forecasts. Default: bdystep.
843 @param prepfcst If True AND prep=True, use prep_hybrid for
844 boundary conditions. This changes how realfcst, ungribfcst
845 and metgridfcst are run.
846 @param kwargs Other keyword arguments are passed to HWRFTask.__init__
848 if 'workdir' not in kwargs:
851 kwargs[
'workdir']=conf.getdir(
'WORKhwrf')
852 super(FGATInit,self).
__init__(ds,conf,section,**kwargs)
862 if prepfcst
and not prep:
863 raise NotImplementedError(
864 'When running prep_hybrid for boundary conditions, you '
865 'must also run it for initial conditions.')
875 ibdystep=self.
confint(
'ibdystep',0)
876 if ibdystep<1: ibdystep=0
879 if outdir
is None: self.
outdir=os.path.join(self.
getdir(
'intercom'),
885 if in_ftimes
is None:
886 in_ftimes=[ to_datetime_rel(t,in_atime) \
891 assert(
'ftime2init' in self.__dict__)
895 if 'in_dataset' in kwargs: dsopt[
'in_dataset']=kwargs[
'in_dataset']
896 assert(
'in_dataset' in dsopt)
897 assert(dsopt[
'in_dataset'] ==
'gdas1')
902 centrack=ceninit.rstage3.get_track()
903 log.info(
'centrack %s'%(centrack))
905 init.rstage3.centrack=centrack
907 """!Get the subtask for one time.
909 Returns the initialization InitBeforeGSI object for the
910 specified time (the earliest time not before the specified
911 time). The time can be an absolute time (2015091418) or a
912 forecast hour (12), as long as it is accepted by the first
913 argument of to_datetime_rel. Raises an exception if the time
914 has no InitBeforeGSI objects."""
915 when=to_datetime_rel(when,self.
_in_atime)
918 """!Iterates over needed input data.
920 Calls all inputiter functions for all child objects, hence
921 iterating over all input sources required for all FGAT hours."""
922 for t,p
in self.ftime2init.iteritems():
923 for d
in p.inputiter():
926 """!Get all ghost output products.
927 @param domain The domain of interest, an hwrf.wrf.WRFDomain
929 Returns a TimeMapping, mapping from init time to the ghost
930 product output from the runghost member of each init time."""
932 for t,p
in self.ftime2init.iteritems():
934 if 'runghost' in i.__dict__:
936 gg=rg.get_ghost(domain)
940 """!Get hwrf.relocate.Stage3 objects or output products for
943 Returns a TimeMapping of objects, one per init time. If a
944 domain is specified, the objects are the wrfinput or ghost
945 product output by the relocation for that domain. If a domain
946 is NOT specified, then the objects are the relocate stage 3
948 @param domain The domain of interest."""
950 for t,p
in self.ftime2init.iteritems():
957 rdom=i.wrfghost[domain]
959 rg=rr.wrfinput_at_time(t,rdom)
961 rg=rr.get_ghost(rdom)
964 'Error: %s does not exist at time %s'
969 """!Iterates over all fgat times as datetime.datetime objects."""
970 for ftime
in self.ftime2init.iterkeys():
971 assert(isinstance(ftime,datetime.datetime))
974 """!Iterates over pairs of (fhr,init) where fhr is a
975 fraction.Fraction FGAT hour, and init is an InitBeforeGSI
976 object for that time."""
978 for ftime,init
in self.ftime2init.iteritems():
979 fhr=to_fraction(ftime-self.
_in_atime)/3600.0
981 def _default_ftimes(self):
982 """!Internal function that implements other iterators.
984 This is an iterator that generates the default FGAT hours from
985 the configuration file. The iterator yields the forecast
986 times for the input model as datetime.datetime objects."""
991 raise ValueError(
'ERROR: in hwrf.init.FGATInit the FGATINV must '
992 'be at least one minute, but you provided %f '
997 assert(now
is not None)
999 assert(rel
is not None)
1002 def _make_init(self,in_ftime,taskname,**kwargs):
1003 """!Internal implementation function that generates the
1004 InitBeforeGSI object for one FGAT time.
1006 @param in_ftime The forecast time of interest
1007 @param taskname The name of the child task
1008 @param kwargs Additional keyword arguments passed to
1009 InitBeforeGSI.__init__
1010 @returns the resulting InitBeforeGSI object"""
1011 wrf=self._wrf.copy()
1012 tstart=to_datetime_rel(in_ftime, self.
_in_atime)
1013 ftime=wrf.simend()-wrf.simstart()
1015 wrf.set_timing(start=tstart,end=tend)
1016 wrfghost=self._wrfghost.copy()
1017 wrfghost.set_timing(start=tstart,end=tend)
1020 assert(fgat_times
is not None)
1025 taskname=taskname,prep_one_time=
True,ibdystep=self.
_ibdystep,
1027 gsi_d03=self.
_gsi_d03,fgat_times=fgat_times,
1028 prepfcst=self.
_prepfcst,ungrib_one_time=
True,**kwargs)
1029 assert(child.ungrib.one_time)
1031 def _make_inits(self,**kwargs):
1032 """!Creates all child InitBeforeGSI objects.
1034 Creates InitBeforeGSI objects for all input times in
1035 self.ftime2init and self.inits. The self._make_init is used
1036 to make each individual object. The self.inits will be a list
1037 of InitBeforeGSI objects, and self.ftime2init will be a
1038 mapping from time to InitBeforeGSI.
1039 @param kwargs Passed to _make_init()"""
1040 assert(
'ftime2init' in self.__dict__)
1043 self.
log().debug(
'process ftime %s'%(repr(in_ftime),))
1044 taskname=taskname=
'%s.t%s'%(self.
taskname,in_ftime.strftime(
'%Y%m%d%H%M'))
1045 child=self.
_make_init(in_ftime,taskname,**kwargs)
1046 self.inits.append(child)
1050 """!Runs all InitBeforeGSI.run() commands in sequence."""
1051 for init
in self.
inits: init.run()
1053 """!Runs all InitBeforeGSI.run_through_anl() commands in sequence."""
1054 for init
in self.
inits: init.run_through_anl()
1056 """!Runs all InitBeforeGSI.run_after_anl() commands in sequence."""
1057 for init
in self.
inits: init.run_init_after_anl()
1059 """!Runs all InitBeforeGSI.run_real_bdy() commands in sequence."""
1060 for init
in self.
inits: init.run_real_bdy()
1062 """!Runs all InitBeforeGSI.run_relocate() commands in sequence."""
1063 for init
in self.
inits: init.run_relocate()
post
if track=True, this is the hwrf.post.PostOneWRF object used to post-process the wrfanl job's time 0 o...
def _make_track(self, ds, conf, moad, starttime, c, t, so, sw)
Makes the gribber and tracker member variables.
rstage2
The hwrf.relocation.Stage2 task.
initlen
timedelta for length of initialization
external_geogrid
if a geogrid argument was sent to the constructor, it is stored here
def _make_realfcst(self, prep, prepfcst, ds, conf, fwrf, fcstlen, wpsloc, in_atime, in_ftime, ungrib_opts, geogrid, c, t, so, sw)
Makes the ungribfcst, metgridfcst and realfcst member variables:
Runs regrib operations on many input times, sending output to an hwrf.gribtask.GRIBTask.
ibdystep
Timestep between boundary information for the 1 minute forecast.
ungrib
the hwrf.wps.Ungrib object for running ungrib
def inputiter(self)
Iterates over all needed input data.
ghost_domains
List of ghost domains as hwrf.wrf.WRFDomain objects.
runs wrf to generate ghost (wrfanl) and wrfout files
runghost
the hwrf.fcsttask.WRFGhost to run the ghost if requested.
taskname
Read-only property: the name of this task.
gribber
the hwrf.gribtask.GRIBTask object used to regrib the output of self.post
The base class of tasks run by the HWRF system.
rstage1
The hwrf.relocation.Stage1 task.
def run_relocate(self)
Runs the relocate jobs, if present.
This is a HWRF task that encapsulates stage 3 of the vortex relocation which relocates and pastes the...
This task runs the GFDL Vortex Tracker on HWRF output.
This is a HWRF task that horizontally interpolates the meteorological fields extracted by ungrib to t...
conf
This HWRFTask's hwrf.config.HWRFConfig object.
dstore
Read-only property, an alias for getdatastore(), the Datastore in which this Datum resides...
a HWRFTask subclass that runs real_nmm
storminfo
The hwrf.storminfo.StormInfo describing the vitals information for the storm processed by this HWRFTa...
rstage3
The hwrf.relocation.Stage3 task.
def __init__(self, ds, conf, section, wrf, initlen, fcstlen, outdir=None, realfcst=False, wrfghost=None, prep=True, track=True, in_ftime=None, in_atime=None, geogrid=None, prep_one_time=None, relocate=True, modin=None, ibdystep=None, fgat_times=None, prepfcst=None, kwargs)
HWRFInit constructor.
def run_init_after_anl(self)
Runs the following jobs if they are enabled: ghost, post, gribber, tracker.
def _make_inits(self, kwargs)
Creates all child InitBeforeGSI objects.
def fhr_and_init(self)
Iterates over pairs of (fhr,init) where fhr is a fraction.Fraction FGAT hour, and init is an InitBefo...
runs wrfanl and generates a track file
def getrlimit
Gets the current resource limits.
This is an HWRFTask that post-processes output data for a single WRF stream, from several WRF domains...
geogrid
the hwrf.wps.Geogrid object for running geogrid.exe
wrffcst
Task for running or monitoring the WRF forecast.
def get_relocates
Get hwrf.relocate.Stage3 objects or output products for each FGAT time.
def confbool
Alias for self.conf.getbool for section self.section.
A GRIBBase that subsets GRIB files, keeping only certain parameters.
section
The confsection in self.section for this HWRFTask (read-only)
wrfghost
the WRFSimulation representing the ghost if requested.
Base class of tasks run by HWRF.
A shell-like syntax for running serial, MPI and OpenMP programs.
relocation
The hwrf.relocation.Relocation group of tasks.
metgrid
the hwrf.metgrid.Metgrid object for running metgrid
def getdir
Alias for hwrf.config.HWRFConfig.get() for the "dir" section.
def init_at_time(self, when)
Get the subtask for one time.
outdir
The directory in which this task should deliver its final output.
def run_relocate(self)
Runs all InitBeforeGSI.run_relocate() commands in sequence.
PrepHybrid runs the prep_hybrid program to transform GFS spectral files to the HWRF grid...
Runs the real_nmm or wrf executables.
Runs the FGAT initialization for one FGAT member.
metgridfcst
the hwrf.wps.Metgrid object for running metgrid for the full WRF forecast job if prep=False ...
def get_ghosts(self, domain)
Get all ghost output products.
def run_real_bdy(self)
Runs boundary processing jobs.
def run_real_bdy(self)
Runs all InitBeforeGSI.run_real_bdy() commands in sequence.
def parent_fhrs(self)
Iterates over all fgat times as datetime.datetime objects.
Time manipulation and other numerical routines.
Declares GRIBTask, which automates regribbing operations.
This module allows querying resource usage and limits, as well as setting resource limits...
This module contains Tasks to run the WRF Preprocessing System (WPS): Geogrid, Ungrib and Metgrid...
An hwrf.hwrftask.HWRFTask that performs regribbing operations.
def get_atime(self)
Returns the parent model analysis time.
workdir
The directory in which this task should be run.
def confint
Alias for self.conf.getint for section self.section.
fcstlen
timedelta for length of forecast
def conffloat
Alias for self.conf.getfloat for section self.section.
Represents a specific location on the earth as a latitude, longitude pair.
def fgat_times(self)
Iterates over all fgat times, if known.
def log
Obtain a logging domain.
def _make_relocate(self, ds, conf, wrfghost, track, modin, c, t, so, sw)
Makes the relocation, rstage1, rstage2 and rstage3 member variables.
def _subworkdir(self, childname)
Helper function for constructor workdir arguments.
Runs the deterministic model initialization.
def _make_relocate_kwargs(self, ds, conf, wrfghost, track, modin, dest_dir, so, sw)
Makes a dict containing the keyword arguments to send in to the constructor for the hwrf...
bdytimes
An array of boundary times needed by the forecast run of WRF.
inits
InitBeforeGSI objects for individual times.
ungribfcst
the hwrf.wps.Ungrib object for running ungrib for the full WRF forecast job, if prep=False ...
def run(self)
Runs all InitBeforeGSI.run() commands in sequence.
def __init__(self, ds, conf, section, wrf, initlen, fcstlen, outdir=None, realfcst=False, wrfghost=None, prep=True, track=True, in_ftimes=None, in_atime=None, cycling_interval=6 *3600, gsi_d01=None, gsi_d02=None, gsi_d03=None, ibdystep=None, prepfcst=True, kwargs)
Creates an FGATInit, passing most arguments to the child InitBeforeGSI objects' constructors.
This is a HWRF task that extracts the meteorological fields from GRIB formatted files and write the f...
def _make_ghost(self, ds, conf, wrfghost, geogrid, c, t, so, sw)
Makes the wrfghost, runghost and ghost_domains member variables.
vinttave
An alias for GRIB1VintTave.
Runs the Unified Post Processor on outputs from the WRF-NMM, producing E grid GRIB files as EGRIB1Pro...
This is a HWRF task that pre processes the geogrid to define the model domains and interpolates stati...
def __init__(self, ds, conf, section, gsi_d01=None, gsi_d02=None, gsi_d03=None, fgat_times=None, kwargs)
Creates a new InitBeforeGSI object.
def _suboutdir(self, childname)
Helper function for constructor outdir arguments.
This module contains tasks to prepare input for the GFDL Vortex Tracker, run the tracker and deliver ...
def get_ftime(self)
Returns the parent model forecast hour treated as this HWRFInit object's analysis time...
def _default_ftimes(self)
Internal function that implements other iterators.
The FGATInit represents an array of InitBeforeGSI objects, each run for one forecast hour of some par...
Exceptions raised by the hwrf package.
def run_init_after_anl(self)
Runs all InitBeforeGSI.run_after_anl() commands in sequence.
def confstr
Alias for self.conf.getstr for section self.section.
def run_through_anl(self)
Runs all InitBeforeGSI.run_through_anl() commands in sequence.
Describes regribbing operations using an algebraic structure.
prep
the hwrf.prep.PrepHybrid object to run prep_hybrid.
rusage
Alias for produtil.rusage.RUsage.
runs a short WRF simulation to generate wrfanl files named "ghost"
def igrb1(task, kwargs)
This is a convenient alias for the GRIB1Selector constructor.
def run(self)
Runs all steps of the initialization in sequence.
Exceptions for hwrf.regrib.GRIBTask for certain internal errors.
This module implements Python classes that run the 2014 HWRF Relocation.
wrfinit
Task for running the ~1 minute forecast to generate wrfanl files.
Runs the prep_hybrid program on GFS spectral files.
def _make_realinit(self, prep, ds, conf, fwrf, iwrf, endtime, wpsloc, in_atime, in_ftime, ungrib_opts, geogrid, c, t, so, sw)
Makes the ungrib, metgrid and realinit member variables.
Raised by hwrf.input when trying to get the wrong domain from its hwrf.relocate.Relocate child object...
ibdytimes
An array of boundary times needed by the ~1 minute wrf forecast used to create wrfanl and ghost files...
def inputiter(self)
Iterates over needed input data.
realfcst
the hwrf.fcsttask.RealNMM object
realinit
the hwrf.fcsttask.RealNMM object for running real for the WRF init jobs
tracker
the hwrf.tracker.TrackerTask object used to run the tracker on the gribber
ftime2init
A mapping from forecast time to InitBeforeGSI objects.
runwrfanl
the hwrf.fcsttask.WRFAnl4Trak object used to run the WRF for to produce the wrfanl files and outer do...
def _make_init(self, in_ftime, taskname, kwargs)
Internal implementation function that generates the InitBeforeGSI object for one FGAT time...
def run_through_anl(self)
Runs the following jobs, if they are enabled: geogrid, ungrib, metgrid, init-length prep_hybrid...
This represents all three stages of the relocate.
wrfdoms
WRFDomain objects from that wrffcst object.