コード例 #1
0
    'band': 'WISE_W2',
    'magnitude': 12.990,
    'magnitude_error': 0.028,
    'telescope': 'WISE',
    'reference': 'Cutr12'
}, {
    'source': '2MASS J13571237+1428398',
    'band': 'WISE_W3',
    'magnitude': 12.476,
    'magnitude_error': 0.279,
    'telescope': 'WISE',
    'reference': 'Cutr12'
}, {
    'source': '2MASS J13571237+1428398',
    'band': 'WISE_W4',
    'magnitude': 9.560,
    'magnitude_error': None,
    'telescope': 'WISE',
    'reference': 'Cutr12'
}]
db.Photometry.insert().execute(phot_data)

# Checking object
_ = db.inventory('2MASS J13571237+1428398', pretty_print=True)

# Save single object
db.save_json('2MASS J13571237+1428398', 'data')

# Save entire database to directory 'data'
db.save_database('data')
コード例 #2
0
ファイル: bdnyc_example.py プロジェクト: zjzhang42/SIMPLE-db
                                'systems', 'telescopes', 'versions', 'instruments'],
              primary_table='sources',
              primary_table_key='id',
              foreign_key='source_id',
              column_type_overrides={'spectra.spectrum': types.TEXT(),
                                     'spectra.local_spectrum': types.TEXT()})

# Query similarly to SIMPLE
results = db.query(db.sources).limit(10).all()
for row in results: print(row)

# The spectra table contains columns of type SPECTRUM, the column_type_overrides allows us to work with them as text
for c in db.spectra.columns: print(c, c.type)
db.query(db.spectra).limit(10).all()

_ = db.inventory(11, pretty_print=True)

# Can output the full contents of BDNYC as json files
db.save_db('bdnyc')

# Copy to another database
source_connection_string = 'sqlite:///../BDNYCdb-1/bdnyc_database.db'  # SQLite
destination_connection_string = 'postgresql://localhost/BDNYC'  # Postgres
copy_database_schema(source_connection_string, destination_connection_string)

# Load database contents from JSON
db = Database(destination_connection_string,
              reference_tables=['changelog', 'data_requests', 'publications', 'ignore', 'modes',
                                'systems', 'telescopes', 'versions', 'instruments'],
              primary_table='sources',
              primary_table_key='id',
コード例 #3
0
spec_data = [{
    'source': '2MASS J00192626+4614078',
    'regime': 'infrared',
    'spectrum': 'https://s3.amazonaws.com/bdnyc/SpeX/Prism/U10013_SpeX.fits',
    'telescope': 'IRTF',
    'instrument': 'SpeX',
    'mode': 'Prism',
    'reference': 'Cruz18',
    'wavelength_units': 'um',
    'flux_units': 'erg s-1 cm-2 A-1',
    'observation_date': datetime.fromisoformat('2004-11-08')
}]
db.Spectra.insert().execute(spec_data)

# Verify inventory lists the new spectrum
_ = db.inventory('2MASS J00192626+4614078', pretty_print=True)

# Getting spectrum object as a specutils Spectrum1D object
# Refer to https://astrodbkit2.readthedocs.io/en/latest/#general-queries-with-transformations for more information
t = db.query(db.Spectra.c.spectrum).filter(
    db.Spectra.c.source == '2MASS J00192626+4614078').table(
        spectra=['spectrum'])
t = db.query(db.Spectra.c.spectrum).filter(
    db.Spectra.c.source == '2MASS J00192626+4614078').limit(1).spectra()

# Confirm that it is a Spectrum1D object
spec = t[0][0]
print(type(spec))

# Save database modifications to disk
db.save_database('data')