U g@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||_t||_dSN)filename ncepgrib2Z Grib2Decodemsgs)selfrr H/lfs/h1/ops/prod/packages/ens_tracker.v1.3.6/ush/FSUgenesisPY/grib2py.py__init__szgribfile.__init__Nccsx|jD]l}|jdd}|jd}|jd}||dkr||dkr|dk rV||krVqt|t|j|VqdS)N gY@r)rZproduct_definition_templateloggingdebugvalues)rreq_deflevelZ_msgZ_levZprod_defZsub_defr r r get_msgs     zgribfile.get_msgcCsVddgddgddgddgddgddgdd gd }||d}|dkrRtd ||S) Nr r )msletghuvlhtflrcapez${shortName} not found in definitions)get ValueErrorformat) shortNameZdefsrr r r get_req_def$s zgribfile.get_req_defcCs ||}t|j||d}|S)N)r)r&listr)rr%rrmsgr r r select4s zgribfile.select)N)N)__name__ __module__ __qualname__r r staticmethodr&r)r r r r rs   rcCstdSr)NotImplementedErrorr r r r gaulats:sr/ccst|VdSr)r)rr r r open>sr0) __doc__ contextlibrrrobjectrr/r0r r r r s '