Skip to content

Commit

Permalink
changed rv ingest to use actual ultracool sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
Exu-112 committed Jun 14, 2024
1 parent 593019b commit 8ecaef5
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
70 changes: 70 additions & 0 deletions scripts/ingests/ultracool_sheet/Ingest_radial_velocities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from astrodb_utils import load_astrodb, find_source_in_db, AstroDBError
import logging
from astropy.io import ascii
from urllib.parse import quote
import requests
from astropy.table import Table
import sys
sys.path.append( '.' )
from simple.schema import *
from simple.schema import REFERENCE_TABLES
from math import isnan
import sqlalchemy.exc



logger = logging.getLogger("AstroDB")
logger.setLevel(logging.INFO)


RECREATE_DB = False
db = load_astrodb("SIMPLE.sqlite", recreatedb=RECREATE_DB, reference_tables=REFERENCE_TABLES)

# Load Ultracool sheet
doc_id = "1i98ft8g5mzPp2DNno0kcz4B9nzMxdpyz5UquAVhz-U8"
sheet_id = "361525788"
link = f"https://docs.google.com/spreadsheets/d/{doc_id}/export?format=csv&gid={sheet_id}"
# link = "scripts/ultracool_sheet/UltracoolSheet - Main_010824.csv"
#link = "scripts/ingests/ultracool_sheet/Radial_velocities_with_references.csv"

# read the csv data into an astropy table
uc_sheet_table = ascii.read(
link,
format="csv",
data_start=1,
header_start=0,
guess=False,
fast_reader=False,
delimiter=",",
)

#Ingest loop
for source in uc_sheet_table:
if(isnan(source["rv_lit"])):
#skip if no rv
continue
uc_sheet_name = source["name"]
match = find_source_in_db(
db,
uc_sheet_name,
ra=source["ra_j2000_formula"],
dec=source["dec_j2000_formula"],
)

if len(match) == 1:
#1 Match found. INGEST!
simple_source = match[0]
logger.info(f"Match found for {uc_sheet_name}: {simple_source}")
print(f"Match found for {uc_sheet_name}: {simple_source}")
rv_data = [{"source": simple_source, "radial_velocity_km_s": source["rv_lit"], "radial_velocity_error_km_s": source["rverr_lit"],"reference": source["ref_rv_lit"]}]
try:
with db.engine.connect() as conn:
conn.execute(db.RadialVelocities.insert().values(rv_data))
conn.commit()
logger.info(f" Radial Velocity added to database: {rv_data}\n")
except sqlalchemy.exc.IntegrityError as e:
msg = f"Could not add {rv_data} to database."
logger.warning(msg)
#raise AstroDBError(msg) from e

#db.save_database(directory="data/")
15 changes: 15 additions & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,3 +695,18 @@ def test_modeledparameters(db):
.astropy()
)
assert len(t) == 5, f"found {len(t)} modeled parameters with {ref} reference"

def test_radial_velocities(db):
t = (
db.query(db.RadialVelocities)
.astropy()
)
assert len(t) == 1261, f"found {len(t)} radial velociies"

ref = "Abaz09"
t = (
db.query(db.RadialVelocities)
.filter(db.RadialVelocities.c.reference == ref)
.astropy()
)
assert len(t) == 447, f"found {len(t)} radial velociies with {ref} reference"

0 comments on commit 8ecaef5

Please sign in to comment.