22from __future__
import annotations
24__all__ = [
"ApdbConfig",
"Apdb"]
27from abc
import ABC, abstractmethod
28from typing
import Iterable, Mapping, Optional
32from felis.simple
import Table
36from .apdbSchema
import ApdbTables
39def _data_file_name(basename: str) -> str:
40 """Return path name of a data file in sdm_schemas package.
42 return os.path.join(
"${SDM_SCHEMAS_DIR}",
"yml", basename)
46 """Part of Apdb configuration common to all implementations.
48 read_sources_months = Field[int](
49 doc="Number of months of history to read from DiaSource",
52 read_forced_sources_months = Field[int](
53 doc=
"Number of months of history to read from DiaForcedSource",
56 schema_file = Field[str](
57 doc=
"Location of (YAML) configuration file with standard schema",
58 default=_data_file_name(
"apdb.yaml")
60 schema_name = Field[str](
61 doc=
"Name of the schema in YAML configuration file.",
64 extra_schema_file = Field[str](
65 doc=
"Location of (YAML) configuration file with extra schema, "
66 "definitions in this file are merged with the definitions in "
67 "'schema_file', extending or replacing parts of the schema.",
70 deprecated=
"This field is deprecated, its value is not used."
75 """Abstract interface for APDB.
78 ConfigClass = ApdbConfig
81 def tableDef(self, table: ApdbTables) -> Optional[Table]:
82 """Return table schema definition for a given table.
87 One of the known APDB tables.
91 tableSchema : `felis.simple.Table` or `
None`
92 Table schema description, `
None`
is returned
if table
is not
93 defined by this implementation.
95 raise NotImplementedError()
99 """Create or re-create whole database schema.
104 If True then drop all tables before creating new ones.
106 raise NotImplementedError()
110 """Returns catalog of DiaObject instances from a given region.
112 This method returns only the last version of each DiaObject. Some
113 records in a returned catalog may be outside the specified region, it
114 is up to a client to ignore those records
or cleanup the catalog before
120 Region to search
for DIAObjects.
124 catalog : `pandas.DataFrame`
125 Catalog containing DiaObject records
for a region that may be a
126 superset of the specified region.
128 raise NotImplementedError()
132 object_ids: Optional[Iterable[int]],
134 """Return catalog of DiaSource instances from a given region.
139 Region to search for DIASources.
140 object_ids : iterable [ `int` ], optional
141 List of DiaObject IDs to further constrain the set of returned
142 sources. If `
None` then returned sources are
not constrained. If
143 list
is empty then empty catalog
is returned
with a correct
146 Time of the current visit.
150 catalog : `pandas.DataFrame`,
or `
None`
151 Catalog containing DiaSource records. `
None`
is returned
if
152 ``read_sources_months`` configuration parameter
is set to 0.
156 This method returns DiaSource catalog
for a region
with additional
157 filtering based on DiaObject IDs. Only a subset of DiaSource history
158 is returned limited by ``read_sources_months`` config parameter, w.r.t.
159 ``visit_time``. If ``object_ids``
is empty then an empty catalog
is
160 always returned
with the correct schema (columns/types). If
161 ``object_ids``
is `
None` then no filtering
is performed
and some of the
162 returned records may be outside the specified region.
164 raise NotImplementedError()
168 object_ids: Optional[Iterable[int]],
170 """Return catalog of DiaForcedSource instances from a given region.
175 Region to search for DIASources.
176 object_ids : iterable [ `int` ], optional
177 List of DiaObject IDs to further constrain the set of returned
178 sources. If list
is empty then empty catalog
is returned
with a
179 correct schema. If `
None` then returned sources are
not
180 constrained. Some implementations may
not support latter case.
182 Time of the current visit.
186 catalog : `pandas.DataFrame`,
or `
None`
187 Catalog containing DiaSource records. `
None`
is returned
if
188 ``read_forced_sources_months`` configuration parameter
is set to 0.
193 May be raised by some implementations
if ``object_ids``
is `
None`.
197 This method returns DiaForcedSource catalog
for a region
with additional
198 filtering based on DiaObject IDs. Only a subset of DiaSource history
199 is returned limited by ``read_forced_sources_months`` config parameter,
200 w.r.t. ``visit_time``. If ``object_ids``
is empty then an empty catalog
201 is always returned
with the correct schema (columns/types). If
202 ``object_ids``
is `
None` then no filtering
is performed
and some of the
203 returned records may be outside the specified region.
205 raise NotImplementedError()
209 start_time: dafBase.DateTime,
211 region: Optional[Region] =
None) -> pandas.DataFrame:
212 """Returns catalog of DiaObject instances from a given time period
213 including the history of each DiaObject.
218 Starting time for DiaObject history search. DiaObject record
is
219 selected when its ``validityStart`` falls into an interval
220 between ``start_time`` (inclusive)
and ``end_time`` (exclusive).
222 Upper limit on time
for DiaObject history search.
224 Region to search
for DiaObjects,
if not specified then whole sky
225 is searched. If region
is specified then some returned records may
226 fall outside of this region.
230 catalog : `pandas.DataFrame`
231 Catalog containing DiaObject records.
235 This part of API may
not be very stable
and can change before the
236 implementation finalizes.
238 raise NotImplementedError()
242 start_time: dafBase.DateTime,
244 region: Optional[Region] =
None) -> pandas.DataFrame:
245 """Returns catalog of DiaSource instances from a given time period.
250 Starting time for DiaSource history search. DiaSource record
is
251 selected when its ``midPointTai`` falls into an interval between
252 ``start_time`` (inclusive)
and ``end_time`` (exclusive).
254 Upper limit on time
for DiaSource history search.
256 Region to search
for DiaSources,
if not specified then whole sky
257 is searched. If region
is specified then some returned records may
258 fall outside of this region.
262 catalog : `pandas.DataFrame`
263 Catalog containing DiaObject records.
267 This part of API may
not be very stable
and can change before the
268 implementation finalizes.
270 raise NotImplementedError()
274 start_time: dafBase.DateTime,
276 region: Optional[Region] =
None) -> pandas.DataFrame:
277 """Returns catalog of DiaForcedSource instances from a given time
283 Starting time for DiaForcedSource history search. DiaForcedSource
284 record
is selected when its ``midPointTai`` falls into an interval
285 between ``start_time`` (inclusive)
and ``end_time`` (exclusive).
287 Upper limit on time
for DiaForcedSource history search.
289 Region to search
for DiaForcedSources,
if not specified then whole
290 sky
is searched. If region
is specified then some returned records
291 may fall outside of this region.
295 catalog : `pandas.DataFrame`
296 Catalog containing DiaObject records.
300 This part of API may
not be very stable
and can change before the
301 implementation finalizes. Some implementations may
not support region
302 filtering, they will
return records
from the whole sky.
304 raise NotImplementedError()
308 """Returns catalog of SSObject instances.
312 catalog : `pandas.DataFrame`
313 Catalog containing SSObject records, all existing records are
316 raise NotImplementedError()
320 visit_time: dafBase.DateTime,
321 objects: pandas.DataFrame,
322 sources: Optional[pandas.DataFrame] =
None,
323 forced_sources: Optional[pandas.DataFrame] =
None) ->
None:
324 """Store all three types of catalogs in the database.
330 objects : `pandas.DataFrame`
331 Catalog with DiaObject records.
332 sources : `pandas.DataFrame`, optional
333 Catalog
with DiaSource records.
334 forced_sources : `pandas.DataFrame`, optional
335 Catalog
with DiaForcedSource records.
339 This methods takes DataFrame catalogs, their schema must be
340 compatible
with the schema of APDB table:
342 - column names must correspond to database table columns
343 - types
and units of the columns must match database definitions,
344 no unit conversion
is performed presently
345 - columns that have default values
in database schema can be
347 - this method knows how to fill interval-related columns of DiaObject
348 (validityStart, validityEnd) they do
not need to appear
in a
350 - source catalogs have ``diaObjectId`` column associating sources
353 raise NotImplementedError()
357 """Store or update SSObject catalog.
361 objects : `pandas.DataFrame`
362 Catalog with SSObject records.
366 If SSObjects
with matching IDs already exist
in the database, their
367 records will be updated
with the information
from provided records.
369 raise NotImplementedError()
373 """Associate DiaSources with SSObjects, dis-associating them
379 Maps DiaSource IDs to their new SSObject IDs.
384 Raised
if DiaSource ID does
not exist
in the database.
386 raise NotImplementedError()
390 """Implement daily activities like cleanup/vacuum.
392 What should be done during daily activities is determined by
393 specific implementation.
395 raise NotImplementedError()
399 """Return the number of DiaObjects that have only one DiaSource
400 associated with them.
402 Used
as part of ap_verify metrics.
407 Number of DiaObjects
with exactly one associated DiaSource.
411 This method can be very inefficient
or slow
in some implementations.
413 raise NotImplementedError()
417 """Make a `~lsst.pex.config.ConfigurableField` for Apdb.
422 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)
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)
Optional[Table] tableDef(self, ApdbTables table)
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.