Ejemplo n.º 1
0
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
spectral_type_codes = convert_spt_string_to_code(spectral_types, verbose=True)

# add new references to Publications table
ref_list = spt_refs.tolist()
included_ref = db.query(db.Publications.c.name).filter(
    db.Publications.c.name.in_(ref_list)).all()
included_ref = [s[0] for s in included_ref]
new_ref = list(set(ref_list) - set(included_ref))
new_ref = [{'name': s} for s in new_ref]

if len(new_ref) > 0:
    db.Publications.insert().execute(new_ref)

# Make astropy table with all relevant columns and add to SpectralTypes Table
SpT_table = Table(
    [db_names, spectral_types, spectral_type_codes, regime, spt_refs],
    names=('source', 'spectral_type_string', 'spectral_type_code', 'regime',
           'reference'))
db.add_table_data(SpT_table, table='SpectralTypes', fmt='astropy')

db.save_db('../../data')
spt_ref = ['Manj19'] * len(db_names_spex)
# adopted = False * len(db_names_spex) # Should have specified adopted column
SpT_table_spex = Table(
    [db_names_spex, spex_types_string, spex_types_codes, regime, spt_ref],
    names=('source', 'spectral_type_string', 'spectral_type_code', 'regime',
           'reference'))
SpT_table_spex_df = SpT_table_spex.to_pandas(
)  # make a Pandas dataframe to explore  with Pycharm

# Report results
print("\n", len(db_names_spex), "Spex SpTypes to be added")
verboseprint(SpT_table_spex_df)

# Add to database
if not DRY_RUN:
    db.add_table_data(SpT_table_spex, table='SpectralTypes', fmt='astropy')

# Update adopted field after spectral types were already added
update_adopted = db.SpectralTypes.update().where(
    db.SpectralTypes.c.reference == 'Manj19').values(adopted=False)
db.engine.execute(update_adopted)

# Verify results
n_Manj19_types = db.query(
    db.SpectralTypes).filter(db.SpectralTypes.c.reference == 'Manj19').count()
print("\n", n_Manj19_types,
      'spectral types referenced to Manj19 now found database')
verboseprint(
    db.query(db.SpectralTypes).filter(
        db.SpectralTypes.c.reference == 'Manj19').table())
Ejemplo n.º 3
0
        db_names.append(db.search_object(name, resolve_simbad=True)[0].source)

    else:
        missing_sources.append(i)
        db_names.append(resolved_name[i])

# renaming column heads for ingest
ATLAS["reference"] = ["Missing"] * len(ATLAS["Name"])
ATLAS["source"] = resolved_name
#ATLAS.rename_column('Name', 'source')
ATLAS.rename_column('_RAJ2000', 'ra')
ATLAS.rename_column('_DEJ2000', 'dec')

# add missing objects to Sources table
if len(missing_sources) > 0:
    db.add_table_data(ATLAS[missing_sources], table='Sources', fmt='astropy')

# add new sources in Names table too
names_data = []
for ms in missing_sources:
    names_data.append({
        'source': ATLAS['source'][ms],
        'other_name': ATLAS['source'][ms]
    })
    if ATLAS['source'][ms] != ATLAS['Name'][ms]:
        names_data.append({
            'source': ATLAS['source'][ms],
            'other_name': ATLAS['Name'][ms]
        })
if len(missing_sources) > 0:
    db.Names.insert().execute(names_data)
Ejemplo n.º 4
0
        db_names.append(Ydwarfs['source'][i])

# add missing references
ref_list = Ydwarfs['reference'].tolist()
included_ref = db.query(db.Publications.c.name).filter(
    db.Publications.c.name.in_(ref_list)).all()
included_ref = [s[0] for s in included_ref]
new_ref = list(set(ref_list) - set(included_ref))
new_ref = [{'name': s} for s in new_ref]

if len(new_ref) > 0:
    db.Publications.insert().execute(new_ref)

# add missing objects to Sources table
if len(missing_sources) > 0:
    db.add_table_data(Ydwarfs[missing_sources], table='Sources', fmt='astropy')

# add new sources in Names table too
names_data = []
for ms in missing_sources:
    names_data.append({
        'source': Ydwarfs['source'][ms],
        'other_name': Ydwarfs['source'][ms]
    })
if len(missing_sources) > 0:
    db.Names.insert().execute(names_data)

# add other names for existing sources if alternative names not in database yet
other_names_data = []
for es in existing_sources:
    es_names = db.search_object(db_names[es], output_table='Names')