66 lines
1.8 KiB
Python
66 lines
1.8 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 astrobasis.models import GaiaSourceFile, GAIADR2
|
|
|
|
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 os
|
|
import glob
|
|
import logging
|
|
|
|
def mark_gaia():
|
|
|
|
gaia_empty = GaiaSourceFile.objects.filter(status__exact='empty')
|
|
total_empty = gaia_empty.count()
|
|
total = 0
|
|
for gaia in gaia_empty:
|
|
total_linked = gaia.gaiadr2_set.all().count()
|
|
#print("%s %s linked: %d nrows: %d" % (gaia.filename, gaia.status,total_linked,gaia.nrows))
|
|
|
|
if (gaia.nrows == 0):
|
|
""" empty and not still started to load """
|
|
continue
|
|
|
|
if (total_linked == 0):
|
|
""" looks like currently loading """
|
|
continue
|
|
|
|
if (total_linked == gaia.nrows):
|
|
print(gaia.filename+" -- loaded")
|
|
gaia.status='loaded'
|
|
gaia.save()
|
|
total+=1
|
|
else:
|
|
""" delete leftovers if any """
|
|
#linked = gaia.gaiadr2_set.all()
|
|
#linked.delete()
|
|
print(gaia.filename+" "+str(total_linked)+" != "+str(gaia.nrows))
|
|
|
|
print("Total %d marked as loaded from %d empty selected" % (total, total_empty,))
|
|
pass
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Initiates data dase'
|
|
|
|
def handle(self, *args, **options):
|
|
mark_gaia()
|
|
|
|
|
|
|