HWRF  trunk@4391
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
hwrf.revital.Revital Class Reference

This class reads one or more tcvitals files and rewrites them as requested. More...

Detailed Description

This class reads one or more tcvitals files and rewrites them as requested.

Definition at line 38 of file revital.py.

Public Member Functions

def __init__
 Creates a Revital object: More...
 
def append (self, vital)
 Appends a vital entry to self.vitals. More...
 
def extend (self, vitals)
 Given the specified iterable object, appends its contents to my own. More...
 
def copy (self)
 Returns a deep copy of this Revital. More...
 
def readvitals
 Same as readfiles except the tcvitals have already been parsed and the vitals are being passed in, not the filelist. More...
 
def readfiles
 Reads the list of files and parses them as tcvitals files. More...
 
def move_latlon (self, vital, dt)
 Returns a tuple containing the latitude and longitude of the storm at a different position according to the storm motion vector. More...
 
def readcarq (self, longstormid)
 Tries to find the CARQ data for the specified storm. More...
 
def clean_up_vitals
 Calls the hwrf.storminfo.clean_up_vitals on this object's vitals. More...
 
def renumber
 Renumbers storms with numbers 90-99, if possible, to have the same number as later 1-49 numbered storms. More...
 
def delete_invest_duplicates (self)
 Deletes Invest entries that have the same location and time as non-invest entries. More...
 
def swap_numbers (self)
 Calls swap_numbers on all vitals to swap old and new storm IDs. More...
 
def mirror_renumbered_vitals (self)
 Duplicates all vitals that have been renumbered, creating one StormInfo with the old number and one with the new number. More...
 
def discard_except (self, keep_condition)
 Discards all vitals except those for which the keep_condition function returns True. More...
 
def swap_names (self)
 This subroutine undoes the effect of renaming by swapping old and new names.
 
def rename (self)
 This subroutine renames storms so that they have the last name seen for their storm number. More...
 
def add_stormtype (self)
 Add the storm type parameter from the CARQ entries in the A deck. More...
 
def sort_by_function (self, cmpfun)
 Resorts the vitals using the specified cmp-like function. More...
 
def sort_by_storm (self)
 Resorts the vitals by storm instead of date. More...
 
def __iter__ (self)
 Iterates over all vitals, yielding StormInfo objects for each one. More...
 
def each
 Iterates over all vitals that match the specified stormid. More...
 
def print_vitals
 Print the vitals to the given stream in a specified format. More...
 
def hrd_multistorm_sorter (self, a, b)
 A drop-in replacement for "cmp" that can be used for sorting or comparison. More...
 
def multistorm_priority (self)
 Does nothing. More...
 

Public Attributes

 carqdat
 Contains CARQ entries read from the adeckdir A deck files. More...
 
 carqfail
 Set of longstormid entries that had no CARQ data. More...
 
 vitals
 The list of hwrf.storminfo.StormInfo objects being revitalized. More...
 
 search_dx
 Search radius in km for deciding whether two storms are the same. More...
 
 search_dt
 Search timespan for finding two storms that are the same.
 
 logger
 The logging.Logger to use for log messages.
 
 debug
 If True, send numerous extra log messages at DEBUG level. More...
 
 invest_number_name
 Rename stores to have the last non-INVEST name seen.
 
 adeckdir
 Directory with A deck files. More...
 
 is_cleaned
 Has clean_up_vitals() been called since the last operation that modified the vitals?
 

Protected Member Functions

def renumber_one (self, vital, lastvit, vit_motion, other_motion, threshold)
 Internal function that handles renumbering of storms. More...
 

Constructor & Destructor Documentation

def hwrf.revital.Revital.__init__ (   self,
  logger = None,
  invest_number_name = False,
  stormid = None,
  adeckdir = None,
  renumberlog = None,
  search_dx = 200e3,
  search_dt = None,
  debug = True,
  copy = None 
)

Creates a Revital object:

Parameters
loggerA logging.Logger object for logging or None to disable. Default: None
invest_number_nameRename storms to have the last non-INVEST name seen
stormidIgnored.
adeckdirDirectory with A deck files. This is used to read the storm type information from CARQ entries and append them to produce vitals with the storm type from vitals that lack it.
renumberlogIgnored.
search_dxSearch radius in km for deciding whether two storms are the same.
search_dtSearch timespan for finding two storms that are the same.
debugIf True, enables DEBUG level logging.
copyUsed by copy() to make a shallow copy of a Revital. If specified, the other arguments are ignored, and the copy's contents are copied. Do not use this argument. If you need a copy, use copy() instead.

Definition at line 43 of file revital.py.

Member Function Documentation

def hwrf.revital.Revital.__iter__ (   self)

Iterates over all vitals, yielding StormInfo objects for each one.

Definition at line 576 of file revital.py.

def hwrf.revital.Revital.add_stormtype (   self)

Add the storm type parameter from the CARQ entries in the A deck.

