Table of Contents

Class: MadrigalMetaFile metadata.py

MadrigalMetaFile is an object that provides access to Madrigal file info from the metadata.

This object provides access to all Madrigal experiment information in the metadata file fileTab.txt.

Usage example:

        import madrigal.metadata

        import madrigal.admin

        try:

            test = madrigal.metadata.MadrigalMetaFile()

            print test.getFileCount()

        except madrigal.admin.MadrigalError, e:

            print e.getExceptionStr()

Non-standard Python modules used: None

MadrigalError exception thrown if:

  1. MadrigalMetadata fails to open or parse metadata file

  2. Columns expected to be ints or floats cannot be converted

Change history:

Written by Bill Rideout May. 7, 2002

Methods   
__init__
__str__
deleteRowByFilename
getAccessByPosition
getAnalystByFilename
getAnalystByPosition
getAnalystEmailByFilename
getAnalystEmailByPosition
getCategoryByFilename
getCategoryByPosition
getExpIdByFilename
getExpIdByPosition
getFileCount
getFilenameByPosition
getHasCatalogByFilename
getHasCatalogByPosition
getHasHeaderByFilename
getHasHeaderByPosition
getKindatByFilename
getKindatByPosition
getLine
getMetadataSummaryByFilename
getStatusByFilename
getStatusByPosition
setAccess
setAccessByPosition
setAnalystByPosition
setAnalystEmailByPosition
setCategoryByPosition
setExpIdByPosition
setHasCatalogByPosition
setHasHeaderByPosition
setKindatByPosition
  __init__ 
__init__ (
        self,
        madDB=None,
        initFile=None,
        )

__init__ initializes MadrigalMetaFile by reading from fileTab.txt (or initFile).

Inputs: Existing MadrigalDB object, by default = None.

String representing the full path to the metadata file. Default is None, in which case file read is MadrigalDB.getMetadataDir()/fileTab.txt.

Returns: void

Affects: Initializes all the class member variables.

Exceptions: MadrigalError thrown by MadrigalMetadata if file not opened or parsed successfully.

Exceptions   
madrigal.admin.MadrigalError( 'Error in count of first row of ' + str( self.__filename ), None )
  __str__ 
__str__ ( self )

return possibly modified file as a string in same format as writeMetadata

  deleteRowByFilename 
deleteRowByFilename ( self,  filename )

deleteRowByFilename deletes a row with a given filename.

Inputs: filename - name of file to search for.

Returns: None.

Affects: Removes item from self.__fileList if filename found

Exceptions: Thrown if filename not found.

Exceptions   
madrigal.admin.MadrigalError( 'Could not delete file ' + filename + ' from ' + self.__filename, None )
  getAccessByPosition 
getAccessByPosition ( self,  position=0 )

getAccessByPosition returns the access (0=public, 1=private) of the file at given position.

Inputs: position of file in list (first position is zero). Defaults to first.

Returns: the access level (0=public, 1=private) of the file at given position as an integer. Returns None if position >= number of experiments.

Affects: None

Exceptions: Thrown if access column cannot be parsed into an integer

Exceptions   
madrigal.admin.MadrigalError('Error in fileTab.txt parsing metadata row: ' + str( position ), traceback.format_exception(sys.exc_info() [ 0 ], sys.exc_info() [ 1 ], sys.exc_info() [ 2 ] ) )
  getAnalystByFilename 
getAnalystByFilename ( self,  filename )

getAnalystByFilename returns file analyst name if there, None otherwise.

Inputs: filename - name of file to search for.

Returns: file analyst name if there, None otherwise. Since not all fileTab.txt files may have this column, returns None if the column does not exist.

Affects: None

Exceptions: None

  getAnalystByPosition 
getAnalystByPosition ( self,  position=0 )

getAnalystByPosition returns file analyst name if there, None otherwise.

Inputs: position of file in list (first position is zero). Defaults to first.

