128 lines
5.4 KiB
Python
Executable File
128 lines
5.4 KiB
Python
Executable File
from django.db import models
|
|
from django.contrib.auth.models import User
|
|
from astropy.coordinates import SkyCoord
|
|
from polymorphic.models import PolymorphicModel
|
|
import datetime
|
|
|
|
class GenericCatalog(PolymorphicModel):
|
|
""" Base class for eRosita daily source list """
|
|
name = models.CharField(max_length=51, blank=True)
|
|
""" Unique ObsID """
|
|
nsource = models.IntegerField(default=0)
|
|
""" Number of sources in catalog """
|
|
created = models.DateTimeField(auto_now_add=True)
|
|
""" Date and time of creation. Fully automatic. """
|
|
modified = models.DateTimeField(auto_now=True)
|
|
""" Date and time of the last modification. Fully automatic. """
|
|
start = models.DateTimeField(blank=True)
|
|
""" Start date and time """
|
|
stop = models.DateTimeField(blank=True)
|
|
""" Stop date and time """
|
|
mjd_start = models.FloatField(default=0.0)
|
|
""" MJD start """
|
|
mjd_stop = models.FloatField(default=0.0)
|
|
""" MJD stop """
|
|
ordering = ['-mjd_start',]
|
|
tfield = models.FloatField(default=0.0)
|
|
|
|
class GenericCatalogsGroup(models.Model):
|
|
name = models.CharField(max_length=51, blank=True)
|
|
catalog = models.ManyToManyField(GenericCatalog) #, on_delete=models.CASCADE)
|
|
|
|
|
|
class GenericSource(PolymorphicModel):
|
|
"""
|
|
General class for a source, described with two sets of spherical coordinates (assumed fk5 and Gal)
|
|
some overhead, appended here is softxflux - which is useless for sources, obtained not in X-ray flux
|
|
but very helpfull for X-ray transient search
|
|
"""
|
|
catalog = models.ManyToManyField(GenericCatalog) #, on_delete=models.CASCADE)
|
|
healpix = models.BigIntegerField(db_index=True, default=0)
|
|
healpix_plate = models.IntegerField(db_index=True, default=0)
|
|
src_class = models.CharField(max_length=21, default="")
|
|
ra = models.FloatField(default=0.0)
|
|
""" Right Ascension of the Source """
|
|
dec = models.FloatField(default=0.0)
|
|
""" Declination of the Source """
|
|
lii = models.FloatField(default=0.0)
|
|
""" Galactic Longitude """
|
|
bii = models.FloatField(default=0.0)
|
|
""" Galactic Latitude """
|
|
error_radius = models.FloatField(default=0.0)
|
|
""" Positional Uncertainty (arcsec) """
|
|
sxflux = models.FloatField(default=0.0)
|
|
""" x-ray flux in 0.5-2 keV (required for transients search)"""
|
|
mjdobs = models.FloatField(default=0.0)
|
|
""" observation date in mjd """
|
|
connections = models.ManyToManyField("self", through="GenericConnection",
|
|
symmetrical=False)
|
|
|
|
name = models.CharField(max_length=50,blank=True, default='')
|
|
""" Source name """
|
|
def description(self):
|
|
return self.__class__.__name__
|
|
|
|
def get_absolute_url(self):
|
|
return "/genericsource/%i/source" % (self.pk)
|
|
|
|
def add_neighbours(self, obj):
|
|
sc = SkyCoord(self.ra, self.dec, unit="deg", frame="fk5")
|
|
if issubclass(type(obj), GenericSource): obj = [obj,]
|
|
for src in obj:
|
|
scother = SkyCoord(src.ra, src.dec, unit="deg", frame="fk5")
|
|
GenericConnection(connectto=self, connected=src,
|
|
separation=sc.separation(scother).arcsec).save()
|
|
GenericConnection(connectto=src, connected=self,
|
|
separation=sc.separation(scother).arcsec).save()
|
|
|
|
class GenericConnection(models.Model):
|
|
connectto = models.ForeignKey(GenericSource, on_delete=models.CASCADE, related_name="connectto")
|
|
connected = models.ForeignKey(GenericSource, on_delete=models.CASCADE, related_name="connected")
|
|
separation = models.FloatField(default=0.)
|
|
probability = models.FloatField(default=1.)
|
|
class Meta:
|
|
unique_together = ('connectto', 'connected')
|
|
|
|
class SourceComment(models.Model):
|
|
src = models.ForeignKey(GenericSource, on_delete=models.CASCADE)
|
|
author = models.ForeignKey(User, on_delete=models.CASCADE)
|
|
created = models.DateTimeField(auto_now_add=True)
|
|
text = models.TextField(max_length=1000)
|
|
class Meta:
|
|
ordering = ["created", ]
|
|
|
|
class ConnectionComment(models.Model):
|
|
connection = models.ForeignKey(GenericConnection, on_delete=models.CASCADE)
|
|
text = models.TextField(max_length=1000)
|
|
|
|
class CatalogComment(models.Model):
|
|
catalog = models.ForeignKey(GenericCatalog, on_delete=models.CASCADE)
|
|
text = models.TextField(max_length=10000)
|
|
|
|
class SrcAuxDATA(models.Model):
|
|
src = models.OneToOneField(GenericSource, on_delete=models.CASCADE)
|
|
spec = models.CharField(max_length=101, default="")
|
|
specimg = models.CharField(max_length=101, default="")
|
|
arf = models.CharField(max_length=101, default="")
|
|
rmf = models.CharField(max_length=101, default="")
|
|
bkg = models.CharField(max_length=101, default="")
|
|
img = models.CharField(max_length=101, default="")
|
|
reg = models.CharField(max_length=101, default="")
|
|
log = models.CharField(max_length=101, default="")
|
|
xcm = models.CharField(max_length=101, default="")
|
|
lcfits = models.CharField(max_length=101, default="")
|
|
lcpdf = models.CharField(max_length=101, default="")
|
|
gamma = models.FloatField(default=0.)
|
|
gammaeu = models.FloatField(default=0.)
|
|
gammael = models.FloatField(default=0.)
|
|
nh = models.FloatField(default=0.)
|
|
norm = models.FloatField(default=0.)
|
|
|
|
|
|
class GSBibliogrpahy(models.Model):
|
|
title = models.CharField(max_length=1000, default="")
|
|
code = models.CharField(max_length=100, default="")
|
|
addedby = models.ForeignKey(User, on_delete=models.CASCADE)
|
|
addedat = models.DateTimeField(auto_now_add=True)
|
|
srcs = models.ManyToManyField(GenericSource)
|