Ejemplo n.º 1
0
    def test_storeForcedSources(self):
        """Store and retrieve DiaForcedSources."""

        config = PpdbConfig(db_url="sqlite:///",
                            isolation_level="READ_UNCOMMITTED",
                            read_sources_months=12,
                            read_forced_sources_months=12)
        ppdb = Ppdb(config)
        ppdb.makeSchema()

        pixel_ranges = _makePixelRanges()
        visit_time = datetime.datetime.now()

        # have to store Objects first
        if self.use_pandas:
            objects = _makeObjectCatalogPandas(pixel_ranges)
            catalog, oids = _makeForcedSourceCatalogPandas(objects)
        else:
            objects = _makeObjectCatalog(pixel_ranges)
            catalog, oids = _makeForcedSourceCatalog(objects)

        ppdb.storeDiaObjects(objects, visit_time)

        # save them
        ppdb.storeDiaForcedSources(catalog)

        # read it back and check sizes
        res = ppdb.getDiaForcedSources(oids, visit_time, return_pandas=self.use_pandas)
        self._assertCatalog(res, len(catalog), type=self.data_type)
Ejemplo n.º 2
0
    def test_storeObjectsLast(self):
        """Store and retrieve DiaObjects using DiaObjectLast table."""
        # don't care about sources.
        config = PpdbConfig(db_url="sqlite:///",
                            isolation_level="READ_UNCOMMITTED",
                            dia_object_index="last_object_table",
                            object_last_replace=True)
        ppdb = Ppdb(config)
        ppdb.makeSchema()

        pixel_ranges = _makePixelRanges()
        visit_time = datetime.datetime.now()

        # make afw catalog with Objects
        if self.use_pandas:
            catalog = _makeObjectCatalogPandas(pixel_ranges)
        else:
            catalog = _makeObjectCatalog(pixel_ranges)

        # store catalog
        ppdb.storeDiaObjects(catalog, visit_time)

        # read it back and check sizes
        res = ppdb.getDiaObjects(pixel_ranges, return_pandas=self.use_pandas)
        self._assertCatalog(res, len(catalog), type=self.data_type)
Ejemplo n.º 3
0
    def test_emptyGetsBaseline0months(self):
        """Test for getting data from empty database.

        All get() methods should return empty results, only useful for
        checking that code is not broken.
        """

        # set read_sources_months to 0 so that Forced/Sources are None
        config = PpdbConfig(db_url="sqlite:///",
                            isolation_level="READ_UNCOMMITTED",
                            read_sources_months=0,
                            read_forced_sources_months=0)
        ppdb = Ppdb(config)
        ppdb.makeSchema()

        pixel_ranges = _makePixelRanges()
        visit_time = datetime.datetime.now()

        # get objects by region
        res = ppdb.getDiaObjects(pixel_ranges, return_pandas=self.use_pandas)
        self._assertCatalog(res, 0, type=self.data_type)

        # get sources by region
        res = ppdb.getDiaSourcesInRegion(pixel_ranges, visit_time, return_pandas=self.use_pandas)
        self.assertIs(res, None)

        # get sources by object ID, empty object list
        res = ppdb.getDiaSources([], visit_time, return_pandas=self.use_pandas)

        # get forced sources by object ID, empty object list
        res = ppdb.getDiaForcedSources([], visit_time, return_pandas=self.use_pandas)
        self.assertIs(res, None)
Ejemplo n.º 4
0
 def test_makeSchema(self):
     """Test for making an instance of Ppdb using in-memory sqlite engine.
     """
     # sqlite does not support default READ_COMMITTED, for in-memory
     # database have to use connection pool
     config = PpdbConfig(db_url="sqlite://",
                         isolation_level="READ_UNCOMMITTED")
     ppdb = Ppdb(config)
     # the essence of a test here is that there are no exceptions.
     ppdb.makeSchema()
 def setUp(self):
     self.ppdbCfg = PpdbConfig()
     # Create DB in memory.
     self.ppdbCfg.db_url = 'sqlite://'
     self.ppdbCfg.isolation_level = "READ_UNCOMMITTED"
     self.ppdbCfg.dia_object_index = "baseline"
     self.ppdbCfg.dia_object_columns = []
     self.ppdb = Ppdb(
         config=self.ppdbCfg,
         afw_schemas=dict(DiaObject=afwTable.SourceTable.makeMinimalSchema(),
                          DiaSource=afwTable.SourceTable.makeMinimalSchema()))
     self.ppdb._schema.makeSchema()
Ejemplo n.º 6
0
    def test_emptyGetsObjectLast(self):
        """Test for getting DiaObjects from empty database using DiaObjectLast
        table.

        All get() methods should return empty results, only useful for
        checking that code is not broken.
        """

        # don't care about sources.
        config = PpdbConfig(db_url="sqlite:///",
                            isolation_level="READ_UNCOMMITTED",
                            dia_object_index="last_object_table")
        ppdb = Ppdb(config)
        ppdb.makeSchema()

        pixel_ranges = _makePixelRanges()

        # get objects by region
        res = ppdb.getDiaObjects(pixel_ranges, return_pandas=self.use_pandas)
        self._assertCatalog(res, 0, type=self.data_type)
 def _dummyPpdbConfig():
     config = PpdbConfig()
     config.db_url = "sqlite://"  # in-memory DB
     config.isolation_level = "READ_UNCOMMITTED"
     return config