76 lines
2.7 KiB
Python
76 lines
2.7 KiB
Python
from django.core.management.base import BaseCommand, CommandError
|
|
|
|
from datetime import date
|
|
import datetime
|
|
from django.utils import timezone
|
|
import astropy
|
|
from astropy.io import ascii
|
|
import pandas as pd
|
|
import pymysql
|
|
from sqlalchemy import create_engine
|
|
|
|
from heasarc.tdat import tDat
|
|
from heasarc.models import HeasarcTable, TableColumn, HeasarcObjectClass, NSIDE_SOURCES, ORDER, HeasarcXrayMaster, HeasarcXMMSSC, HeasarcBase
|
|
from srgcat.models import ArtCat, ArtSource
|
|
from astropy.table import Table
|
|
from astropy_healpix import HEALPix, neighbours
|
|
from astropy.coordinates import SkyCoord # High-level coordinates
|
|
from astropy.coordinates import ICRS, Galactic, FK4, FK5 # Low-level frames
|
|
from astropy.coordinates import Angle, Latitude, Longitude # Angles
|
|
import astropy.units as u
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Initiates data dase'
|
|
|
|
# def add_arguments(self, parser):
|
|
# parser.add_argument('poll_id', nargs='+', type=int)
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
radius_cut=30.0
|
|
hp = HEALPix(nside=NSIDE_SOURCES, order=ORDER, frame=FK5())
|
|
|
|
srcs = ArtSource.objects.all() # get(name__contains="J175524.3-260347")
|
|
|
|
for src in srcs:
|
|
print("***",src.name,src.healpix)
|
|
src.heasarc.clear()
|
|
c = SkyCoord(src.ra, src.dec, frame="fk5", unit="deg")
|
|
|
|
"""
|
|
Add central pixel:
|
|
"""
|
|
try:
|
|
heasarcs = HeasarcBase.objects.filter(healpix=src.healpix)#.distinct('srcid')
|
|
except:
|
|
print("healpix not found ", src.healpix)
|
|
continue
|
|
|
|
for heasarc in heasarcs:
|
|
#print(heasarc.name)
|
|
c0 = SkyCoord(heasarc.ra, heasarc.dec, frame="fk5", unit="deg")
|
|
sep=c.separation(c0)
|
|
if(sep.arcsecond < radius_cut):
|
|
src.heasarc.add(heasarc)
|
|
src.save()
|
|
|
|
"""
|
|
Add neighbour pixels:
|
|
"""
|
|
around = neighbours(src.healpix, NSIDE_SOURCES, order=ORDER)
|
|
for index in around:
|
|
try:
|
|
heasarcs = HeasarcBase.objects.filter(healpix=index)#.distinct('srcid')
|
|
except:
|
|
print("healpix not found ", src.healpix)
|
|
continue
|
|
for heasarc in heasarcs:
|
|
#print(heasarc.name)
|
|
c0 = SkyCoord(heasarc.ra, heasarc.dec, frame="fk5", unit="deg")
|
|
sep=c.separation(c0)
|
|
if(sep.arcsecond < radius_cut):
|
|
src.heasarc.add(heasarc)
|
|
src.save()
|
|
|
|
self.stdout.write(self.style.SUCCESS('Done'))
|