def load_database(connection_string): # Create and load the database create_database(connection_string) # Now that the database is created, connect to it and load up the JSON data db = Database(connection_string, reference_tables=REFERENCE_TABLES) db.load_database(DB_PATH, verbose=False) print('New database generated.') # Close all connections db.session.close() db.engine.dispose()
def db(): # Create a fresh temporary database and assert it exists # Because we've imported simple.schema, we will be using that schema for the database if os.path.exists(DB_NAME): os.remove(DB_NAME) connection_string = 'sqlite:///' + DB_NAME create_database(connection_string) assert os.path.exists(DB_NAME) # Connect to the new database and confirm it has the Sources table db = Database(connection_string) assert db assert 'source' in [c.name for c in db.Sources.columns] return db
def load_db(): # Utility function to load the database db_file = 'SIMPLE.db' db_file_path = Path(db_file) db_connection_string = 'sqlite:///SIMPLE.db' # SQLite browser if RECREATE_DB and db_file_path.exists(): os.remove(db_file) # removes the current .db file if one already exists if not db_file_path.exists(): create_database(db_connection_string) # creates empty database based on the simple schema db = Database(db_connection_string) # connects to the empty database db.load_database('data/') # loads the data from the data files into the database else: db = Database(db_connection_string) # if database already exists, connects to .db file return db
def db(): # Create a fresh temporary database and assert it exists # Because we've imported simple.schema, we will be using that schema for the database if os.path.exists(DB_NAME): os.remove(DB_NAME) connection_string = 'sqlite:///' + DB_NAME create_database(connection_string) assert os.path.exists(DB_NAME) # Connect to the new database and confirm it has the Sources table db = Database(connection_string) assert db assert 'source' in [c.name for c in db.Sources.columns] # Load the database contents # This should take care of finding serious issues (key/column violations) db.load_database(DB_PATH, verbose=False) return db
def load_simpledb(db_file, recreatedb=True): # Utility function to load the database db_file_path = Path(db_file) db_connection_string = 'sqlite:///' + db_file if recreatedb and db_file_path.exists(): os.remove( db_file) # removes the current .db file if one already exists if not db_file_path.exists(): try: # Use fancy in-memory database, if supported by astrodbkit2 db = Database( 'sqlite://' ) # creates and connects to a temporary in-memory database db.load_database( 'data/' ) # loads the data from the data files into the database db.dump_sqlite(db_file) # dump in-memory database to file db = Database(db_connection_string ) # replace database object with new file version except RuntimeError: # use in-file database create_database( db_connection_string ) # creates empty database based on the simple schema db = Database( db_connection_string) # connects to the empty database db.load_database( 'data/' ) # loads the data from the data files into the database else: db = Database(db_connection_string ) # if database already exists, connects to .db file return db
# Script to add Y dwarfs spectral types from astrodbkit2.astrodb import create_database from astrodbkit2.astrodb import Database #from simple.schema import * from astropy.table import Table import numpy as np import re from utils import convert_spt_string_to_code connection_string = 'sqlite:///../../SIMPLE.db' # SQLite create_database(connection_string) db = Database(connection_string) db.load_database('../../data') # load table ingest_table = Table.read('Y-dwarf_table.csv', data_start=2) names = ingest_table['source'] n_sources = len(names) regime = ['infrared' ] * n_sources # all source have IR spectral classifications spectral_types = ingest_table['SpT'] spt_refs = ingest_table['spt_ref'] # sources names in database Names table db_names = [] for name in names: db_name = db.search_object(name, output_table='Sources')[0].source db_names.append(db_name) # Convert SpT string to code
DRY_RUN = False #modifies .db file but not the data files RECREATE_DB = True #recreates the .db file from the data files VERBOSE = False verboseprint = print if VERBOSE else lambda *a, **k: None db_file = 'SIMPLE.db' db_file_path = Path(db_file) db_connection_string = 'sqlite:///SIMPLE.db' # SQLite browser if RECREATE_DB and db_file_path.exists(): os.remove(db_file) #removes the current .db file if one already exists if not db_file_path.exists(): create_database(db_connection_string ) #creates empty database based on the simple schema db = Database(db_connection_string) #connects to the empty database db.load_database( 'data/') #loads the data from the data files into the database else: db = Database(db_connection_string ) #if database already exists, connects to .db file #Adding missing publications to publication table add_publication(db, name='Sahl16', bibcode='J/MNRAS/455/357', dryrun=False) add_publication(db, name='Liu16', bibcode='J/ApJ/833/96', dryrun=False) add_publication(db, name='Wang18', bibcode='2018PASP..130f4402W', dryrun=False) add_publication(db, name='Bedi17', bibcode='2017MNRAS.470.1140B', dryrun=False) add_publication(db, name='Delo17', bibcode='2017A&A...608A..79D', dryrun=False) add_publication(db, name='Luhm16', bibcode='2016AJ....152...78L', dryrun=False)