Table of Contents

Class: MadrigalParameters data.py

MadrigalParameters is an object that provides information about Madrigal parameters.

This class provides access to the Cedar/Madrigal standards for parameters (such as getMnemonic, getDescription, getCodeFromMnemonic) and categories. It will also examine an expression (string) and return the parameter mnemonics it contains.

Usage example:

        import madrigal.data.MadrigalParameters

        test = madrigal.data.MadrigalParameters()

        parcode = test.getParmCodeFromMnemonic("YEAR")

        print parcode

Non-standard Python modules used: None

Change history:

Written by Bill Rideout Nov. 27, 2001 Added getMnemonicListFromExpression Jul. 16, 2002

Methods   
__init__
__reorder
__sortList
getCategoryDict
getIsprintHeader
getMadCategoryIndex
getMnemonicListFromExpression
getParametersForInstruments
getParmCategory
getParmCodeFromMnemonic
getParmDescription
getParmDescriptionList
getParmFormat
getParmMnemonic
getParmMnemonicList
getParmScaleFactor
getParmType
getParmUnits
getSimpleParmDescription
getStdExpression
hasAddIncrement
hasHtmlDesc
isAddIncrement
isError
normalizeParmList
orderParms
  __init__ 
__init__ ( self,  madDB=None )

__init__ initializes MadrigalParameters by getting some basic information from MadrigalDB.

Inputs: Existing MadrigalDB object, by default = None.

Returns: void

Affects: Initializes self.__binDir.

Exceptions: None.

  __reorder 
__reorder (
        self,
        validList,
        sortedParmList,
        parmList,
        )

Private function that returns a new valid list sorted in the same parameter order as parmList.

  __sortList 
__sortList ( self,  parmList )

Private function that returns a new list of parameters sorted as isprint sorts parameters.

  getCategoryDict 
getCategoryDict ( self,  parmList )

getCategoryDict returns a python dict with key = category index, item = category name and ordered parameters Inputs: parmList - the list of parameters (integers or mnemonics)

Returns: a python dict, with key = category index. Each item is a list of two items. The first item is the category name (string). The second item is a list of parameter mnemonics from parmList belonging in that category. Ordering is alphabetical, except that an error parameter immediately follows its non-error parameter.

Affects: None

Exceptions: none

  getIsprintHeader 
getIsprintHeader ( self,  mnemonicList )

getIsprintHeader returns a string with mnemonics as it would appear at the top of isprint.

Inputs: mnemonic: a list of Madrigal mnemonics (string or integer)

Returns: a string with mnemonics as it would appear at the top of isprint

Affects: none

Exceptions: If any mnemonic not found.

  getMadCategoryIndex 
getMadCategoryIndex ( self,  category )

getMadCategoryIndex returns the index (order) of a given category.

Inputs: a Madrigal category (string)

Returns: an integer representing the index (order). Returns -32767 if not found.

Affects: none

Exceptions: none

  getMnemonicListFromExpression 
getMnemonicListFromExpression ( self,  expressionStr )

getMnemonicListFromExpression returns a list of unique cedar mnemonics in a python logical expression.

Inputs: expressionStr - a string containing a valid python logical expression with cedar mnemonics as variables. Expression can contain any python logical operator (and, or, not, ==, <, >, <=, >=, !=), any operator, any number, and valid python math function, and any variable that is a valid cedar mnemonic. A substring is assumed to be a cedar mnemonic if it begins with a letter, contains only alphanumerics, period, plus, or underscore, and is not immediately followed by a open parenthesis. Each potential cedar mnemonic is verified, and an exception is thrown if it is not valid. The validity of the entire expression is then verified by replacing all the valid cedar mnemonics by "1.0" and executing the resulting expression. If any exception besides divide by zero or value error occurs, an exception is thrown. Otherwise, the list of cedar mnemonics found is returned.

Returns: a list of unique cedar mnemonics (upper case).

Affects: None

Exceptions: Error thrown if any non-valid mnemonic found, or if expression throws an exception when run (except divide by zero or value error).

Exceptions   
'The expression "' + expressionStr + '" contains an error: ' + str(sys.exc_info() [ 1 ] )
'The expression ' + expressionStr + ' contains an illegal mnemonic: ' + thisMnemonic
  getParametersForInstruments 
getParametersForInstruments (
        self,
        instrumentList,
        parmListName='Comprehensive',
        )

getParametersForInstruments returns a list of unique Madrigal mnemonics associated with a list of instruments.

This method's purpose is to return a list of parameters appropriate for a user to select from given that a certain list of instruments is under consideration. This method will return a list of all measured parameters found in data files associated with those instruments, and also all parameters in the parmNameList that can be derived from those measured parameters. The passed in parmNameList must be a valid name of a parameter list found in the madrigal.ui.web.MadrigalWebFormat class, and defaults to the "Comprehensive" list of parameters used in the madDataBrowse web page.

Inputs: instrumentList - a python list on instruments as integers (kinst values).

parmListName - a name (string) of a list of parameters in the MadrigalWebFormat class. Defaults to "Comprehensive"

Returns: an ordered list of unique Madrigal mnemonics.

Affects: None

Exceptions: None.

  getParmCategory 
getParmCategory ( self,  parm )

getParmCategory returns a category (String) given a cedar parameter (integer or mnemonic string).

Inputs: a cedar code (integer)

Returns: a category string

Affects: none

Exceptions: none

  getParmCodeFromMnemonic 
getParmCodeFromMnemonic ( self,  mnemonic )

getParmCodeFromMnemonic converts a string to the cedar code (integer).

Inputs: mnemonic: the cedar mnemonic (string or integer in string form)

Returns: integer (cedar code)

Affects: none

Exceptions: MadrigalError thrown if code not found.

