def __init__(self, db_file): """Create similar configuration for tasks ad in ap_pipe. """ self.log = Log.getLogger("RunAssociation") self.apdbConfig = ApdbConfig() self.apdbConfig.db_url = "sqlite:///" + db_file self.apdbConfig.isolation_level = "READ_UNCOMMITTED" self.apdbConfig.dia_object_index = "baseline" self.apdbConfig.dia_object_columns = [] self.apdbConfig.connection_timeout = 240 self.apdbConfig.schema_file = _data_file_name("apdb-schema.yaml", "dax_apdb") self.apdbConfig.column_map = _data_file_name( "apdb-ap-pipe-afw-map.yaml", "ap_association") self.apdbConfig.extra_schema_file = _data_file_name( "apdb-ap-pipe-schema-extra.yaml", "ap_association") self.apdb = Apdb(config=self.apdbConfig, afw_schemas=dict(DiaObject=make_dia_object_schema(), DiaSource=make_dia_source_schema())) # apdb.makeSchema() self.differencerConfig = ImageDifferenceConfig() # Schema is different if we do decorrelation self.differencerConfig.doDecorrelation = True self.differencerSchema = ImageDifferenceTask( config=self.differencerConfig).schema self.diaSourceDpddifier = MapDiaSourceTask( inputSchema=self.differencerSchema) self.associator = AssociationTask() self.diffType = "deep"
def makeApdb(args=None): """Create an APDB according to a config. The command-line arguments should provide config values or a config file for `ApdbConfig`. Parameters ---------- args : `list` [`str`], optional List of command-line arguments; if `None` use `sys.argv`. Returns ------- apdb : `lsst.dax.apdb.Apdb` The newly configured APDB object. """ parser = ConfigOnlyParser() parsedCmd = parser.parse_args(args=args) apdb = Apdb(config=parsedCmd.config, afw_schemas=dict(DiaObject=make_dia_object_schema(), DiaSource=make_dia_source_schema())) apdb.makeSchema() return apdb
def create_test_points_pandas(point_locs_deg, wcs=None, start_id=0, schema=None, scatter_arcsec=1.0, indexer_ids=None, associated_ids=None): """Create dummy DIASources or DIAObjects for use in our tests. Parameters ---------- point_locs_deg : array-like (N, 2) of `float`s Positions of the test points to create in RA, DEC. wcs : `lsst.afw.geom.SkyWcs` Wcs to convert RA/Dec to x/y if provided. start_id : `int` Unique id of the first object to create. The remaining sources are incremented by one from the first id. schema : `lsst.afw.table.Schema` Schema of the objects to create. Defaults to the DIASource schema. scatter_arcsec : `float` Scatter to add to the position of each DIASource. indexer_ids : `list` of `ints`s Id numbers of pixelization indexer to store. Must be the same length as the first dimension of point_locs_deg. associated_ids : `list` of `ints`s Id numbers of associated DIAObjects to store. Must be the same length as the first dimension of point_locs_deg. Returns ------- test_points : `pandas.DataFrame` Catalog of points to test. """ if schema is None: schema = make_dia_source_schema() sources = afwTable.SourceCatalog(schema) for src_idx, (ra, dec,) in enumerate(point_locs_deg): src = sources.addNew() src['id'] = src_idx + start_id coord = geom.SpherePoint(ra, dec, geom.degrees) if scatter_arcsec > 0.0: coord = coord.offset( np.random.rand() * 360 * geom.degrees, np.random.rand() * scatter_arcsec * geom.arcseconds) if indexer_ids is not None: src['pixelId'] = indexer_ids[src_idx] if associated_ids is not None: src['diaObjectId'] = associated_ids[src_idx] src.setCoord(coord) if wcs is not None: xyCentroid = wcs.skykToPixel(coord) src.set("x", xyCentroid.getX()) src.set("y", xyCentroid.getY()) sources = sources.asAstropy().to_pandas() return sources
def __init__(self, butler, *args, **kwargs): pipeBase.CmdLineTask.__init__(self, *args, **kwargs) self.makeSubtask("ccdProcessor", butler=butler) self.makeSubtask("differencer", butler=butler) self.ppdb = self.config.ppdb.apply( afw_schemas=dict(DiaObject=make_dia_object_schema(), DiaSource=make_dia_source_schema())) self.makeSubtask("diaSourceDpddifier", inputSchema=self.differencer.schema) self.makeSubtask("associator") self.makeSubtask("diaForcedSource")
def __init__(self, initInputs=None, **kwargs): super().__init__(**kwargs) self.apdb = self.config.apdb.apply( afw_schemas=dict(DiaObject=make_dia_object_schema(), DiaSource=make_dia_source_schema())) self.makeSubtask("diaSourceDpddifier", inputSchema=initInputs["diaSourceSchema"].schema) self.makeSubtask("diaCatalogLoader") self.makeSubtask("associator") self.makeSubtask("diaForcedSource") if self.config.doPackageAlerts: self.makeSubtask("alertPackager")
def _roundTripThroughApdb(objects, sources, forcedSources, dateTime): """Run object and source catalogs through the Apdb to get the correct table schemas. Parameters ---------- objects : `pandas.DataFrame` Set of test DiaObjects to round trip. sources : `pandas.DataFrame` Set of test DiaSources to round trip. forcedSources : `pandas.DataFrame` Set of test DiaForcedSources to round trip. dateTime : `datetime.datetime` Time for the Apdb. Returns ------- objects : `pandas.DataFrame` Round tripped objects. sources : `pandas.DataFrame` Round tripped sources. """ tmpFile = tempfile.NamedTemporaryFile() apdbConfig = ApdbConfig() apdbConfig.db_url = "sqlite:///" + tmpFile.name apdbConfig.isolation_level = "READ_UNCOMMITTED" apdbConfig.dia_object_index = "baseline" apdbConfig.dia_object_columns = [] apdbConfig.schema_file = _data_file_name("apdb-schema.yaml", "dax_apdb") apdbConfig.column_map = _data_file_name("apdb-ap-pipe-afw-map.yaml", "ap_association") apdbConfig.extra_schema_file = _data_file_name( "apdb-ap-pipe-schema-extra.yaml", "ap_association") apdb = Apdb(config=apdbConfig, afw_schemas=dict(DiaObject=make_dia_object_schema(), DiaSource=make_dia_source_schema())) apdb.makeSchema() minId = objects["pixelId"].min() maxId = objects["pixelId"].max() diaObjects = apdb.getDiaObjects([[minId, maxId + 1]], return_pandas=True).append(objects) diaSources = apdb.getDiaSources(np.unique(objects["diaObjectId"]), dateTime, return_pandas=True).append(sources) diaForcedSources = apdb.getDiaForcedSources( np.unique(objects["diaObjectId"]), dateTime, return_pandas=True).append(forcedSources) apdb.storeDiaSources(diaSources) apdb.storeDiaForcedSources(diaForcedSources) apdb.storeDiaObjects(diaObjects, dateTime) diaObjects = apdb.getDiaObjects([[minId, maxId + 1]], return_pandas=True) diaSources = apdb.getDiaSources(np.unique(diaObjects["diaObjectId"]), dateTime, return_pandas=True) diaForcedSources = apdb.getDiaForcedSources(np.unique( diaObjects["diaObjectId"]), dateTime, return_pandas=True) diaObjects.set_index("diaObjectId", drop=False, inplace=True) diaSources.set_index(["diaObjectId", "filterName", "diaSourceId"], drop=False, inplace=True) diaForcedSources.set_index(["diaObjectId"], drop=False, inplace=True) return (diaObjects, diaSources, diaForcedSources)