Table of Contents

Class: MadrigalFile data.py

MadrigalFile is an object that provides access to information in a single Madrigal File.

This object provides access to a single Madrigal file.

Usage example:

        import os, madrigal.data

        filepath = os.environ.get('MAD' + 'ROOT') + '/experiments/1998/mlh/20jan98/mil980120g.003'

        test = madrigal.data.MadrigalFile(filepath)

        print test.toString()

        print test.getMaxValidAltitude()

Non-standard Python modules used:

None

MadrigalError exception thrown if:

  1. No data records found in file

Notes: This class depends on the python extension class madrigal._Madrec, which in turn depends on the madrigal C API as implemented in libmadrec.so. When Madrigal is installed, this file is put in $madroot/lib. If madroot is changed, this file can still be located by python by setting the LD_LIBRARY_PATH to the new location of libmadrec.so.

Change history:

Written by Bill Rideout Nov. 26, 2001

Modified by Bill Rideout June 4, 2002 to use summary information in header records if available.

Modified by Bill Rideout Jan 24, 2003 to use the high level maddata module.

Modified by Bill Rideout Jan 24, 2003 to use overview/[filename].summary file if available.

Modified by Bill Rideout Feb 15, 2005 to add more summary data.

Modified by Miguel Urco May 04, 2011 to handle hdf5 files.

Methods   
__getExistingSummary
__getLayoutDescription
__init__
__parseSummary
__setToOne
__str__
__writeSummary
_parseCachedIni
basicIsprint
exportToHdf
getCachedHdf5
getCatalogHeaderStr
getEarliestTime
getKindatList
getKinstList
getKinstListStr
getLatestTime
getMaxLatitude
getMaxLongitude
getMaxPulseLength
getMaxValidAltitude
getMeasDervBothParmLists
getMeasured1dParmList
getMeasured2dParmList
getMeasuredParmList
getMinLatitude
getMinLongitude
getMinPulseLength
getMinValidAltitude
getMissingParmList
  __getExistingSummary 
__getExistingSummary ( self )

__getExistingSummary returns a list of strings summarizing a file via header/cat records or overview file if possible.

If all the required information is not found in the first two records of the file, the file overview/[filename].summary is used. If that fails, returns None.

Inputs: None

Returns: A list of strings summarizing the MadrigalFile. These strings are: kinstList: a string of comma separated integers kindatList: a string of comma separated integers parameterList: a string of comma separated integers missingList: a string of comma separated integers maxPulseLen: a single integer string minPulseLen: a single integer string maxValidAltitude: a single integer string minValidAltitude: a single integer string maxLatitude: a single integer string minLatitude: a single integer string maxLongitude: a single integer string minLongitude: a single integer string earliestTime: a string of six comma sepatated integers: [year, month, day, hour, min, sec] latestTime: a string of six comma sepatated integers: [year, month, day, hour, min, sec] param1dList: a string of comma separated integers param2dList: a string of comma separated integers

If all required information not found in either source, returns None. The following items are not required, and default to missingVal or empty: minPulseLen, minValidAltitude, maxLatitude, minLatitude, maxLongitude, minLongitude, param1dList, param2dList

Affects: Nothing

Exceptions: None

  __getLayoutDescription 
__getLayoutDescription ( self,  format )

__getLayoutDescription returns a description of the layout selected.

Inputs: format: Alternates format available

Returns: LayoutDescription: A list of strings summarizing the Layout Description

Affects: Nothing

Exceptions: None

  __init__ 
__init__ (
        self,
        initFile,
        madDB=None,
        )

__init__ initializes MadrigalFile by finding all summary data.

Inputs: self, String representing the full path to the madrigal file.

Existing MadrigalDB object, by default = None.

Returns: void

Affects: Initializes self.__summary, which is a list of summary data about the file. The information is first searched for in the header records, and if not found, then the file overview/[filename].summary is used. If that also fails, the file is analyzed using _Madrec.getSummary, which will write its results to overview/[filename].summary. All public functions simply return this summarized data.

