|
6 | 6 |
|
7 | 7 | from spectral.utilities.python23 import IS_PYTHON3, tobytes, frombytes |
8 | 8 |
|
| 9 | +from .spectral_database import SpectralDatabase |
| 10 | + |
9 | 11 | if IS_PYTHON3: |
10 | 12 | readline = lambda fin: fin.readline() |
11 | 13 | open_file = lambda filename: open(filename, encoding='iso-8859-1') |
@@ -132,7 +134,7 @@ def read_aster_file(filename): |
132 | 134 | return s |
133 | 135 |
|
134 | 136 |
|
135 | | -class AsterDatabase: |
| 137 | +class AsterDatabase(SpectralDatabase): |
136 | 138 | '''A relational database to manage ASTER spectral library data.''' |
137 | 139 | schemas = table_schemas |
138 | 140 |
|
@@ -307,12 +309,6 @@ class Sig: |
307 | 309 |
|
308 | 310 | return sigs |
309 | 311 |
|
310 | | - def _connect(self, sqlite_filename): |
311 | | - '''Establishes a connection to the Specbase sqlite database.''' |
312 | | - import sqlite3 |
313 | | - self.db = sqlite3.connect(sqlite_filename) |
314 | | - self.cursor = self.db.cursor() |
315 | | - |
316 | 312 | def get_spectrum(self, spectrumID): |
317 | 313 | '''Returns a spectrum from the database. |
318 | 314 |
|
@@ -406,76 +402,6 @@ def get_signature(self, spectrumID): |
406 | 402 | sig.y = list(y) |
407 | 403 | return sig |
408 | 404 |
|
409 | | - def query(self, sql, args=None): |
410 | | - '''Returns the result of an arbitrary SQL statement. |
411 | | -
|
412 | | - Arguments: |
413 | | -
|
414 | | - `sql` (str): |
415 | | -
|
416 | | - An SQL statement to be passed to the database. Use "?" for |
417 | | - variables passed into the statement. |
418 | | -
|
419 | | - `args` (tuple): |
420 | | -
|
421 | | - Optional arguments which will replace the "?" placeholders in |
422 | | - the `sql` argument. |
423 | | -
|
424 | | - Returns: |
425 | | -
|
426 | | - An :class:`sqlite3.Cursor` object with the query results. |
427 | | -
|
428 | | - Example:: |
429 | | -
|
430 | | - >>> sql = r'SELECT SpectrumID, Name FROM Samples, Spectra ' + |
431 | | - ... 'WHERE Spectra.SampleID = Samples.SampleID ' + |
432 | | - ... 'AND Name LIKE "%grass%" AND MinWavelength < ?' |
433 | | - >>> args = (0.5,) |
434 | | - >>> cur = db.query(sql, args) |
435 | | - >>> for row in cur: |
436 | | - ... print row |
437 | | - ... |
438 | | - (356, u'dry grass') |
439 | | - (357, u'grass') |
440 | | - ''' |
441 | | - if args: |
442 | | - return self.cursor.execute(sql, args) |
443 | | - else: |
444 | | - return self.cursor.execute(sql) |
445 | | - |
446 | | - def print_query(self, sql, args=None): |
447 | | - '''Prints the text result of an arbitrary SQL statement. |
448 | | -
|
449 | | - Arguments: |
450 | | -
|
451 | | - `sql` (str): |
452 | | -
|
453 | | - An SQL statement to be passed to the database. Use "?" for |
454 | | - variables passed into the statement. |
455 | | -
|
456 | | - `args` (tuple): |
457 | | -
|
458 | | - Optional arguments which will replace the "?" placeholders in |
459 | | - the `sql` argument. |
460 | | -
|
461 | | - This function performs the same query function as |
462 | | - :meth:`spectral.database.Asterdatabase.query` except query results are |
463 | | - printed to **stdout** instead of returning a cursor object. |
464 | | -
|
465 | | - Example: |
466 | | -
|
467 | | - >>> sql = r'SELECT SpectrumID, Name FROM Samples, Spectra ' + |
468 | | - ... 'WHERE Spectra.SampleID = Samples.SampleID ' + |
469 | | - ... 'AND Name LIKE "%grass%" AND MinWavelength < ?' |
470 | | - >>> args = (0.5,) |
471 | | - >>> db.print_query(sql, args) |
472 | | - 356|dry grass |
473 | | - 357|grass |
474 | | - ''' |
475 | | - ret = self.query(sql, args) |
476 | | - for row in ret: |
477 | | - print("|".join([str(x) for x in row])) |
478 | | - |
479 | 405 | def create_envi_spectral_library(self, spectrumIDs, bandInfo): |
480 | 406 | '''Creates an ENVI-formatted spectral library for a list of spectra. |
481 | 407 |
|
|
0 commit comments