def get_signature(self, spectrumID): '''Returns a spectrum with some additional metadata. Usage:: sig = aster.get_signature(spectrumID) Arguments: `spectrumID` (int): The **SpectrumID** value for the desired spectrum from the **Spectra** table in the database. Returns: `sig` (:class:`~spectral.database.aster.Signature`): An object with the following attributes: ============== ===== ======================================== Attribute Type Description ============== ===== ======================================== measurement_id int SpectrumID value from Spectra table sample_name str **Sample** from the **Samples** table sample_id int **SampleID** from the **Samples** table x list list of band center wavelengths y list list of spectrum values for each band ============== ===== ======================================== ''' import array # Retrieve spectrum from Spectra table query = '''SELECT Samples.Name, Samples.SampleID, XData, YData FROM Samples, Spectra WHERE Samples.SampleID = Spectra.SampleID AND Spectra.SpectrumID = ?''' result = self.cursor.execute(query, (spectrumID, )) results = result.fetchall() if len(results) < 1: raise "Measurement record not found" sig = Signature() sig.measurement_id = spectrumID sig.sample_name = results[0][0] sig.sample_id = results[0][1] x = array.array(arraytypecode) frombytes(x, results[0][2]) sig.x = list(x) y = array.array(arraytypecode) frombytes(y, results[0][3]) sig.y = list(y) return sig
def get_spectrum(self, spectrumID): '''Returns a spectrum from the database. Usage: (x, y) = aster.get_spectrum(spectrumID) Arguments: `spectrumID` (int): The **SpectrumID** value for the desired spectrum from the **Spectra** table in the database. Returns: `x` (list): Band centers for the spectrum. `y` (list): Spectrum data values for each band. Returns a pair of vectors containing the wavelengths and measured values values of a measurment. For additional metadata, call "get_signature" instead. ''' import array query = '''SELECT XData, YData FROM Spectra WHERE SpectrumID = ?''' result = self.cursor.execute(query, (spectrumID, )) rows = result.fetchall() if len(rows) < 1: raise 'Measurement record not found' x = array.array(arraytypecode) frombytes(x, rows[0][0]) y = array.array(arraytypecode) frombytes(y, rows[0][1]) return (list(x), list(y))
def array_from_blob(blob): a = array.array(arraytypecode) frombytes(a, blob) return a