Skip to content

Commit

Permalink
Initial data class commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
astronomerritt committed Feb 13, 2024
1 parent 28f9273 commit 14bf334
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 31 deletions.
24 changes: 9 additions & 15 deletions src/adler/AdlerPlanetoid.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from lsst.rsp import get_tap_service, retrieve_query
from DataSchema import Observations, MPCORB, SSObject

class AdlerPlanetoid:

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
Expand All @@ -21,9 +20,7 @@ def __init__(self, ssObjectId, sql_filename=None):
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,
Expand All @@ -35,12 +32,12 @@ def populate_observations(self):
WHERE
ssObject.ssObjectId = {self.ssObjectId} and band='r'
"""

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



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,
Expand All @@ -50,12 +47,10 @@ def populate_MPCORB(self):
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,
Expand All @@ -66,6 +61,5 @@ def populate_SSObject(self):
WHERE
ssObjectId = {self.ssObjectId}
"""

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

28 changes: 12 additions & 16 deletions src/adler/DataSchema.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import numpy as np

class DataSchema():

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
Expand All @@ -14,28 +16,23 @@ def __init__(self, ssObjectId, sql_query, service, sql_filename=None):
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])
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])

Expand All @@ -44,8 +41,9 @@ 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)
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.
Expand All @@ -57,14 +55,13 @@ def __init__(self, ssObjectId, observations_query, service, sql_filename=None):
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.
"""

"""Grabs information from MPCORB."""

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

Expand All @@ -86,9 +83,8 @@ def __init__(self, ssObjectId, observations_query, service, sql_filename=None):


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

"""Grabs information from MPCORB."""

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

Expand All @@ -103,4 +99,4 @@ def __init__(self, ssObjectId, observations_query, service, sql_filename=None):
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")
self.medianExtendedness = self.get_float_from_table("medianExtendedness")

0 comments on commit 14bf334

Please sign in to comment.