U  g@sdZddgZddlZddlZddlZddlZddlZddlZ ddl Z ddl Z ddl Z ddl Z ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlmZm Z ddl m!Z!ddl m"Z"m#Z#m$Z$ddl m%Z%dd lm&Z&m'Z'm(Z(m)Z)m*Z*d d Z+d d Z,ddZ-Gddde j.j/Z0Gddde j.j/Z1Gddde2Z3Gddde3Z4dS)a*!Combines multiple tasks together to make the HWRF post-processing system. This is a wrapper around the hwrf.post, hwrf.gribtask, hwrf.tracker, hwrf.nhc_products and hwrf.gsipost that creates customizable post-processing tasks. The main purpose of this module is to simplify the hwrf_expt module.HWRFGSIPostProcessingHWRFForecastPostProcessingN)exealias)to_datetime_rel) WRFDomain WRFSimulationExternalWRFTask) PostManyWRF) RegribManyigrb1clatlonGRIB2SATGRIB2c Cs||d}|d}t|dks(tt|d}t|d}t|d}t|d} t|d} t|d } t|d } ||t|||g|| g| | | gd d S) ag!Add a domain-centered lat-lon grid to a RegribMany object. Adds to the given hwrf.regrib.RegribMany object a latitude-longitude grid centered on some GRIB product. The grid will be re-centered at every forecast time, so the grid is allowed to move. Centering information comes from the name+"_grid" option in the task's section. The value should be a comma-separated list of seven values: * res1,res2 - grid resolution for GRIB1 grid 255 * size1,size2 - size in degrees for GRIB1 grid 255 * scan - scanning mode flags for GRIB1 grid 255 * n1,n2 - gridpoint count for GRIB1 grid 255 @param task the task that provides configuration information @param r the hwrf.regrib.RegribMany object to receive the grid @param name the name of the new grid @param rel the GRIB product in r on which this grid is centered_grid,r)ressizescannN)confstrrsplitlenAssertionErrorfloatintaddr ) taskrnamerelcontentssplitres1res2Zsize1Zsize2rn1n2r.rproducts d_wrfprodd_finalgetboolrpranger"mathfloortimestrrrry wrfcopier)rEZwrfcopier_namerZ copystartZcopyendZcopysteprrrrZcopiedfhrZ prodstreamproductZfhr2rrfcstlenZpom_output_secZpom_output_hrsZioutrfromnametonamerctimepZrstimer.r.r/make_wrfcopiers                  z)HWRFForecastPostProcessing.make_wrfcopierTc! Csr|j|j}}|j|j|j}}}|j} |dd} |dd} t||d} t||d} t||d}t||d}t||d}t||d}t j dt j j d}t j dt j jd}t j j| d| d d }| jj}|d ks|d kr|jd kr|jd 7_d|ddf}ttt| djdddtt| djdddtt| djdddtt| djddddd|ftt| djdddd}t||d| |d}t||d| |d}t||d| |d}t||d||d}t j j}|d||| | t|d ||| | t|d!||| | t|d"||| | |d#|d"tt|d|t|d#|t|d!|t|d ||d$|||| || ||d%t j |d$t|d%||r|d&||||t!|d'||||t!|d(||||t!|d)||||t!t|d&|t|d)|t|d(|t|d'||r|d*|||| ||d+t j |d*|d,||||d-t j |d,t|d-|t|d+|t j"j#|j$| d.|| j%d/| d/d0}t j j&|j$| d1| j%|d2dd/| d/d0}|'| j|d%|(d3| )d4d5|*d6| )d4d7}|j+d8d9| )d4d:d;|j+d| )d4d?d@|j+dAdB| )d4dCdD|j+dEdB| )d4dFdD|r(|j+dGdB| j)d4dHdIdJdDt j,j-|j$| dK|j.||j/|jj| dL} | |_0||_1||_ ||_2|||| fS)Ma !Generate the regribbing objects and the main tracker. Generates the gribber, tracker, track and nhcp member variables and returns them in a tuple: * nhcp --- the hwrf.nhc_products.NHCProducts object that makes NHC-specific output products and validates the wrfdiag files. * track --- the final track file output by the tracker, returned by hwrf.tracker.send_atcfunix() called on the new tracker object * tracker --- the hwrf.tracker.TrackerTask that runs the GFDL vortex tracker * gribber --- the hwrf.gribtask.GRIBTask that runs the regribbing on the post-processors created by make_satpost() and make_nonsatpost() @param extra_trackers logical flag: are the parent and intermediate domain trackers also desired? If so, extra regribbing is arranged, that will be required by make_extra_trackers() @param satpost_flag logical flag: is satellite post-processing desired @pre The make_nonsatpost() must have been called. If the satpost_flag=True, then make_satpost() must also have been called. @returns a tuple (nhcp,track,tracker,gribber) of the objects that were createdrrcombinetrack_fhrg(@)r`partN)rdomlat)rdomlon)latlonALEPgv@rQrRrSrTrrUrXr\rYrZr[r])rTrXr\r^r_ZstormcoreZtrkd3ZsynopZ p123_coreZ p123_synopZ p123_globalZp123_storm_grib1Z p123_stormZtrkin123hwrftrkZ s123_coreZ s123_synopZ s123_globalZ s123_stormZtrkin12 hwrftrkd02Ztrkin1 hwrftrkd01 regribberrdrer9 tracker_step rawatcfunixdirz {com}/{out_prefix}.trak.hwrf.raw cleanatcfunixz%{com}/{out_prefix}.trak.hwrf.atcfunixZ atcf3hourlyrz${com}/{out_prefix}.trak.hwrf.3hourly)freqlocationZ atcfshort6hrrpz%{com}/{out_prefix}.trak.hwrf.short6hr)rcutrZ combinetrack zB{com}/{vit[stnum]:02d}{basin1lc}.trak.hwrf.atcfunix.{YMDH}.combine)rrZcombinetrack_ucz@{com}/{vit[stnum]:02d}{basin1}.trak.hwrf.atcfunix.{YMDH}.combineZcombinetrack_00z&{realstormcom}/relocate.trak.{YMDH}.goz {fakestormid}) realstorm nhc_products)r)3rrrrrrGrprr r8regrib GRIBSubsetterr9hwrf_combine_subsettracker_subset FixedLocationsyndat pubbasin2ewcenterr rrrqrrr0rt quarterDegreer#r_rr;rBvinttaverrwrxriry TrackerTaskadd_moving_gridsend_raw_atcfunix strinterp send_atcfunixsend_atcfunix_subsetr NHCProductsrrnhcptrackgribber)!rEextra_trackers satpost_flag gofile_flagrrrrrrGrrZgrid3grid2grid1ZsatE3ZsatE2ZsatE1Zhwrfsubtrksubdomlocbasinrr%Z stormgridZcoregridZ trkd3gridZ synopgridZqdrr9rrr.r.r/make_gribber_trackers          &                    z/HWRFForecastPostProcessing.make_gribber_trackercCs|j}|j}|j}|ddd}|dd}tjj||d|j||dd}| |j |d| d | d d | d | d d tjj||d|j||dd}| |j |d| d | d d| d | d d||_||_||fS)a(!Generates intermediate and outermost domain trackers. Generates trackers that use intermediate and outermost domain data to track the storm and analyze its intensity. These are intended for use in analyzing the effects of resolution and upscale feedback on hurricane track, structure and intensity. Creates these member variables and returns them: * trackerd01 --- a tracker that just uses the outermost domain data * trackerd02 --- a tracker that uses the outermost and intermediate domain data @return A tuple (trackerd01,trackerd02) of the new trackers @pre The make_gribber_tracker() must have been called with extra_trackers=True, so it will add the extra GRIB products needed by the new trackers.rrrrrd trackerd02rerrrz#{com}/{out_prefix}.trak.hwrfd02.rawrz({com}/{out_prefix}.trak.hwrfd02.atcfunix trackerd01rz#{com}/{out_prefix}.trak.hwrfd01.rawz({com}/{out_prefix}.trak.hwrfd01.atcfunix)rirGrgetintrr8r9rryrrrrrrr)rErFrGrrrrrr.r.r/make_extra_trackerss@      z.HWRFForecastPostProcessing.make_extra_trackers)r)r)rF)FTF) rrrrrDrrrrrrr.r.rJr/rsg 7   W ;cs$eZdZfddZddZZS) ForecastBasecsZtt||||||f\|_|_|_|_|_|||_|_ d|_ d|_ d|_ d|_ dSN)rCrrDrGrFrpominitww3init hycominitocstatusrww3post hycompostrealwrf)rErGrFrrrrr rJr.r/rD s zForecastBase.__init__c Cs|jdd}|jddd}|jdd}|jddd}|jddd }|jd d d }|jd d d }|jddd}|r|dkr|r|dkrtjj|j|j||j|j d |j |j d|_ n&tj j|j|j||j|j d |j d|_ n|rT|dkrT|r0|dkr0tjj|j|j||jd |j|j d|_ n"tjj|j|j||jd |jd|_ ntjj|j|j||jd d|_ |r|dkrtjj|j|jd|||j d|_|r|dkrtj j|j|jd||j d|_|j |_|jS)Nrrrrr wave_modelWW3forecast_sectionrforecast_productsww3_output_stepi`Tww3_pntout_steprrHYCOM)tasknamerr)rr)rrr)rrrr )outsteppntstepww3r )rhycom)rGrrrr8rZ WRFWW3HYCOMrFrr rrrrZWRFCoupledHYCOMZ WRFWW3POMrmpipomtcZ WRFCoupledPOMfcsttaskWRFAtmosZWW3Postr Z HYCOMPostr r ) rE ocean_flagocean wave_flagwavefcst_secrrrr.r.r/ make_forecasts      zForecastBase.make_forecastrrrrDr"rr.r.rJr/rs rcs$eZdZfddZddZZS)FakeStormForecastc s8tt||||dddd||_||_||_||_dSr)rCr$rDmultistorm_sids finalmerge stormNouter stormNinner)rErGrFrr%r&r'r(rJr.r/rD?s zFakeStormForecast.__init__c Cs.|jdd}|jdd}|jddd}|jd}t|j}|sH|rTtjdtjj |j |j||j dd}tj |j |jd |j ||j |j}||||||j||td |d D]L}|j|d } |j|| |||jd ||||j d |q||j||_dS) NrrrrrrzmOcean and wave must be disabled when running in multi-storm mode ([config] run_ocean and run_wave must = no).rfakeinitrz storm%souterz storm%sinner)rGrrr%rr8 exceptionsHWRFConfigUnsupportedrWRFAtmosMultiStormrFrFakeInitr(r' add_metgrid add_geogrid add_fort65 add_wrfbdyr& add_wrfinputr add_merge add_wrfanlr) rErrr!Z prioritystormnum_realstormsrr)istormidr.r.r/r"GsL   zFakeStormForecast.make_forecastr#r.r.rJr/r$>s r$)5r__all__ossysrprodutil.datastoreprodutil produtil.run hwrf.configr8hwrf.wrf hwrf.post hwrf.numerics hwrf.launcher hwrf.regrib hwrf.gribtask hwrf.trackerhwrf.storminfohwrf.wpshwrf.nhc_products hwrf.copywrf hwrf.fcsttask hwrf.ensda hwrf.relocate hwrf.init hwrf.prephwrf.gsiZ hwrf.mpipomtc hwrf.bufrprep hwrf.hwrftaskhwrf.multistormrrrrrr r r r r rrr0r<rBhwrftaskHWRFTaskrrobjectrr$r.r.r.r/s2 ( ((  %  6