Returns: file analyst name if there, None otherwise. Since not all fileTab.txt files may have this column, returns None if the column does not exist. Returns None if position >= number of experiments.

Affects: None

Exceptions: None

  getAnalystEmailByFilename 
getAnalystEmailByFilename ( self,  filename )

getAnalystEmailByFilename returns file analyst email if there, None otherwise.

Inputs: filename - name of file to search for.

Returns: file analyst email if there, None otherwise. Since not all fileTab.txt files may have this column, returns None if the column does not exist.

Affects: None

Exceptions: None

  getAnalystEmailByPosition 
getAnalystEmailByPosition ( self,  position=0 )

getAnalystEmailByPosition returns file analyst email if there, None otherwise.

Inputs: position of file in list (first position is zero). Defaults to first.

Returns: file analyst email if there, None otherwise. Since not all fileTab.txt files may have this column, returns None if the column does not exist. Returns None if position >= number of experiments.

Affects: None

Exceptions: None

  getCategoryByFilename 
getCategoryByFilename ( self,  filename )

getCategoryByFilename returns the category (eg., 1=default, 2=variant, 3=history, 4=real-time) of the file with the given filename.

Inputs: filename - name of file to search for.

Returns: the category (eg., 1=default, 2=variant, 3=history, 4=real-time) of the first row found with the given filename. Since filename may not be unique (although it usually is), the first match found is used. If no matches found, returns None.

Affects: None

Exceptions: Thrown if category column cannot be parsed into an integer

Exceptions   
madrigal.admin.MadrigalError('Error in fileTab.txt parsing metadata row: ' + str( position ), traceback.format_exception(sys.exc_info() [ 0 ], sys.exc_info() [ 1 ], sys.exc_info() [ 2 ] ) )
  getCategoryByPosition 
getCategoryByPosition ( self,  position=0 )

getCategoryByPosition returns the category (eg., 1=default, 2=variant, 3=history, 4=real-time) of the file at given position.

Inputs: position of file in list (first position is zero). Defaults to first.

Returns: the category (eg., 1=default, 2=variant, 3=history, 4=real-time) of the file at given position as an integer. Returns None if position >= number of experiments.

Affects: None

Exceptions: Thrown if category column cannot be parsed into an integer

Exceptions   
madrigal.admin.MadrigalError('Error in fileTab.txt parsing metadata row: ' + str( position ), traceback.format_exception(sys.exc_info() [ 0 ], sys.exc_info() [ 1 ], sys.exc_info() [ 2 ] ) )
  getExpIdByFilename 
getExpIdByFilename ( self,  filename )

getExpIdByFilename returns the first experiment id (integer) with the given filename.

Inputs: filename - name of file to search for.

Returns: the experiment id (integer) of the first row found with the given filename. Since filename may not be unique (although it usually is), the first match found is used. If no matches found, returns None.

Affects: None

Exceptions: Thrown if exp id cannot be parsed into an integer

Exceptions   
madrigal.admin.MadrigalError('Error in fileTab.txt parsing metadata row: ' + str( position ), traceback.format_exception(sys.exc_info() [ 0 ], sys.exc_info() [ 1 ], sys.exc_info() [ 2 ] ) )
  getExpIdByPosition 
getExpIdByPosition ( self,  position=0 )

getExpIdByPosition returns the experiment id (integer) of the file at given position.

Inputs: position of file in list (first position is zero). Defaults to first.

Returns: the experiment id (integer) of the file at given position as an integer. Returns None if position >= number of experiments.

Affects: None

Exceptions: Thrown if kinst exp id cannot be parsed into an integer

Exceptions   
madrigal.admin.MadrigalError('Error in fileTab.txt parsing metadata row: ' + str( position ), traceback.format_exception(sys.exc_info() [ 0 ], sys.exc_info() [ 1 ], sys.exc_info() [ 2 ] ) )
  getFileCount 
getFileCount ( self )

getFileCount returns the number of files (rows) in the metadata file.

