81 lines
2.4 KiB
Python
81 lines
2.4 KiB
Python
from django.core.management.base import BaseCommand, CommandError
|
|
from django.db.models import F, Q
|
|
|
|
from datetime import date
|
|
import datetime
|
|
from django.utils import timezone
|
|
import astropy
|
|
from astropy.io import ascii
|
|
import pandas as pd
|
|
import pymysql
|
|
import numpy as np
|
|
from sqlalchemy import create_engine
|
|
from astropy import units as u
|
|
from astropy.coordinates import SkyCoord
|
|
from astropy.coordinates import ICRS, Galactic, FK5
|
|
from astropy_healpix import HEALPix, neighbours
|
|
|
|
from heasarc.models import HeasarcBase
|
|
from artsurvey.models import ArtSurveySource, ArtSurvey, EnergyBand
|
|
from astrobasis.models import GAIADR2
|
|
from srglib.utils import find_counterparts
|
|
from srglib.utils import crossmatch
|
|
from srglib.utils import transfer
|
|
from heasarc.models import NSIDE_SOURCES, ORDER
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
|
|
|
""" arcsecond """
|
|
minrad=40.0
|
|
maxdist=120.0
|
|
survey1=1.1
|
|
survey2=12.1
|
|
sig_min=0.0
|
|
sig_max=1000.0
|
|
print('***')
|
|
print("*** Filter: sig_min={} sig_max={} minrad={:.1f}'' maxdist={}'' ***".format(sig_min,sig_max,minrad,maxdist))
|
|
print('***')
|
|
|
|
try:
|
|
band = EnergyBand.objects.get(slug='E0')
|
|
except EnergyBand.DoesNotExist:
|
|
print("EnergyBand bot found")
|
|
return
|
|
|
|
print("use EnergyBand {}".format(band))
|
|
|
|
|
|
|
|
try:
|
|
s1 = ArtSurvey.objects.get(version=survey1)
|
|
except ArtSurvey.DoesNotExist:
|
|
print("ArtSurvey {} not found".format(survey1))
|
|
return
|
|
|
|
try:
|
|
s2 = ArtSurvey.objects.get(version=survey2)
|
|
except ArtSurvey.DoesNotExist:
|
|
print("ArtSurvey {} not found".format(survey2))
|
|
return
|
|
|
|
srcs1=s1.artsurveysource_set.all().filter(band=band).filter(Q(sig__gt=sig_min) & Q(sig__lt=sig_max))
|
|
srcs2=s2.artsurveysource_set.all().filter(band=band).filter(Q(sig__gt=sig_min) & Q(sig__lt=sig_max))
|
|
|
|
print("use ArtSurvey {} nrows={}".format(s1, srcs1.count()))
|
|
print("use ArtSurvey {} nrows={}".format(s2, srcs2.count()))
|
|
match_count=transfer(srcs1, srcs2, minrad=minrad, maxdist=maxdist)
|
|
print("Total matched {}".format(match_count))
|
|
|
|
self.stdout.write(self.style.SUCCESS('Done'))
|