22 from __future__
import annotations
24 __all__ = [
"ApdbTest"]
26 from abc
import ABC, abstractmethod
27 from typing
import Any, Optional
33 from lsst.sphgeom import Angle, Circle, Region, UnitVector3d
34 from .data_factory
import makeObjectCatalog, makeForcedSourceCatalog, makeSourceCatalog
38 """Base class for Apdb tests that can be specialized for concrete
41 This can only be used as a mixin class for a unittest.TestCase and it
42 calls various assert methods.
45 time_partition_tables =
False
46 visit_time =
DateTime(
"2021-01-01T00:00:00", DateTime.TAI)
48 fsrc_requires_id_list =
False
49 """Should be set to True if getDiaForcedSources requires object IDs"""
52 n_obj_columns = 91 + 2
53 n_obj_last_columns = 17
59 """Make config class instance used in all tests."""
60 raise NotImplementedError()
64 """Return number of columns for a specified table."""
65 raise NotImplementedError()
68 """Make a region used in tests"""
74 def assert_catalog(self, catalog: Any, rows: int, table: ApdbTables) ->
None:
75 """Validate catalog type and size
80 Expected type of this is ``type``.
82 Expected number of rows in a catalog.
86 self.assertIsInstance(catalog, pandas.DataFrame)
87 self.assertEqual(catalog.shape[0], rows)
88 self.assertEqual(catalog.shape[1], self.
n_columnsn_columns(table))
91 """Test for makeing APDB schema."""
96 self.assertIsNotNone(apdb.tableDef(ApdbTables.DiaObject))
97 self.assertIsNotNone(apdb.tableDef(ApdbTables.DiaObjectLast))
98 self.assertIsNotNone(apdb.tableDef(ApdbTables.DiaSource))
99 self.assertIsNotNone(apdb.tableDef(ApdbTables.DiaForcedSource))
102 """Test for getting data from empty database.
104 All get() methods should return empty results, only useful for
105 checking that code is not broken.
116 res: Optional[pandas.DataFrame]
119 res = apdb.getDiaObjects(region)
123 res = apdb.getDiaSources(region,
None, visit_time)
126 res = apdb.getDiaSources(region, [], visit_time)
130 res = apdb.getDiaSources(region, [1, 2, 3], visit_time)
134 res = apdb.getDiaForcedSources(region, [], visit_time)
135 self.
assert_catalogassert_catalog(res, 0, ApdbTables.DiaForcedSource)
138 res = apdb.getDiaForcedSources(region, [1, 2, 3], visit_time)
139 self.
assert_catalogassert_catalog(res, 0, ApdbTables.DiaForcedSource)
143 with self.assertRaises(NotImplementedError):
144 apdb.getDiaForcedSources(region,
None, visit_time)
146 apdb.getDiaForcedSources(region,
None, visit_time)
147 self.
assert_catalogassert_catalog(res, 0, ApdbTables.DiaForcedSource)
150 """Test for getting data from empty database.
152 All get() methods should return empty DataFrame or None.
156 config = self.
make_configmake_config(read_sources_months=0,
157 read_forced_sources_months=0)
164 res: Optional[pandas.DataFrame]
167 res = apdb.getDiaObjects(region)
171 res = apdb.getDiaSources(region,
None, visit_time)
172 self.assertIs(res,
None)
175 res = apdb.getDiaSources(region, [], visit_time)
176 self.assertIs(res,
None)
179 res = apdb.getDiaForcedSources(region, [], visit_time)
180 self.assertIs(res,
None)
183 """Store and retrieve DiaObjects."""
197 apdb.store(visit_time, catalog)
200 res = apdb.getDiaObjects(region)
201 self.
assert_catalogassert_catalog(res, len(catalog), ApdbTables.DiaObject)
204 """Store and retrieve DiaSources."""
214 oids =
list(objects[
"diaObjectId"])
218 apdb.store(visit_time, objects, sources)
221 res = apdb.getDiaSources(region,
None, visit_time)
222 self.
assert_catalogassert_catalog(res, len(sources), ApdbTables.DiaSource)
225 res = apdb.getDiaSources(region, oids, visit_time)
226 self.
assert_catalogassert_catalog(res, len(sources), ApdbTables.DiaSource)
229 res = apdb.getDiaSources(region, [], visit_time)
233 """Store and retrieve DiaForcedSources."""
244 oids =
list(objects[
"diaObjectId"])
247 apdb.store(visit_time, objects, forced_sources=catalog)
250 res = apdb.getDiaForcedSources(region, oids, visit_time)
251 self.
assert_catalogassert_catalog(res, len(catalog), ApdbTables.DiaForcedSource)
254 res = apdb.getDiaForcedSources(region, [], visit_time)
255 self.
assert_catalogassert_catalog(res, 0, ApdbTables.DiaForcedSource)
258 """Test for time filtering of DiaSources.
266 src_time1 =
DateTime(
"2021-01-01T00:00:00", DateTime.TAI)
267 src_time2 =
DateTime(
"2021-01-01T00:00:02", DateTime.TAI)
268 visit_time0 =
DateTime(
"2021-12-26T23:59:59", DateTime.TAI)
269 visit_time1 =
DateTime(
"2021-12-27T00:00:01", DateTime.TAI)
270 visit_time2 =
DateTime(
"2021-12-27T00:00:03", DateTime.TAI)
273 oids =
list(objects[
"diaObjectId"])
275 apdb.store(src_time1, objects, sources)
278 apdb.store(src_time2, objects, sources)
281 res = apdb.getDiaSources(region, oids, src_time2)
285 res = apdb.getDiaSources(region, oids, visit_time0)
289 res = apdb.getDiaSources(region, oids, visit_time1)
293 res = apdb.getDiaSources(region, oids, visit_time2)
297 """Test for time filtering of DiaForcedSources.
304 src_time1 =
DateTime(
"2021-01-01T00:00:00", DateTime.TAI)
305 src_time2 =
DateTime(
"2021-01-01T00:00:02", DateTime.TAI)
306 visit_time0 =
DateTime(
"2021-12-26T23:59:59", DateTime.TAI)
307 visit_time1 =
DateTime(
"2021-12-27T00:00:01", DateTime.TAI)
308 visit_time2 =
DateTime(
"2021-12-27T00:00:03", DateTime.TAI)
311 oids =
list(objects[
"diaObjectId"])
313 apdb.store(src_time1, objects, forced_sources=sources)
316 apdb.store(src_time2, objects, forced_sources=sources)
319 res = apdb.getDiaForcedSources(region, oids, src_time2)
320 self.
assert_catalogassert_catalog(res, 200, ApdbTables.DiaForcedSource)
323 res = apdb.getDiaForcedSources(region, oids, visit_time0)
324 self.
assert_catalogassert_catalog(res, 200, ApdbTables.DiaForcedSource)
327 res = apdb.getDiaForcedSources(region, oids, visit_time1)
328 self.
assert_catalogassert_catalog(res, 100, ApdbTables.DiaForcedSource)
331 res = apdb.getDiaForcedSources(region, oids, visit_time2)
332 self.
assert_catalogassert_catalog(res, 0, ApdbTables.DiaForcedSource)
Class for handling dates/times, including MJD, UTC, and TAI.
None test_midPointTai_src(self)
int n_columns(self, ApdbTables table)
ApdbConfig make_config(self, **Any kwargs)
None test_empty_gets(self)
None assert_catalog(self, Any catalog, int rows, ApdbTables table)
None test_storeSources(self)
None test_makeSchema(self)
None test_empty_gets_0months(self)
None test_storeForcedSources(self)
None test_midPointTai_fsrc(self)
bool fsrc_requires_id_list
None test_storeObjects(self)
Angle represents an angle in radians.
Circle is a circular region on the unit sphere that contains its boundary.
UnitVector3d is a unit vector in ℝ³ with components stored in double precision.
daf::base::PropertyList * list
Apdb make_apdb(ApdbConfig config)
pandas.DataFrame makeSourceCatalog(pandas.DataFrame objects, DateTime visit_time, int start_id=0, int ccdVisitId=1)
pandas.DataFrame makeObjectCatalog(Region region, int count)
pandas.DataFrame makeForcedSourceCatalog(pandas.DataFrame objects, DateTime visit_time, int ccdVisitId=1)