Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bard14 Spectra #439

Merged
merged 14 commits into from
Dec 29, 2023
3 changes: 3 additions & 0 deletions scripts/ingests/ingest_backyard_worlds_benchmarks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test


79 changes: 79 additions & 0 deletions scripts/ingests/ingest_bard14_spectra.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from scripts.ingests.ingest_utils import *
from scripts.ingests.utils import *
from astropy.table import Table
from astropy.io import ascii
import astropy.units as u
from astropy.coordinates import Angle


SAVE_DB = False # True: save the data files(json) in addition to modifying the .db file
RECREATE_DB = True # recreates the .db file from the data files
# LOAD THE DATABASE
db = load_simpledb('SIMPLE.db', recreatedb=RECREATE_DB)

#bard14 url : https://docs.google.com/spreadsheets/d/11o5NRGA7jSbHKaTNK7SJnu_DTECjsyZ6rY3rcznYsJk/edit#gid=0

SHEET_ID = '11o5NRGA7jSbHKaTNK7SJnu_DTECjsyZ6rY3rcznYsJk'
SHEET_NAME = 'bard14'
full = 'all'

url = f'https://docs.google.com/spreadsheets/d/{SHEET_ID}/gviz/tq?tqx=out:csv&sheet={full}'

bard14_table = ascii.read(
url,
format="csv",
data_start=1,
header_start=0,
guess=False,
fast_reader=False,
delimiter=",",
)

#print result table
print(bard14_table.info)


#Loop through data and ingest spectra
def ingest_all_spectra(db):
for row in bard14_table[0:19]:

# Print spectra information
print("Spectra Information:")

for col_name in row.colnames:
print(f"{col_name}: {row[col_name]}")


# Ingest SPECTRAL TYPES, loop through data
ingest_spectra(db,
sources = "Source",
spectrum= "Spectrum",
original_spectrum= "Original Spectrum",
regimes = "regime",
telescope= "telescope",
instrument= "instrument",
mode= "mode",
observation_date= "observation date",
spectrum_comments= "spectrum comments",
spectrum_reference= "spectrum reference",
ra= "ra",
dec= "dec",
aperture= "aperture",
raise_error=True,
search_db= True,
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this particular case, since we are updating the spectra entries and not adding entirely new ones, we can't use this function.

Suggested change
# Ingest SPECTRAL TYPES, loop through data
ingest_spectra(db,
sources = "Source",
spectrum= "Spectrum",
original_spectrum= "Original Spectrum",
regimes = "regime",
telescope= "telescope",
instrument= "instrument",
mode= "mode",
observation_date= "observation date",
spectrum_comments= "spectrum comments",
spectrum_reference= "spectrum reference",
ra= "ra",
dec= "dec",
aperture= "aperture",
raise_error=True,
search_db= True,
)

#DB Table has local spectrum, comments(spectrum comments on sheet), reference(spectrum reference on sheet)
#reference and other_references as categories not listed on sheet
#Sheet has ra, sec and aperture not in db

# Add a separator between rows for better readability
print("-" * 50)

#Call spectral types function
ingest_all_spectra(db)



# WRITE THE JSON FILES
if SAVE_DB:
db.save_database(directory="data/")