80 lines
2.7 KiB
Python
80 lines
2.7 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
|
|
import time
|
|
|
|
from astrobasis.models import GaiaSourceFileDR3, GAIADR3
|
|
|
|
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 load_gaia_bulk():
|
|
start_time = time.time()
|
|
path='/data/tmp/george/Gaia/gedr3/gaia_source/fits/fits/'
|
|
batch_size = 500
|
|
gaia_empty=GaiaSourceFileDR3.objects.filter(status__exact='empty')
|
|
|
|
for gaia in gaia_empty:
|
|
srcs = gaia.gaiadr3_set.all()
|
|
if(srcs):
|
|
srcs.delete()
|
|
print("Clear ",gaia.filename," back ref: ",len(srcs))
|
|
|
|
filepath=path+gaia.filename+'.fits'
|
|
data = astropy.table.Table.read(filepath, format='fits')
|
|
|
|
|
|
gaia.nrows = len(data)
|
|
gaia.save()
|
|
print("Bulk create for %s" % gaia.filename)
|
|
objs = (GAIADR3(filename=gaia,
|
|
ra=data[i]['ra'],
|
|
dec=data[i]['dec'],
|
|
name=data[i]['designation'],
|
|
#solution_id = data[i]['solution_id'],
|
|
source_id = data[i]['source_id'],
|
|
#ref_epoch = data[i]['ref_epoch'],
|
|
ra_error = data[i]['ra_error'],
|
|
dec_error = data[i]['dec_error'],
|
|
parallax = data[i]['parallax'],
|
|
parallax_error = data[i]['parallax_error'],
|
|
pmra = data[i]['pmra'],
|
|
pmra_error = data[i]['pmra_error'],
|
|
pmdec = data[i]['pmdec'],
|
|
pmdec_error = data[i]['pmdec_error'],
|
|
phot_g_mean_mag = data[i]['phot_g_mean_mag'],
|
|
phot_bp_mean_mag = data[i]['phot_bp_mean_mag'],
|
|
phot_rp_mean_mag = data[i]['phot_rp_mean_mag'],)
|
|
for i in range(len(data)))
|
|
|
|
GAIADR3.objects.bulk_create(objs,batch_size)
|
|
gaia.status="ready"
|
|
gaia.save()
|
|
|
|
|
|
print("--- %s seconds ---" % (time.time() - start_time))
|
|
pass
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Initiates data dase'
|
|
|
|
def handle(self, *args, **options):
|
|
load_gaia_bulk()
|
|
|