177 lines
4.0 KiB
Python
177 lines
4.0 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 django.db.models import Q
|
|
|
|
from heasarc.models import HeasarcBase
|
|
from artsurvey.models import ArtSurveySource, ArtSurvey
|
|
from artsurvey.models import EnergyBand
|
|
|
|
from srglib.utils import load_vizier_nvss
|
|
from srglib.utils import load_vizier_first
|
|
from srglib.utils import load_vizier_sumss
|
|
from astrobasis.models import GAIADR3
|
|
from srglib.utils import find_counterparts
|
|
from srglib.utils import load_vizier_allwise
|
|
from srglib.utils import load_simbad_for_skymap_sources
|
|
|
|
from heasarc.models import HeasarcSwiftBAT105m
|
|
from heasarc.models import HeasarcXMMSL2
|
|
from heasarc.models import Heasarc4FGL
|
|
from heasarc.models import HeasarcIntegral2020, HeasarcMAXI7YR, HeasarcRASS2RXS
|
|
|
|
def do_all(survey_version,slug, log_ml_nfalse=None):
|
|
minrad=40
|
|
maxdist=600
|
|
|
|
#minrad=180
|
|
#maxdist=640
|
|
|
|
try:
|
|
band = EnergyBand.objects.get(slug=slug)
|
|
except EnergyBand.DoesNotExist:
|
|
print("EnergyBand bot found")
|
|
return
|
|
|
|
|
|
try:
|
|
survey = ArtSurvey.objects.get(version=survey_version)
|
|
print("use ArtSurvey {}".format(survey))
|
|
except ArtSurvey.DoesNotExist:
|
|
print("ArtSurvey {} not found".format(survey_version))
|
|
return
|
|
|
|
|
|
srcs = survey.artsurveysource_set.all().filter(band=band).filter(log_ml_nfalse__lte=log_ml_nfalse)
|
|
|
|
for src in srcs:
|
|
src.xrays=False
|
|
src.save()
|
|
|
|
SwiftBAT105m=0
|
|
XMMSL2=0
|
|
FGL=0
|
|
Integral2020=0
|
|
MAXI7YR=0
|
|
RASS2RXS=0
|
|
for src in srcs:
|
|
heasarcs = src.heasarc.all()
|
|
#if not (heasarcs.count()):
|
|
# continue
|
|
|
|
if (heasarcs.filter(instance_of=HeasarcSwiftBAT105m).count()):
|
|
SwiftBAT105m+=1
|
|
src.xrays=True
|
|
src.save()
|
|
|
|
if (heasarcs.filter(instance_of=HeasarcXMMSL2).count()):
|
|
XMMSL2+=1
|
|
src.xrays=True
|
|
src.save()
|
|
|
|
if (heasarcs.filter(instance_of=Heasarc4FGL).count()):
|
|
FGL+=1
|
|
src.xrays=True
|
|
src.save()
|
|
|
|
if (heasarcs.filter(instance_of=HeasarcIntegral2020).count()):
|
|
Integral2020+=1
|
|
src.xrays=True
|
|
src.save()
|
|
|
|
if (heasarcs.filter(instance_of=HeasarcMAXI7YR).count()):
|
|
MAXI7YR+=1
|
|
src.xrays=True
|
|
src.save()
|
|
|
|
if (heasarcs.filter(instance_of=HeasarcRASS2RXS).count()):
|
|
RASS2RXS+=1
|
|
src.xrays=True
|
|
src.save()
|
|
|
|
print("{} {}".format(src,heasarcs.count()))
|
|
|
|
selection=srcs.filter(xrays__exact=True)
|
|
print("Xrays=True for {} from {}".format(selection.count(),srcs.count()))
|
|
|
|
print("SwiftBAT105m={}".format(SwiftBAT105m))
|
|
print("XMMSL2={}".format(XMMSL2))
|
|
print("4FGL={}".format(FGL))
|
|
print("Integral2020={}".format(Integral2020))
|
|
print("MAXI7YR={}".format(MAXI7YR))
|
|
print("RASS2RXS={}".format(RASS2RXS))
|
|
|
|
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):
|
|
#do_all(12.5,'E0')
|
|
#do_all(1.7)
|
|
#do_all(2.7)
|
|
|
|
#do_all(12345.13,'E5', log_ml_nfalse=-3.1264)
|
|
do_all(12345.14,'E5', log_ml_nfalse=-3.1264)
|
|
|
|
self.stdout.write(self.style.SUCCESS('Done'))
|
|
|
|
"""
|
|
|
|
SwiftBAT105m=7
|
|
XMMSL2=2
|
|
4FGL=26
|
|
Integral2020=8
|
|
MAXI7YR=7
|
|
RASS2RXS=6
|
|
|
|
SwiftBAT105m=10
|
|
XMMSL2=1
|
|
4FGL=17
|
|
Integral2020=7
|
|
MAXI7YR=1
|
|
RASS2RXS=4
|
|
|
|
Xrays=True for 41 from 1541
|
|
SwiftBAT105m=5
|
|
XMMSL2=2
|
|
4FGL=20
|
|
Integral2020=6
|
|
MAXI7YR=3
|
|
RASS2RXS=6
|
|
|
|
Xrays=True for 30 from 1541
|
|
SwiftBAT105m=7
|
|
XMMSL2=1
|
|
4FGL=13
|
|
Integral2020=3
|
|
MAXI7YR=7
|
|
RASS2RXS=4
|
|
|
|
Xrays=True for 34 from 1541
|
|
SwiftBAT105m=5
|
|
XMMSL2=1
|
|
4FGL=18
|
|
Integral2020=2
|
|
MAXI7YR=5
|
|
RASS2RXS=4
|
|
|
|
Xrays=True for 44 from 1541
|
|
SwiftBAT105m=5
|
|
XMMSL2=7
|
|
4FGL=17
|
|
Integral2020=9
|
|
MAXI7YR=9
|
|
RASS2RXS=4
|
|
|
|
|
|
"""
|