MadrigalInstrumentKindats is an object that provides access to the metadata file that summarizes the kindat codes associated with each instrument.
This object provides access to all Madrigal instrument kindat information in the metadata file instKindatTab.txt.
The metadata file instKindatTab.txt lists, for any given instrument, all the kindat codes found in all the
data files in the database associated with that instrument.
This class also contains a method to rebuild the table instKindatTab.txt by examining all the metadata in the database.
This is presumably a somewhat slow process and should be done in the background.
Usage example:
import madrigal.metadata
import madrigal.admin
try:
test = madrigal.metadata.MadrigalInstrumentKindats()
print test.getKindatListForInstruments([20,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 Aug. 15, 2002
Methods
|
|
__init__
getKindatListForInstruments
rebuildInstKindatTable
|
|
__init__
|
__init__ (
self,
madDB=None,
initFile=None,
)
__init__ initializes MadrigalInstrumentKindats by reading from instKindatTab.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()/instKindatTab.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 instKindatTab.txt file was new with the release of the madrigal python api, and this
function will throw an error if file not there.
|
|
getKindatListForInstruments
|
getKindatListForInstruments ( self, kinstList )
getKindatListForInstruments returns a list of kindat codes as integers for the given instrument list.
Inputs: kinstList: a list of kinst integers to get associated kindat list. Also accepts a single integer.
Returns: a list of kindat codes as integers associated with the given instrument list.
Affects: None
Exceptions: if error in metadata file
Exceptions
|
|
madrigal.admin.MadrigalError('Error in instKindatTab.txt parsing metadata row: ' + str( inst ), traceback.format_exception(sys.exc_info() [ 0 ], sys.exc_info() [ 1 ], sys.exc_info() [ 2 ] ) )
|
|
|
rebuildInstKindatTable
|
rebuildInstKindatTable ( self )
rebuildInstKindatTable rebuilds the instKindatTab.txt metadata file.
The table instKindatTab.txt is a listing of every kindat found for a given
instrument. Since these files are constantly updated, this table needs to be updated on a regular
basis. Data from other Madrigal sites is also imported into this table.
How it works: For each instrument in instTab.txt, this method first creates a list
of all the experiments that used that instrument. It then loops
through the file table. For each file listing, if the file is the
default one, and its experiment id is in the list of experiments just
created, the kindat is added to the list if its not already there.
Data from all other Madrigal sites is then added via getMetadata. It then writes
the metadata file in the form: 10, 1001 1002 1003, where the first column in the
instrument code and the second column is a space delimited list of kindat codes.
Inputs: None.
Returns: None.
Affects: Writes file instKindatTab.txt in metadata directory
Exceptions: If unable to write instKindatTab.txt file.
Exceptions
|
|
madrigal.admin.MadrigalError( 'Unable to write: ' + str( filename ), None )
|
|
|