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

Reworking how ingest_spectrum works using the ORM #501

Merged
merged 15 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions simple/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import enum
from datetime import datetime

import sqlalchemy as sa
from astrodbkit2.astrodb import Base
Expand Down Expand Up @@ -344,28 +345,30 @@ class Gravities(Base):
class Spectra(Base):
# Table to store references to spectra
__tablename__ = 'Spectra'

source = Column(
String(100),
ForeignKey("Sources.source", ondelete="cascade", onupdate="cascade"),
nullable=False,
primary_key=True,
)

# Data
access_url = Column(String(1000), nullable=False) # URL of spectrum location
original_spectrum = Column(
String(1000)
) # URL of original spectrum location, if applicable
local_spectrum = Column(
String(1000)
) # local directory (via environment variable) of spectrum location

# URL of original spectrum location, if applicable
original_spectrum = Column(String(1000))
# local directory (via environment variable) of spectrum location
local_spectrum = Column(String(1000))

regime = Column(
String(30),
ForeignKey("Regimes.regime", ondelete="cascade", onupdate="cascade"),
primary_key=True,
)
telescope = Column(String(30))
instrument = Column(String(30))
mode = Column(String(30)) # eg, Prism, Echelle, etc
telescope = Column(String(30), nullable=False)
instrument = Column(String(30), nullable=False)
mode = Column(String(30), nullable=False) # eg, Prism, Echelle, etc
observation_date = Column(DateTime, primary_key=True)

# Common metadata
Expand All @@ -387,6 +390,23 @@ class Spectra(Base):
{},
)

@validates("access_url", "regime", "source", "telescope", "instrument", "mode")
def validate_required(self, key, value):
if value is None:
raise ValueError(f"Value required for {key}")
dr-rodriguez marked this conversation as resolved.
Show resolved Hide resolved
return value

@validates("observation_date")
def validate_date(self, key, value):
if value is None:
raise ValueError(f"Invalid date received: {value}")
elif not isinstance(value, datetime):
# Convert to datetime for storing in the database
# Will throw error if unable to convert
print("WARNING: Value will be converted to ISO format.")
value = datetime.fromisoformat(value)
return value
dr-rodriguez marked this conversation as resolved.
Show resolved Hide resolved


class ModeledParameters(Base):
# Table to store derived/inferred paramaters from models
Expand Down
Loading