22from __future__
import annotations
24__all__ = [
"ApdbConfig",
"Apdb"]
26from abc
import ABC, abstractmethod
29from typing
import Iterable, Mapping, Optional
34from .apdbSchema
import ApdbTables, TableDef
37def _data_file_name(basename: str) -> str:
38 """Return path name of a data file in sdm_schemas package.
40 return os.path.join(
"${SDM_SCHEMAS_DIR}",
"yml", basename)
44 """Part of Apdb configuration common to all implementations.
48 doc="Number of months of history to read from DiaSource",
51 read_forced_sources_months =
Field(
53 doc=
"Number of months of history to read from DiaForcedSource",
58 doc=
"Location of (YAML) configuration file with standard schema",
59 default=_data_file_name(
"apdb.yaml")
63 doc=
"Name of the schema in YAML configuration file.",
68 doc=
"Location of (YAML) configuration file with extra schema, "
69 "definitions in this file are merged with the definitions in "
70 "'schema_file', extending or replacing parts of the schema.",
73 deprecated=
"This field is deprecated, its value is not used."
78 """Abstract interface for APDB.
81 ConfigClass = ApdbConfig
84 def tableDef(self, table: ApdbTables) -> Optional[TableDef]:
85 """Return table schema definition for a given table.
90 One of the known APDB tables.
94 tableSchema : `TableDef` or `
None`
95 Table schema description, `
None`
is returned
if table
is not
96 defined by this implementation.
98 raise NotImplementedError()
102 """Create or re-create whole database schema.
107 If True then drop all tables before creating new ones.
109 raise NotImplementedError()
113 """Returns catalog of DiaObject instances from a given region.
115 This method returns only the last version of each DiaObject. Some
116 records in a returned catalog may be outside the specified region, it
117 is up to a client to ignore those records
or cleanup the catalog before
123 Region to search
for DIAObjects.
127 catalog : `pandas.DataFrame`
128 Catalog containing DiaObject records
for a region that may be a
129 superset of the specified region.
131 raise NotImplementedError()
135 object_ids: Optional[Iterable[int]],
137 """Return catalog of DiaSource instances from a given region.
142 Region to search for DIASources.
143 object_ids : iterable [ `int` ], optional
144 List of DiaObject IDs to further constrain the set of returned
145 sources. If `
None` then returned sources are
not constrained. If
146 list
is empty then empty catalog
is returned
with a correct
149 Time of the current visit.
153 catalog : `pandas.DataFrame`,
or `
None`
154 Catalog containing DiaSource records. `
None`
is returned
if
155 ``read_sources_months`` configuration parameter
is set to 0.
159 This method returns DiaSource catalog
for a region
with additional
160 filtering based on DiaObject IDs. Only a subset of DiaSource history
161 is returned limited by ``read_sources_months`` config parameter, w.r.t.
162 ``visit_time``. If ``object_ids``
is empty then an empty catalog
is
163 always returned
with the correct schema (columns/types). If
164 ``object_ids``
is `
None` then no filtering
is performed
and some of the
165 returned records may be outside the specified region.
167 raise NotImplementedError()
171 object_ids: Optional[Iterable[int]],
173 """Return catalog of DiaForcedSource instances from a given region.
178 Region to search for DIASources.
179 object_ids : iterable [ `int` ], optional
180 List of DiaObject IDs to further constrain the set of returned
181 sources. If list
is empty then empty catalog
is returned
with a
182 correct schema. If `
None` then returned sources are
not
183 constrained. Some implementations may
not support latter case.
185 Time of the current visit.
189 catalog : `pandas.DataFrame`,
or `
None`
190 Catalog containing DiaSource records. `
None`
is returned
if
191 ``read_forced_sources_months`` configuration parameter
is set to 0.
196 May be raised by some implementations
if ``object_ids``
is `
None`.
200 This method returns DiaForcedSource catalog
for a region
with additional
201 filtering based on DiaObject IDs. Only a subset of DiaSource history
202 is returned limited by ``read_forced_sources_months`` config parameter,
203 w.r.t. ``visit_time``. If ``object_ids``
is empty then an empty catalog
204 is always returned
with the correct schema (columns/types). If
205 ``object_ids``
is `
None` then no filtering
is performed
and some of the
206 returned records may be outside the specified region.
208 raise NotImplementedError()
212 start_time: dafBase.DateTime,
214 region: Optional[Region] =
None) -> pandas.DataFrame:
215 """Returns catalog of DiaObject instances from a given time period
216 including the history of each DiaObject.
221 Starting time for DiaObject history search. DiaObject record
is
222 selected when its ``validityStart`` falls into an interval
223 between ``start_time`` (inclusive)
and ``end_time`` (exclusive).
225 Upper limit on time
for DiaObject history search.
227 Region to search
for DiaObjects,
if not specified then whole sky
228 is searched. If region
is specified then some returned records may
229 fall outside of this region.
233 catalog : `pandas.DataFrame`
234 Catalog containing DiaObject records.
238 This part of API may
not be very stable
and can change before the
239 implementation finalizes.
241 raise NotImplementedError()
245 start_time: dafBase.DateTime,
247 region: Optional[Region] =
None) -> pandas.DataFrame:
248 """Returns catalog of DiaSource instances from a given time period.
253 Starting time for DiaSource history search. DiaSource record
is
254 selected when its ``midPointTai`` falls into an interval between
255 ``start_time`` (inclusive)
and ``end_time`` (exclusive).
257 Upper limit on time
for DiaSource history search.
259 Region to search
for DiaSources,
if not specified then whole sky
260 is searched. If region
is specified then some returned records may
261 fall outside of this region.
265 catalog : `pandas.DataFrame`
266 Catalog containing DiaObject records.
270 This part of API may
not be very stable
and can change before the
271 implementation finalizes.
273 raise NotImplementedError()
277 start_time: dafBase.DateTime,
279 region: Optional[Region] =
None) -> pandas.DataFrame:
280 """Returns catalog of DiaForcedSource instances from a given time
286 Starting time for DiaForcedSource history search. DiaForcedSource
287 record
is selected when its ``midPointTai`` falls into an interval
288 between ``start_time`` (inclusive)
and ``end_time`` (exclusive).
290 Upper limit on time
for DiaForcedSource history search.
292 Region to search
for DiaForcedSources,
if not specified then whole
293 sky
is searched. If region
is specified then some returned records
294 may fall outside of this region.
298 catalog : `pandas.DataFrame`
299 Catalog containing DiaObject records.
303 This part of API may
not be very stable
and can change before the
304 implementation finalizes. Some implementations may
not support region
305 filtering, they will
return records
from the whole sky.
307 raise NotImplementedError()
311 """Returns catalog of SSObject instances.
315 catalog : `pandas.DataFrame`
316 Catalog containing SSObject records, all existing records are
319 raise NotImplementedError()
323 visit_time: dafBase.DateTime,
324 objects: pandas.DataFrame,
325 sources: Optional[pandas.DataFrame] =
None,
326 forced_sources: Optional[pandas.DataFrame] =
None) ->
None:
327 """Store all three types of catalogs in the database.
333 objects : `pandas.DataFrame`
334 Catalog with DiaObject records.
335 sources : `pandas.DataFrame`, optional
336 Catalog
with DiaSource records.
337 forced_sources : `pandas.DataFrame`, optional
338 Catalog
with DiaForcedSource records.
342 This methods takes DataFrame catalogs, their schema must be
343 compatible
with the schema of APDB table:
345 - column names must correspond to database table columns
346 - types
and units of the columns must match database definitions,
347 no unit conversion
is performed presently
348 - columns that have default values
in database schema can be
350 - this method knows how to fill interval-related columns of DiaObject
351 (validityStart, validityEnd) they do
not need to appear
in a
353 - source catalogs have ``diaObjectId`` column associating sources
356 raise NotImplementedError()
360 """Store or update SSObject catalog.
364 objects : `pandas.DataFrame`
365 Catalog with SSObject records.
369 If SSObjects
with matching IDs already exist
in the database, their
370 records will be updated
with the information
from provided records.
372 raise NotImplementedError()
376 """Associate DiaSources with SSObjects, dis-associating them
382 Maps DiaSource IDs to their new SSObject IDs.
387 Raised
if DiaSource ID does
not exist
in the database.
389 raise NotImplementedError()
393 """Implement daily activities like cleanup/vacuum.
395 What should be done during daily activities is determined by
396 specific implementation.
398 raise NotImplementedError()
402 """Return the number of DiaObjects that have only one DiaSource
403 associated with them.
405 Used
as part of ap_verify metrics.
410 Number of DiaObjects
with exactly one associated DiaSource.
414 This method can be very inefficient
or slow
in some implementations.
416 raise NotImplementedError()
420 """Make a `~lsst.pex.config.ConfigurableField` for Apdb.
425 Help text for the field.
Class for handling dates/times, including MJD, UTC, and TAI.
ConfigurableField makeField(cls, str doc)
Optional[pandas.DataFrame] getDiaSources(self, Region region, Optional[Iterable[int]] object_ids, dafBase.DateTime visit_time)
Optional[TableDef] tableDef(self, ApdbTables table)
pandas.DataFrame getDiaSourcesHistory(self, dafBase.DateTime start_time, dafBase.DateTime end_time, Optional[Region] region=None)
None store(self, dafBase.DateTime visit_time, pandas.DataFrame objects, Optional[pandas.DataFrame] sources=None, Optional[pandas.DataFrame] forced_sources=None)
pandas.DataFrame getSSObjects(self)
pandas.DataFrame getDiaObjects(self, Region region)
Optional[pandas.DataFrame] getDiaForcedSources(self, Region region, Optional[Iterable[int]] object_ids, dafBase.DateTime visit_time)
None makeSchema(self, bool drop=False)
pandas.DataFrame getDiaForcedSourcesHistory(self, dafBase.DateTime start_time, dafBase.DateTime end_time, Optional[Region] region=None)
pandas.DataFrame getDiaObjectsHistory(self, dafBase.DateTime start_time, dafBase.DateTime end_time, Optional[Region] region=None)
None storeSSObjects(self, pandas.DataFrame objects)
int countUnassociatedObjects(self)
None reassignDiaSources(self, Mapping[int, int] idMap)
Region is a minimal interface for 2-dimensional regions on the unit sphere.