3 O`@sHdZddlmZddlZddlZGdddeZddZedd ZdS) a3 This here contains an abomination of a py2.7 work around. We'll spoof the pygrib.open function to work with ncepgrib2 on WCOSS. pygrib open is used as a context manager, so will mock that interface and replicate the .select() method to find the grib message based on shortName and level and return the ncepgrib2 message, thankfully the ncepgrib2 message has both .values and .latlons(). ncepgrib2 doesn't utilise Grib Definitions so we'll define very basic mapping between shortName and ProductTemplateDefinitions here but this will be massively restricted. )contextmanagerNc@s4eZdZddZd ddZeddZd dd ZdS) gribfilecCs||_tj||_dS)N)filename ncepgrib2Z Grib2Decodemsgs)selfrrG/gpfs/hps/nco/ops/nwprod/ens_tracker.v1.2.2/ush/FSUgenesisPY/grib2py.py__init__szgribfile.__init__Nccs|xv|jD]l}|jdd}|jd}|jd}||dkr||dkr|dk rX||krXqtj|tj|j|VqWdS)N gY@r)rZproduct_definition_templateloggingdebugvalues)rreq_deflevelZ_msgZ_levZprod_defZsub_defrrr get_msgs     zgribfile.get_msgcCsVddgddgddgddgddgddgdd gd }|j|d}|dkrRtd j||S) Nr r )msletghuvlhtflrcapez${shortName} not found in definitions)get ValueErrorformat) shortNameZdefsrrrr get_req_def$s  zgribfile.get_req_defcCs |j|}t|j||d}|S)N)r)r%listr)rr$rrmsgrrr select4s zgribfile.select)N)N)__name__ __module__ __qualname__r r staticmethodr%r(rrrr rs rcCstdS)N)NotImplementedErrorrrrr gaulats:sr.ccst|VdS)N)r)rrrr open>sr/) __doc__ contextlibrr robjectrr.r/rrrr  s  '