U $g@sdZdddgZddlZddlZddlZddlZddlZddlZ ddl Z ddl Z ddl Z ddl Z ddlZ ddlZ ddlZ ddlZ ddlZ ddlmZddlmZmZddlmZdd lmZmZmZmZmZdd l mZdd lmZm Z Gd ddeZ!Gd dde!Z"GdddeZ#dS)a(!Combines Tasks from multiple modules into a single initialization object. This class combines Tasks from several hwrf modules to make two different initialization systems: the InitBeforeGSI and the HWRFInit. Also, the FGATInit is provided, which is an array of InitBeforeGSI, one per FGAT time.HWRFInit InitBeforeGSIFGATInitN)set_ecflow_label)aliasexe)HWRFTask)to_datetime_rel to_timedelta to_datetime TimeMapping to_fraction)clatlon) NoSuchDomain GribberErrorcseZdZdZddZddZd+fd d Zd d Zd dZddZ ddZ ddZ ddZ ddZ ddZddZddZeedddZeeddd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*ZZS),ra!Runs the deterministic model initialization. This class runs the WPS, real, prep_hybrid (if enabled), WRF wrfanl and ghost jobs, and runs the tracker to find the parent vortex. Passes that into the relocation (if enabled) to produce the final vortex. It encapsulates that logic within one top-level wrapper object, and provides a way to run several parts of the initialization from a single function call.cCstj|j|}|S)a !Helper function for constructor workdir arguments. Generates a workdir location for input to an HWRFTask constructor by appending the child name as a new directory path component after self.workdir. @param childname the child task name)ospathjoinworkdirselfZ childnamedirr7/lfs/h1/ops/prod/packages/hwrf.v13.2.9/ush/hwrf/init.py _subworkdir;szHWRFInit._subworkdircCstj|j|}|S)a !Helper function for constructor outdir arguments. Generates a outdir location for input to an HWRFTask constructor by appending the child name as a new directory path component after self.outdir. @param childname the child task name)rrroutdirrrrr _suboutdirEszHWRFInit._suboutdirNFTc' sRttj|||f|t|_|r2| s2td|dkr@| }|_j}j}}|_ |_ |dkrt j dj_ j}j}t||_t||_|dk st|dkrވdd}|dkrd}|_|_jjjddd jD_|_jjjd|dk r@j|j}j}|}d d | D}d d | D_ d d | D_!|"|"kr| r|rtd |}|d}|#jdjdkstfdd} fdd}!t$}"t$}#d|kr<|d}$|$|"d<|$|#d<|dkr<|$%}d|krVt|d|"d<|dkrdd}|dk rv|_&n8t'j(j)||| d|jj|!d|||dd _*j*}| r|"|"krΈj!}%nj }%t'j+j,||| d||-|f|%|!d| |||d|dd|#_+|}&n<| rD|"|"kr>j!}%n|}&n|dkrVj}&n|}&.| |||||&||| |"|| |!|||r/| |||||||| |"|| |!||t'j0j1||| d||!d|d|dd2j34|5j6_7| r 8||||| |!||| dk r.9||| || |!|||rN:||| | || |!|| dS)ap!HWRFInit constructor. Creates the deterministic HWRF initialization. Which pieces are selected, and how they are plugged in to one another, is dependent on the input arguments. @param ds passed to Datum: the Datastore object for this Task @param conf the conf object for this task @param section the conf section for this task @param wrf (required) the WRFSimulation representing the full WRF forecast @param initlen (required) the length of the real_nmm run for the initialization @param fcstlen (required) the length of the real_nmm run for the full forecast @param outdir The directory in intercom to receive output. Default: intercom/{taskname}. Individual initialization components will be in subdirectories. @param realfcst Flag: do we need to run real for the full forecast length? @param wrfghost hwrf.wrf.WRFSimulation object for the wrfghost files. If absent, no wrfghost-related jobs will be run @param prep if True, use prep_hybrid input. This changes the way in which real_nmm, ungrib and metgrid are run. @param prepfcst If True AND prep=True, use prep_hybrid for boundary conditions. This changes how realfcst, ungribfcst and metgridfcst are run. @param track Run a post, regribber and tracker on the wrfanl history file for domain 1, to find the location of the parent vortex. @param in_ftime parent model forecast hour to treat as "time 0." This is used for the FGAT to use GDAS forecasts as input @param in_atime parent model analysis time. Default: start time of wrf @param geogrid Should be an hwrf.wps.Geogrid, or None. This is used to avoid running expensive geogrid jobs multiple times for multiple FGAT hours. (This is especially important for hourly FGAT.) If None or missing, a Geogrid is created. @param prep_one_time Flag. If True, pretend hour 0 is also hour 1, 2, 3, and so on. This is only used by prep_hybrid, and is intended to prevent expensive spectral to grid transformations of hour 3 when only the analysis time is needed from WRF. @param relocate If True, vortex relocation is performed. @param modin The modin argument to hwrf.relocate task constructors. Default: in_dataset.upper() @param ibdystep Optional: the boundary input frequency for the ~1 minute forecasts. Default: bdystep. @param fgat_times: the times at which FGAT is run. @param kwargs Passed to hwrf.hwrftask.HWRFTask.__init__ @note If "in_dataset" is in kwargs, it is the option sent to hwrf.input.DataCatalog.locate used for obtaining input files for Ungrib and PrepHybrid. ---------------------------------------------------------- This constructor creates the following public member variables or accessors. These are intended to be used to query various components of the initialization. The scripting layer can run the sub-objects via their run methods, or it can simply call the self.run_* subroutines to run them in groups. Reference variables: initlen -- timedelta for length of initialization fcstlen -- timedelta for length of forecast wrffcst -- Task for running or monitoring the WRF forecast wrfdoms -- WRFDomain objects from that wrffcst object wrfinit -- Task for running the wrfanl run of WRF bdytimes -- an array of boundary times needed by the forecast run ibdytimes -- an array of boundary times needed by the init run of wrf Initialization-Length WRF Init: geogrid -- the hwrf.wps.Geogrid object for running geogrid.exe external_geogrid -- if a geogrid argument was sent to the constructor, it is stored here ungrib -- the hwrf.wps.Ungrib object for running ungrib metgrid -- the hwrf.metgrid.Metgrid object for running metgrid realinit -- the hwrf.fcsttask.RealNMM object for running real for the WRF init jobs runwrfanl -- the hwrf.fcsttask.WRFAnl4Trak object used to run the WRF for to produce the wrfanl files and outer domain time 0 wrfout file wrfghost -- the WRFSimulation representing the ghost if requested. This is the same as the wrfghost argument to the constructor runghost -- the hwrf.fcsttask.WRFGhost to run the ghost if requested. Prep Hybrid: prep -- the hwrf.prep.PrepHybrid object to run prep_hybrid. The same prep object is used for both the init-length and fcst-length initialization. Forecast-Length WRF Init: ungribfcst -- the hwrf.wps.Ungrib object for running ungrib for the full WRF forecast job, if prep=False metgridfcst -- the hwrf.wps.Metgrid object for running metgrid for the full WRF forecast job if prep=False realfcst -- the hwrf.fcsttask.RealNMM object Parent domain vortex detection: post -- if track=True, this is the hwrf.post.PostOneWRF object used to post-process the wrfanl job's time 0 outer domain wrfout file gribber -- the hwrf.gribtask.GRIBTask object used to regrib the output of self.post tracker -- the hwrf.tracker.TrackerTask object used to run the tracker on the gribber ^When running prep_hybrid for boundary conditions, you must also run it for initial conditions.Nintercomibdystepr)endcSsg|]}|qSrr.0drrr sz%HWRFInit.__init__..cSsg|]}|qSrrr#xrrrr%scSsg|]}|qSrrr&rrrr%scSsg|]}|qSrrr&rrrr%sagYou have asked me to run prep_hybrid to produce full simulation length inputs AND you specified different boundary input timesteps for the initialization-length and forecast-length jobs. I cannot do that. You need to either disable realfcst or disable prep_hybrid, or use the same boundary input timesteps for forecast-length and initialization-length jobs.wps/cs ||S)N)confstrsrrrczHWRFInit.__init__..ccsdj|fS)Nz%s/%s)tasknamer+r-rrtr/zHWRFInit.__init__..t in_datasetungrib_one_timeone_timeGFSgeogrid) incrementr0locationrr prep_hybrid)timesr0ftimeatimer4rrgfsinitwrfanlr0rr);superr__init__bool _prepfcstNotImplementedErrorrrlog _fgat_timesrrrrgetdirr0dstoreconfr simstartinitlenfcstlenAssertionErrorconfintrcopyZwrffcst set_timingwrfdomswrfinit set_bdystepget_moadbdytimes ibdytimesbdystepfinddictupperZexternal_geogridhwrfr(Geogridr6prep PrepHybridgeodat_make_realinit_make_realfcstfcsttask WRFAnl4Trak add_metgridmetgrid add_geogridadd_realrealinit runwrfanl _make_track _make_ghost_make_relocate)'rdsrIsectionwrfrKrLrrealfcstwrfghostr] highresgribtrackin_ftimein_atimer6 prep_one_timerelocatemodinr fgat_timesprepfcstkwargssoswloggerfwrfiwrfmoadrU starttimewpslocr.r1 ungrib_optsZ prep_optsdstZ pbdytimesendtime __class__r-rrAOs t                  zHWRFInit.__init__c Cstjj||| d||jf|j|| d||| ||dd| |_tjj||| d||j|j|| d||d|d |_tjj ||| d|| d|d|dd |j | |_ |r|j |jdS) a<!Makes the ungrib, metgrid and realinit member variables. @param prep True if prep_hybrid is in use @param ds the produtil.datastore.Datastore object @param conf the hwrf.config.HWRFConfig @param fwrf the hwrf.wrf.WRFSimulation for the forecast-length run @param iwrf the hwrf.wrf.WRFSimulation for the init-length run @param endtime the end time of the iwrf @param wpsloc directory in which to run WPS @param in_atime the analysis time for the parent model @param in_ftime the forecast time for the parent model that corresponds to the analysis time of this HWRFInit @param ungrib_opts - dict of keyword arguments to send to the hwrf.wps.Ungrib.__init__ @param geogrid the hwrf.wps.Geogrid @param c - function to generate config section names for subtasks @param t - function to generate task names for subtasks @param so - function to generate outdirs for subtasks @param sw - function to generate workdirs for subtasksungribr()r7rr0r8rurtrrre)r7rr0rrr8rhr?N)r[r(UngribrQrrMetgridrerbRealNMMrdrfrhadd_prep_hybridr])rr]rmrIrrrrrurtrr6r.r1r|r}rrrr`@sFzHWRFInit._make_realinitcCs|s|tjj||| d||jf|j|| d||| |d|d| |_tjj||| d||j|j|| d|d|||jd |_tj j ||| d||d|d| dd  | |_ |r|j |j|jn|j |jd S) a:!Makes the ungribfcst, metgridfcst and realfcst member variables: @param prep True if prep_hybrid is in use @param prepfcst True if prep_hybrid is in use for boundary conditions @param ds the produtil.datastore.Datastore object @param conf the hwrf.config.HWRFConfig @param fwrf the WRFSimulation for the forecast-length run @param fcstlen the length of the forecast as a datetime.time_delta @param wpsloc directory in which to run WPS @param in_atime the analysis time for the parent model @param in_ftime the forecast time for the parent model that corresponds to the analysis time of this HWRFInit @param ungrib_opts dict of keyword arguments to send to hwrf.wps.Ungrib.__init__ @param geogrid the hwrf.wps.Geogrid @param c function to generate config section names for subtasks @param t function to generate task names for subtasks @param so function to generate outdirs for subtasks @param sw function to generate workdirs for subtasksr ungribfcstZwpsfcst)r7rr0r8rurtrrre metgridfcst)r7rr0rrr8 geogrid_fromrp)rrr0N)r[r(SteppingUngribrQrrrr6rrbrrfrprr]rdre)rr]rzrmrIrrLrrurtrr6r.r1r|r}rrrraasJzHWRFInit._make_realfcstc  Cs\tjj|j|g||d|d|d|d|dd |_tjj|j|d} tjdtjjd} tjj |d|dd } tjj |j j |j j d } |j j } | d ks| d kr| jd kr| jd 7_tjjtt|d tt|dd}|dt| ddgddgdddgd|dt| ddgddgdddgd|d| |d|d|d| |dtj|d|dtj|d|d }||d!d||d"d||d#dtjj|||d ||d$||d ||d d% |_ tjj!|||d&|d&|d$||d&|d&d' |_|j"|j |j d|j#d(|j$d)dS)*a'!Makes the gribber and tracker member variables. @param ds the produtil.datastore.Datastore object @param conf the hwrf.config.HWRFConfig @param moad the hwrf.wrf.WRFDomain for the outermost domain @param starttime the start time of this HWRFInit's WRF simulations @param c function to generate config section names for subtasks @param t function to generate task names for subtasks @param so function to generate outdirs for subtasks @param sw function to generate workdirs for subtaskspostF)timeneedcrtmr0rr)domainpartN)configdomlat)rdomlon)latlonALEPgv@copygbwgrib)rrZp25gridg?gV@g[@iii)ressizescanntrkgridg4@QZquarter_degreesubsethwrftrkr regribberz/quarter_degree.grbz /subset.grbz$/{out_prefix}.hwrftrk.grbf{fahr:02d})startstepr!r0r<rtracker)r0rrr!rrtrack0z/gfs.track0.atcfunix)%r[r PostOneWRFriregribigrb1 GRIBSubsetterrtracker_subset FixedLocation storminforr pubbasin2rZewcenter RegribManyrrgetexeaddrgridGRIBvinttaverrrrG to_intercomgribtaskGRIBTaskgribber TrackerTaskadd_moving_grid send_atcfunixr)rrmrIrrr.r1r|r}grid1trksubdomlocstormlocbasinrbasedirrrrrjs    zHWRFInit._make_trackc Cs`||_tjj|||d|j|d|d|dd|j||j|_ dd|jD|_ dS)a!Makes the wrfghost, runghost and ghost_domains member variables. @param ds the produtil.datastore.Datastore object @param conf the hwrf.config.HWRFConfig @param wrfghost the WRFSimulation for the ghost run of wrf @param geogrid the hwrf.wps.Geogrid @param c function to generate config section names for subtasks @param t function to generate task names for subtasks @param so function to generate outdirs for subtasks @param sw function to generate workdirs for subtasksrqghostr?cSsg|]}|qSrrr"rrrr%sz(HWRFInit._make_ghost..N) rqr[rbWRFGhostrdrerfrgrhrunghost ghost_domains rrmrIrqr6r.r1r|r}rrrrks" zHWRFInit._make_ghostc CsZt|j|j|j|j|j|||d|dd } |dk rB| j|jd|rV| j|jdd| S)aO!Makes a dict containing the keyword arguments to send in to the constructor for the hwrf.relocate task(s). @param ds the produtil.datastore.Datastore object @param conf the hwrf.config.HWRFConfig @param wrfghost the wrfghost argument to the constructor @param track the track argument to the constructor @param modin the modin argument to the constructor @param dest_dir the directory in which to run the relocate @param so function to generate outdirs for subtasks @param sw function to generate workdirs for subtasksrw) r>wrfinputsimdomainsrrxdest_dirrrN)rqr) parentTrack trackName) rYrirhrRrQrupdaterr rrmrIrqrsrxrr|r}r{rrr_make_relocate_kwargss zHWRFInit._make_relocate_kwargsc Cs|dkrtdtj|jd} ||||||| || } tjj|||dfd|ddi| |_ |j j |_ |j j |_ |j j |_ dS)al!Makes the relocation, rstage1, rstage2 and rstage3 member variables. @param ds the produtil.datastore.Datastore object @param conf the hwrf.config.HWRFConfig @param wrfghost the wrfghost argument to the constructor @param track the track argument to the constructor @param modin the modin argument to the constructor @param c function to generate config section names for subtasks @param t function to generate task names for subtasks @param so function to generate outdirs for subtasks @param sw function to generate workdirs for subtasksNzHWhen in HWRFInit.__init__, when relocate=True, wrfghost must not be Nonerwtaskname_patternzrelocate.stagez%d) Z ArgumentErrorrrrrrr[rw Relocation relocationrstage1rstage2rstage3) rrmrIrqrsrxr.r1r|r}rr{rrrrls    zHWRFInit._make_relocateccs |jdk r|jD] }|VqdS)z(!Iterates over all fgat times, if known.N)ry)rr1rrrrys  zHWRFInit.fgat_timescCsld|jkrh|j|jd|jkrF|jd|jkrF|j|jjrh|jjrh|jjrh|jdS)z$!Runs the relocate jobs, if present.rrrN)__dict__r delete_temprunrrscrubr-rrr run_relocates       zHWRFInit.run_relocatecCs|jS)z`!Returns the parent model forecast hour treated as this HWRFInit object's analysis time.)Z _in_ftimer-rrr get_ftimeszHWRFInit.get_ftimecCs|jS)zy!Returns the parent model analysis time. The value of that may differ from this HWRFInit object's analysis time.) _in_atimer-rrr get_atimeszHWRFInit.get_atimez:!Forecast time of parent model used for initializing HWRF.zAnalysis time of parent model.cCs$||||dS)z2!Runs all steps of the initialization in sequence.N)run_through_anlrun_init_after_anlr run_real_bdyr-rrrr!sz HWRFInit.runcCs|dd|jkr,tdd|jtdd|jtdd|jd|jkrtddtt |j D](}|j |}||j krq|j |qvtdd |jtdd |jtdd d S) z!Runs the following jobs, if they are enabled: geogrid, ungrib, metgrid, init-length prep_hybrid, init-length real_nmm and wrfanl.rr6statusz[geogrid] process terrainz[ungrib] process parent GRIBz"[metgrid] interpolate horizontallyr]z[prep] process parent spectralz[realinit] make wrfinput filez[runwrfanl] make wrfanl fileszPassed through anl.N)rEwarningrrr6rrrerangelenrVrKr] run_ipiecerhririr1rrrr(s(               zHWRFInit.run_through_anlc Cs|}|dd|jkrXtjj|dtjj|dtdd|jW5QRXd|jkr|j }|j |j W5QRXtdd|j jdd tdd |j jdd |j rtdd |jnd }||t|tdd dS)zT!Runs the following jobs if they are enabled: ghost, post, gribber, tracker.rr)r~rz[runghost] make wrfghost filesrz [post] post wrfghost for trackerT)raiseallz%[gribber] regrid wrfghost for trackerz[tracker] find parent vortexzJError regridding inputs to tracker. See earlier log messages for details.zPassed full init except bdy.N)rErrprodutilrusage getrlimitrrrrH transactionrunrunr is_completedrerrorr)rr~r1msgrrrr?s,            zHWRFInit.run_init_after_anlcCs|dd|jkr,tdd|jd|jkrJtdd|jd|jkrd|jkr|jrtt |j D]@}|j |}||j kr| d | d fqr|j|qrtdd |jtdd d S)a!Runs boundary processing jobs. Runs the forecast-length versions of the following jobs if they are enabled: ungribfcst, metgridfcst, prep_hybrid and real. Note that ungribfcst and metgridfcst should be disabled if prep_hybrid is enabled. That is done in the constructor though; the run_real_bdy will happily run all four jobs if requested.rrrz&[ungribfcst] process parent GRIB (all)rz+[metgridfcst] interpolate parent GRIB (all)rpr]z=%s: skipping: is an initial bdy time (should already be done)z%Y%m%d%Hz([realfcst] interpolate parent GRIB (all)zEntire init complete.N)rErrrrrrrCrrrUrVinfostrftimer]rrprrrrrYs,             zHWRFInit.run_real_bdyccshd|jkr |jD] }|Vqd|jkr@|jD] }|Vq4d|jkrd|jjddD] }|VqXdS)z!Iterates over all needed input data Calls the inputiter for the ungrib, ungribfcst and prep members, iterating over all data they need to run the initialization.rrr]F)optionalN)rr inputiterrr])rr$rrrrvs   zHWRFInit.inputiter)NFNTFTNNNNTNNNN)__name__ __module__ __qualname____doc__rrrAr`rarjrkrrlryrrrpropertyr;r<rrrrr __classcell__rrrrrsN  r!(4 cs6eZdZdZd fdd ZfddZddZZS) rz!Runs the FGAT initialization for one FGAT member This class serves a similar purpose to its superclass, HWRFInit, but is intended for initialization that runs before the GSI. It has a modified list of arguments to the hwrf.relocate classes.Nc  st|dk s tt|ts0tdt|jt|f||_||_||_ t t |j |||fd|i||j dk sptdS)a!Creates a new InitBeforeGSI object. See the HWRFInit.__init__ for details. @param ds passed to Datum: the Datastore object for this Task @param conf the conf object for this task @param section the conf section for this task @param gsi_d01 passed to the hwrf.relocate constructors' gsi_d01 argument @param gsi_d02 passed to the hwrf.relocate constructors' gsi_d02 argument @param gsi_d03 passed to the hwrf.relocate constructors' gsi_d03 argument @param fgat_times array of FGAT times @param kwargs All other keyword arguments are passed to HWRFInit.__init__ NzKIn InitBeforeGSI.__init__, fgat_times must be a list or tuple, not a %s %s.ry)rM isinstancelist TypeErrortyperrepr_gsi_d01_gsi_d02_gsi_d03r@rrArF) rrmrIrngsi_d01gsi_d02gsi_d03ryr{rrrrAs$   zInitBeforeGSI.__init__c sJ|jdk sttt|||||||||} | j|j|j|j|jd| S)z!Makes the FGAT relocation. This serves the same purpose as the HWRFInit._make_relocate_kwargs(), but it adds to those arguments the gsi_d01, d02 and d03 sent to the constructor, plus the fgat_times.N)rrrry) rFrMr@rrrr r r rrrrrs   z#InitBeforeGSI._make_relocate_kwargsc Cs`||_tjj|||d|j|d|d|dd|j||j|_ dd|jD|_ dS)a!Makes the wrfghost, runghost and ghost_domains member variables. Overrides the HWRFInit._make_ghost() to use the WRFGhostForPost class instead of WRFGhost in order to get the wrfout "ghout_d0X" files for each domain for post-processing. @param ds the produtil.datastore.Datastore object @param conf the hwrf.config.HWRFConfig @param wrfghost the WRFSimulation for the ghost run of wrf @param geogrid the hwrf.wps.Geogrid @param c function to generate config section names for subtasks @param t function to generate task names for subtasks @param so function to generate outdirs for subtasks @param sw function to generate workdirs for subtasksrqrr?cSsg|]}|qSrrr"rrrr%sz-InitBeforeGSI._make_ghost..N) rqr[rbWRFGhostForPostrdrerfrgrhrrrrrrrks"zInitBeforeGSI._make_ghost)NNNN)rrrrrArrkrrrrrrs " c seZdZdZd$fdd Zdd Zd d Zd d Zd%ddZddZ ddZ ddZ ddZ ddZ ddZddZddZd d!Zd"d#ZZS)&rz!The FGATInit represents an array of InitBeforeGSI objects, each run for one forecast hour of some parent model (usually GDAS).NFT`Tc sd|kr|d|d<tt|j|||f||}||_||_||_||_|r^| s^t d| |_ ||_ | |_ ||_ | |_||_||_t||_|dkr|dd}|dkrd}||_|dkrtj|d|j|_t||_dkr||j|_| dkrfd d |D} d d | D|_t|_ t!|jd d |_"d|j#ksXt$t%}d|krt|d|d<d|kst$|ddkst$|j&f||j st$|'|j(}|j)*}|+d||,D]\}}||j)_-qdS)a !Creates an FGATInit, passing most arguments to the child InitBeforeGSI objects' constructors. The cycling_interval is the time to subtract from this model's analysis time to get the parent model's analysis time. The default of six hours (6*3600 as an int) is correct for the operational HWRF and GDAS. @param ds passed to Datum: the Datastore object for this Task @param conf the conf object for this task @param section the conf section for this task @param wrf (required) the WRFSimulation representing the full WRF forecast @param initlen (required) the length of the real_nmm run for the initialization @param fcstlen (required) the length of the real_nmm run for the full forecast @param outdir The directory in intercom to receive output. Default: intercom/{taskname}. Individual initialization components will be in subdirectories. @param outdir The directory in intercom to receive output. Default: intercom/{taskname}. Individual initialization components will be in subdirectories. @param realfcst Flag: do we need to run real for the full forecast length? @param wrfghost hwrf.wrf.WRFSimulation object for the wrfghost files. If absent, no wrfghost-related jobs will be run @param prep if True, use prep_hybrid input. This changes the way in which real_nmm, ungrib and metgrid are run. @param track Run a post, regribber and tracker on the wrfanl history file for domain 1, to find the location of the parent vortex. @param in_ftimes array of parent model forecast hours to treat as "time 0" for each FGAT time. This is used for the FGAT to use GDAS forecasts as input @param in_atime parent model analysis time. Default: start time of wrf @param cycling_interval HWRF cycling interval in seconds. @param gsi_d01 passed to the hwrf.relocate constructors' gsi_d01 argument @param gsi_d02 passed to the hwrf.relocate constructors' gsi_d02 argument @param gsi_d03 passed to the hwrf.relocate constructors' gsi_d03 argument @param ibdystep Optional: the boundary input frequency for the ~1 minute forecasts. Default: bdystep. @param prepfcst If True AND prep=True, use prep_hybrid for boundary conditions. This changes how realfcst, ungribfcst and metgridfcst are run. @param kwargs Other keyword arguments are passed to HWRFTask.__init__ rWORKhwrfrNrrr rcsg|]}t|qSr)r r#r1rurrr%sz%FGATInit.__init__..cSsg|]}|qSrrrrrrr%scSsdS)Nr rrrrrr/z#FGATInit.__init__.. ftime2initr2gdas1z centrack %s).rGr@rrArErr r r rD_preprC_track_wrf _wrfghost_initlen_fcstlenrB _realfcstrN _ibdysteprrrr0r _cycling_intervalrJr_default_ftimes _in_ftimesrinitsr rrrMrY _make_inits init_at_timecycler get_trackdebug fhr_and_initcentrack)rrmrIrnrorKrLrrprqr]rsZ in_ftimesrucycling_intervalrrrrrzr{rEZdsoptceninitr+fhrinitrrrrA/sj7          zFGATInit.__init__cCst||j}|j|S)a!Get the subtask for one time. Returns the initialization InitBeforeGSI object for the specified time (the earliest time not before the specified time). The time can be an absolute time (2015091418) or a forecast hour (12), as long as it is accepted by the first argument of to_datetime_rel. Raises an exception if the time has no InitBeforeGSI objects.)r rr)rwhenrrrr&s zFGATInit.init_at_timeccs,|jD]\}}|D] }|Vqq dS)z!Iterates over needed input data. Calls all inputiter functions for all child objects, hence iterating over all input sources required for all FGAT hours.N)ritemsr)rr1pr$rrrrs zFGATInit.inputitercCsNt|j}|jD]4\}}||}d|jkr|j}||}|||<q|S)z!Get all ghost output products. @param domain The domain of interest, an hwrf.wrf.WRFDomain Returns a TimeMapping, mapping from init time to the ghost product output from the runghost member of each init time.r)r r#rr1r&rr get_ghost)rrretr1r2rrgZggrrr get_ghostss     zFGATInit.get_ghostsc Cst|j}|jD]\}}||}|j}|dkr>|||<qt|tjj sPt |j |}| rp| ||}n ||}|dkrtdt|t|f|||<q|S)a!Get hwrf.relocate.Stage3 objects or output products for each FGAT time. Returns a TimeMapping of objects, one per init time. If a domain is specified, the objects are the wrfinput or ghost product output by the relocation for that domain. If a domain is NOT specified, then the objects are the relocate stage 3 tasks. @param domain The domain of interest.Nz#Error: %s does not exist at time %s)r r#rr1r&rrr[rwStage3rMrqis_moadwrfinput_at_timer3rstr) rrr4r1r2rZrrZrdomr5rrr get_relocatess(     zFGATInit.get_relocatesccs*|jD]}t|tjst|Vq dS)z;!Iterates over all fgat times as datetime.datetime objects.N)riterkeysrdatetimerM)rr;rrr parent_fhrsszFGATInit.parent_fhrsccs>|js t|jD]$\}}t||jd}||fVqdS)z!Iterates over pairs of (fhr,init) where fhr is a fraction.Fraction FGAT hour, and init is an InitBeforeGSI object for that time.g @N)r$rMrr1r r)rr;r/r.rrrr*s zFGATInit.fhr_and_initccs|ddd}|ddd}|ddd}|dkrFtd|f|}|d |kr|jd k sdt|d k sptt||j}|d k stt|j|V||7}qJd S) z!Internal function that implements other iterators. This is an iterator that generates the default FGAT hours from the configuration file. The iterator yields the forecast times for the input model as datetime.datetime objects.FGATSTRgrFGATINVFGATEND<zaERROR: in hwrf.init.FGATInit the FGATINV must be at least one minute, but you provided %f secondsN) conffloat ValueErrorrrMr r!)rrrr!nowrelrrrr"s    zFGATInit._default_ftimesc Ks|j}t||j}||}||}|j||d|j}|j||d||j}dd|D} | dk s|t t f|j |j |j ||j|jd|j||j|j||j|d|j|j|j|j| |jdd|} | jjst | S)a^!Internal implementation function that generates the InitBeforeGSI object for one FGAT time. @param in_ftime The forecast time of interest @param taskname The name of the child task @param kwargs Additional keyword arguments passed to InitBeforeGSI.__init__ @returns the resulting InitBeforeGSI object)rr!cSsg|]}|qSrrrrrrr%sz'FGATInit._make_init..NT)rmrIrnrorKrLrrprqr]rsrtrur0rvrrrrryrzr3)rrOr rsimendrJrPrr>rMrrHrIrnrrrrrr r r r rCrr4) rrtr0r{roZtstartr;tendrqrychildrrr _make_initsD      zFGATInit._make_initcKsd|jkst|jst|jD]d}|dt|fd|j|df}}|j||f|}|j ||j sxt||j |<qdS)a!Creates all child InitBeforeGSI objects. Creates InitBeforeGSI objects for all input times in self.ftime2init and self.inits. The self._make_init is used to make each individual object. The self.inits will be a list of InitBeforeGSI objects, and self.ftime2init will be a mapping from time to InitBeforeGSI. @param kwargs Passed to _make_init()rzprocess ftime %sz%s.t%sz %Y%m%d%H%MN) rrMr#rEr)r r0rrLr$appendr)rr{rtr0rKrrrr%s     zFGATInit._make_initscCs|jD] }|qdS)z3!Runs all InitBeforeGSI.run() commands in sequence.N)r$rrr/rrrr/s z FGATInit.runcCs|jD] }|qdS)z?!Runs all InitBeforeGSI.run_through_anl() commands in sequence.N)r$rrNrrrr2s zFGATInit.run_through_anlcCs|jD] }|qdS)z=!Runs all InitBeforeGSI.run_after_anl() commands in sequence.N)r$rrNrrrr5s zFGATInit.run_init_after_anlcCs|jD] }|qdS)zr*r"rLr%rrrrrrrrrrr!s: q  )$r__all__rr=pdb produtil.runrprodutil.rusage hwrf.hwrftaskr[hwrf.wps hwrf.fcsttask hwrf.post hwrf.regrib hwrf.gribtask hwrf.tracker hwrf.prep hwrf.relocatehwrf.exceptionsprodutil.ecflowrrrr hwrf.numericsr r r r r rrrrrrrrrrs$ P   :Q