MadrigalInstrumentParameters is an object that provides access to the metadata file that summarizes the parameters associated with each instrument.
This object provides access to all Madrigal instrument parameter information in the metadata file instParmTab.txt.
The metadata file instParmTab.txt lists, for any given instrument, all the measured parameters found in all the
data files in the database associated with that instrument.
This class also contains a method to rebuild the table instParmTab.txt by examining every data file in the database.
This is presumably a slow process and should be done in the background.
Usage example:
import madrigal.metadata
import madrigal.admin
try:
test = madrigal.metadata.MadrigalInstrumentParameters()
print test.getParameters(30)
except madrigal.admin.MadrigalError, e:
print e.getExceptionStr()
Non-standard Python modules used:
None
MadrigalError exception thrown if:
MadrigalMetadata fails to open or parse metadata file
Change history:
Written by Bill Rideout Jul. 17, 2002
Methods
|
|
__init__
getParameters
rebuildInstParmTable
|
|
__init__
|
__init__ (
self,
madDB=None,
initFile=None,
)
__init__ initializes MadrigalInstrumentParameters by reading from instParmTab.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()/instParmTab.txt.
Returns: void
Affects: Initializes all the class member variables.
Exceptions: MadrigalError thrown by MadrigalMetadata if file not opened or parsed successfully.
Note that the instParmTab.txt file was new with the release of the madrigal python api, and this
function will throw an error if file not there.
|
|
getParameters
|
getParameters ( self, kinst )
getParameters returns a list of parameters in mnemonic form (strings or unknown integers as strings) that matches kinst argument, or None if not found or blank.
Inputs: kinst integer to get parameters. If 0, get parameters from all instruments.
Returns: a list of mnemonic strings or unknown integer strings, or None if kinst not found or blank.
Affects: None
Exceptions: if error in metadata file
Exceptions
|
|
madrigal.admin.MadrigalError('Error in instTab.txt parsing metadata row: ' + str( inst ), traceback.format_exception(sys.exc_info() [ 0 ], sys.exc_info() [ 1 ], sys.exc_info() [ 2 ] ) )
|
|
|
rebuildInstParmTable
|
rebuildInstParmTable ( self, completeRebuildFlag=0 )
rebuildInstParmTable rebuilds the instParmTab.txt metadata file.
The table instParmTab.txt is a listing of every measured parameter found in any data file for a given
instrument. It now will also import data from other Madrigal sites instParmTab.txt files.
Since these files are constantly updated, this table needs to be updated on a regular
basis. This methods works in one of two ways, depending on the value of completeRebuildFlag and whether
a file called instParmLastUpdate.txt exists in the metadata directory.
If completeRebuildFlag = 1 or instParmLastUpdate.txt does not exist, the method rebuildInstParmTable
loops through each instrument in the instTab.txt. For each
instrument, it loops through every data file associated with that instrument. For every data file, it
gets the list of parameters in that file, and adds them to the list for that instrument if they are unique.
Since this process involves every file in the database, it may take a great deal of time and should
be run in the background.
If completeRebuildFlag = 0 and instParmLastUpdate.txt does exist, the method rebuildInstParmTable
first stores all the existing parameters from the instParmTab.txt. It reads the date of the last update
from instParmLastUpdate.txt, and only reads data files newer than that date that are associated with
each instrument. For every new data file, it gets the list of parameters in that file, and adds
them to the list for that instrument if they are unique. This makes rebuildInstParmTable faster,
but possibly keeps invalid parameters if experiments are ever deleted.
Finally, the instParmTab.txt file of every other site is obtained via getMetadata, and those parameters are
also added.
Inputs: completeRebuildFlag: if 0 (the default), only add parameters from new files, where new means
newer than the date in the instParmLastUpdate.txt file (stored as a float). If 1, rebuild the table completely. This will
eliminate any parameters no longer found in files, but will take longer. If no instParmLastUpdate.txt
file is found, the table is always rebuilt completely.
Returns: None.
Affects: Writes file instParmTab.txt in metadata directory
Exceptions: If unable to write instParmTab.txt file or the instParmLastUpdate.txt file.
Exceptions
|
|
madrigal.admin.MadrigalError( 'No data found for: ' + str( filename ), None )
madrigal.admin.MadrigalError( 'Unable to write: ' + self.__madDB.getMetadataDir() + '/instParmLastUpdate.txt', None )
madrigal.admin.MadrigalError( 'Unable to write: ' + str( filename ), None )
|
|
|