Exceptions: MadrigalError thrown if no data record in file.

  __parseSummary 
__parseSummary ( self,  summaryStr )

__parseSummary returns a list of strings summarizing a string if possible.

If all the required information is not found in the string, returns None.

Inputs: summaryStr read from header records or summary file.

Returns: A list of strings summarizing the MadrigalFile. These strings are: kinstList: a string of comma separated integers kindatList: a string of comma separated integers parameterList: a string of comma separated integers missingList: a string of comma separated integers maxPulseLen: a single integer string minPulseLen: a single integer string maxValidAltitude: a single integer string minValidAltitude: a single integer string maxLatitude: a single integer string minLatitude: a single integer string maxLongitude: a single integer string minLongitude: a single integer string earliestTime: a string of six comma sepatated integers: [year, month, day, hour, min, sec] latestTime: a string of six comma sepatated integers: [year, month, day, hour, min, sec] param1dList: a string of comma separated integers param2dList: a string of comma separated integers

If all required information not found in either source, returns None. The following items are not required, and default to missingVal or empty list: minPulseLen, minValidAltitude, maxLatitude, minLatitude, maxLongitude, minLongitude, param1dList, param2dList

Affects: Nothing

Exceptions: None

  __setToOne 
__setToOne ( self,  x )

Private function used to initialize a list to ones

  __str__ 
__str__ ( self )

  __writeSummary 
__writeSummary ( self )

__writeSummary writes a summary file to overview/[filename].summary.

Uses data from self.__summary.

Inputs: None.

Returns: None

Affects: writes a summary file to overview/[filename].summary

Exceptions: If file cannot be written

  _parseCachedIni 
_parseCachedIni (
        self,
        kinst,
        kindat,
        iniFile=None,
        )

_parseCachedIni parses an ini file for information needed to create cached files

Inputs:

kinst - the instrument kinst (integer)

kindat - the data kindat (integer)

iniFile - the ini file to use. If None, uses default ini file $MADROOT/cachedFiles.ini

Returns: a tuple with two items: 1. a list of extra parameters (string mnemonics) 2. a dictionary of alternate formats (see exportToHdf)

Algorithm:

  1. If iniFile == None and no default file, returns ([], {}) 2. Searches ini file for section [%i] % (kinst). If not found, returns ([], {}) 3. Searches right section for key %i_parms % (kindat). If not found, searches for default_parms. If not found, extra parameters are [] 4. Searches right section for key %i_formats % (kindat). If not found, searches for default_formats. If not found, alternate format dictionary is {}

  basicIsprint 
basicIsprint (
        self,
        output=None,
        parmLine=True,
        extraParameters=[],
        )

basicIsprint writes the file in isprint format, using all the parameters in the file, and the six time parameters year,month,day,hour,min,sec. No filtering used.

Inputs:

output - file to write isprint output too. If None (the default), write to stdout

parmLine - if True (the default), add text line with parameter names as first line. If False, no parameter line.

extraParameters - These parameters will be added to the output file if they are not already in the input file.

  exportToHdf 
exportToHdf (
        self,
        output=None,
        alternateFormatDict={},
        extraParameters=[],
        filter=None,
        showWarnings=False,
        )

exportToHdf will write the Cedar file self.__filename to a hdf5 export format. That hdf5 file will contain the alternate formats listed in alternateFormatDict. For now the available alternate formats are {'array':'range', }.

Inputs:

output - hdf5 file to write. If None (the default), write to self.__filename + hdf5

alternateFormatDict - For this dictionary, the keys are always a format name, such as array, and the values are whatever additional arguments might be required, such as range

Available alternate formats are:

Array: {'array':<independent parm>} where <independent parm> is independent parm such as range, gdalt, etc.

extraParameters - These parameters will be added to the output file if they are not already in the input file.