Inputs: None

Returns: the number of files (rows) in the metadata file.

Affects: None

Exceptions: None

  getFilenameByPosition 
getFilenameByPosition ( self,  position=0 )

getFilenameByPosition returns the filename of the file at given position.

Inputs: position of file in list (first position is zero). Defaults to first.

Returns: the filename of the file at given position as a string. Returns None if position >= number of experiments.

Affects: None

Exceptions: None

  getHasCatalogByFilename 
getHasCatalogByFilename ( self,  filename )

getHasCatalogByFilename returns true if the file with the given name has any catalog records, False otherwise.

Inputs: filename - name of file to search for.

Returns: true if the file with the given name has any catalog records, False otherwise. Returns none if name not found

Affects: None

Exceptions: None.

  getHasCatalogByPosition 
getHasCatalogByPosition ( self,  position=0 )

getHasCatalogByPosition returns True if the file at given position has any catalog records, False otherwise.

Inputs: position of file in list (first position is zero). Defaults to first.

Returns: True if the file at given position has any catalog records, False otherwise Returns None if position >= number of experiments.

Affects: None

Exceptions: None

  getHasHeaderByFilename 
getHasHeaderByFilename ( self,  filename )

getHasHeaderByFilename returns true if the file with the given name has any header records, False otherwise.

Inputs: filename - name of file to search for.

Returns: true if the file with the given name has any header records, False otherwise. Returns none if name not found

Affects: None

Exceptions: Thrown if filename not found.

  getHasHeaderByPosition 
getHasHeaderByPosition ( self,  position=0 )

getHasHeaderByPosition returns True if the file at given position has any header records, False otherwise.

Inputs: position of file in list (first position is zero). Defaults to first.

Returns: True if the file at given position has any header records, False otherwise Returns None if position >= number of experiments.

Affects: None

Exceptions: None

  getKindatByFilename 
getKindatByFilename ( self,  filename )

getKindatByFilename returns the first kindat (integer) with the given filename.

Inputs: filename - name of file to search for.

Returns: the kindat (integer) of the first row found with the given filename. Since filename may not be unique (although it usually is), the first match found is used. If no matches found, returns None.

Affects: None

Exceptions: Thrown if kindat cannot be parsed into an integer

Exceptions   
madrigal.admin.MadrigalError('Error in fileTab.txt parsing metadata row: ' + str( position ), traceback.format_exception(sys.exc_info() [ 0 ], sys.exc_info() [ 1 ], sys.exc_info() [ 2 ] ) )
  getKindatByPosition 
getKindatByPosition ( self,  position=0 )

getKindatByPosition returns the kindat (kind of data code) of the file at given position.

Inputs: position of file in list (first position is zero). Defaults to first.

Returns: the kinst (kind of instrument code) of the file at given position as an integer. Returns None if position >= number of experiments.

Affects: None

Exceptions: Thrown if kinst column cannot be parsed into an integer

Exceptions   
madrigal.admin.MadrigalError('Error in fileTab.txt parsing metadata row: ' + str( position ), traceback.format_exception(sys.exc_info() [ 0 ], sys.exc_info() [ 1 ], sys.exc_info() [ 2 ] ) )
  getLine 
getLine ( self,  position )

getLine returns the line at a given position. Returns None if position > number of lines.

Inputs: position - position in file. First line = 0

  getMetadataSummaryByFilename 
getMetadataSummaryByFilename (
        self,
        filename,
        madExpObj=None,
        madInstObj=None,
        madKindatObj=None,
        )

getMetadataSummaryByFilename returns a string summarizing the file's metadata given a filename.

Inputs: filename - name of file to search for.

The next three inputs are other metadata objects. If these objects already exist, performance will be improved by passing them in rather than recreating them. If they do not exist, they will be created:

madExpObj - a MadrigalExperiment object to get experiment metadata from. If None (the default), a new MadrigalExperiment object is created.

