U $gl@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Zddl mZmZmZmZmZmZmZmZmZmZmZmZmZddl mZmZmZmZm Z ddl m!Z!m"Z"dddd d d d d ddddddgZ#dZ$dZ%dZ&Gddde'Z(Gdd d e(Z)Gddde(Z*dZ+ddZ,dd Z-d!d"Z.d#d$Z/d%d&Z0dSd'd(Z1d)d*Z2d+d,Z3d-d.Z4d/d0Z5Gd1d2d2e'Z6Gd3d4d4e6Z7Gd5d d e7Z8e8d6d7dZ9Gd8d9d9e7Z:Gd:d;d;e7Z;GdGdBdCdCe>Z?GdDdde6Z@GdEdde@ZAGdFdde@ZBGdGdHdHeBZCGdIddeBZDGdJddeAZEGdKdde!eBZFGdLdMdMeBZGdNdOZHGdPdde"eEZIGdQdRdRe"eDZJdS)UaO!Describes regribbing operations using an algebraic structure. This module provides an object-oriented interface to the low-level GRIB manipulation routines in produtil.gribop. It also sits on top of the produtil.datastore module, providing a means to grab GRIB files from Task and Product objects, processing them upon availability.N) RegribErrorGRIBInputError SubsetlessInvalidRegribResultRegribProductErrorNoProductErrorProductAmbiguityErrorRegribManyErrorRegribKeyErrorRegribGridError GridlessErrorGridMismatchError NoIndexError)exealiasrunrunstrbigexe) UpstreamFile FileProductGRIBOpGRIB2OpGRIB1OpGRIBGrid GRIBSubsetterZ GRIB1MergeRegribGRIB1GRIB2 GRIB1File GRIB2File UpstreamGRIB1 GRIB2Product quarterDegreec seZdZdZd&fdd ZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZeddZee e ddZeedddZeedddZee ddd Zeeddd!Zeeddd"Zee ddd#Zeeddd$Zeeddd$Zee ddd%ZZS)' RegribBasez!This is the abstract base class of Regrib and RegribMany and should not be instantiated directly. It exists only to reduce code duplication.Nc stt||dk rz|j|_|j|_|j|_|j |_ |j |_ |j |_|j|_|j|_|j|_t|j|_t|j|_n0| dk st| dkrttd} |dkrttd}|dkrttdd}|dkrttdd}| dkrttdd} |dkrttdd }| dkr&ttd } | dkr!Returns the GRIBBase object that performs this Regrib's work.)rarKrIrIrJgetopsz Regrib.getopz _name_deliverr&r0rcr@_gens_order_kwargscopy _delivery_data threadingRLock_lock)rC_copyrgrhfrIrIrJr0s,      zRegribMany.__init__cCsdS)aO!Has no effect. This is for forward compatibility to a later thread-safe implementation. @note This used to be implemented but it turns out that Python locks are VERY slow, so the locking had to be removed. Multiple simultaneous regrib operrations are now done through multiple processesNrIrKrIrIrJ __enter__szRegribMany.__enter__cCsdS)a!Has no effect. This is for forward compatibility to a later thread-safe implementation. @param etype,evalue,traceback Exception information. @note This used to be implemented but it turns out that Python locks are VERY slow, so the locking had to be removed. Multiple simultaneous regrib operations are now done through multiple processes.NrI)rCetypeevalue tracebackrIrIrJ__exit__szRegribMany.__exit__c Cs&|||jkW5QRSQRXdS)zg!Returns True if an operation by the given name exists. @param name the operation name to queryN)rrCnamerIrIrJhas_name'szRegribMany.has_namec Cs| d|_W5QRXdS)z!Erases all cached results.N)rrKrIrIrJro,szRegribMany.resetc Cs&|t|dW5QRSQRXdS)z/!Returns a copy of self with no cached results.)rN)rrKrIrIrJr0szRegribMany.copycCs|j|t|S)z!Returns a GRIB1Fetcher object that will grab the GRIB1 data with the given name. @param name the operation name to query)r GRIB1FetcherrrIrIrJGRIB4s zRegribMany.GRIBccs,|jD]\}}t|ts ||fVq dS)zc!Iterates over all non-GRIBOp operations yielding tuples containing the name and operation.NritemsrurrCkvrIrIrJ nonGRIBOps:s zRegribMany.nonGRIBOpsccs,|jD]\}}t|tr ||fVq dS)z_!Iterates over all GRIBOp operations yielding tuples containing the name and operation.NrrrIrIrJGRIBOps@s zRegribMany.GRIBOpscCst|j|dtS)z_!Returns True if the name corresponds to a grid @param name the operation name to queryN)rurget GRIBGridBaserrIrIrJis_gridFszRegribMany.is_gridcCs|j|t|S)z!Returns a GRIBGridFetcher object that will grab the grid structure with the given name. @param name the operation name to query)rGRIBGridFetcherrrIrIrJgridJs zRegribMany.gridcCs|j|t|S)z!Returns a GRIBSubsetterFetcher object that will grab the GRIB subsetter with the given name. @param name the operation name to query)rGRIBSubsetterFetcherrrIrIrJsubsetPs zRegribMany.subsetc KsT|F||jkr"tjd|f||j|<|j|t||j|<W5QRXdS)a !Adds the given generator "arg" under the specified name (in "name") to this object. @param name the operation name to query @param arg A object of a subclass of GRIBBase @param kwargs Stored for later passing to function calls to argz/%s: tried to add duplicate product to regribberN)rhwrf exceptionsrrappendr@r)rCrargrhrIrIrJaddVs   zRegribMany.addTc Cst|tstt|tst|dks2t|ts2t|dksHt|tsHtt|tsVt|J||jkrttd|fd|||||g}|j||j||W5QRXdS)a!Requests delivery to the com directory in file "location" of operation "name". @param category,prodname The category and prodname are used to create the FileProduct object. @param keep Sent to the final deliver_file operation. It should be left as True. @param name the operation's name @param location the destination, which will be sent through hwrf.config.HWRFConfig.conftimestrinterp() by the hwrf.gribtask.GRIBTaskN%s: no such keycom rur|rBboolrr rrrrClocationrcategoryprodnamekeepZdeldatrIrIrJto_comcs   zRegribMany.to_comc Cst|tstt|tst|dks2t|ts2t|dksHt|tsHtt|tsVt|J||jkrttd|fd|||||g}|j||j||W5QRXdS)a!Requests delivery to the intercom directory in file "location" of operation "name". @param category,prodname The category and prodname are used to create the FileProduct object. @param keep Sent to the final deliver_file operation. It should be left as True. @param name the operation's name @param location the destination, which will be sent through hwrf.config.HWRFConfig.conftimestrinterp() by the hwrf.gribtask.GRIBTaskNrintercomrrrIrIrJ to_intercomzs   zRegribMany.to_intercomccs>|jD]2\}}}}}}|dks&||kr||||||fVqdS)a!Iterates over all deliveries yielding a six element tuple @param name The name of the operation of interest. The tuple contents: 1. "com" or "intercom" 2. operation name 3. location within target directory 4. requested category or None 5. requested prodname or None 6. keep flag from the to_com or to_intercomN)r)rCrwhereZinameloccatprodrrIrIrJ deliveriess zRegribMany.deliveriesc Cs*|t|jdkW5QRSQRXdS)z!Returns True if there are any requested deliveries and False otherwise. @returns True if to_com() or to_intercom() were called for a known name.rN)lenrrKrIrIrJhas_deliveriesszRegribMany.has_deliveriesc Ks|jdkr|j|f|St|j|}||||d<|@|j.|jj|f|dk W5QRW5QRSQRXW5QRXdS)a!Returns True if there is a cached result for the specified operation. @param kwargs The keyword arguments are passed on to the get_data routine for the caching object (usually an hwrf.gribtask.GRIBTask). @param name The operation name.N regribmany)rrqr@rupdateget_data)rCrrhargsrIrIrJhas_datas  zRegribMany.has_datac KsN||j|}W5QRXd|kr.|jf|St|}||d<|jf|SdS)a !Determines if the specified operation is ready. @param name Obtains the operation by the specified name. @param kwargs The is_ready funciton is called on the named operation's generator, passing the given keyword arguments to it.rN)rrqr@rCrrhrfrrIrIrJrqs zRegribMany.is_readyc KsN||j|}W5QRXd|kr.|jf|St|}||d<|jf|SdS)a>!Determines if it is possible to run the specified operation with the given keyword arguments. @param name Obtains the operation by the specified name. @param kwargs The input_valid function is called on the generator for the named operation, passing these keyword arguments.rN)rrsr@rrIrIrJrss zRegribMany.input_validc Ks(t|j|}||||d<|`|jdk rv|j:|jj|f|}|dk rl|W5QRW5QRSW5QRX|j|}W5QRXt||tj |j |d|d}|j f|}t |t st |tstdt|t|jt|t|t|f|$|jdk r|jj||f|W5QRX|S)a~!Executes the operation previously stored in self.add(), passing it the given keyword arguments, returning the result. If a cache is available (usually a GRIBTask), stores the result in that cache. @param name the name of the operation of interest @param kwargs Passed to the make function in the generator for the named operationrNrj)rgrFzdInvalid result for %s: type=%s repr=%s which came from running r.make(**args) on an r=%s and args=%s)r@rrrrrrrkrlrmrcrtrurvrrr|ryrZrzset_data)rCrrhrgotrfrrerIrIrJrts:   &   zRegribMany.makeccs|jD] }|VqdS)z]!Iterates over the names provided to self.add(name,...) in the order they were added.N)rrrIrIrJnamess zRegribMany.names)NN)NNT)NNT)N)rZr[r\r]r0rrrrorrrrrrrrrrrrrrqrsrtrrIrIrIrJris0     rc CsR|dkr"|jdk r|jddSzt|}|jtk}|sf|jdk r`|jdt||jfWdSt|j}|s|jdk r|jdt||jfWdSWnt k rL}z|j t j kr|jdk r|jdt|t |j fWYNdS|j t j kr:|jdk r0|jdt|t |j fWY dSW5d}~XYnXdS) a!Internal function for validating GRIB files. This is a low-level implementation function. It should not be called directly. This checks a file to make sure it exists, is a regular file (or symlink to a regular file) and is large enough to plausibly contain some GRIB1 or GRIB2 data. Returns True for such plausible files and False otherwise. Does not open the file, and performs only a single stat. Uses errno ENOENT (no such file or directory) and ELOOP (too many symbolic links) to detect non-existence. Other exceptions will be passed to the caller. @param regrib a regrib for logging information @param filename the name of the file of interestNz/checkgrib: filename=None. Probable code error.Fz%s: size=%d < 8 bytesz%s: not a regular filez)%s: input GRIB1/2 file does not exist: %szZ%s: input GRIB1/2 file path results in too many symlinks (likely a symbolic link loop): %sT)r;warningrkstatst_sizeGRIB_FILE_MIN_SIZEr|S_ISREGst_modeEnvironmentErrorerrnoENOENTstrerrorZELOOP)regribfilenamesZsizeokZtypeokerIrIrJ checkgribsB                 rc Os2|jddd\}}tj|js0td|jf|j|j|f}|jdk rZ|jt |t |}|dkr|j |j|f}|jdk r|jt ||jdt |}|dkrtd|ftj|std |f|j d |f|k}|jdk r|jt |t |}|dkr&td |ft ||dS) !Converts GRIB1 file to GRIB2 This is a low-level implementation function. It should not be called directly. This function is sent as a parameter to GRIB1Op to produce a GRIB2 version of a GRIB1 file. It uses regrib.cnvgrib_g12 to perform the conversion. @param op The GRIBBase operation running this funciton. @param regrib a Regrib for data information @param infile The input filename. @param args,kwargs Ignored @returns a new GRIB2File for the output filegrb2idxr%s: input file is emptyNrz8convert grib1 to grib2 failed, try again with -nv optionzrrrrmrrrkrlrnr(r;rrzrrr.poprrrBr|errorrr)#rfrrrrhZifilesZsfilesrZgfileZlfilesZoutfile1Z outindex1Zoutfile2Z outindex2rrZsubtmpZifiles1Zifiles2Zifiles10Zifiles20ZsrcfileZtgtfile1Ztgtfile2rrZrunme1Zex1Zrunme2Zex2Zcmd1Zcmd2ZruncatrmessagerIrIrJaction_grib1regridmerges        .*     B     ,     rc Ks|dk s t|dk st|j}|j}|j}|dkr|dk rJ|d|f|d}tt|d}tj j |||f|d||_n|dk r|d||f|S)a!Runs the grbindex program on a GRIB1 file. This is a low-level implementation function. It should not be called directly. This function adds a grbindex output to the specified input file's product, unless one is already available. Unlike most action_* functions, this one does not create a new GRIBFile or GRIBProduct, instead it modifies the existing one to add the location of the grbindex output. @param op The GRIBBase operation running this funciton. @param regrib a Regrib for data information @param ingrib The input GRIBBase that represents the input file. @param task An hwrf.hwrftask.HWRFTask to provide the path to grbindex @param kwargs Ignored @returns ingribNz%s: make the grbindexz .grbindexgrbindexr;z%s: already has grbindex %s) rBr grib1grbindexr;rrrgetexerrcheckrun) rfrZingribtaskrhrZinindexr;rrIrIrJaction_grbindexs  r cKs|j}|j}|dkr,|dkr,td|fn:|dkr:|}n,|dkrH|}n||krbtd||fn|}|j} |j} t|| } t|| } | r| r|d\}} |jd|d| | |f}|jdk r|jt |t |}|dkrd| | |f}|jdk r |j |t |t |d|S| rNt td d t td t| d |S| r~t td d t td t| d |Std | | fdS)a0!Merges two GRIB1 files that must already have the same grid. This is a low-level implementation function. It should not be called directly. This function is sent as a parameter to GRIB1Op to do a copygb merge (-xM) of two GRIB1 files to produce a single GRIB1 file. It requires that at least one of the files have a known grid, and if both have a known grid then their grids must mach. @param op The GRIBBase operation running this funciton. @param regrib a Regrib for data information @param in1,in2 The input GRIBGrid objects that provide filenames @param kwargs Ignored @returns The resulting GRIB1File, which may be in1, in2 or a new GRIB1File @bug This function calls pwd and ls -l if things go wrong. It needs to use produtil.listing instead.Nz0%s: unable to guess the grid for this GRIB mergez4input grids to not match in GRIB merge: (%s) != (%s)z merge.grb1-gz-xMrz+%s + %s: GRIB1 merge failed: exit status %dlsz-lpwdz: not ok (empty or missing)z8%s, %s: both inputs to GRIB1 merge are empty or missing.)rr r rrrr'r;rrzrrrrrr)rfrZin1Zin2rhZgrid1Zgrid2rrfile1file2Zok1Zok2rrrrrIrIrJaction_grib1merge@sd            rc Os|d|j\}}|j}|dkr*td|jd|jd|j|f} |jdk r^|jt| t | } | dkr|t d| ft ||t |d|jS)a@!Regrids a GRIB1 file. This is a low-level implementation function. It should not be called directly. This is sent as a parameter to GRIB1Op to convert a GRIB1 file from one grid to another. The output has a known grid, so it can be sent into an action_grib1merge. @param op The GRIBBase operation running this funciton. @param regrib a Regrib for data information @param infile The input filename. @param ingrid Input GRIB1Grid that specifies the target grid. @param args,kwargs Ignored @returns a new GRIB1File for the output fileZto_NzSTried to regrid a GRIB1 file, but the GRIBGrid did not have GRIB1 grid information.r z-xrz7ERROR: copygb regrid command failed with exit status %d) rgridnamerr r'rr;rrzrrrr) rfrrZingridrrhrrrrrrIrIrJaction_grib1regrids   rc Os|d|j\}}|jdkr.td|tf||}dd||D} |jdd|jd|fd | >} |j dk r|j t | t | |j d } | d krt d | ft|d|j|j|jS) aX!Subsets a GRIB1 file. This is a low-level implementation function. It should not be called directly. It subsets a GRIB1 file infile using the given subsetter. The subsetter should have a list of strings accessible via subsetter.grib1sub. It should also have a name accessible through subsetter.subsetname. The wgrib -s output of infile is scanned. Any line in wgrib -s's output that contains the entirety of any line in the subsetter.grib1sub is retained. The subsetting is done via wgrib -i -grib (infile) -o (outfile). @param op The GRIBBase operation running this funciton. @param regrib a Regrib for data information @param infile The input filename. @param subsetter A GRIBSubsetter that chooses the fields to keep. @param args,kwargs Ignored @returns a new GRIB1File for the output fileZsub_Nz3%s: cannot create: no GRIB1 subsetter for subset %scSsg|]}|qSrIrI).0linerIrIrJ sz&action_grib1subset..rrr rrz6ERROR: wgrib subset command failed with exit status %d)r subsetnamegrib1subZSubsetlessErrorZsubnamerr(rrmr;rrzrrrrnscenterewcenter) rfrr subsetterrrhrrindexZsubindexrrrIrIrJaction_grib1subsets*    rc  Ks|jdk st|jdt|j} t|j} |jdk rp|jdt|t|t|t|t|t| | | ft|d}t|d}t| }t|}t| }t| dd|d}t| dd|d}t| dd|d}t| dd|d}dt| d@kr>|jdk r4|jdt| f||}}dt| d @kr||jdk rr|jd t| f||}}dt| d @kr|jdk r|jd t| f|| } }|dkst|dkstd |||||||||f }t||dS)ae!Generates a latitude-longitude grid centered on a GRIB file or specified point. This is an internal implementation function that should not be called directly. It queries the center object's nscenter and ewcenter properties to get the objects location. It then adds a border around that, creating a GRIB1 grid 255 grid specification centered on the @c center object. @param op The GRIBBase operation running this funciton. @param center The GRIBBase operation on which to center the grid @param regrib a Regrib for data information @param name the name of the resulting grid, for storage in a RegribMany @param nsres,ewres GRIB1 grid 255 resolution information @param nssize,ewsize GRIB1 grid 255 size information, but in degrees. It will be converted to millidegrees for passing to underlying GRIB manipulation programs. @param nscount,ewcount Number of gridpoints in each direction, for the GRIB1 grid 255 information. @param scan GRIB1 grid 255 scanning mode byte @param kwargs Ignored @returns a new GRIBGrid for the new gridNz IN CLATLONzVCLATLON: nsres=%s ewres=%s nssize=%s ewsize=%s nscount=%s ewcount=%s nscen=%f ewcen=%fir$rzCLATLON scan=%d, swap EW@zCLATLON scan=%d, swap NS z!CLATLON scan=%d, swap NS-EW sizesz"255 0 %d %d %d %d %d %d %d %d %d 0) r;rBrfloatrrrzintr)rfrrcenterZnsresZewresZnssizeZewsizeZnscountZewcountscanrhZnscenZewcenZiewresZinsresZiscanZinscountZiewcountZinlatZislatZielonZiwlonrrIrIrJaction_clatlons`             r%c@s(eZdZdZddZddZddZdS) rva!Base class for the regridding object tree. This is the abstract base class for all GRIB files, operators, subsetters and grids. Everything that is representable as an Regrib operation is a subclass of GRIBBase. This class should never be instantiated directly.cOsdS)z!Returns True if this object and its subobjects are all ready for a call to make, and False otherwise. @param args,kwargs Ignored, but used by subclasses.TrIrCrrhrIrIrJrq szGRIBBase.is_readycKsdS)z!Returns True if the specified kwargs are valid and False otherwise. @param kwargs Ignored, but used by subclassesTrIrrrIrIrJrsszGRIBBase.input_validcKs|S)z!Runs the action this object should perform and returns another GRIBBase object. @param regrib a Regrib for data information @param kwargs Ignored, but used by subclasses.rI)rCrrhrIrIrJrtsz GRIBBase.makeN)rZr[r\r]rqrsrtrIrIrIrJrvsrvc@seZdZdZdS)rzs!This abstract base class represents something that is able to produce a GRIBGrid object when make() is called.N)rZr[r\r]rIrIrIrJrsrcs|eZdZdZdfdd ZddZddZd d Zd d Zd dZ ddZ e edddZ e e dddZ e e dddZZS)rz;!This class represents a GRIB1 or GRIB2 grid specification.Ncs$tt|||_||_||_dS)a!Creates a GRIBGrid with a given name, a copygb -g style GRIB1 grid specification and a GRIB2 grid specification that is currently unused. @param gridname The gridname is mandatory and will be used to generate temporary filenames. @param grib1grid The GRIB1 grid information, a string @param grib2grid The GRIB2 grid information (unsupported)N)r/rr0 _gridname _grib1grid _grib2grid)rCrr grib2gridrGrIrJr0"szGRIBGrid.__init__cOsdS)zq!Returns True. The grid information is always ready. @param args,kwargs Ignored, but used by subclasses.TrIr&rIrIrJrq.szGRIBGrid.is_readycKsdS)z!Returns True. The grid information is always available, regardless of the kwargs. @param kwargs Ignored, but used by subclasses.TrIrrrIrIrJrs2szGRIBGrid.input_validcOs|S)zv!Returns self. This grid is the output grid of this grid. @param args,kwargs Ignored, but used by subclasses.rIr&rIrIrJrt7sz GRIBGrid.makecCs|jS)zG!Returns the name of this grid, as provided to the constructor.)r'rKrIrIrJ getgridname;szGRIBGrid.getgridnamecCs|jS)zk!Returns the GRIB1 (wgrib) style grid information, as sent to the constructor's grib1grid argument.r(rKrIrIrJ getgrib1grid?szGRIBGrid.getgrib1gridcCs|jS)z!This is a placeholder to return the GRIB2-style grid information. At present, it returns whatever was sent to the constructor's grib2grid argumentr)rKrIrIrJ getgrib2gridCszGRIBGrid.getgrib2gridzRThe name of this grid. This is used to generate output filenames when regridding.zIA string to send to copygb's -g parameter for interpolating to this grid.z/GRIB2 regridding information, currently unused.)NN)rZr[r\r]r0rqrsrtr+r-r/r^rrr*r_rIrIrGrJr s" ZQuarter_Degree_Grid_193Z193c@s0eZdZdZddZddZddZdd Zd S) rz!This class represents a GRIBGrid that is stored in a RegribMany object. It is able to check for readiness via RegribMany.is_ready and produce a result via RegribMany.make.cCs ||_dS)z!GRIBGridFetcher constructor @param name The name of the grid that is fetched. This is used to generate temporary filenames and is used in RegribMany for the generator name.N_namerrIrIrJr0aszGRIBGridFetcher.__init__cOs$|d}|st|j|jf||S)a*!Calls kwargs['regribmany'].has_data to see if the specified operation has produced its grid. @param args,kwargs Passed to source.has_data. The meaning is implementation-specific, but generally the kwargs are used for string replacement in an hwrf.config.HWRFConfigrrBrr1rCrrhsourcerIrIrJrqgszGRIBGridFetcher.is_readycKs |d}|st|j|jf|S)a6!Calls kwargs['regribmany'].input_valid to see if the specified kwargs make a valid input to the operation. @param kwargs Passed to source.input_valid. The meaning is implementation-specific, but generally the kwargs are used for string replacement in an hwrf.config.HWRFConfigrrBrsr1rCrhr4rIrIrJrspszGRIBGridFetcher.input_validcOs |d}|st|j|jf|S)z!Calls kwargs['regribmany'].make to produce the grid. @param args,kwargs Passed to source.make. The meaning is implementation-specific, but generally the kwargs are used for string replacement in an hwrf.config.HWRFConfigrrBrtr1r3rIrIrJrtyszGRIBGridFetcher.makeNrZr[r\r]r0rqrsrtrIrIrIrJr]s   rc@s0eZdZdZddZddZddZdd Zd S) GRIBGridComputez!This class represents a GRIBGrid that must be computed from some other input, usually a GRIB file. This is used to create storm-centered or E-grid GRIB-centered grids for the HWRF.cGs||_||_t||_dS)a!Creates a new GRIBGridCompute with the given name and action. The action is a function or callable object that takes this object, the regrib, the name and the contents of args. Also, any keyword arguments given to self.make are passed on as well. @param name The name of the computed grid. @param action The function that computes the grid. @param args Additional positional arguments are sent to the function.N)r1_actionr>_args)rCractionrrIrIrJr0s zGRIBGridCompute.__init__cOs,|jD] }t|tr|j||sdSqdS)a*!Returns the logical "or" of is_ready(*args,**kwargs) called on all subobjects. Subobjects that are not instances of GRIBBase are assumed to be ready. @param args,kwargs Passed to arg.is_ready, for all args sent to the constructor that are subclasses of GRIBBaseFT)r;rurvrqrCrrhrrIrIrJrqs zGRIBGridCompute.is_readycOs,|jD] }t|tr|jf|sdSqdS)a*!Returns the logical "or" of input_valid(**kwargs) called on all subobjects. Subobjects that are not instances of GRIBBase are assumed to be ready. @param args,kwargs Passed to arg.input_valid, for all args sent to the constructor that are subclasses of GRIBBaseFT)r;rurvrsr=rIrIrJrss zGRIBGridCompute.input_validcKsRg}|jD].}t|tr.||j|f|q ||q |j|||jf||S)ag!Runs the action specified in the constructor, providing as arguments regrib, and the result of running make on all of the other arguments sent to the constructor. @param regrib The Regrib object for data storage. @param kwargs Passed to arg.make, for all args sent to the constructor that are subclasses of GRIBBase)r;rurvrrtr:r1)rCrrhrrrIrIrJrts    zGRIBGridCompute.makeNr8rIrIrIrJr9s    r9c@sTeZdZdZddZddZddZdd Zd d Ze eed d Z e eed dZ d S) FixedLocationz!Represents a specific location on the earth as a latitude, longitude pair. This is meant to be used with action_clatlon to generate fixed lat-lon grids.cCst||_t||_dS)z_!FixedLocation constructor @param lat,lon The fixed location in degrees North and East.N)r!_FixedLocation__lat_FixedLocation__lon)rClatlonrIrIrJr0s zFixedLocation.__init__cCs|jS)z!Returns the point's latituder?rKrIrIrJgetlatszFixedLocation.getlatcCs|jS)z!Returns the point's longitude.r@rKrIrIrJgetlonszFixedLocation.getloncCs ||_dS)zP!Sets the point's latitude @param val The new latitude in degrees North.NrCrUrIrIrJsetlatszFixedLocation.setlatcCs ||_dS)zQ!Sets the point's longitude. @param val The new longitude in degrees EastNrErUrIrIrJsetlonszFixedLocation.setlonNz$The latitude of this fixed location.z%The longitude of this fixed location.) rZr[r\r]r0rDrFrGrHr^rrrIrIrIrJr>sr>c Cst|dkr$|ddkr$|ddks(tt|dkrL|ddkrL|ddksPt|dkr`|dksdtt|dkr|ddkr|ddkst|dkrdt|dt|df}t|t||d|d|d|d|d|d| S)a^!Create a GRIBGridCompute that makes a lat-lon grid. Returns a GRIBGridCompute that will produce a lat-lon grid centered on the given object. The provided object must have nscenter and ewcenter properties that produce real lats and lons that are positive North and positive East. The res parameter is a two element array containing the resolution in degrees. @param name the new grid's name @param center An object on which to center. Must have nscenter and ewcenter properties. @param res The GRIB1 grid 255 resolution information in a two-element array. @param size The size parameter is a two-element array containing the extent in degrees. @param n The n parameter contains the number of gridpoints. @param scan The "scan" parameter is the scanning mode parameter: 128 means E-W are reversed, 64 means N-S are reversed, and 32 means the data is transposed. @note All three, res, size and n, are two element arrays with the N-S value first and the E-W value second. These are turned into a GRIB1 grid 255 specification.r$rr#Nz clatlon%dx%dp)rrBr"r9r%)r#ressizenr$rrIrIrJclatlons(((rNcs|eZdZdZdfdd ZddZddZd d Zd d Zd dZ ddZ e edddZ e e dddZ e e dddZZS)rzE!A GRIBBase that subsets GRIB files, keeping only certain parameters.Ncs$tt|||_||_||_dS)aL!GRIBSubsetter constructor. Creates a GRIBSubsetter with a given name, a callable object grib1sub that will be sent to produtil.gribop.grib1subset, and an unused grib2sub that will be used for GRIB2 subsetting one day. @param grib1sub Callable object that iterates over wgrib -s output and yields only fields that should be kept, potentially in a new order. @param grib2sub Unsupported: GRIB2 subsetter. @param subsetname The subsetname is mandatory and will be used to generate temporary filenames.N)r/rr0 _subsetname _grib1sub _grib2sub)rCrrgrib2subrGrIrJr0s zGRIBSubsetter.__init__cOsdS)z!Returns True. The subsetter is its own product, so it is always "ready." @param args,kwargs Ignored, but used by subclasses. TrIr&rIrIrJrq szGRIBSubsetter.is_readycKsdS)z!Returns True. The subsetter's product (itself) does not vary with the kwargs, so any input is valid. @param kwargs Ignored, but used by subclasses.TrIrrrIrIrJrsszGRIBSubsetter.input_validcOs|S)zm!Returns self. The subsetter is its own product. @param args,kwargs Ignored, but used by subclasses.rIr&rIrIrJrtszGRIBSubsetter.makecCs|jS)z4!Returns a name of this subset for use in filenames.)rOrKrIrIrJ getsubsetnameszGRIBSubsetter.getsubsetnamecCs|jS)zb!Returns an iterator that takes as its only argument an array of lines of wgrib -s output.)rPrKrIrIrJ getgrib1subszGRIBSubsetter.getgrib1subcCs|jS)zC!This is a placeholder for future GRIB2 subsetting support.)rQrKrIrIrJ getgrib2subszGRIBSubsetter.getgrib2subzTThe name of this GRIB1/2 subset. This is used to generate output filenames.zUA callable object to send to produtil.gribop.grib1subset's subsetter argument.z/GRIB2 subsetting information, currently unused.)NN)rZr[r\r]r0rqrsrtrSrTrUr^rrrRr_rIrIrGrJrs"c@s0eZdZdZddZddZddZdd Zd S) rz;!This class grabs a GRIBSubsetter from a RegribMany object.cCs ||_dS)zL!GRIBSubsetterFetcher constructor @param name the name of the subsetNr0rrIrIrJr08szGRIBSubsetterFetcher.__init__cKs |d}|st|j|jf|S)z!Calls kwargs['regribmany'].input_valid to see if the kwargs make a valid input. @param kwargs Contains a regribmany key mapping to a RegribMany objectrr5r6rIrIrJrs<sz GRIBSubsetterFetcher.input_validcOs$|d}|st|j|jf||S)a !Calls kwargs['regribmany'].has_data to see if the operation has produced its subsetter yet. @param kwargs Contains a regribmany key mapping to a RegribMany object. Is also passed to has_data @param args Additional positional arguments passed to has_datarr2r3rIrIrJrqCszGRIBSubsetterFetcher.is_readycOs |d}|st|j|jf|S)z!Calls kwargs['regribmany'].make to produce the subsetter. @param args,kwargs Passed to source.make. The meaning is implementation-specific, but generally the kwargs are used for string replacement in an hwrf.config.HWRFConfigrr7r3rIrIrJrtLszGRIBSubsetterFetcher.makeNrZr[r\r]r0rsrqrtrIrIrIrJr6s  rc@sVeZdZdZddZddZddZeeddd Zd d Z d d Z ddZ ddZ dS)rz|!This is the abstract base class for all GRIB1 and GRIB2 files and operators. It should never be instantiated directly.cGs||_t||_dS)a!Creates a GRIBOp that has a number of child GRIBBase objects, with a specified action to perform in the GRIBOp.make method. The action should be a callable object that takes as input a Regrib, the contents of args and any keyword arguments sent to make. @param action the function that performs the operation @param args arguments to the actionN)r:r>r;rCr<rrIrIrJr0ZszGRIBOp.__init__cCs|jS)z3!Returns the action, a function or callable object.)r:rKrIrIrJ getactiondszGRIBOp.getactionccs|jD] }|VqdS)z*!Iterates over all child GRIBBase objects.N)r;)rCrrIrIrJrgs z GRIBOp.argsNz,cSsg|] }t|qSrI)rz)rxrIrIrJrsz#GRIBOp.__repr__..)ryrZrzr:rmrrKrIrIrJ__repr__szGRIBOp.__repr__) rZr[r\r]r0rXrr^r<rqrsrtr[rIrIrIrJrWs   cs8eZdZdZfddZddZddZdd ZZS) rz!This subclass of GRIBOp produces GRIB2 files, and can be converted to GRIB1 via obj*GRIB1 or obj.to_grib1(). Calls to obj.to_grib2() or obj*GRIB2 simply return self.cstt|j|f|dS)zI!GRIB2Op constructor @param action,args Passed to GRIBOp.__init__N)r/rr0rWrGrIrJr0szGRIB2Op.__init__cCs tt|S)zA!Returns a GRIB2Op that converts this operation's output to GRIB1)rrrKrIrIrJto_grib1szGRIB2Op.to_grib1cCs|S)z4!Returns self (converting GRIB2 to GRIB2 is a no-op)rIrKrIrIrJto_grib2szGRIB2Op.to_grib2cCs,|tkr|S|tkr|S|tkr(|StS)a!If grid is the special constant GRIB1, this is the same as to_grib1(), if GRIB2, then returns self. Otherwise, returns NotImplemented to indicate that GRIB2 regridding is not implemented yet. @param grid The constant GRIB1, GRIB2, or a GRIBGrid)rr\rSATGRIB2NotImplementedrCrrIrIrJ__mul__szGRIB2Op.__mul__) rZr[r\r]r0r\r]rar_rIrIrGrJrs  cs`eZdZdZfddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ Z S)ra!This subclass of GRIBOp produces GRIB1 files. It introduces a number of convenience calls: * file1 + file2 + file3 = a copygb merge of the three files * file1*grid = copygb interpolate file1 to the specified GRIBGrid * file1*GRIB2 = convert to GRIB2 * file1*GRIB1 = no-op (returns self) * file1/subsetter = subsets the GRIB1 file using the given GRIBSubsetter These can be combined, of course, and follow the usual Python order of precedence: * (file1*grid + file2*grid + file3/subsetter*grid)*GRIB1 As with the GRIB2Op, there are also to_grib1() and to_grib2() methods which return self, and a GRIB2 conversion of self, respectively.cstt|j|f|dS)z!Creates a new GRIB1Op, passing all arguments to the superclass constructor. @param action,args Passed to GRIBOp.__init__N)r/rr0rWrGrIrJr0szGRIB1Op.__init__cCs|S)z:!Returns self. The GRIB1Op already produces a GRIB1 file.rIrKrIrIrJr\szGRIB1Op.to_grib1cCs tt|S)zU!Returns a GRIB2Op that will make a GRIB2 version of this operation's output.)rrrKrIrIrJr]szGRIB1Op.to_grib2cCs tt|S)zi!Returns a GRIB2Op that will make a GRIB2 version of this operation's output using hwrf_satgrib2.)rrrKrIrIrJ to_satgrib2szGRIB1Op.to_satgrib2cGst|tstdt|jft}|||||D]:}|}t|tsptdt|jt |f||q@tt f|S)aq!Returns a GRIB1Op that will ask hwrf_regrid_merge to convert one or more files to a target grid and paste them on top of one another, without making intermediate files. @param grid The target grid (GRIBGrid) for both objects @param args All other positional arguments contain the other GRIB1 file producers to regrid. zPFirst argument to GRIB1Op.regridmerge must be a GRIBGridBase subclass, not a %s.zmSecond and later arguments to GRIB1Op.regridmerge must convertable to GRIB1Op objects. You provided a %s %s.) rurr}ryrZr>rr\rrzr)rCrrlargsrZarg1rIrIrJr.s&     zGRIB1Op.regridmergecCs tt|S)zj!Returns a GRIB1Op that will run grbindex and save the results, unless that has already been done.)rr rKrIrIrJ make_grbindexszGRIB1Op.make_grbindexcCst|trtt||StS)z!Returns a GRIB1Op that will subset this one using the specified subsetter. @param subsetter a GRIBSubsetter to do the subsetting.)rurrrr_)rCrrIrIrJ __truediv__s  zGRIB1Op.__truediv__cCsJt|trtt||S|tkr&|S|tkr6|S|tkrF| St S)a\!If the grid is a GRIBGridBase, returns a GRIB1Op that will regrid this GRIB1Op's output to that grid. If grid is the special constant GRIB2, returns self.to_grib2. If it is the constant GRIB1, returns self.to_grib1. Otherwise, returns NotImplemented. @param grid Constants GRIB1, GRIB2, or a GRIBGridBase) rurrrrr\rr]r^rbr_r`rIrIrJras  zGRIB1Op.__mul__cCst|trtt||StS)a3!If the argument is a GRIBOp, returns a GRIB1Op that will paste a GRIB1 version of that operations output onto this operation's output. For any other argument type, returns NotImplemented. @param other a GRIBOp whose output will be interpolated on top of this one.)rurrrr\r_)rCotherrIrIrJ__add__ s zGRIB1Op.__add__)rZr[r\r]r0r\r]rbr.rdrerargr_rIrIrGrJrs c@s0eZdZdZddZddZddZdd Zd S) rzX!The GRIB1Fetcher is a GRIB1Op subclass that fetches a GRIB1 file from a RegribMany.cCs ||_dS)z!Creates a GRIB1Fetcher for the specified operation name. @param name the name of this operation for temporary filename generationNr0rrIrIrJr0szGRIB1Fetcher.__init__cKs |d}|st|j|jf|S)a !Calls kwargs['regribmany'].input_valid to determine if the specified keyword arguments make a valid input to the operation. @param kwargs Contains a regribmany key mapping to a RegribMany object. Is also passed to source.input_validrr5r6rIrIrJrs szGRIB1Fetcher.input_validcOs$|d}|st|j|jf||S)a!!Calls kwargs['regribmany'].has_data to see if there is cached output from the operation. @param kwargs Contains a regribmany key mapping to a RegribMany object. Is also passed to source.has_data. @param args Positional arguments passed to source.has_datarr2r3rIrIrJrq)szGRIB1Fetcher.is_readycOs |d}|st|j|jf|S)a!Calls kwargs['regribmany'].make to produce the operation's output. @param kwargs Contains a regribmany key mapping to a RegribMany object. Is also passed to source.make. @param args Additional positional arguments are unused.rr7r3rIrIrJrt2szGRIB1Fetcher.makeNrVrIrIrIrJrs   rcseZdZdZd"fdd ZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZee dddZee dddZee dddZee e ddZeedddZeeddd Zee ddd!ZZS)#rz!This subclass of GRIB1Op represents a GRIB1 file on disk that is ALREADY PRESENT. Its is_ready function is overridden to assume the file is always ready, and its "make" method simply returns self.Ncstt|d||_||_||_||_|dksTt|dk sTtd|j j t |f|dkst|dk std|j j t |f||_ ||_ d|_dS)aP!GRIB1File constructor. @param grib1file The file path. @param grib1index Path to the wgrib -s output @param grib1grid Grid information. @param nscenter,ewcenter Latitude and longitude of the grid center point, in degrees North and East @param grib1grbindex Path to the grbindex output.NzAewcenter must be None, or an int or float, not a %s (ewcenter=%s)zAnscenter must be None, or an int or float, not a %s (nscenter=%s))r/rr0 _grib1file _grib1indexr(_grib1grbindexr!r}rHrZrz _ewcenter _nscenter _indexdata)rCr grib1indexrrrrrGrIrJr0As zGRIB1File.__init__cKsdSzu!Returns True. The file is already present, so any kwargs make a valid input. @param kwargs Ignored.TrIrrrIrIrJrsXszGRIB1File.input_validcOsdSz!Returns True. The operation is ready to run because it has nothing to do: the file is already present. @param args,kwargs Ignored.TrIr&rIrIrJrq]szGRIB1File.is_readycOs|S)zx!Returns self. This class represents a GRIB1 file, so it is its own output. @param args,kwargs Ignored.rIr&rIrIrJrtbszGRIB1File.makecCs|jS)z$!Returns the domain center latitude.)rlrKrIrIrJ getnscentergszGRIB1File.getnscentercCs|jS)z%!Returns the domain center longitude.)rkrKrIrIrJ getewcenterjszGRIB1File.getewcentercCs|jS)z#!Returns the GRIB1 file's location.)rhrKrIrIrJ getgrib1filemszGRIB1File.getgrib1filecCs|jS)zM!Returns the location of the file that stores the output of wgrib -s.)rirKrIrIrJ getgrib1indexpszGRIB1File.getgrib1indexcCs|jS)zo!Returns the location of the file that stores the output of the grbindex program run on the GRIB1 file.rjrKrIrIrJgetgrib1grbindextszGRIB1File.getgrib1grbindexcCs ||_dS)zl!Sets the location of the file that stores the output of the grbindex program run on the GRIB1 file.Nru)rChererIrIrJsetgrib1grbindexxszGRIB1File.setgrib1grbindexcCs|jS)z0!Returns the GRIB1 grid information as a string.r,rKrIrIrJr-|szGRIB1File.getgrib1gridc Cs|jdk r|jS|j}|dks*tj|sl||j}t|jd|jf}t |d}| |W5QRXnt |d}| }W5QRX| |_|jS)z!Returns the output of wgrib -s run on this file, which may be from cached data. @param regrib a Regrib for data storageNrwtrt) rmrnrkrlexistsrrrr(openwritereadall splitlines)rCrZ indexfilerrrIrIrJrs     zGRIB1File.wgrib_sz9The path to the result file, in this case the GRIB1 file.z=The path to the GRIB1 file which is assumed to already exist.z:Either None or the wgrib -s index file for the GRIB1 file.zAEither None or the grbindex binary index file for the GRIB1 file.zDEither None or the copygb -g argument data for the GRIB1 file's gridz7Returns None or the center latitude of this GRIB1 file.z8Returns None or the center longitude of this GRIB1 file.)NNN)rZr[r\r]r0rsrqrtrqrrrsrtrvrxr-rr^ resultfilerrnrrrrr_rIrIrGrJr<sJcseZdZdZfddZddZddZdd Zd d Zd d Z ddZ e edddZ e edddZ e e dddZe e dddZZS)rz!This subclass of GRIB2Op represents a GRIB2 file on disk that is ALREADY PRESENT. Its is_ready function is overridden to assume the file is always ready, and its "make" method simply returns self.cs&tt|d||_||_||_dS)z!GRIB2File constructor @param grib2file The grib2 file path. @param grib2index The grib 2 index file path. @param grib2grid GRIB2 grid information.N)r/rr0 _grib2file _grib2indexr))rCr grib2indexr*rGrIrJr0szGRIB2File.__init__cOsdSrprIr&rIrIrJrqszGRIB2File.is_readycKsdSrorIrrrIrIrJrsszGRIB2File.input_validcOs|S)zx!Returns self. This class represents a GRIB2 file, so it is its own output. @param args,kwargs Ignored.rIr&rIrIrJrtszGRIB2File.makecCs|jS)z#!Returns the GRIB2 file's location.)rrKrIrIrJ getgrib2fileszGRIB2File.getgrib2filecCs|jS)zp!This is a placeholder for future development. It returns the grib2index argument from the constructor.)rrKrIrIrJ getgrib2indexszGRIB2File.getgrib2indexcCs|jS)zo!This is a placeholder for future development. It returns the grib2grid argument from the constructor.r.rKrIrIrJr/szGRIB2File.getgrib2gridNz9The path to the result file, in this case the GRIB2 file.z=The path to the GRIB2 file which is assumed to already exist.z9This is a placeholder for future GRIB2 subsetting supportz9This is a placeholder for future GRIB2 regridding support)rZr[r\r]r0rqrsrtrrr/r^rrrr*r_rIrIrGrJrs( c@s@eZdZdZddZddZddZdd Zee j d d d Z d S) r a!This subclass of GRIB1Op and UpstreamFile represents a GRIB1 file that is produced by an upstream workflow. The is_ready subroutine calls self.check to check the modification time and file size. The make subroutine copies the file to a local location.cOs$tj||f||t|ddS)z!UpstreamGRIB1 constructor @param dstore the produtil.datastore.Datastore for database info @param args,kwargs All other arguments passed to produtil.datastore.UpstreamFile.__init__N)rr0rrCdstorerrhrIrIrJr0szUpstreamGRIB1.__init__cOs"d|kr||dS|SdS)a@!Runs the check function on the upstream product, and returns its results. If the frominfo argument is in kwargs, it is passed as the first positional parameter to check. @param kwargs The frominfo argument to UpstreamFile.check() @param args Additional positional arguments are ignored.frominfoNcheckr&rIrIrJrqszUpstreamGRIB1.is_readycKsdS)zC!Returns True. @param kwargs Keyword arguments are ignored.TrIrrrIrIrJrsszUpstreamGRIB1.input_validcOs@|j}|dtj|\}}tjj|||jdt |ddS)z!Calls deliver_file to copy the file to a temporary location decided by regrib.gribtemp. Returns a GRIB1File for that file. @param regrib a Regrib for data storage @param args,kwargs All other arguments are ignored.z upstream.rN rrrkrlrnrr deliver_filer;rrCrrrhrrrrIrIrJrt szUpstreamGRIB1.makeNz8The path to the result file, in this case self.location.) rZr[r\r]r0rqrsrtr^r getlocationrrIrIrIrJr s  c@s@eZdZdZddZddZddZdd Zd d Zd d Z dS) GRIB1Selectorz!This object produces a GRIB1Op from a call to a Task object's Task.product. This is the class that underlies the implementation of igrb1.cKs||_t||_dS)z!Creates a GRIB1Selector for the specified task. @param task The task whose products function is called. @param kwargs All other arguments are sent to task.products.N)_taskr@r)rCr rhrIrIrJr0szGRIB1Selector.__init__cKs||}|S)zr!Returns True if the task's product is available. @param kwargs All keyword arguments are sent to select())select is_availablerCrhproductrIrIrJrq%s zGRIB1Selector.is_readycKs,z||}WdStk r&YdSXdS)z!Returns True if select() is able to find a product and False if NoProductError is raised. @param kwargs Keyword arguments are passed to select()TFN)rrrrIrIrJrs*s  zGRIB1Selector.input_validcKs*||}t|tstd|j|f|S)z!Calls self.select(kwargs) to get the product, and calls make on the result. @param regrib A Regrib for data storage @param kwargs Keyword arguments are passed to select()z'Selected product is not a GRIB product.)rrurrrt)rCrrhrrIrIrJrt3s  zGRIB1Selector.makecCst|j}||dd|jjf|D}t|dkrBtdnFt|dkrXtdn0|d}t|t st dt |j t |f|SdS) a|!Attempts to attain a Product from the supplied Task. @protected Calls a Task's products function to get the Product of interest. The kwargs is a dict of keyword arguments to pass to task.products. Those will override any keyword arguments that were sent to the constructor. If more than one Product is yielded, then ProductAmbiguityError is raised. If no Product is yielded, NoProductError is raised. If the returned Product is not a GRIBBase, TypeError is raised. Otherwise, the result is returned. @param kwargs a dict to pass to task.productscSsg|]}|qSrIrI)rprIrIrJrLsz(GRIB1Selector.select..r#z3Specified arguments produced more than one product.rz(Specified arguments produced no product.zvERROR: in GRIB1Selector, a Task.products call returned something that was not a GRIBBase object. It returned a %s %s.N)r@rrrproductsrrrrurvr}ryrZrz)rCrhrrrrIrIrJr<s       zGRIB1Selector.selectcCsd|jj|jjjfS)z*!Returns a Pythonic representation of selfz%s(%s))rHrZrrKrIrIrJr[YszGRIB1Selector.__repr__N) rZr[r\r]r0rqrsrtrr[rIrIrIrJrs  rcKs t|f|S)zx!This is a convenient alias for the GRIB1Selector constructor. @param task,kwargs Passed to GRIB1Selector.__init__())r)r rhrIrIrJigrb1]src@seZdZdZddZddZddZdd Zd d Zd d Z ddZ e e ee dZ ddZ ddZddZe ee edZddZddZe eeddZe eeddZd#dd Zd!d"ZdS)$r!z!This class represents a GRIB2 file that is produced by this workflow. It is a direct subclass of both GRIB2File and FileProduct.cOs^d|kr|ddksttj||f||t|dddd|_|jdk rV|jdksZtdS)aP!Creates a new GRIB2Product. @param dstore The dstore is the produtil.datastore.Datastore for database storage. @param args,kwargs All other arguments are passed on to FileProduct's constructor. @note The GRIB2File constructor is initialized with None for the file, index and grid.rN)rBrr0rrmrrrIrIrJr0hs zGRIB2Product.__init__cKsdS)z!Returns True. Since this object is already its product, any kwargs make a valid input. @param kwargs Ignored.TrIrrrIrIrJrsvszGRIB2Product.input_validcOs"d|kr|tdS|SdS)a!Calls self.check to see if the product is available. @param args Additional positional arguments are ignored. @param kwargs Additional keyword arguments. If frominfo is in the kwargs, it is passed as the first positional argument to check.rN)rZkwrargsr&rIrIrJrq{szGRIB2Product.is_readycOs@|j}|dtj|\}}tjj|||jdt |ddS)a!Calls deliver_file to copy the file to a new temporary location from regrib.gribtemp. Returns a GRIB2File for that temporary file. @param regrib A Regrib for data storage @param args,kwargs All other arguments are ignored.prod.rN) rrrkrlrnrrrr;rrrIrIrJrtszGRIB2Product.makecCs(|dks|dks|dkrdS||d<dS)zM!Sets the grib2 grid information. @param grid GRIB2 grid information.NrNoner*rIr`rIrIrJ setgrib2gridszGRIB2Product.setgrib2gridcCs |ddS)z$!Returns the grib2 grid information.r*NrrKrIrIrJr/szGRIB2Product.getgrib2gridcCs |d=dS)z#!Clears the grib2 grid information.r*NrIrKrIrIrJ delgrib2gridszGRIB2Product.delgrib2gridz$The GRIB2 grid information if known.cCs(|dks|dks|dkrdS||d<dS)z"!Sets the grib2 index information.NrrrrIrCrrIrIrJ setgrib2indexszGRIB2Product.setgrib2indexcCs |ddS)z>!Gets the grib2 index information, or returns None if unknown.rNrrKrIrIrJrszGRIB2Product.getgrib2indexcCs |d=dS)a!Cleares the stored information about the index location. Does NOT delete the index file.rNrIrKrIrIrJ delgrib2indexszGRIB2Product.delgrib2indexz*The disk location of the GRIB2 index file.cCs|jS)z;!Returns the location of the GRIB2 file from self.location.rrKrIrIrJrszGRIB2Product.getgrib2filecCs ||_dS)z>!Sets the location of the GRIB2 file by setting self.location.NrrUrIrIrJ setgrib2fileszGRIB2Product.setgrib2fileNSynonym for self.locationTc Cst|tr tj||||ddSt|ts2td|j|dk rJ|n|j}|dkrjt j d|j d\}} z |j }Wn"tk r} zW5d} ~ XYnXz |j} Wn(tk r} z |j} W5d} ~ XYnXW5QRX|dk rt|nd|f} | dk r | dkst|dk r$|dks(tt jj| ||dd } |dk rv| dk rvt j|rvt jj|| |dd } |jP||_| r| |_ z |j|_Wn$tk r} zW5d} ~ XYnXd |_W5QRX|j|d dS) a!Delivers a GRIB2 file to its destination. May also deliver other files associated with that GRIB2 file. @param location Delivery location. @param index Index file delivery location @param grbindex Ignored. @param frominfo Either a source filename, or a GRIB2Op. @param keep If True, the source file will be copied instead of moved. @param logger A logging.Logger for log information.rrrNzWGRIB2Product.deliver requires a frominfo that is either a string filename or a GRIB2Op.P%s: no location known when delivering product. Specify a location to deliver().NNz%s.idxr)rFTr)rur|rdeliverrr}r transactionrr datastoreUnknownLocationdidrAttributeErrorrrrBrrrr* availablecall_callbacks) rCrrrrrr;r fromindextoindexKeyErrorfromloc haveindexrIrIrJrs\      "   zGRIB2Product.deliverc CsP|j}|dk r"|dkr"tj||j}|j|`|`d|_W5QRXdS)zV!Deletes the delivered GRIB2 file and discards the index and grid information.NrF) rrr remove_filerrrr*r)rCrrrIrIrJ undelivers  zGRIB2Product.undeliver)NNNNTN)rZr[r\r]r0rsrqrtrr/rr^r*rrrrrrrrrrrIrIrIrJr!ds<   rNrrrrrrrrr rrr!rrIrIrIrJsxH< @}#-+%x #B$A; %3" ?!Ae$x=)C*