def testCodec(self):
     p = ConvexPolygon(
         [UnitVector3d.Z(),
          UnitVector3d.X(),
          UnitVector3d.Y()])
     s = p.encode()
     self.assertEqual(ConvexPolygon.decode(s), p)
     self.assertEqual(Region.decode(s), p)
Example #2
0
 def test_codec(self):
     e = Ellipse(UnitVector3d.X(), UnitVector3d.Y(), Angle(2 * math.pi / 3))
     s = e.encode()
     self.assertEqual(Ellipse.decode(s), e)
     self.assertEqual(Region.decode(s), e)
 def testCodec(self):
     p = ConvexPolygon([UnitVector3d.Z(), UnitVector3d.X(), UnitVector3d.Y()])
     s = p.encode()
     self.assertEqual(ConvexPolygon.decode(s), p)
     self.assertEqual(ConvexPolygon.cast(Region.decode(s)), p)
Example #4
0
 def test_codec(self):
     b = Box.fromRadians(0, 0, 1, 1)
     s = b.encode()
     self.assertEqual(Box.decode(s), b)
     self.assertEqual(Region.decode(s), b)
Example #5
0
 def test_codec(self):
     c = Circle(UnitVector3d.Y(), 1.0)
     s = c.encode()
     self.assertEqual(Circle.decode(s), c)
     self.assertEqual(Region.decode(s), c)
Example #6
0
 def process_result_value(
         self, value: Optional[str],
         dialect: sqlalchemy.engine.Dialect) -> Optional[Region]:
     if value is None:
         return None
     return Region.decode(super().process_result_value(value, dialect))
Example #7
0
    def visit(self,
              db: Apdb,
              visit_id: int,
              dt: DateTime,
              region: Region,
              sources: numpy.ndarray,
              indices: numpy.ndarray,
              tile: Optional[Tuple[int, int]] = None) -> None:
        """AP processing of a single visit (with known sources)

        Parameters
        ----------
        db : `Apdb`
            APDB interface
        visit_id : `int`
            Visit ID.
        dt : `DateTime`
            Time of visit
        region : `sphgeom.Region`
            Region, could be the whole FOV (Circle) or small piece of it
        sources : `numpy.array`
            Array of xyz coordinates of sources, this has all visit sources,
            not only current tile
        indices : `numpy.array`
            array of indices of sources, 1-dim ndarray, transient sources
            have negative indices
        tile : `tuple`
            tile position (x, y)
        """

        name = ""
        if tile is not None:
            name = "tile={}x{} ".format(*tile)

        src_read_period = self.config.src_read_period
        src_read_visits = round(self.config.src_read_period *
                                self.config.src_read_duty_cycle)
        do_read_src = visit_id % src_read_period < src_read_visits

        # make a mask
        for i in range(len(sources)):
            xyz = sources[i]
            if not region.contains(UnitVector3d(xyz[0], xyz[1], xyz[2])):
                indices[i] = _OUTSIDER

        with timer.Timer(name + "Objects-read"):

            # Retrieve DiaObjects (latest versions) from database for matching,
            # this will produce wider coverage so further filtering is needed
            latest_objects = db.getDiaObjects(region)
            _LOG.info(name + 'database found %s objects',
                      _nrows(latest_objects))

            # filter database objects to a mask
            latest_objects = self._filterDiaObjects(latest_objects, region)
            _LOG.info(name + 'after filtering %s objects',
                      _nrows(latest_objects))

        with timer.Timer(name + "S2O-matching"):

            # create all new DiaObjects
            objects = self._makeDiaObjects(sources, indices, dt)

            # make all sources
            srcs = self._makeDiaSources(sources, indices, dt, visit_id)

            # do forced photometry (can extends objects)
            fsrcs, objects = self._forcedPhotometry(objects, latest_objects,
                                                    dt, visit_id)

            if self.config.fill_empty_fields:
                self._fillRandomData(objects, ApdbTables.DiaObject, db)
                self._fillRandomData(srcs, ApdbTables.DiaSource, db)
                self._fillRandomData(fsrcs, ApdbTables.DiaForcedSource, db)

        if do_read_src:
            with timer.Timer(name + "Source-read"):

                latest_objects_ids = list(latest_objects['diaObjectId'])

                read_srcs = db.getDiaSources(region, latest_objects_ids, dt)
                _LOG.info(name + 'database found %s sources',
                          _nrows(read_srcs))

                read_srcs = db.getDiaForcedSources(region, latest_objects_ids,
                                                   dt)
                _LOG.info(name + 'database found %s forced sources',
                          _nrows(read_srcs))
        else:
            _LOG.info("skipping reading of sources for this visit")

        if not self.args.no_update:

            with timer.Timer(name + "L1-store"):

                # store new versions of objects
                _LOG.info(name + 'will store %d Objects', len(objects))
                _LOG.info(name + 'will store %d Sources', len(srcs))
                _LOG.info(name + 'will store %d ForcedSources', len(fsrcs))
                db.store(dt, objects, srcs, fsrcs)