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, MetaSource from artsurvey.utils import update_marshall 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 def update_local(survey_version,survey_name,en='E0',minrad=15,maxdist=120): try: s = ArtSurvey.objects.get(Q(version=survey_version) & Q(name=survey_name)) except ArtSurvey.DoesNotExist: print("ArtSurvey {} {} not found".format(survey_name,survey_version)) return try: band = EnergyBand.objects.get(slug=en) except EnergyBand.DoesNotExist: print("EnergyBand bot found") return srcs=s.artsurveysource_set.all().filter(band=band) count = update_marshall(srcs) print("use ArtSurvey {} band={} nrows={} , marshall={}".format(s, band, srcs.count(), count)) 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=30.0 maxdist=500.0 """ Detele MetaSource """ #msrcs=MetaSource.objects.all() #print("Delete MetaSource nrows={}".format(msrcs.count())) #msrcs.delete() update_local(12345.14, "1-5", en='E5') self.stdout.write(self.style.SUCCESS('Done'))