Package qtcm :: Module field :: Class Field
[hide private]
[frames] | no frames]

Class Field

source code

object --+
         |
        Field

Class for QTCM fields.

QTCM fields are model parameters or variables, and includes
diagnotic and prognostic variables, run parameters, coefficients,
etc.  They can be scalars (numeric or string) or arrays.  The
values of these QTCM parameter objects can be changed in the
model by a call at the Python level, though the types of their
compiled model counterparts cannot be changed (without recompiling
the compiled model, of course).

The default values of QTCM fields that are defined in the
defaults module specify the type of the variables, as well as
the rank.  This information is used by the Qtcm class to properly
interface with the compiled model.  Thus, fields that are not
specified in the defaults module will not properly interface
with the compiled model.  However, some fields only need to be
defined at the Python level; those fields do not have to be
listed in defaults.

Class Instance Attributes:
* id:  A string naming the field (e.g., 'Qc', 'mrestart').  This 
  string should contain no whitespace.
* value:  The value of the field.  Can be of any type, though
  typically is either a string or numeric scalar or a numeric 
  array.
* units:  A string giving the units of the field.
* long_name:  A string giving a description of the field.

Class Instance Methods:
* rank:  Returns the rank of value.
* typecode:  Returns the typecode of value.

Instance Methods [hide private]
 
__init__(self, *args, **kwds)
Initialize Field object.
source code
 
rank(self)
Return the rank of self.value.
source code
 
typecode(self)
Return the typecode of self.value.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, *args, **kwds)
(Constructor)

source code 
Initialize Field object.

The Field object is instantiated either with one or two
positional input parameters, and up to two optional keyword
input parameters.

Positional Input Parameters:
* One argument:  The argument is a string that specifies
  the name of the field.  The name must match a key in
  defaults.qtcm_fields.  The value of the Field instance
  is set to the default value given in defaults.qtcm_fields.

* Two arguments:  The first argument is a string specifying
  the name of the field (as in the one argument case).  The
  second argument is the value that the Field instance is
  set to.  If the second argument is a Field object, the
  value of that Field object is extracted as the value for
  creating the current Field object.

Keyword Input Parameters:
* units:  String specifying the units of the field.

* long_name:  String specifying the long name of the field.

Examples:
>>> a = Field('dt')
>>> print a.id
dt
>>> print a.value
1200.0

>>> a = Field('dt', 1200.)
>>> print a.id
dt
>>> print a.value
1200.0
>>> print a.units
s
>>> print a.long_name
time step

>>> a = Field('dt', Field('dt'), units='h')
>>> print a.id
dt
>>> print a.value
1200.0
>>> print a.units
h

>>> a = Field(23)
Traceback (most recent call last):
    ...
TypeError: Field id must be string

Overrides: object.__init__

rank(self)

source code 

Return the rank of self.value.

If self.value does not exist, returns None.

typecode(self)

source code 

Return the typecode of self.value.

The typecode is determined by first converting self.value into an array, and then returning the dtype.char (in numpy). This is defined in the module num_settings, and is a function of what type of array package you're using. As a result, you shouldn't assume this method is very precise (e.g., don't use it to distinguish between single and double precision float), but rather, use it to distinguish between different categories of types (e.g., float vs. int). If self.value does not exist, returns None.