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

Add radial velocities table #72

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
52 changes: 51 additions & 1 deletion schema/schema_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ def count_significant_digits(numstr):
"Instruments",
"PhotometryFilters",
"Versions",
"Regimes"
"Regimes",
"RadialVelocities"
]




class Publications(Base):
"""ORM for publications table.
This stores reference information (DOI, bibcodes, etc) and
Expand Down Expand Up @@ -405,6 +408,53 @@ def validate_parallax_sig_figs(self, key, value):

return value


class RadialVelocities(Base):
# This is an example of a measurement table (see below, commented-out table as another example)
arjunsavel marked this conversation as resolved.
Show resolved Hide resolved

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

# always note units, following the practices of Chen et al. 2022.
radial_velocity_km_s = Column(Float, nullable=False)

radial_velocity_error_km_s = Column(Float) # todo: make asymmetric errors
kelle marked this conversation as resolved.
Show resolved Hide resolved
adopted = Column(Boolean) # flag for indicating if this is the adopted
comments = Column(String(1000))
reference = Column(
String(30),
ForeignKey("Publications.reference", onupdate="cascade"),
primary_key=True,
)

@validates("comments")
def validate_comment_length(self, key, value):
check_string_length(value, 1000, key)
return value

@validates("radial_velocity_km_s")
def validate_rv_sig_figs(self, key, value):
if value is None:
raise ValueError(f"Provided {key} is invalid; None: {value}")

if hasattr(self, 'radial_velocity_error_km_s') and self.radial_velocity_error_km_s is not None:

n_sig_figs_error = count_significant_digits(self.radial_velocity_error_km_s)
n_sig_figs_value = count_significant_digits(value)

if n_sig_figs_value > n_sig_figs_error:
# raise warning instead of error.
logger.warning(f"Provided {key} is invalid; more significant figures than error: {value}")
else:
pass

return value

# class Measurement(Base):
# # This is a template table that you can fill in with your own measurement.
# . This is a placeholder for a table that would store measurements such as parallax.
Expand Down
19 changes: 19 additions & 0 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Telescopes,
Versions,
Parallax,
RadialVelocities,
Regimes
)

Expand Down Expand Up @@ -138,6 +139,24 @@ def test_parallax_schema(values, error_state):
"""
schema_tester(Parallax, values, error_state)

@pytest.mark.parametrize("values, error_state",
[
({"radial_velocity_km_s": 30}, None),
({"radial_velocity_km_s": -30}, None),
({"radial_velocity_km_s": None}, ValueError),
({"radial_velocity_error_km_s": None}, None),
({"radial_velocity_error_km_s": 30}, None),
({"radial_velocity_error_km_s": -30}, None),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the uncertainty be allowed to be negative?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I guess not! I was thinking about the "negative parallaxes are not unexpected" Gaia results, and I must've mixed them up with errors. I can fix this for parallaxes and RVs.

({"comments": 'string i will make far too long' * 1000}, ValueError),
({"comments": 'string that i will not make very long'}, None)
])
def test_radial_velocities_schema(values, error_state):
"""
These quantities are validated in the schema. For instance, the schema ensures that
comments must not be more than 1000 characters long.
"""
schema_tester(RadialVelocities, values, error_state)



@pytest.mark.parametrize("values, error_state",
Expand Down
Loading