Definition at line 541 of file revital.py.

def hwrf.revital.Revital.append (   self,
  vital 
)

Appends a vital entry to self.vitals.

Parameters
vitalan hwrf.storminfo.StormInfo to append

Definition at line 130 of file revital.py.

def hwrf.revital.Revital.clean_up_vitals (   self,
  name_number_checker = None,
  basin_center_checker = None,
  vitals_cmp = None 
)

Calls the hwrf.storminfo.clean_up_vitals on this object's vitals.

The optional arguments are passed to hwrf.storminfo.clean_up_vitals.

Parameters
name_number_checkera function like hwrf.storminfo.name_number_okay() for validating the storm name and number
vitals_cmpa cmp-like function for ordering hwrf.storminfo.StormInfo objects
basin_center_checkera function like hwrf.storminfo.basin_center_okay() for checking the storm basin and forecast center (RSMC)
Postcondition
is_cleaned=True

Definition at line 243 of file revital.py.

Referenced by hwrf.revital.Revital.readcarq(), and hwrf.revital.Revital.renumber().

def hwrf.revital.Revital.copy (   self)
def hwrf.revital.Revital.delete_invest_duplicates (   self)

Deletes Invest entries that have the same location and time as non-invest entries.

Definition at line 453 of file revital.py.

Referenced by hwrf.revital.Revital.renumber().

def hwrf.revital.Revital.discard_except (   self,
  keep_condition 
)

Discards all vitals except those for which the keep_condition function returns True.

Parameters
keep_conditionA function that receives a StormInfo object as its only argument, returning True if the vital should be kept and False if not.
Note
The list will be unmodified if an exception is thrown.

Definition at line 498 of file revital.py.

def hwrf.revital.Revital.each (   self,
  stormid = None,
  old = False 
)

Iterates over all vitals that match the specified stormid.

If no stormid is given, iterates over all vitals.

Parameters
stormidthe storm ID to search for. This can be a stormid3, stormid4 or longstormid.
oldIf old=True, also searches the old_ copy of the stormid. Any of stormid3, stormid4 or longstormid are accepted.

Definition at line 580 of file revital.py.

Referenced by hwrf.revital.Revital.print_vitals().

def hwrf.revital.Revital.extend (   self,
  vitals 
)

Given the specified iterable object, appends its contents to my own.

Parameters
vitalsan iterable object filled with hwrf.storminfo.StormInfo

Definition at line 136 of file revital.py.

def hwrf.revital.Revital.hrd_multistorm_sorter (   self,
  a,
  b 
)

A drop-in replacement for "cmp" that can be used for sorting or comparison.

Returns -1 if a<b, 1 if a>b or 0 if a=b. Decision is made in this order:

  1. User priority (a.userprio): lower (priority 1) is "more important" than higher numbers (priority 9999 is fill value).
  2. Invest vs. non-invest: invest is less important
  3. wind: stronger wind is more important than weaker wind
  4. North Atlantic (L) storms: farther west is more important
  5. North East Pacific (E) storms: farther East is more important

If all of the above values are equal, 0 is returned.

Returns
-1, 0 or 1
Parameters
a,bthe vitals to compare

Definition at line 660 of file revital.py.

def hwrf.revital.Revital.mirror_renumbered_vitals (   self)

Duplicates all vitals that have been renumbered, creating one StormInfo with the old number and one with the new number.

Definition at line 486 of file revital.py.

def hwrf.revital.Revital.move_latlon (   self,
  vital,
  dt 
)

Returns a tuple containing the latitude and longitude of the storm at a different position according to the storm motion vector.

Parameters
vitalthe hwrf.storminfo.StormInfo for the storm fix being extrapolated
dtthe time difference in hours

Definition at line 202 of file revital.py.

Referenced by hwrf.revital.Revital.renumber_one().

def hwrf.revital.Revital.multistorm_priority (   self)

Does nothing.

Definition at line 690 of file revital.py.

def hwrf.revital.Revital.print_vitals (   self,
  stream,
  renumberlog = None,
  format = 'line',
  stormid = None,
  old = False 
)

Print the vitals to the given stream in a specified format.

Parameters
streamThe stream (eg.: opened file) to receive the vitals.
formatEither "tcvitals" to reformat as tcvitals (cleaning up any errors); or "line" to simply print the original data for each line; or "HHS" to use the HHS output format. (Do not use the "HHS" option unless you are HHS.)
renumberlogIf given, sends information about renaming and renumbering of the vitals to a second stream.
stormidThe "stormid" argument is used to restrict printing to only a certain stormid.
oldIf True, then vitals with an old_stormid that matches are also printed.

Definition at line 626 of file revital.py.

Referenced by hwrf.revital.Revital.each().

def hwrf.revital.Revital.readcarq (   self,
  longstormid 
)

Tries to find the CARQ data for the specified storm.