filter - Filter argument as in isprint command as string (eg, ti.500,2000). Just one filter allowed.

showWarnings - if True, print warnings about problems to stdout. If False (the default), do not

Affects: Nothing

Exceptions: Parameter required is not in the file nor can it be derived. No records selected with the filters above

Exceptions   
madrigal.admin.MadrigalError( 'The independent parameter required, %s, is not in the file nor can it be derived' % parmMnem.upper(), None )
madrigal.admin.MadrigalError( 'isprint error: ' + str( line ), None )
  getCachedHdf5 
getCachedHdf5 (
        self,
        iniFile=None,
        overwrite=False,
        showWarnings=False,
        )

getCachedHdf5 will get the full path to the cached version of the HDF5 file. It will create the file if it does not already exist.

Inputs: iniFile - ini file to use to create hdf5 with, if one needs to be created. If None, uses default ini file $MADROOT/cachedFiles.ini overwrite - if True, overwrite existing hdf5 file. If False (the default), use existing hdf5 file showWarnings - if True, print warnings about problems to stdout. If False (the default), do not Returns: full path to cached Hdf5 file

  getCatalogHeaderStr 
getCatalogHeaderStr ( self )

getCatalogHeaderStr returns a string formatted for printing containing all catalog and header records.

Input: None

Returns: a string formatted for printing containing all catalog and header records. Returns '' if no catalog or header records.

  getEarliestTime 
getEarliestTime ( self )

getEarliestTime returns a list of 6 numbers representing the earliest time in the file.

Inputs: self

Returns: a list of 6 numbers representing the earliest time in the file. The format is [Year, Month, Day, Hour, Minute, Second]

Affects: Nothing

Exceptions: None

  getKindatList 
getKindatList ( self )

getKindatList returns a list of integers of all kindat values in file.

Inputs: self

Returns: a list of integers of all kindat values in file.

Affects: Nothing

Exceptions: None

  getKinstList 
getKinstList ( self )

getKinstList returns a list of integers of all kinst values in file.

Inputs: self

Returns: a list of integers of all kinst values in file.

Affects: Nothing

Exceptions: None

  getKinstListStr 
getKinstListStr ( self )

getKinstListStr returns a comma-separated string with the names of kinst values in file.

Inputs: self

Returns: a comma-separated string with the names of kinst values in file.

Affects: Nothing

Exceptions: None

  getLatestTime 
getLatestTime ( self )

getLatestTime returns a list of 6 numbers representing the latest time in the file.

Inputs: self

Returns: a list of 6 numbers representing the latest time in the file. The format is [Year, Month, Day, Hour, Minute, Second]

Affects: Nothing

Exceptions: None

  getMaxLatitude 
getMaxLatitude ( self )

getMaxLatitude returns a double representing maximum latitude in degrees in file.

Inputs: self

Returns: a double representing maximum latitude in degrees in file.

Affects: Nothing

Exceptions: None

  getMaxLongitude 
getMaxLongitude ( self )

getMaxLongitude returns a double representing maximum longitude in degrees in file.

Inputs: self

Returns: a double representing maximum longitude in degrees in file.

Affects: Nothing

Exceptions: None

  getMaxPulseLength 
getMaxPulseLength ( self )

getMaxPulseLength returns a double representing maximum pulse length in microseconds in file.

Inputs: self

Returns: a double representing maximum pulse length in seconds in file.

Affects: Nothing

Exceptions: None

  getMaxValidAltitude 
getMaxValidAltitude ( self )

getMaxValidAltitude returns a double representing maximum valid altitude in km in file.

Inputs: self

Returns: a double representing maximum valid altitude in km in file.

Affects: Nothing

Exceptions: None

  getMeasDervBothParmLists 
getMeasDervBothParmLists (
        self,
        parmList,
        measParmList,
        derivedParmList,
        allParmList,
        sureParmList,
        )

getMeasDervBothParmLists sets up four lists: measured parms, derived parms, both, and sure parms given a parm list to verify.

