astrodbtoolkit / astrodbtoolkit/astrodb_utils

make `ingest_radial_velocity` function

Open
#52 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
0
Forks
10
PR merge metrics
No merged PRs in 30d

Description

@exu-112 made an `ingest_radial` velocity function which I think is ready to be added to astrodb_utils.

First, the a Radial Velocity table needs to be added to the template: https://github.com/astrodbtoolkit/astrodb-template-db/issues/69

the new function needs :

- [ ] LOTS of tests
- [ ] docstring
- [ ] mention in the docs

```python
def ingest_radial_velocity(
source: str = None,
rv: float = None,
rv_err: float = None,
reference: str = None,
raise_error: bool = True,
):
rv_data = {
"source": source,
"radial_velocity_km_s": rv,
"radial_velocity_error_km_s": rv_err,
"reference": reference,
}

try:
rv_obj = RadialVelocities(**rv_data)
with db.session as session:
session.add(rv_obj)
session.commit()
logger.info(f" Radial Velocity added to database: {rv_data}\n")
except sqlalchemy.exc.IntegrityError as e:
if (
"UNIQUE constraint failed: RadialVelocities.source, RadialVelocities.reference"
in str(e)
):
msg = f"Radial Velocity with same reference already exists in database: {rv_data}"
if raise_error:
raise AstroDBError(msg) from e
else:
msg2 = f"SKIPPING: {source}. Radial Velocity with same reference already exists in database."
logger.warning(msg2)
else:
msg = f"Could not add {rv_data} to database. Error: {e}"
logger.warning(msg)
raise AstroDBError(msg) from e
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.