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

Initial data class commit. #29

Merged
merged 8 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ classifiers = [
dynamic = ["version"]
dependencies = [
"ipykernel", # Support for Jupyter notebooks
"numpy",
"lsst-rsp"
]

[project.urls]
Expand All @@ -38,6 +40,9 @@ dev = [
"ipython", # Also used in building notebooks into Sphinx
]

[project.scripts]
adler = "adler.adler:main"

[build-system]
requires = [
"setuptools>=62", # Used to build and package the Python project
Expand Down
Binary file added src/adler/.DS_Store
Binary file not shown.
5 changes: 2 additions & 3 deletions src/adler/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from .example_module import greetings, meaning

__all__ = ["greetings", "meaning"]
from . import dataclasses
from . import science
26 changes: 26 additions & 0 deletions src/adler/adler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import argparse

from adler.dataclasses.AdlerPlanetoid import AdlerPlanetoid


def runAdler(args):
planetoid = AdlerPlanetoid(args.ssoid)

planetoid.do_pretend_science()


def main():
parser = argparse.ArgumentParser(description="Runs Adler for a select planetoid and given user input.")

parser.add_argument("-s", "--ssoid", help="SSObject ID of planetoid.", type=str, required=True)

# can add arguments to specify a date range etc later
# alternatively we may start using a config file

args = parser.parse_args()

runAdler(args)


if __name__ == "__main__":
main()
Binary file added src/adler/dataclasses/.DS_Store
Binary file not shown.
71 changes: 71 additions & 0 deletions src/adler/dataclasses/AdlerPlanetoid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from lsst.rsp import get_tap_service
from adler.dataclasses.DataSchema import Observations, MPCORB, SSObject
from adler.science.DummyScience import DummyScience


class AdlerPlanetoid:
def __init__(self, ssObjectId, sql_filename=None):
self.ssObjectId = ssObjectId
self.sql_filename = sql_filename
# can also include date ranges at some point

# can draw from a local SQL database
if not sql_filename:
self.service = get_tap_service("ssotap")
else:
self.service = None

# this creates the AdlerPlanetoid.Observations, AdlerPlanetoid.MPCORB and
# AdlerPlanetoid.SSObject objects.
self.populate_observations()
self.populate_MPCORB()
self.populate_SSObject()

def populate_observations(self):
observations_sql_query = f"""
SELECT
ssObject.ssObjectId, mag, magErr, band, midpointMjdTai as mjd, ra, dec, phaseAngle,
topocentricDist, heliocentricDist
FROM
dp03_catalogs_10yr.ssObject
JOIN dp03_catalogs_10yr.diaSource ON dp03_catalogs_10yr.ssObject.ssObjectId = dp03_catalogs_10yr.diaSource.ssObjectId
JOIN dp03_catalogs_10yr.ssSource ON dp03_catalogs_10yr.diaSource.diaSourceId = dp03_catalogs_10yr.ssSource.diaSourceId
WHERE
ssObject.ssObjectId = {self.ssObjectId} and band='r'
"""

self.Observations = Observations(
self.ssObjectId, observations_sql_query, self.service, self.sql_filename
)

def populate_MPCORB(self):
MPCORB_sql_query = f"""
SELECT
ssObjectId, mpcDesignation, mpcNumber, mpcH, mpcG, epoch, peri, node, incl, e, n, q,
uncertaintyParameter, flags
FROM
dp03_catalogs_10yr.MPCORB
WHERE
ssObjectId = {self.ssObjectId}
"""

self.MPCORB = MPCORB(self.ssObjectId, MPCORB_sql_query, self.service, self.sql_filename)

def populate_SSObject(self):
SSObject_sql_query = f"""
SELECT
discoverySubmissionDate, firstObservationDate, arc, numObs,
r_H, r_G12, r_Herr, r_G12err, r_nData,
maxExtendedness, minExtendedness, medianExtendedness
FROM
dp03_catalogs_10yr.SSObject
WHERE
ssObjectId = {self.ssObjectId}
"""

self.SSObject = SSObject(self.ssObjectId, SSObject_sql_query, self.service, self.sql_filename)

def do_pretend_science(self):
self.DummyScienceResult = DummyScience().science_result

print(self.DummyScienceResult)
102 changes: 102 additions & 0 deletions src/adler/dataclasses/DataSchema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import numpy as np


class DataSchema:
"""Parent class for Observations (a join of DiaSource and SSSource), MPCORB
and SSObject data classes.
"""

def __init__(self, ssObjectId, sql_query, service, sql_filename=None):
self.ssObjectId = ssObjectId
self.sql_query = sql_query
self.service = service

if not sql_filename:
self.data_table = self.get_RSP_table(self.sql_query)
else:
self.data_table = self.get_SQL_table(self.sql_query)

def get_RSP_table(self, sql_query):
rsp_table = self.service.search(sql_query).to_table()
return rsp_table

def get_SQL_table(self, sql_query, testing_filename):
pass

# should be one function to get whatever from the table and type accordingly
def get_array_from_table(self, column_name):
return np.array(self.data_table[column_name])

def get_string_from_table(self, column_name):
return str(self.data_table[column_name][0])

def get_float_from_table(self, column_name):
return float(self.data_table[column_name][0])

def get_int_from_table(self, column_name):
return int(self.data_table[column_name][0])


class Observations(DataSchema):
"""This is a SQL join of DiaSource and SSSource which contains all of the
observations of the object.
"""

def __init__(self, ssObjectId, observations_query, service, sql_filename=None):
super().__init__(ssObjectId, observations_query, service, sql_filename)

# This populates each of the variables with a numpy array of the specific column.
# This should probably be moved to a constructor class method.
self.mag = self.get_array_from_table("mag")
self.magErr = self.get_array_from_table("magErr")
self.mjd = self.get_array_from_table("mjd")
self.ra = self.get_array_from_table("ra")
self.dec = self.get_array_from_table("dec")
self.phaseAngle = self.get_array_from_table("phaseAngle")
self.topocentricDist = self.get_array_from_table("topocentricDist")
self.heliocentricDist = self.get_array_from_table("heliocentricDist")

self.reduced_mag = self.mag - 5 * np.log10(self.topocentricDist * self.heliocentricDist)


class MPCORB(DataSchema):
"""Grabs information from MPCORB."""

def __init__(self, ssObjectId, observations_query, service, sql_filename=None):
super().__init__(ssObjectId, observations_query, service, sql_filename)

self.mpcDesignation = self.get_string_from_table("mpcDesignation")
self.mpcNumber = self.get_string_from_table("mpcNumber")
self.mpcH = self.get_float_from_table("mpcH")
self.mpcG = self.get_float_from_table("mpcH")
self.epoch = self.get_float_from_table("epoch")
self.peri = self.get_float_from_table("peri")
self.node = self.get_float_from_table("node")
self.incl = self.get_float_from_table("incl")
self.e = self.get_float_from_table("e")
self.n = self.get_float_from_table("n")
self.q = self.get_float_from_table("q")
self.uncertaintyParameter = self.get_string_from_table("uncertaintyParameter")
self.flags = self.get_string_from_table("flags")

# no mean anomaly, no a in MPCORB table


class SSObject(DataSchema):
"""Grabs information from MPCORB."""

def __init__(self, ssObjectId, observations_query, service, sql_filename=None):
super().__init__(ssObjectId, observations_query, service, sql_filename)

self.discoverySubmissionDate = self.get_float_from_table("discoverySubmissionDate")
self.firstObservationDate = self.get_float_from_table("firstObservationDate")
self.arc = self.get_float_from_table("arc")
self.numObs = self.get_int_from_table("numObs")
self.r_H = self.get_float_from_table("r_H")
self.r_G12 = self.get_float_from_table("r_G12")
self.r_Herr = self.get_float_from_table("r_Herr")
self.r_G12Err = self.get_float_from_table("r_G12err")
self.r_nData = self.get_int_from_table("r_nData")
self.maxExtendedness = self.get_float_from_table("maxExtendedness")
self.minExtendedness = self.get_float_from_table("minExtendedness")
self.medianExtendedness = self.get_float_from_table("medianExtendedness")
23 changes: 0 additions & 23 deletions src/adler/example_module.py

This file was deleted.

3 changes: 3 additions & 0 deletions src/adler/science/DummyScience.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class DummyScience:
def __init__(self):
self.science_result = "look, science!"
Binary file added tests/adler/.DS_Store
Binary file not shown.
Empty file removed tests/adler/conftest.py
Empty file.
5 changes: 5 additions & 0 deletions tests/adler/dataclasses/dummy_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# placeholder test to ensure tests work


def test_dummytest():
print("test complete")
13 changes: 0 additions & 13 deletions tests/adler/test_example_module.py

This file was deleted.

Loading