Inputs: parmList: A list of parameters (integers or mnemonics to be considered)

measParmList: an empty python list. Will be filled with an list of all measured parameters (mnemonics) found in file when function returns.

derivedParmList: an empty python list. Will be filled with an list of all parameters (mnemonics) in parmList that can be derived from file when function returns.

allParmList: an empty python list. Will be filled with an list of all parameters in measParmList or derivedParmList when function returns.

sureParmList: an empty python list. Will be filled with an list of all parameters from the measured list that are never missing, and parameters that can be derived from those. These parameters can then be derived for every record (excluding the fact that the value of the parameter in the record may be "missing").

Returns: void (see Affects below)

Affects: adds items to measParmList, derivedParmList, and allParmList. All items will be mnemonics.

Exceptions: None

Usage example:

            import os, madrigal.data

            filepath = os.environ.get('MAD' + 'ROOT') + '/experiments/1998/mlh/20jan98/mil980120g.003'

            test = madrigal.data.MadrigalFile(filepath)

            measParmList = []

            derivedParmList = []

            allParmList = []

            sureParmList = []

            test.getMeasDervBothParmLists(madrigal.ui.web.MadrigalWebFormat().getFormat('Short'),
                                          measParmList,
                                          derivedParmList,
                                          allParmList,
                                          sureParmList)

            #print lists

            print 'Measured parms are: ' + str(measParmList)

            print 'Derived parms are: ' + str(derivedParmList)

            print 'All good parms are: ' + str(allParmList)

            print 'Parameters sure to exist are: ' + str(sureParmList)

  getMeasured1dParmList 
getMeasured1dParmList ( self )

getMeasured1dParmList returns a list of integers of all 1d parameters stored in file.

Inputs: self

Returns: a list of integers of all 1d parameters found in file.

Affects: Nothing

Exceptions: None

  getMeasured2dParmList 
getMeasured2dParmList ( self )

getMeasured2dParmList returns a list of integers of all 2d parameters stored in file.

Inputs: self

Returns: a list of integers of all 2d parameters found in file.

Affects: Nothing

Exceptions: None

  getMeasuredParmList 
getMeasuredParmList ( self )

getMeasuredParmList returns a list of integers of all parameters stored in file.

Inputs: self

Returns: a list of integers of all parameters found in file.

Affects: Nothing

Exceptions: None

  getMinLatitude 
getMinLatitude ( self )

getMinLatitude returns a double representing minimum latitude in degrees in file.

Inputs: self

Returns: a double representing minimum latitude in degrees in file.

Affects: Nothing

Exceptions: None

  getMinLongitude 
getMinLongitude ( self )

getMinLongitude returns a double representing minimum longitude in degrees in file.

Inputs: self

Returns: a double representing minimum longitude in degrees in file.

Affects: Nothing

Exceptions: None

  getMinPulseLength 
getMinPulseLength ( self )

getMinPulseLength returns a double representing minimum pulse length in microseconds in file.

Inputs: self

Returns: a double representing minimum pulse length in seconds in file.

Affects: Nothing

Exceptions: None

  getMinValidAltitude 
getMinValidAltitude ( self )

getMinValidAltitude returns a double representing minimum valid altitude in km in file.

Inputs: self

Returns: a double representing minimum valid altitude in km in file.

Affects: Nothing

Exceptions: None

  getMissingParmList 
getMissingParmList ( self )

getMissingParmList returns a list of integers, one for each parameters stored in file.

Inputs: self

Returns: a list of integers, one for each parameters stored in file. If 1, that parameter was found to missing from at least one record in the file. If -1, not missing in any data record.

Affects: Nothing

Exceptions: None

  toString 
toString ( self )

toString returns a simple string representation of a MadrigalFile object.

Inputs: None

Returns: String describing a simple representation of a MadrigalFile object.

Affects: Nothing

Exceptions: None


Table of Contents

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