Reads it into the self.carqdat array, or adds the stormid to self.carqfail if the data cannot be read in.

Parameters
longstormidthe long stormid of the storm to read
Postcondition
the self.carqfail will contain longstormid OR self.carqdat[longstormid] will contain data for that storm

Definition at line 222 of file revital.py.

Referenced by hwrf.revital.Revital.add_stormtype().

def hwrf.revital.Revital.readfiles (   self,
  filelist,
  raise_all = True 
)

Reads the list of files and parses them as tcvitals files.

Parameters
filelista list of string filenames
raise_allif True, all exceptions are raised. If False, then exceptions are ignored, and the function will attempt to process all files, even if earlier ones failed.

Definition at line 169 of file revital.py.

def hwrf.revital.Revital.readvitals (   self,
  vitalslist,
  raise_all = True 
)

Same as readfiles except the tcvitals have already been parsed and the vitals are being passed in, not the filelist.

This was created to handle the multistorm fake storm. This is being used to validate any self generated vitals by the fake storm.

Parameters
vitalslista list of strings with tcvitals data
raise_allif True, raise exceptions for any parsing errors.
Returns
self

Definition at line 147 of file revital.py.

def hwrf.revital.Revital.rename (   self)

This subroutine renames storms so that they have the last name seen for their storm number.

Definition at line 522 of file revital.py.

def hwrf.revital.Revital.renumber (   self,
  unrenumber = False,
  clean = True,
  threshold = 0,
  discard_duplicates = True 
)

Renumbers storms with numbers 90-99, if possible, to have the same number as later 1-49 numbered storms.

Loops over all vitals from last to first, renumbering 90-99 storms to have the same storm number as later 1-49 storms.

Parameters
thresholdIf a threshold is given, then a cycle will only be considered for renumbering if it is either above that threshold, or is not an Invest.
unrenumberIf unrenumber is True, the original storm numbers are restored after renumbering.
discard_duplicateIf True, discard invests that are duplicates of non-invests. This feature is disabled if unrenumber is enabled or cleaning is disabled.
cleanIf clean is True (the default), then self.clean_up_vitals is called, which will (among other things) delete vitals lines that have the same time and storm ID. The cleaning is done after unrenumbering, so if both options are turned on, the result will contain only one entry per storm ID per time, but with all storm IDs that are available for a given storm at any one time.

Definition at line 382 of file revital.py.

Referenced by hwrf.revital.Revital.renumber_one().

def hwrf.revital.Revital.renumber_one (   self,
  vital,
  lastvit,
  vit_motion,
  other_motion,
  threshold 
)
protected

Internal function that handles renumbering of storms.

This is an internal implementation function that should never be called directly. It handles part of the work of renumbering storms in the list of vitals. You should call "renumber" instead.

Parameters
vitalthe vital being renumbered
lastvitthe last vital seen
vit_motiontime since vital
other_motiontime since other storms vital
thresholdcold start threshold, used to decide when to stop connecting an invest to a non-invest

Definition at line 265 of file revital.py.

Referenced by hwrf.revital.Revital.renumber().

def hwrf.revital.Revital.sort_by_function (   self,
  cmpfun 
)

Resorts the vitals using the specified cmp-like function.

Parameters
cmpfuna cmp-like function for comparing hwrf.storminfo.StormInfo objects

Definition at line 567 of file revital.py.

def hwrf.revital.Revital.sort_by_storm (   self)

Resorts the vitals by storm instead of date.

See hwrf.storminfo.vit_cmp_by_storm for details.

Definition at line 572 of file revital.py.

def hwrf.revital.Revital.swap_numbers (   self)

Calls swap_numbers on all vitals to swap old and new storm IDs.

Definition at line 480 of file revital.py.

Referenced by hwrf.revital.Revital.renumber().

Member Data Documentation

hwrf.revital.Revital.adeckdir

Directory with A deck files.

This is used to read the storm type information from CARQ entries and append them to produce vitals with the storm type from vitals that lack it.

Definition at line 83 of file revital.py.

Referenced by hwrf.revital.Revital.__init__(), and hwrf.revital.Revital.readcarq().

hwrf.revital.Revital.carqdat

Contains CARQ entries read from the adeckdir A deck files.

Definition at line 70 of file revital.py.

Referenced by hwrf.revital.Revital.add_stormtype(), and hwrf.revital.Revital.readcarq().

hwrf.revital.Revital.carqfail

Set of longstormid entries that had no CARQ data.

Definition at line 75 of file revital.py.

Referenced by hwrf.revital.Revital.readcarq().

hwrf.revital.Revital.debug
hwrf.revital.Revital.search_dx

Search radius in km for deciding whether two storms are the same.

Definition at line 78 of file revital.py.

Referenced by hwrf.revital.Revital.__init__(), and hwrf.revital.Revital.renumber_one().

hwrf.revital.Revital.vitals

The documentation for this class was generated from the following file: