class PawprintXTile(db.Model): __tablename__ = "PawprintXTile" __table_args__ = ( db.UniqueConstraint('pawprint_id', 'tile_id', name='_pawprint_tile_uc'), ) statuses = db.Enum( "raw", "pending", "sync", name="pawprint_x_tile_statuses") id = db.Column(db.Integer, db.Sequence('pxt_id_seq'), primary_key=True) pawprint_id = db.Column( db.Integer, db.ForeignKey('Pawprint.id'), nullable=False) pawprint = db.relationship( "Pawprint", backref=db.backref("pxts")) tile_id = db.Column(db.Integer, db.ForeignKey('Tile.id'), nullable=False) tile = db.relationship("Tile", backref=db.backref("pxts")) status = db.Column(statuses, default="raw") def __repr__(self): string = "<PXT '{}: {}'>" return string.format(self.tile.name, self.pawprint.name)
class Match(db.Model): __tablename__ = "Match" __table_args__ = ( db.UniqueConstraint('pawprint_src_id', 'master_src_id', 'tile_id', name='_match_uc'), ) id = db.Column(db.Integer, db.Sequence('match_id_seq'), primary_key=True) band = db.Column( db.Enum("k", "j", "h", name="match, bands"), index=True) tile_id = db.Column( db.Integer, db.ForeignKey('Tile.id'), index=True, nullable=False) tile = db.relationship( "Tile", backref=db.backref("matches"), lazy="joined") master_src_id = db.Column( db.Integer, db.ForeignKey('MasterSource.id'), index=True, nullable=False) master_src = db.relationship( "MasterSource", backref=db.backref("matches"), lazy="joined") master_src_order = db.Column(db.Integer) master_src_ra = db.Column(db.Float) master_src_dec = db.Column(db.Float) pawprint_id = db.Column( db.Integer, db.ForeignKey('Pawprint.id'), index=True, nullable=False) pawprint = db.relationship( "Pawprint", backref=db.backref("matches"), lazy="joined") pawprint_src_id = db.Column( db.Integer, db.ForeignKey('PawprintSource.id'), index=True, nullable=False) pawprint_src = db.relationship( "PawprintSource", backref=db.backref("matches"), lazy="joined") pawprint_src_order = db.Column(db.Integer) pawprint_src_ra = db.Column(db.Float) pawprint_src_dec = db.Column(db.Float) pawprint_src_mag = db.Column(db.Float) pawprint_src_mag_err = db.Column(db.Float) pawprint_src_hjd = db.Column(db.Float, nullable=True) pawprint_src_chip_nro = db.Column(db.Float) pawprint_src_stel_cls = db.Column(db.Float) pawprint_src_elip = db.Column(db.Float) pawprint_src_pos_ang = db.Column(db.Float) tile_id = db.Column( db.Integer, db.ForeignKey('Tile.id'), index=True, nullable=False) tile = db.relationship( "Tile", backref=db.backref("matches"), lazy="joined") def __repr__(self): return u"<Match '{}->{}'>".format(self.master_src, self.pawprint_src)
class PawprintStackXTile(db.Model): """Relation between a pawprint-stack and a tile. Because the virca, overlap some pawprints can be in two tiles """ __tablename__ = "PawprintStackXTile" __table_args__ = (db.UniqueConstraint('pawprint_stack_id', 'tile_id', name='_pawprint_tile_uc'), ) statuses = db.Enum("raw", "ready-to-match", "matched", name="pxt_statuses") id = db.Column(db.Integer, db.Sequence('pxt_id_seq'), primary_key=True) pawprint_stack_id = db.Column(db.Integer, db.ForeignKey('PawprintStack.id'), nullable=False) pawprint_stack = db.relationship("PawprintStack", backref=db.backref("pxts")) tile_id = db.Column(db.Integer, db.ForeignKey('Tile.id'), nullable=False) tile = db.relationship("Tile", backref=db.backref("pxts")) _npy_filename = db.Column("npy_filename", db.Text) matched_number = db.Column(db.Integer, nullable=True) status = db.Column(statuses, default="raw") def __repr__(self): string = "<PXT '{}: {}'>" return string.format(self.tile.name, self.pawprint_stack.name) @property def npy_file_path(self): if self._npy_filename: return os.path.join(settings.MATCHS_DIR, self.tile.name, self._npy_filename) def store_npy_file(self, arr): self._npy_filename = "{}_{}.npy".format(self.tile.name, self.pawprint_stack.name) file_dir = os.path.dirname(self.npy_file_path) if not os.path.isdir(file_dir): os.makedirs(file_dir) np.save(self.npy_file_path, arr) def load_npy_file(self): return np.load(self.npy_file_path)
class Tile(db.Model): """Represent a VVV tile. Can has 3 states: - `raw`: The tile is discovery and only a path to the original path is added - `measures`: The tile know how many sources they has and the serialized version of the file is loaded. - `loaded`: All the sources of the tile are created on *MasterSource* table """ __tablename__ = "Tile" statuses = db.Enum("raw", "measured", "loaded", name="tile_statuses") ready = db.Column(db.Boolean, default=False) id = db.Column(db.Integer, db.Sequence('tile_id_seq'), primary_key=True) name = db.Column(db.String(255), nullable=False, index=True, unique=True) _filename = db.Column("filename", db.Text) data = db.Column(db.PickleType, nullable=True) data_size = db.Column(db.Integer, nullable=True) data_readed = db.Column(db.Integer, nullable=True) status = db.Column(statuses, default="raw") def __repr__(self): return "<Tile '{}'>".format(self.name) def file_path(self): if self._filename: return os.path.join( settings.STORED_TILES_DIR, self._filename) def store_file(self, fpath): self._filename = os.path.basename(fpath) shutil.copyfile(fpath, self.file_path())
class Pawprint(db.Model): __tablename__ = "Pawprint" statuses = db.Enum("raw", "measured", "loaded", name="pawprint_statuses") id = db.Column( db.Integer, db.Sequence('pawprint_id_seq'), primary_key=True) name = db.Column(db.String(255), nullable=False, unique=True) mjd = db.Column(db.Float, nullable=True) data = db.Column(db.PickleType, nullable=True) data_size = db.Column(db.Integer, nullable=True) data_readed = db.Column(db.Integer, nullable=True) _filename = db.Column("filename", db.Text) status = db.Column(statuses, default="raw") def __repr__(self): return "<Pawprint '{}'>".format(repr(self.name)) def file_path(self): if self._filename: yearmonth = self._filename[1:7] day = self._filename[7:9] return os.path.join( settings.STORED_PAWPRINT_DIR, yearmonth, day, self._filename) def store_file(self, fpath): self._filename = os.path.basename(fpath) file_path = self.file_path() file_dir = os.path.dirname(file_path) if not os.path.isdir(file_dir): os.makedirs(file_dir) shutil.copyfile(fpath, file_path)