madInstObj - a MadrigalInstrument object to get experiment metadata from. If None (the default), a new MadrigalInstrument object is created.

madKindatObj - a MadrigalKindat object to get experiment metadata from. If None (the default), a new MadrigalKindat object is created.

Returns: A string summarizing the metadata about the file. The format is:

                Start Date and Time: 01/06/1997  14:07  
                End Date and Time:   01/10/1997  23:45
                Instrument: Millstone Hill Incoherent Scatter Radar
                Experiment name: World Day - Mesosphere/Lower-Thermosphere Coupling Study
                Kind of data: INSCAL (8.0) Basic Derived Parameters

Affects: None

Exceptions: Thrown if any parsing error in metadata.

  getStatusByFilename 
getStatusByFilename ( self,  filename )

getStatusByFilename returns the status description of the file with the given name.

Inputs: filename - name of file to search for.

Returns: the status description of the file with the given name. Returns none if name not found

Affects: None

Exceptions: Thrown if filename not found.

  getStatusByPosition 
getStatusByPosition ( self,  position=0 )

getStatusByPosition returns the status description of the file at given position.

Inputs: position of file in list (first position is zero). Defaults to first.

Returns: the status description of the file at given position as a string. Returns None if position >= number of experiments.

Affects: None

Exceptions: None

  setAccess 
setAccess ( self,  accessType )

setAccess sets the access column to all 0's (public) or all 1's (private).

Inputs: accessType - either 0 to set to public access, or 1 to set to private access.

Returns: None.

Affects: Overwrite fileTab.txt file with access column set to all 0's (public) or all 1's (private).

Exceptions: Thrown if file cannot be written, if accessType is not 0 or 1

Exceptions   
madrigal.admin.MadrigalError( 'MadrigalMetaFile.setAccess called with arg = ' + str( accessType ) + ', must be either 0 or 1', None )
  setAccessByPosition 
setAccessByPosition (
        self,
        position,
        access,
        )

setAccessByPosition sets the value of access for the file at the given position.

Inputs:

position - position of file in list (first position is zero).

access - 0 of False for public, 1 or True for private

Returns: None.

Affects: None

Exceptions: If position beyond length.

Exceptions   
ValueError, 'Illegal value for access in setAccessByPosition: %s' %(str( access ) )
ValueError, 'setAccessByPosition called for position %i beyond length %i' %(position, len( self.__fileList ) )
  setAnalystByPosition 
setAnalystByPosition (
        self,
        position,
        analyst,
        )

setAnalystByPosition sets the file analyst name for the given position

Inputs:

position - position of file in list (first position is zero).

analyst - name of file analyst

Returns: None.

Affects: None

Exceptions: If position beyond length.

Exceptions   
ValueError, 'setAnalystByPosition called for position %i beyond length %i' %(position, len( self.__fileList ) )
madrigal.admin.MadrigalError('Error in setAnalystByPosition with args %s: %s' %( str( position ), analyst ), [traceback.format_exc() ] )
  setAnalystEmailByPosition 
setAnalystEmailByPosition (
        self,
        position,
        analystEmail,
        )

setAnalystEmailByPosition sets the file analyst email for the given position

Inputs:

position - position of file in list (first position is zero).

analystEmail - email of file analyst

Returns: None.

Affects: None

Exceptions: If position beyond length.

Exceptions   
ValueError, 'setAnalystEmailByPosition called for position %i beyond length %i' %(position, len( self.__fileList ) )
madrigal.admin.MadrigalError('Error in setAnalystEmailByPosition with args %s: %s' %(str( position, analystEmail ), [traceback.format_exc() ] ) )
  setCategoryByPosition 
setCategoryByPosition (
        self,
        position,
        category,
        )

setCategoryByPosition sets the value of category for the file at the given position.

Inputs:

position - position of file in list (first position is zero).

category - 1=default, 2=variant, 3=history, 4=real-time

Returns: None.

