1 """!low-level wrf implementation, underlying hwrf.wrf
3 This module contains low-level classes that underlie the
4 implementation of the hwrf.wrf module. It also contains the WRFOutput
5 class, which is used to describe a WRF output file, and the
6 parse_wrf_outname, which turns WRF-style filename formats
7 (wrfout_d<domain>_<date>) into filenames."""
9 import fractions,math,re,datetime, pdb, logging
17 __all__=[
'parse_wrf_outname',
'WRFOutput',
'WRFDomainBase',
'WRFDomains']
22 """!generates wrf filenames from templates like construct_filename
24 Takes a wrf outname, a grid_id and a date and produces the final
25 string outname. The mandatory boolean argument nocolons is set to
26 the namelist &time_control nocolons value. This mimics the
27 construct_filename family of functions in the WRF source code.
28 @param outname the filename format as passed to WRF
29 @param grid_id the integer grid ID
30 @param date the date (anything accepted by hwrf.numerics.to_datetime)
31 @param nocolons if True, colons in the date are converted to underscores
32 @return the string filename"""
33 assert(isinstance(outname,basestring))
35 if re.search(
'(?i)<domain>',out):
36 out=re.sub(
'(?i)<domain>',
'%02d'%(int(grid_id),),out)
37 if re.search(
'(?i)<date>',out):
38 out=re.sub(
'(?i)<date>',to_datetime(date).\
39 strftime(
'%Y-%m-%d_%H:%M:%S'),out)
41 out=out[0:2]+re.sub(
':',
'_',out[2:])
47 """!A class that provides information about WRF output and input files.
49 This class is used throughout the HWRF scripts to identify WRF
50 input and output filenames. The underlying implementation knows
51 how to deal with the odd rounding issues involved in predicting
52 WRF filenames based on timesteps, including fractional timesteps.
53 This class also tracks the analysis time, forecast time, stream
54 and full path to the file."""
55 def __init__(self,anltime,stream,domain,path,validtime=None,
57 """!Creates a WRFOutput object that knows the path to its file
58 (self.path()), the output time as a datetime
59 (self.validtime()), the simulation start time as a datetime
60 (self.anltime()), the output forecast second as a timedelta
61 (self.fcstdelta()), the name of the WRF stream
62 (self.stream()), and the WRF domain object (self.domain()).
63 Do not modify the domain object or many things may break.
65 You must specify exactly one of validtime or fcstdelta. If
66 you specify both, OverspecifiedOutputTime will be raised. If
67 you specify neither, NoOutputTime will be raised."""
68 assert(isinstance(stream,basestring))
69 assert(isinstance(path,basestring))
71 if validtime
is None and delta
is None:
72 raise NoOutputTime(
'In WRFOutput.__init__, both validtime and '
73 'fcstdelta were None')
74 elif validtime
is not None:
77 elif fcstdelta
is not None:
82 'In WRFOutput.__init__, both validtime and fcstdelta were '
83 'specified. You must specify exactly one.')
86 assert(domain
is None or isinstance(domain,WRFDomainBase))
89 """!provides an integer hash value so this object can be used
94 """!does this WRFOutput equal that one?
96 Returns True if the other WRFOutput object is identical to
97 this one, and False if it is not. For anything other than a
98 WRFOutput, returns NotImplemented.
99 @param other another object"""
100 if not isinstance(other,WRFOutput):
101 return NotImplemented
102 if not self.
_domain==other._domain:
return False
103 if not self.
_stream==other._stream:
return False
104 if not self.
_path==other._path:
return False
105 if not self.
_validtime==other._validtime:
return False
106 if not self.
_anltime==other._anltime:
return False
109 """!a string representation of this output file"""
110 return '%s output stream=%s path=%s' % \
113 """!a detailed string representation of this output file"""
114 return 'WRFOutput(%s,%s,%s,%s,validtime=%s)' % \
118 """!Returns the full path to the output file."""
121 """!Returns the lower-case name of the WRF stream."""
124 """!the hwrf.wrf.WRFDomain object
126 Returns the domain object for this output file's WRF domain.
127 Do not modify the returned object or many things will break."""
130 """!the difference between the analysis and forecast time.
132 Returns the time difference between the valid (output) time
133 and the analysis (simulation start) time."""
136 """!Returns the output time as a datetime.datetime."""
139 """!Returns the analysis time as a datetime.datetime."""
145 """!superclass of WRFDomain
147 This is the superclass of WRFDomain and it should not be
148 instantiated directly. It exists to eliminate a cyclic dependency
149 in the module imports. """
150 def __init__(self,conf,section,name=None,copy=None):
151 """!Creates a new WRFDomainBase.
152 conf - an HWRFConfig with configuration information
153 section - the section to read for information about this domain
154 name - the name of the domain. Default: section name.
155 copy - do not specify this. It is used by self.copy()
156 to copy a WRFDomainBase."""
165 self.
nl=copy.nl.copy()
169 (copy._start,copy._end,copy._dt,copy.nestlevel,copy.parent,
173 self.
name=str(section)
204 """!an integer representation for hashing"""
205 return hash(self.
name)
207 """!a detailed string representation"""
208 return '<WRFDomain name=%s>'%(str(self.
name),)
210 """!integer comparison for sorting, like the cmp function.
211 Sorts by domain's string name.
212 @param other the domain to compare against"""
213 return cmp(self.
name,other.name)
215 """!synonym for __repr__()"""
218 """!returns the analysis time
220 Returns the parent _start time if there is a parent, otherwise
221 returns this domain's analysis time."""
222 if self.
parent is not None:
223 return self.parent._start
227 """!Raises NotImplementedError. The WRFDomain overrides this
228 to return the grid id."""
229 raise NotImplementedError(
230 'WRFDomainBase does not implement get_grid_id')
232 """!removes forbidden namelist entries
234 Removes all namelist entries that the conf files are forbidden
235 from specifying. Generally this is anything related to domain
236 start, end, size, I/O or timesteps."""
238 def _nl_subsetter(self,s,v):
241 This returns True. It is intended to be overridden in
242 subclasses to subset the namelist values provided by the
243 configuration files. It should return True to keep the
244 variable, or False to reject it.
245 @param s the namelist name
246 @param v the variable name"""
249 """!Returns a copy of this object. The copy has its own data
250 structures, so modifying the copy will not modify the
253 def _validate_timespan(self,start,end,timestep):
254 """!checks if a timespan is valid
256 Analyzes a potential WRF simulation start, end and timestep
257 to make sure it matches assumptions made within WRF, and
258 within the hwrf package.
259 1. There must be no timezone (UTC only)
260 2. The start time must not contain microseconds.
261 3. The end time must be at or after the start time
262 @param start the start time of the simulation
263 @param end the end time of the simulation
264 @param timestep the simulation timestep or output frequency
265 @returns a tuple (ts,te,dt) where:
266 - ts = the start time as a datetime.datetime
267 - te = the end time as a datetime.datetime
268 - dt = the timestep as a fractions.Fraction"""
269 ts=to_datetime(start)
271 dt=to_fraction(timestep)
272 if te.tzinfo
is not None or ts.tzinfo
is not None:
274 'WRF start and end times must not contain timezones.')
275 if te.microsecond!=0
or ts.microsecond!=0:
277 'WRF start and end times must lie exactly on a second.')
280 'Invalid domain start/end times: end is before start.',ts,te)
283 """!sets the start and end times of this domain, and the domain
286 Validates the provided inputs through _validate_timespan().
287 If accepted, sets the start and end times, and the timestep.
288 @param start the start time of the simulation
289 @param end the end time of the simulation
290 @param timestep the simulation timestep or output frequency"""
296 """!initializes grid ID and non-nesting-related variables
298 Initializes this domain's variables that are unrelated to
300 @param grid_id the grid id in WRF (1=moad, 2=...)"""
302 """!initializes this domain as the outermost domain
304 Initializes this domain's variables so it knows to act as
305 the Mother Of All Domains (MOAD) - the outermost domain.
306 The grid ID is set to 1 and the parent to None.
307 @param simstart simulation start time
308 @param simend simulation end time
309 @param simdt simulation outer domain timestep
310 @param eta_levels NMM eta vertical levels as set in the
311 eta_levels namelist value."""
312 (self._simstart,self._simend,self._simdt)=(simstart,simend,simdt)
313 self.set_timing(simstart,simend,simdt)
317 """!initializes this domain as a nest
319 Initializes this domain's variables to make it a nest within
320 the given parent WRFDomain
321 @param parent the parent of this nest
322 @param grid_id the grid ID
323 @param start the nest's start time
324 @param end the nest's end time"""
327 (self._simstart,self._simend,self._simdt) = \
328 (parent._simstart,parent._simend,parent._simdt)
329 if not is_at_timestep(parent._start,start,parent._dt):
331 'Start time %s for domain %d is not at parent %d timestep.'
332 %(parent._start,grid_id,parent.grid_id))
333 self.
set_timing(parent._simstart,parent._simend,parent._simdt/3)
335 """!creates the wrf namelist as a string, and returns it."""
336 return self.nl.make_namelist()
341 """!abstract base class of WRFSimulation
343 This is the abstract base class of WRFSimulation. You should not
344 instantiate it directly. Its purpose is to combine information
345 about multiple WRFDomainBase objects (or WRFDomain objects) to
346 make a single namelist. It also has the ability to make aggregate
347 changes to those objects, or obtain aggregate information about
348 them. This class exists only to avoid cyclic dependencies."""
350 """! duplicates this object
352 Returns a deep copy of this object, providing new data
353 structures so modifying the copy will not modify the original.
354 The underlying WRFDomain objects and their data structures are
356 return WRFDomains(
None,
None,
None,
None,
None,
None,dup=self)
392 def __init__(self,conf,section,moad,simstart,simend,timestep=None,dup=None):
393 """!WRFDomains constructor
395 Creates a new WRFDomains object.
396 @param conf the HWRFConfig to provide configuration information
397 @param section the section to use in that config object
398 @param moad the Mother of All Domains, as a WRFDomain
399 @param simstart,simend - simulation start and end times
400 @param timestep the simulation timestep
401 @param dup do not use. This is used by the self.copy() do do a deep
402 copy of a WRFDomains."""
405 self.
nl=dup.nl.copy()
407 ( dup._simstart, dup._simend, dup._timestep, dup._io_form )
414 for (name,domain)
in dup._grid.iteritems():
416 self.
_grid[name]=domain.copy()
419 for (a,b)
in dup._parent.iteritems(): self.
_parent[a]=b
422 eta_levels=self.nl.nl_get(
'domains',
'eta_levels')
424 self.
_simend=to_datetime(simend)
426 timestep=self.nl.trait_get(
'dt')
428 iof=self.nl.trait_get(
'io_form',
'missing')
436 mymoad.remove_forbidden()
441 self.
_grid={mymoad.name:mymoad}
442 self.
_to_id={mymoad.name:1}
449 centerthis=
'**CENTERED**'):
450 """!sets i_parent_start and j_parent_start if needed
452 For domains whose i_parent_start or j_parent_start are set
453 automatically (start=centered or start=auto), this fills those
454 domains starts with the provided values. Domains that should
455 be centered in their parent (start=centerthis) are centered
456 relative to their parent if they have one.
458 @param ivalue the i value to set if an external fortran
459 program has to be run to determine the i_parent_start and
461 @param jvalue the j value to set. Defaults to the ivalue
462 @param fillthis do not change - the string to locate for start=auto
463 @param centerthis do not change - the string to locate for start=centered
465 if jvalue
is None: jvalue=ivalue
469 jvalue=(int(jvalue)+1)/2*2-1
471 if isinstance(bob,int):
return bob
475 got=domain.nl.nl_get(
'domains',
'i_parent_start')
476 if isinstance(got,basestring):
478 domain.nl.nl_set(
'domains',
'i_parent_start',ivalue)
479 elif got==centerthis:
480 if domain.parent
is None:
482 '%s: invalid value for start. Only nests can '
483 'have start=centered'%(domain.name,))
484 dxp=intify(domain.parent.nl.nl_get(
'domains',
'e_we'))
485 dxd=intify(domain.nl.nl_get(
'domains',
'e_we'))
486 rat=intify(domain.nl.nl_get(
'domains',
'parent_grid_ratio',3))
487 icen=(dxp-dxd//rat)//2
488 domain.nl.nl_set(
'domains',
'i_parent_start',icen)
491 '%s: invalid value for start. Must be %s, %s or an '
492 'integer'%(got,fillthis,centerthis))
493 got=domain.nl.nl_get(
'domains',
'j_parent_start')
494 if isinstance(got,basestring):
496 domain.nl.nl_set(
'domains',
'j_parent_start',jvalue)
497 elif got==centerthis:
498 if domain.parent
is None:
500 '%s: invalid value for start. Only nests can '
501 'have start=centered'%(domain.name,))
502 dyp=intify(domain.parent.nl.nl_get(
'domains',
'e_sn'))
503 dyd=intify(domain.nl.nl_get(
'domains',
'e_sn'))
504 rat=intify(domain.nl.nl_get(
'domains',
'parent_grid_ratio',3))
505 jcen=(dyp-dyd//rat)//2
506 jcen=(int(jcen)+1)//2*2-1
507 domain.nl.nl_set(
'domains',
'j_parent_start',jcen)
510 '%s: invalid value for start. Must be %s, %s or an '
511 'integer'%(got,fillthis,centerthis))
514 """For domains whose i_parent_start or j_parent_start are set
515 automatically, this fills those domains starts with the
516 provided values, for the fakestorm of a multistorm run.
517 ivalue = a list of i start values for N storms
518 jvalue = a list of j start values for N storms"""
520 numberof_outernests = int((self.
maxdom()-1)/2)
521 numberof_istartvalues = len(ivalues)
522 assert(numberof_outernests==numberof_istartvalues)
526 if jvalues[ij_index]
is None: jvalues[ij_index]=ivalues[ij_index]
530 jvalues[ij_index]=(int(jvalues[ij_index])+1)/2*2-1
539 got=domain.nl.nl_get(
'domains',
'i_parent_start')
540 if not isinstance(got,int):
541 domain.nl.nl_set(
'domains',
'i_parent_start',ivalues[ij_index])
542 got=domain.nl.nl_get(
'domains',
'j_parent_start')
543 if not isinstance(got,int):
544 domain.nl.nl_set(
'domains',
'j_parent_start',jvalues[ij_index])
546 if numberof_istartvalues==ij_index:
552 """!Returns the simulation start time as a datetime.datetime."""
555 """!Returns the simulation end time as a datetime.datetime."""
558 """!Returns the simulation timestep as a datetime.time_delta."""
563 """!Should colons be omitted from filenames?
565 Should colons be omitted from filenames? This is determined
566 from the configuration files, if it is specified there, or
567 from the I/O forms selected (some don't support colons). The
568 return value may be cached. To ensure the value is recomputed
569 instead, you can call get_nocolons."""
570 if '_nocolons_cache' not in self.__dict__:
572 return self._nocolons_cache
575 """!Force a recheck of whether colons be omitted from filenames.
577 Should colons be omitted from filenames? This is determined
578 from the configuration files, if it is specified there, or
579 from the I/O forms selected (some don't support colons). This
580 method guesses the nocolons setting from the WRF/WPS/Real
581 namelist. The result of this calculation is never cached: all
582 namelist options are re-scanned and the flag is recomputed
583 each time. To get the cached value, use the nocolons property
585 nc=self.nl.trait_get(
'nocolons',
True)
587 for var,value
in self.nl.nl_each(
'time_control'):
588 if var.find(
'io_form')>=0:
590 if iof==1
or iof==11:
594 for var,value
in self.nl.trait_each():
595 if var.find(
'io_form')>=0:
597 if iof==1
or iof==11:
600 self.nl.nl_set(
'time_control',
'nocolons',nc)
601 self.__dict__[
'_nocolons_cache']=nc
604 """!Gets the default io_form."""
607 """!Sets the default io_form."""
613 io_form=property(get_io_form,set_io_form,
None,
614 "The default I/O form for this WRF")
617 """!Returns the io_form for the specified stream.
619 @return the io_form for the given stream. If none is
620 specified, the default io_form is returned.
621 @param stream the stream, a lower-case string"""
622 if stream==
'history': stream=
'output'
623 iof=self.nl.trait_get(
'io_form_%s'%(stream),int(self.
_io_form))
626 """!returns the MOAD as a WRFDomain."""
629 """!returns the last domain added to this WRF."""
631 def add_output(self,stream='history',domain=None,io_form=None,
632 start=
None,end=
None,step=
None,frames_per_outfile=
None,
634 """!request output from one or more streams
636 Requests that one or all WRF domains output the specified
637 stream. The stream should be "history" or "auxhistN" for an
638 integer N>0. Optional "domain" specifies the domain that
639 should output this stream, otherwise all domains will output
642 @param stream the stream: "history" or "auxhistN" for an integer N>0
643 @param domain the domain (optional)
644 @param io_form WRF IO form. Simply calls self.set_io_form(stream,io_form)
645 @param start output start time (anything accepted by to_datetime)
646 Default: simulation start time.
647 @param end output end time (anything accepted by to_datetime.
648 Default: simulation end time.
649 @param step output interval, sent into to_out_interval().
650 Default: trait stream+"_interval" or 6hrs
651 @param frames_per_outfile how many output times per output file
652 @param outname output name or array of output names (one per
653 domain). Can only specify for all domains, not for only
654 one. Default: leave unspecified, and let WRF use its
657 NOTE: You cannot add any more domains after calling this
664 if stream==
'inputout':
665 if outname
is None: outname=
'wrfinputout_d<domain>'
666 self.nl.nl_set(
'time_control',
'write_input',
True)
667 if outname
is not None: self.
set_outname(stream,outname)
668 if start
is not None: start=to_datetime_rel(start,self.
_simstart)
672 if domain
is not None and domain!=mydom
and \
673 not mydom.has_output(stream):
674 mydom.no_output(stream)
677 stream,start,end,step,outname,frames_per_outfile,
679 if stream==
'restart':
684 """!Ensure that only one restart frequency is set
686 Unlike most output frequencies, the restart frequency has to
687 be the same for all domains, and is specified as a scalar
688 value, not an array. This function removes per-domain restart
689 frequencies, moving the restart frequency up to the
690 domain-independent namelist values. The frequency used is the
691 one for the last domain listed by self.__iter__."""
693 for n
in [
'restart_begin',
'restart_begin_s',
'restart_begin_m',
694 'restart_begin_h',
'restart_begin_d',
695 'restart_interval',
'restart_interval_s',
696 'restart_interval_m',
'restart_interval_h',
697 'restart_interval_d' ]:
698 if domain.nl.nl_have(
'time_control',n):
699 v=domain.nl.nl_get(
'time_control',n)
700 domain.nl.nl_del(
'time_control',n)
701 self.nl.nl_set(
'time_control',n,v)
703 """!Set the wrf output filename for a stream
705 Sets the WRF output filename format for the specified
706 stream to the given name. The name should contain @<domain@>
707 and @<date@> if appropriate.
708 @param stream the stream to change
709 @param outname the new output filename format"""
710 if stream==
'inputout': stream=
'input'
711 self.nl.nl_set(
'time_control',
'%s_outname'
712 %(str(stream),),str(outname))
714 """!Sets the io_form for the specified stream.
716 Set the io_form for the specified stream. The "history" and
717 "output" streams are synonyms.
718 @param stream the stream
719 @param io_form the io_form"""
720 if stream==
'history': stream=
'output'
721 self.nl.nl_set(
'time_control',
'io_form_%s'%(stream),int(io_form))
722 self.nl.trait_set(
'io_form_%s'%(stream),int(io_form))
724 """!Return the suggested output suffix for filenames
726 Gets the suggested output suffix for the specified stream.
727 Returns "int" for 1 and "nc" for 2 or 11.
728 @param stream the stream. Default: "history" """
732 elif iof == 2
or iof==11:
735 raise NameError(
"Unsupported IO form %d" %self_.io_form)
738 """!return the specified domain
740 Returns a domain with the given name or grid_id. This method
741 may raise IndexError or KeyError if the domain does not exist.
742 If passed a WRFDomainBase, then this simulation's copy of the
743 domain with the same name is returned.
745 @returns the specified domain.
746 @param what If this is a string or WRFDomain, then the domain
747 with that name is returned. If "what" is an integer, the
748 domain with that ID is returned. If it is a WRFDomainBase,
749 then the name stored in that object is used instead."""
750 if isinstance(what,WRFDomainBase):
return self.
_grid[str(what.name)]
751 if isinstance(what,basestring):
return self.
_grid[str(what)]
752 if isinstance(what,int):
return self.
_grid[self.
_to_name[what]]
753 raise KeyError(
'In WRF.get, the key must be a basestring, '
754 'WRFDomain or an int (or subclass thereof). You '
755 'provided %s.'%(repr(what),))
757 """!returns the highest domain number, which is also the number
761 """!Can we still add domains to this simulation?
763 Returns true if this WRF can accept new domains. Certain
764 operations, such as requesting output files, end the ability
766 return not self._domans_done
767 def add(self,child,parent=None):
768 """!Add a WRFDomain to this simulation.
770 Adds the child WRFDomain to this WRF, with the specified
771 parent. If the parent is not specified, the last added domain
772 is used as the parent. If specified, the parent may be
773 anything accepted by self.get. The return value is the new
776 @param child the domain to add
778 @param parent the WRFDomain of the parent
780 @return a new WRFDomain object with the same name as child """
784 'You cannot add any domains after setting up I/O for a '
789 newname=str(child.name)
790 newparent=self.
get_last()
if parent
is None else self.
get(parent)
791 parentname=str(newparent.name)
793 if newname
in self.
_grid:
794 raise DomainExists(
'%s: domain already exists'%(newname,),newname)
798 mine.nl.trait_set(
'id',newid)
800 mine.remove_forbidden()
806 self.
_grid[newname]=mine
807 self.
_to_id[newname]=newid
809 self.
_parent[newname]=parentname
812 self.nl.nl_set(
'domains',
'max_dom',int(self.
maxdom()))
818 """!Same as self.get(what)
821 @param what the grid_id, domain name or WRFDomain to search for.
822 @return the WRFDomain"""
823 return self.
get(what)
825 """!Same as self.maxdom()."""
828 """!does this simulation contain this domain?
830 Returns True if self.get(what) succeeds, and False if it
831 raises KeyError. Any other exceptions are passed to the
833 @param what the grid_id or name of the WRFDomain to search
834 for, or another WRFDomain whose name we should search for."""
838 except KeyError:
pass
841 """!Iterates over all WRFDomain objects in this WRFDomains."""
842 for grid_id
in xrange(1,self.
_nextid):
def stream(self)
Returns the lower-case name of the WRF stream.
def get_moad(self)
returns the MOAD as a WRFDomain.
_parent
mapping from domain name to its parent domain's name
def init_as_moad(self, simstart, simend, simdt, eta_levels)
initializes this domain as the outermost domain
Generates a Fortran namelist entirely from config files.
def maxdom(self)
returns the highest domain number, which is also the number of domains.
_nextid
the next grid_id to use
_start
the start time for this domain
def remove_forbidden(self)
removes forbidden namelist entries
def add_output
request output from one or more streams
nl
the hwrf.namelist.Conf2Namelist with namelist information for this domain
_output
internal data structure used by subclasses to track output streams
def __hash__(self)
provides an integer hash value so this object can be used as a key in a dict
def __iter__(self)
Iterates over all WRFDomain objects in this WRFDomains.
def get_last(self)
returns the last domain added to this WRF.
def set_timing(self, start, end, timestep)
sets the start and end times of this domain, and the domain timestep
def __repr__(self)
a detailed string representation of this output file
def __repr__(self)
a detailed string representation
_timestep
the outermost domain timestep
def copy(self)
Returns a copy of this object.
def make_restart_time_scalar(self)
Ensure that only one restart frequency is set.
_domains_done
if True, we can add more domains
def __str__(self)
a string representation of this output file
def get_io_form(self)
Gets the default io_form.
nocolons
should colons be eliminated from filenames?
Raised when it is no longer possible to add domains, but the caller tried to add one.
def init_domain(self, grid_id)
initializes grid ID and non-nesting-related variables
def simstart(self)
Returns the simulation start time as a datetime.datetime.
def init_as_nest(self, parent, grid_id, start, end)
initializes this domain as a nest
nl
the hwrf.namelist.Conf2Namelist with domain-independent namelist information like eta_levels and debu...
def __hash__(self)
an integer representation for hashing
Time manipulation and other numerical routines.
def add
Add a WRFDomain to this simulation.
Raised when adding a domain, if a domain by the same name already exists.
def fill_auto_starts_multistorm
_grid
mapping from domain name to domain
def can_add(self)
Can we still add domains to this simulation?
def make_namelist(self)
creates the wrf namelist as a string, and returns it.
_dt
this domain's timestep
def nocolons(self)
Should colons be omitted from filenames?
This module provides two different ways to generate Fortran namelist files from HWRFConfig sections: ...
def __init__
Creates a new WRFDomainBase.
Raised when the end of a timespan is before the beginning.
Raised when a time was requested with higher precision than available.
_to_id
mapping from domain name to grid_id
A class that provides information about WRF output and input files.
_io_form
the default io_form
def __str__(self)
synonym for repr()
abstract base class of WRFSimulation
def __init__
WRFDomains constructor.
Raised when a time was required, but none was provided.
def __cmp__(self, other)
integer comparison for sorting, like the cmp function.
def get_io_suffix
Return the suggested output suffix for filenames.
def simend(self)
Returns the simulation end time as a datetime.datetime.
_simstart
the simulation start time
def fill_auto_starts
sets i_parent_start and j_parent_start if needed
def __eq__(self, other)
does this WRFOutput equal that one?
def set_io_form(self, i)
Sets the default io_form.
Raised when a timespan's beginning is not at a timestep.
def path(self)
Returns the full path to the output file.
Raised when a timezone is provided.
def _nl_subsetter(self, s, v)
returns True
def parse_wrf_outname(outname, grid_id, date, nocolons)
generates wrf filenames from templates like construct_filename
def __init__
Creates a WRFOutput object that knows the path to its file (self.path()), the output time as a dateti...
_to_name
mapping from grid_id to domain name
def get_nocolons(self)
Force a recheck of whether colons be omitted from filenames.
def _validate_timespan(self, start, end, timestep)
checks if a timespan is valid
name
the name of this domain
Exceptions raised by the hwrf package.
def domain(self)
the hwrf.wrf.WRFDomain object
def copy(self)
duplicates this object
def get(self, what)
return the specified domain
nestlevel
the wrf nesting level
_end
the end time for this domain
def validtime(self)
Returns the output time as a datetime.datetime.
def anltime(self)
Returns the analysis time as a datetime.datetime.
_simend
the simulation end time
Raised when an output time is specified in two redundant ways.
def get_grid_id(self)
Raises NotImplementedError.
def timestep(self)
Returns the simulation timestep as a datetime.time_delta.
def get_anl_time(self)
returns the analysis time
def __getitem__(self, what)
Same as self.get(what)
def __len__(self)
Same as self.maxdom().
def fcstdelta(self)
the difference between the analysis and forecast time.
def io_form_for(self, stream)
Returns the io_form for the specified stream.
def set_outname(self, stream, outname)
Set the wrf output filename for a stream.
Raised when the hwrf.wrf.WRFDomain start type is unrecognized.
def __contains__(self, what)
does this simulation contain this domain?