U $ùÎgDã@säddlZddlZddlZddlZddlZddlmZddlm Z m Z m Z ddl m Z ddlmZddlmZmZddlZGdd„deƒZeƒZedddfd d „Zd d „Zd d„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Z dS)éN)ÚDBNAlert)ÚrunÚexeÚbatchexe)Újlogger)Úset_ecflow_event)Úto_datetime_relÚ to_datetimec@seZdZdZdS)ÚTrackDeliveryFailedzJ!Raised when the send_nhc_track() is unable to deliver the track file.N)Ú__name__Ú __module__Ú __qualname__Ú__doc__©rrú9/lfs/h1/ops/prod/packages/hwrf.v13.2.9/ush/hwrf_alerts.pyr sr c CsHtj dd¡ ¡dk}|rpddl}|rDt|dƒ}| ¡}W5QRXt d|¡} | D]} |j ||| |dqTdSt j   ¡sˆ|  d¡dSdS|dkržt d ¡}td ƒd d d d|df} |rÈ| |k} n|dk sÔt‚| |>} |tkròtj dd¡}|r| d|f} |  dt|ƒf¡n | d¡t d|¡} | | } t| |d} | S)NÚ RUN_ENVIRÚEMCÚNCOrÚrtú[, ]+)Z to_addressÚ from_namezDSkipping email because you are not NCO and you are not using ecFlow.zhwrf_alerts.send_emailÚsshZslogin1Úmailz-sú'ÚHWRF_EMAIL_FROMúnco.spa@noaa.govz-rúEmail "From:" address is: %súNot changing email "From:" line. Will use system default. This may break email if the system defaulthas a domain that is not world-visible.©Úlogger)ÚosÚenvironÚgetÚupperrÚopenÚreadÚreÚsplitÚsendÚprodutilÚecflowÚ in_ecflowÚinfoÚloggingÚ getLoggerrÚAssertionErrorÚabsentÚreprÚwarningr) Z email_listÚsubjectÚ email_fromÚ content_textÚ content_filerÚi_am_ncorÚfÚ addressesÚaddressÚcmdÚstatusrrrÚ send_emailsB       ÿ    r=c Cs”tj}| d¡}| ¡ dd¡}|jdd|d}|jdd||d}tj  d d ¡p`|  dd d ¡p`d }tj  d d ¡} t   d|¡t ||| ||d|S)a2!Called when an emergency fallback is requested. Return True to allow, False to deny . @param allow True or False, whether the other fallback filters have allowed this fallback thus far. @param name The name of the fallback. @param details Human-readable details about this fallback.Z fallbacksÚ_ú ÚconfigzkHWRF {FALLNAME}: {cyc}Z HWRF{storm_num} {vit[basinname]} Tropical System {vit[stormname]} ({vit[stormid3]}))ZFALLNAMEaóATTN Operator: HWRF storm slot {storm_num} enacted a fallback mechanism to disable an optional part of the HWRF workflow. This is not necessarily an error but should merit operator attention. Storm = {vit[basinname]} Tropical System {vit[stormname]} {vit[stormid3]} R.S.M.C. = {vit[center]} Job = {ENV[job|-unknown]} Storm slot = hwrf{storm_num} Fcst. cycle = {ayear}-{amonth}-{aday} {aHH} Fallback name = {fallback_name} Details: {fallback_details} Sincerely, HWRF )Z fallback_nameZfallback_detailsZHWRF_FALLBACK_EMAIL_LISTÚÚfallback_email_listrrz#Contacting operator about fallback )r5r)Ú hwrf_exptÚconfÚlogr#ÚreplaceÚ strinterpÚ timestrinterpr r!r"Úgetstrrr,r=) ÚallowÚnameÚdetailsrDrZucnamer3ÚcontentrBr4rrrÚfallback_callbackQs2  ýî ÿþÿÿrNc Osjddlm}m}| d¡}tj}| dd¡ ¡dkrB| d¡dS|  d d ¡}|d kr~d |krh|d }nd }|  |¡t |ƒ‚| d d ¡ ¡dk}|s´|dd…dkr´| d¡dS|  d¡j } tj |djf|jjŽ ¡¡} | d| f¡| d| f¡t| dƒF} d} d} | D]2}| ¡}| |d7} |dd…d}| |7} qW5QRXd|kst| d d ¡ ¡dkrÞ|d}|jjjd}tj |d|f¡}| d|f¡tjj||dt|dƒ}| | ¡W5QRXtj | ¡}tjj||dt| dƒ} |  | ¡W5QRX| d | | f¡| d!| ¡tj d"d#d$d%g¡}|| d&d't d(|ddS))a !Sends the track file to special NHC disk locations on the WCOSS supercomputer. @param args,kwargs Ignored. @note This does not sort the track file, and does not grep out the correct storm, since that is already done before this function starts.r)ÚtrackerrDZto_nhcZSENDCOMÚNOÚYESzENot delivering track file to NHC locations because SENDCOM is not YESNÚ COMOUTatcfÚmissingzyABORTING: Cannot deliver track file: $COMOUTatcf is unset, and is not in hwrf.conf. Don't know where to send track file.rrréz/comzyNot delivering track file to NHC locations because you are not NCO and your destination directory is inside /com or /com2Ú cleanatcfunixzO{hwrfbasin2}{stnum:02d}{when.year}/ncep_a{hwrfbasin2}{stnum:02d}{when.year}.datz%s: will read this track filez%s: will append track hererrAÚ épZ COMOUTgltrkédztracks.atcfunix.%02dz%s: will also append track hererÚatz%s: track delivered from %szDBN alert for ncep tracker: %sÚMODELz{type}ú{job}ú {location}Z NHC_ATCF_HWRF)ÚlocationÚtypeZSentTrackToNHC)!rCrOrDrEr r!r"r#r2ÚgetdirÚcriticalr Úproductr]ÚpathÚjoinÚformatÚ storminfoÚ__dict__Úlowerr,r$ÚrstripÚwhenÚyearr)ÚfileopÚmakedirsÚwriteÚdirnameÚdbnalertrr)ÚargsÚkwargsrOrDrÚENVrRÚmsgr7ÚsrcÚtgtr8ZoutfullZout112ÚlineÚrlineZgltrkdirZyyZ glatuxarchÚoZtgtdirZalerterrrrÚsend_nhc_track‰sh       ÿÿ       ÿ rycCsxddlm}m}d}| d¡}| ¡D]>}| dt|ƒt|jƒf¡|d7}| t dddd gƒ¡q&| d |¡d S) a/!Adds dbn alerts for the WRF program's wrfdiag files, which are used by the downstream wave model. Ensures the wrfdiag files have the necessary dbn_alerts to trigger delivery to the NCEP FTP server and ecFlow events (if required). Those files will be delivered by the NHCProducts object at the end of the JHWRF_PRODUCTS job, after the hwrf_nhc_products program completes. We run the hwrf_nhc_products program before delivering the wrfdiag files to ensure that the files are plausable before delivering them to the wave model.r©ÚnhcprDÚadd_wave_alertsz#%s@%s: added alert for this productérZZHWRF_NCr[r\zAdded %d wave alertsN) rCr{rDrEZwrfdiag_productsr,r1ÚdidÚ add_callbackr)r{rDZnalertsrÚprodrrrr|Ús    ÿ r|cCsèddlm}m}| d¡}|jdd tddddgƒ¡|jd d tdd ddgƒ¡|jd d tdd ddgƒ¡|jd d tdd ddgƒ¡|jdd tdd ddgƒ¡|jdd tdd ddgƒ¡| d¡dS)z¦!Adds dbn alerts for the HWRF WW3 wave products. Adds calls to the dbnet alerts so that the WW3 wave product files will be delivered to the NCEP FTP server.r)Úww3postrDÚadd_ww3prod_alertsZww3grb2rZZ HWRF_WW3GB2r[r\Z ww3grb2idxZHWRF_WW3GB2_WIDXZ ww3outpbullZ HWRF_WW3TARZ ww3outpcbullZ ww3outpcsbullZ ww3outpspeczAdded ww3prod alertsN)rCrrDrEÚ _productsrrr,)rrDrrrrr‚ñs       r‚c sjddlm}m}m}| ddd¡}|d}|dd}|dd}t|ƒ‰‡fd d „t|ƒDƒ}‡fd d „t|ƒDƒ}td d d d d } |  ¡D]Z\} } |D]L} |j | | dD]8} |   t d| ddgƒ¡|   t d| dddgƒ¡qšq¬qšqŽtd d d d d}| ¡D]b\} } |D]R} |j | | dD]<} |   t d| ddgƒ¡|   t d| dddgƒ¡qq qqdS)zÀ!Adds dbn alerts for GRIB products by adding DBNAlert objects to the hwrf_expt.gribber. Adds calls to the dbnet alerts so that GRIB files will be delivered to the NCEP FTP server.r)ÚcycleÚgribberrDr@Úforecast_lengthé~ér}écsg|]}td|ˆƒ‘qS)i`T©r©Ú.0Úx©ÚatimerrÚ sz%add_regrib_alerts..csg|]}td|ˆƒ‘qS)i0*rŠr‹rŽrrrsÚHWRF_GB2)Z p123_coreZ p123_stormZ p123_globalZ p123_synop)rKÚtimerZr[r\Z_WIDXz{location}.idx)Z s123_coreZ s123_stormZ s123_globalZ s123_synopN) rCr„r…rDÚgetintr ÚrangeÚdictÚitemsÚproductsrr)r„r…rDZflenÚiflenZnsixZnthreeZ six_hourlyZ three_hourlyZnonsat_mappingÚprodnameZ alertnamer’ÚpZ sat_mappingrrŽrÚadd_regrib_alertss<  ý ýr›cOsBddlm}m}|js$t d¡dS| d¡}tj  dd¡  ¡}|dk}|s`t d|f¡dS|  d dd ¡}|s€t d ¡dS|j } | r–t j | ¡s¨t d | ¡dS| d d ¡} tj  dd¡} | rÜ| dt| ƒf¡n | d¡tj  dd¡p| d dd¡pd} t d| ¡} t d¡t| | | | |d}td|ddS)a!Emails the AFOS file to the NOAA Senior Duty Meterologist (SDM) This function is called from scripts.exhwrf_output to email the AFOS file (simplified track file) to the Senior Duty Meteorologist (NOAA SDM). It is controlled by a number of environment variables, requested by NCEP Central Operations: * EMAIL_SDM=YES/NO --- turn on or off the email * HWRF_TRACK_EMAIL_LIST=(list of emails) --- list of email addresses to receive the AFOS file. * HWRF_EMAIL_SSH_MACHINE --- no longer used. This was the machine to ssh into, to send the mail. The mail is now sent directly from the machine running the exhwrf_output script. The following configuration settings have the same meaning as the environment variables: * [config] email_sdm = $EMAIL_SDM * [config] track_email_list = $HWRF_TRACK_EMAIL_LIST * [config] email_ssh_machine = $HWRF_EMAIL_SSH_MACHINE In all cases, the environment variables override the config file settings (again, by request of NCO). rrzz1Not emailing AFOS file: Product is not available.NÚ email_sdmZ EMAIL_SDMrQz2EMAIL_SDM=%s in environment - disable email to SDMr@Fz3email_sdm=no in config files - disable email to SDMz1Not emailing AFOS file: is empty or nonexistent: zZ{cyc}Z HWRF Output for {vit[basinname]} Tropical System {vit[stormname]} ({vit[stormid3]})rrrrZHWRF_TRACK_EMAIL_LISTrAÚtrack_email_listz SDM@noaa.govrzSending AFOS file to SDM.)r6rZemailSDMr)rCr{rDÚ availablerÚerrorrEr r!r"r#Úgetboolr]r)rkÚ isnonemptyrGr,r1r2rIr&r'r=r)Úafosrprqr{rDrZ email_sdm_strrœZemail_sdm_flagZafosfiler3r4rr9r<rrrÚemail_afos_to_sdm4sV  ÿ ÿÿÿ  ÿþ  ÿr£cCsôddlm}| d¡}| tddddgƒ¡| d¡ tdd ddgƒ¡| d ¡ tdd ddgƒ¡| d ¡ tdd ddgƒ¡| d ¡ tdd ddgƒ¡| d ¡ tddddgƒ¡| d¡ tddddgƒ¡| d¡ tddddgƒ¡dS)z‡!Adds dbn alerts for the hwrf_nhc_products program's output by adding DBNAlert objects to the hwrf_expt.nhcp object's Products.r)r{r¢rZZ HWRF_AFOSr[r\ZhtcfÚ HWRF_ASCIIZrainfallZwind10mZ wind10hrlyÚstatsZ HWRF_STATSZswathr‘ZswathidxZ HWRF_GB2_WIDXN)rCr{rarr)r{r¢rrrÚadd_nhc_alerts}s  r¦cCsàddlm}| d¡}| d¡}| d¡}tj d¡}| d|jf¡| d|jf¡| d |jf¡| td d d d gƒ¡| td d d d gƒ¡| td d d d gƒ¡| t ¡|  ¡sÄt ‚|  ¡sÐt ‚|  ¡sÜt ‚dS)z`!Adds dbn alerts for the tracker and requests delivery of the tracker to NHC deck locations.r)rOZ atcf3hourlyZ atcfshort6hrrUZtracker_alertsz2Add tracker DBN alert: cleaned 3hourly track is %szIAdd tracker DBN alert: cleaned, 112-char-line, 6hourly subset track is %sz4Add tracker DBN alert: cleaned, complete track is %srZr¤r[r\N) rCrOrarDrEÚdebugr~rrryÚ has_callbacksr/)rOZhr3Úhr6ÚtrrrrrÚadd_tracker_alertsŽs        r«)!r Úsocketr&r-Úprodutil.fileopr)Úprodutil.dbnalertrÚ produtil.runrrrÚ produtil.logrÚprodutil.ecflowrÚ hwrf.numericsrr rCÚ Exceptionr Úobjectr0r=rNryr|r‚r›r£r¦r«rrrrÚs,    þ 58Q1I