-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from lsst-uk/initial_data
Initial data class commit.
- Loading branch information
Showing
11 changed files
with
216 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
**/.DS_Store | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class DummyScience: | ||
def __init__(self): | ||
self.science_result = "look, science!" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file was deleted.
Oops, something went wrong.