106 lines
3.4 KiB
Python
106 lines
3.4 KiB
Python
from django.core.management.base import BaseCommand, CommandError
|
|
from django.db.models import 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
|
|
from sqlalchemy import create_engine
|
|
|
|
from heasarc.models import HeasarcBase
|
|
from artsurvey.models import ArtSurveySource, ArtSurvey, EnergyBand
|
|
from srglib.utils import find_counterparts
|
|
from srgcat.models import SrgDataDump
|
|
|
|
def init_survey(init_version,survey_name,dump_name,slug):
|
|
name=dump_name+'.'+slug
|
|
try:
|
|
survey = ArtSurvey.objects.get(Q(version=init_version) & Q(name=survey_name))
|
|
except ArtSurvey.DoesNotExist:
|
|
print("create ArtSurvey")
|
|
survey = ArtSurvey(version=init_version, name=survey_name)
|
|
survey.save()
|
|
|
|
print("use ArtSurvey {}".format(survey))
|
|
|
|
try:
|
|
band = EnergyBand.objects.get(slug=slug)
|
|
print("use EnergyBand {}".format(band))
|
|
except EnergyBand.DoesNotExist:
|
|
print("EnergyBand not found")
|
|
return
|
|
|
|
|
|
|
|
""" copy catalog from this dump """
|
|
dump = SrgDataDump.objects.get(name=name)
|
|
print(dump)
|
|
|
|
srcs = dump.skymapsource_set.all()
|
|
for src in srcs:
|
|
if not (src.artsurvey_source):
|
|
print("{} {}".format(slug,src))
|
|
artsource = ArtSurveySource.objects.create_source(src,survey,band)
|
|
artsource.save()
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Initiates data dase'
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
"""
|
|
bands = ['E0','E1','E2','E3','E4']
|
|
for slug in bands:
|
|
init_survey(12.5,'S12',slug)
|
|
"""
|
|
|
|
#init_survey(123.0,'S123','E0')
|
|
#init_survey(1234.0,'1-4','S1-4','E0')
|
|
#init_survey(3.0,'3','S3','E0')
|
|
|
|
|
|
#version=0.1
|
|
#init_survey(version,'L20','L20','E0')
|
|
|
|
|
|
#init_survey(0.13,'L20rb','L20rb','E0')
|
|
#init_survey(0.15,'L20rb_ml','L20rb_ml','E0')
|
|
#init_survey(12345.12,'1-5', '22y','E0')
|
|
#init_survey(12345.12,'1-5', '22y','E5')
|
|
#init_survey(12345.13,'1-5', '22y','E5')
|
|
init_survey(12345.14,'1-5', '22y','E5')
|
|
|
|
#init_survey(version,'GC2019','GC','E0')
|
|
#init_survey(34.0,'34','S34','E0')
|
|
#init_survey(5.0,'5','S5','E0')
|
|
#init_survey(12345.0,'1-5','S1-5','E0')
|
|
|
|
#init_survey(0.12,'L20','L20','E0')
|
|
#init_survey(0.12,'L20p1','L20p1','E0')
|
|
#init_survey(0.12,'L20p2','L20p2','E0')
|
|
#init_survey(0.12,'L20p3','L20p3','E0')
|
|
#init_survey(0.12,'L20p4','L20p4','E0')
|
|
|
|
|
|
version=0.11
|
|
#fields=[50,45,40,35,30,'025','020','015','010','005','000','355','350','345',]
|
|
#fields=['070','075','080','085','090']
|
|
#fields=['270','275','280','285','290','295','300','305','310','215','320','325']
|
|
#fields=['315']
|
|
|
|
fields=['330','335','340']
|
|
"""
|
|
for field in fields:
|
|
init_survey(version,"GP{}".format(field),"GP{}".format(field),'E0')
|
|
init_survey(version,"GP{}".format(field),"GP{}".format(field),'E1')
|
|
init_survey(version,"GP{}".format(field),"GP{}".format(field),'E2')
|
|
init_survey(version,"GP{}".format(field),"GP{}".format(field),'E3')
|
|
init_survey(version,"GP{}".format(field),"GP{}".format(field),'E4')
|
|
"""
|
|
|
|
self.stdout.write(self.style.SUCCESS('Done'))
|