107 lines
3.4 KiB
Python
107 lines
3.4 KiB
Python
from django.core.management.base import BaseCommand, CommandError
|
|
|
|
from datetime import date
|
|
from heasarc.models import INPUT_DATA_DIR
|
|
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
|
|
import numpy.ma as ma
|
|
from heasarc.tdat import tDat
|
|
from heasarc.models import HeasarcTable, TableColumn, HeasarcIntegral2020, HeasarcObjectClass
|
|
from heasarc.models import NSIDE_SOURCES, ORDER
|
|
from monthplan.models import NSIDE_PLATES
|
|
from astropy_healpix import HEALPix
|
|
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
|
|
import math
|
|
|
|
def load_heasarc_table(filename):
|
|
|
|
|
|
data = astropy.table.Table.read(filename,format='ascii.csv')
|
|
print(data.info)
|
|
|
|
tables = HeasarcIntegral2020.objects.all()
|
|
tables.delete()
|
|
|
|
|
|
hp = HEALPix(nside=NSIDE_SOURCES, order=ORDER, frame=FK5())
|
|
hp_plate = HEALPix(nside=NSIDE_PLATES, order=ORDER, frame=FK5())
|
|
|
|
|
|
for item in data:
|
|
|
|
#crd = SkyCoord(item['ra'], item['dec'], frame=FK5(), unit="deg")
|
|
#healpix = hp.skycoord_to_healpix(crd)
|
|
|
|
|
|
healpix = 0
|
|
ra = 0.0
|
|
dec = 0.0
|
|
lon = 0.0
|
|
lat = 0.0
|
|
|
|
ra = float(item['RA'])
|
|
dec = float(item['Dec'])
|
|
crd = SkyCoord(ra, dec, frame=FK5(), unit="deg")
|
|
lon = crd.galactic.l.value
|
|
lat = crd.galactic.b.value
|
|
healpix = hp.skycoord_to_healpix(crd)
|
|
healpix_plate = hp_plate.skycoord_to_healpix(crd)
|
|
|
|
|
|
sign=item['SIGN']
|
|
#error_radius = math.sqrt((30.5/sign)**2 + 0.1*0.1)
|
|
""" See Eq. 1 in 2018ApJS..235....4O """
|
|
|
|
error_radius = 2.1*60
|
|
|
|
"""
|
|
if(sign <= 10):
|
|
error_radius = 2.1*60
|
|
elif(sign > 10 and sign <= 20):
|
|
error_radius = 1.5*60
|
|
else:
|
|
error_radius = 0.8*60
|
|
"""
|
|
#print(ra,dec,sign,error_radius)
|
|
#continue
|
|
|
|
P=0.98
|
|
koeff=math.sqrt(-2*math.log(1-P))
|
|
""" makes 90% interval for 2D case """
|
|
|
|
obj = HeasarcIntegral2020.objects.create(healpix=healpix,
|
|
healpix_plate=healpix_plate,
|
|
ra=ra,
|
|
dec=dec,
|
|
lii = lon,
|
|
bii = lat,
|
|
name=item['NAME'],
|
|
error_radius = error_radius*koeff,
|
|
sign = item['SIGN'],
|
|
flux = float(item['FLUX']),
|
|
flux_error = float(item['ERR']),
|
|
ref_id = int(item['ID']))
|
|
|
|
|
|
obj.save()
|
|
|
|
print('--> Successfully loaded "%s"' % filename)
|
|
pass
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Initiates data dase'
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
load_heasarc_table('/export/django/srg/data/integral2020/e0017_0060.joint_20210818-112734.csv')
|
|
|
|
self.stdout.write(self.style.SUCCESS('Done'))
|