from django.core.management.base import BaseCommand, CommandError from monthplan.models import SurveyHealpixPlate, NSIDE_PLATES, ORDER from os import listdir from astropy_healpix import HEALPix from astropy import units as u from astropy.coordinates import SkyCoord, RangeError from astropy.coordinates import ICRS, Galactic, FK5 from astropy.coordinates import Angle def init_healpix_plates(nside, order): hp = HEALPix(nside=nside, order=order, frame=FK5()) print("Make Healpix Plates",hp.npix,hp.pixel_area.value,hp.pixel_resolution.value) try: print('Delete existing Healpix Plates') plates = SurveyHealpixPlate.objects.all() plates.delete() except: print('Abort') exit() for heal in range(hp.npix): sc = hp.healpix_to_skycoord(heal) plate = SurveyHealpixPlate(healpix=heal, ra=float(sc.ra.degree), dec=float(sc.dec.degree)) plate.save() pass class Command(BaseCommand): def handle(self, *args, **options): init_healpix_plates(NSIDE_PLATES, ORDER)