Exceptions   
madrigal.admin.MadrigalError( 'Mnemonic: ' + str( mnemonic ) + ' not a legal mnemonic.', None )
  getParmDescription 
getParmDescription ( self,  parm )

getParmDescription returns a description including units and possible links (String) given a parameter (integer or mnemonic).

Inputs: a parameter (integer or mnemonic)

Returns: a description string including units and possible links

Affects: none

Exceptions: none

  getParmDescriptionList 
getParmDescriptionList ( self,  parmList )

getParmDescriptionList returns a list of descriptions (String) given a list of parameters (integer or mnemonic).

Inputs: a list of parameters (integer or mnemonic)

Returns: a list of descriptions (String) given a list of parameters (integer or mnemonic).

Affects: none

Exceptions: none

  getParmFormat 
getParmFormat ( self,  mnemonic )

getParmFormat returns format string from parcods.tab of given mnemonic.

Inputs: mnemonic: the cedar mnemonic (string or integer)

Returns: format string from parcods.tab of given mnemonic

Affects: none

Exceptions: If mnemonic not found.

  getParmMnemonic 
getParmMnemonic ( self,  code )

getParmMnemonic returns a mnemonic (String) given a parameter (integer or mnemonic).

Inputs: a parameter: integer, an integer in string form, or a mnemonic string

Returns: a mnemonic string. If integer not found, returns integer in string form.

Affects: none

Exceptions: none

  getParmMnemonicList 
getParmMnemonicList ( self,  codeList )

getParmMnemonicList returns a list of upper case mnemonics (String) given a list of cedar codes (integer, integer as string, or mnemonic string).

Inputs: a list of cedar codes (integer, integer as string, or mnemonic string)

Returns: a list of upper case mnemonics (String) given a list of cedar codes (integer). If illegal value, returns str(code) for that item

Affects: none

Exceptions: none

  getParmScaleFactor 
getParmScaleFactor ( self,  mnemonic )

getParmScaleFactor returns scale factor as double of given mnemonic.

Inputs: mnemonic: the cedar mnemonic (string or integer)

Returns: scale factor as double of given mnemonic

Affects: none

Exceptions: If mnemonic not found.

  getParmType 
getParmType ( self,  mnemonic )

getParmType returns 1 if mnemonic is a standard parameter, 0 if an error parameter, or -1 if not found.

Inputs: mnemonic: the cedar mnemonic (string or integer in string form)

Returns: 1 if mnemonic is a standard parameter, 0 if an error parameter, or -1 if not found

Affects: none

Exceptions: If non-string passed in.

  getParmUnits 
getParmUnits ( self,  parm )

getParmUnits returns units (String) given a parameter (integer or mnemonic).

Inputs: a parameter (integer or mnemonic)

Returns: units (String)

Affects: none

Exceptions: none

  getSimpleParmDescription 
getSimpleParmDescription ( self,  parm )

getSimpleParmDescription returns a description without units or links (String) given a parameter (integer or mnemonic).

Inputs: a parameter (integer or mnemonic)

Returns: a description string without units or links

Affects: none

Exceptions: none

  getStdExpression 
getStdExpression ( self,  expressionStr )

getStdExpression returns an expression in standard form (upper case mnemonic, all else lower case).

Inputs: expressionStr - a string containing a valid python logical expression with cedar mnemonics as variables. Expression can contain any python logical operator (and, or, not, ==, <, >, <=, >=, !=), any operator, any number, and valid python math function, and any variable that is a valid cedar mnemonic. A substring is assumed to be a cedar mnemonic if it begins with a letter, contains only alphanumerics, period, plus, or underscore, and is not immediately followed by a open parenthesis. Each potential cedar mnemonic is verified, and an exception is thrown if it is not valid.

Returns: an expression (string) in standard form (upper case mnemonic, all else lower case).

Affects: None

Exceptions: Error thrown if any non-valid mnemonic found.

Exceptions   
'The expression ' + expressionStr + ' contains an illegal mnemonic: ' + thisMnemonic
  hasAddIncrement 
hasAddIncrement ( self,  parm )

hasAddIncrement returns True if parm has additional increment parameter, False otherwise

Inputs: a parameter (integer or mnemonic)

Returns: True if parm has additional increment parameter, False otherwise

Affects: none

Exceptions: none

  hasHtmlDesc 
hasHtmlDesc ( self,  parm )

hasHtmlDesc returns 1 if that parameter has a html description in parmDesc.html.

Inputs: a Madrigal mnemonic (string) or parameter

Returns: 1 if that parameter has a html description in parmDesc.html, 0 if not

Affects: none

Exceptions: none

  isAddIncrement 
isAddIncrement ( self,  parm )

isAddIncrement returns True if parm is an additional increment parameter, False otherwise

Inputs: a parameter (integer or mnemonic)

Returns: True if parm is an additional increment parameter, False otherwise

Affects: none

Exceptions: none

  isError 
isError ( self,  parm )

isError returns True if parm is an error parameter, False otherwise

Inputs: a parameter (integer or mnemonic)

Returns: True if parm is an error parameter, False otherwise

Affects: none

Exceptions: none

  normalizeParmList 
normalizeParmList ( self,  parmList )

normalizeParmList returns an ordered list of parameters with all mnemonics changed to integers.

Inputs: parmList - the list of parameters (integers or mnemonics) to convert

Returns: a new parmList that is ordered (negitive values are placed directly after the same positive values) and all parameters are converted to integers

Affects: None

Exceptions: none

  orderParms 
orderParms ( self,  parmList )

orderParms sorts mnemonic parameters based on order in parcods.tab file.

Error parameters directly follow standard parameter.


Table of Contents

This document was automatically generated on Thu Oct 20 16:51:50 2011 by HappyDoc version r1_5