Skip to content

Commit

Permalink
adding MPCORB unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
astronomerritt committed Mar 26, 2024
1 parent 14458d8 commit c0eeb0e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/adler/dataclasses/SSObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ class SSObject:
firstObservationDate: float = 0.0
arc: float = 0.0
numObs: int = 0
H: np.ndarray = field(default_factory=np.zeros(0))
G12: np.ndarray = field(default_factory=np.zeros(0))
Herr: np.ndarray = field(default_factory=np.zeros(0))
G12err: np.ndarray = field(default_factory=np.zeros(0))
nData: np.ndarray = field(default_factory=np.zeros(0))
H: np.ndarray = field(default_factory=lambda: np.zeros(0))
G12: np.ndarray = field(default_factory=lambda: np.zeros(0))
Herr: np.ndarray = field(default_factory=lambda: np.zeros(0))
G12err: np.ndarray = field(default_factory=lambda: np.zeros(0))
nData: np.ndarray = field(default_factory=lambda: np.zeros(0))
maxExtendedness: float = 0.0
minExtendedness: float = 0.0
medianExtendedness: float = 0.0
Expand Down
5 changes: 2 additions & 3 deletions tests/adler/dataclasses/test_Observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
def test_construct_observations_from_data_table():
ssoid = 8268570668335894776
test_db_path = get_test_data_filepath("testing_database.db")
schema = ""
filter_name = "r"
date_range = [61000.0, 62000.0]

Expand All @@ -19,8 +18,8 @@ def test_construct_observations_from_data_table():
topocentricDist, heliocentricDist
FROM
ssObject
JOIN {schema}diaSource ON {schema}ssObject.ssObjectId = {schema}diaSource.ssObjectId
JOIN {schema}ssSource ON {schema}diaSource.diaSourceId = {schema}ssSource.diaSourceId
JOIN diaSource ON ssObject.ssObjectId = diaSource.ssObjectId
JOIN ssSource ON diaSource.diaSourceId = ssSource.diaSourceId
WHERE
ssObject.ssObjectId = {ssoid} AND band = '{filter_name}' AND midPointMjdTai BETWEEN {date_range[0]} AND {date_range[1]}
"""
Expand Down
52 changes: 52 additions & 0 deletions tests/adler/dataclasses/test_SSObject.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from numpy.testing import assert_almost_equal
from numpy.testing import assert_equal
import numpy as np

from adler.utilities.tests_utilities import get_test_data_filepath
from adler.dataclasses.dataclass_utilities import get_data_table
from adler.dataclasses.SSObject import SSObject


def test_construct_SSObject_from_data_table():
ssoid = 8268570668335894776
test_db_path = get_test_data_filepath("testing_database.db")

filter_list = ["r", "g"]

filter_dependent_columns = ""

for filter_name in filter_list:
filter_string = "{}_H, {}_G12, {}_HErr, {}_G12Err, {}_Ndata, ".format(
filter_name, filter_name, filter_name, filter_name, filter_name
)

filter_dependent_columns += filter_string

test_query = f"""
SELECT
discoverySubmissionDate, firstObservationDate, arc, numObs,
{filter_dependent_columns}
maxExtendedness, minExtendedness, medianExtendedness
FROM
SSObject
WHERE
ssObjectId = {ssoid}
"""

data_table = get_data_table(test_query, sql_filename=test_db_path)
test_SSObject = SSObject.construct_from_data_table(ssoid, filter_list, data_table)

assert test_SSObject.ssObjectId == 8268570668335894776
assert test_SSObject.filter_list == filter_list
assert_almost_equal(test_SSObject.discoverySubmissionDate, 60218.0, decimal=6)
assert_almost_equal(test_SSObject.firstObservationDate, 60220.01958, decimal=6)
assert_almost_equal(test_SSObject.arc, 3342.05859375, decimal=6)
assert test_SSObject.numObs == 94
assert_almost_equal(test_SSObject.H, [19.80589294, 20.29232597], decimal=6)
assert_almost_equal(test_SSObject.G12, [1.52932608, 1.72339332], decimal=6)
assert_almost_equal(test_SSObject.Herr, [0.01974303, 0.0302103], decimal=6)
assert_almost_equal(test_SSObject.G12err, [0.05071714, 0.04049731], decimal=6)
assert_equal(test_SSObject.nData, [38.0, 9.0])
assert_equal(test_SSObject.maxExtendedness, 0.0)
assert_equal(test_SSObject.minExtendedness, 0.0)
assert_equal(test_SSObject.medianExtendedness, 0.0)
3 changes: 1 addition & 2 deletions tests/adler/test_MPCORB.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
def test_construct_MPCORB_from_data_table():
ssoid = 8268570668335894776
test_db_path = get_test_data_filepath("testing_database.db")
schema = ""

test_query = f"""
SELECT
ssObjectId, mpcDesignation, mpcNumber, mpcH, mpcG, epoch, peri, node, incl, e, n, q,
uncertaintyParameter, flags
FROM
{schema}MPCORB
MPCORB
WHERE
ssObjectId = {ssoid}
"""
Expand Down

0 comments on commit c0eeb0e

Please sign in to comment.