Affects: None

Exceptions: If position beyond length.

Exceptions   
ValueError, 'Illegal value for category in setCategoryByPosition: %s' %(str( category ) )
ValueError, 'setCategoryByPosition called for position %i beyond length %i' %(position, len( self.__fileList ) )
  setExpIdByPosition 
setExpIdByPosition (
        self,
        position,
        expId,
        )

setExpIdByPosition sets the experiment id of the file at given position.

Inputs:

position - position of file in list (first position is zero).

expId - the new experiment id to use

Returns: None.

Affects: sets the experiment id of the file at given position

Exceptions: MadrigalError if any item in row cannot be cast to correct format, or position not found.

Exceptions   
madrigal.admin.MadrigalError('Error in setExpIdByPosition with args %s: %s' %(str( position ), str( expId ) ), traceback.format_exception(sys.exc_info() [ 0 ], sys.exc_info() [ 1 ], sys.exc_info() [ 2 ] ) )
  setHasCatalogByPosition 
setHasCatalogByPosition (
        self,
        position,
        hasCatalog,
        )

setHasCatalogByPosition sets the value of hasCatalog for the file at the given position.

Inputs:

position - position of file in list (first position is zero).

hasCatalog - 1 or True for yes, 0 or False for no

Returns: None.

Affects: None

Exceptions: If position beyond length.

Exceptions   
ValueError, 'Illegal value for hasCatalog in setHasCatalogByPosition: %s' %(str( hasCatalog ) )
ValueError, 'setHasCatalogByPosition called for position %i beyond length %i' %(position, len( self.__fileList ) )
  setHasHeaderByPosition 
setHasHeaderByPosition (
        self,
        position,
        hasHeader,
        )

setHasHeaderByPosition sets the value of hasHeader for the file at the given position.

Inputs:

position - position of file in list (first position is zero).

hasHeader - 1 or True for yes, 0 or False for no

Returns: None.

Affects: None

Exceptions: If position beyond length.

Exceptions   
ValueError, 'Illegal value for hasHeader in setHasHeaderByPosition: %s' %(str( hasHeader ) )
ValueError, 'setHasHeaderByPosition called for position %i beyond length %i' %(position, len( self.__fileList ) )
  setKindatByPosition 
setKindatByPosition (
        self,
        position,
        kindat,
        )

setKindatByPosition sets the value of kindat for the file at the given position.

Inputs:

position - position of file in list (first position is zero).

kindat - integer kindat value

Returns: None.

Affects: None

Exceptions: If position beyond length.

Exceptions   
ValueError, 'setKindatByPosition called for position %i beyond length %i' %(position, len( self.__fileList ) )
  setStatusByPosition 
setStatusByPosition (
        self,
        position,
        status,
        )

setStatusByPosition sets the value of status string for the file at the given position.

Inputs:

position - position of file in list (first position is zero).

status - string describing status

Returns: None.

Affects: None

Exceptions: If position beyond length.

Exceptions   
ValueError, 'Illegal value for status in setStatusByPosition: %s' %(str( status ) )
ValueError, 'setStatusByPosition called for position %i beyond length %i' %(position, len( self.__fileList ) )
ValueError, 'status string in fileTab.txt cannot contain a comma: <%s> is illegal' %( status )
  writeMetadata 
writeMetadata ( self,  newFullPath=None )

writeMetadata writes a new version of the fileTab.txt file.

Inputs: newFullPath: a new path to write the fileTab.txt file to, if not the same as the original metadata file opened. Defaults to None, which overwrites metadata file that was read from.

Returns: None.

Affects: Writes updated version of metadata file.

Exceptions: If unable to write file

Exceptions   
madrigal.admin.MadrigalError("Unable to write metadata file " + str( newFullPath ), traceback.format_exception(sys.exc_info() [ 0 ], sys.exc_info() [ 1 ], sys.exc_info() [ 2 ] ) )

Table of Contents

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