47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
from django.core.management.base import BaseCommand, CommandError
|
|
from monthplan.models import SurveyHealpixPlate, SurveyHealpixSubPlate, NSIDE_PLATES, NSIDE_SUBPLATES, 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_sub_plates(nside_plates, nside_subplates, order):
|
|
hp_plates = HEALPix(nside=nside_plates, order=order, frame=FK5())
|
|
hp_subplates = HEALPix(nside=nside_subplates, order=order, frame=FK5())
|
|
|
|
print("Make Healpix Plates",hp_plates.npix,hp_plates.pixel_area.value,hp_plates.pixel_resolution.value)
|
|
print("Make Healpix SubPlates",hp_subplates.npix,hp_subplates.pixel_area.value,hp_subplates.pixel_resolution.value)
|
|
try:
|
|
print('Delete existing Healpix Plates')
|
|
subplates = SurveyHealpixSubPlate.objects.all()
|
|
subplates.delete()
|
|
except:
|
|
print('Abort')
|
|
exit()
|
|
|
|
for heal in range(hp_subplates.npix):
|
|
sc = hp_subplates.healpix_to_skycoord(heal)
|
|
crd = SkyCoord(float(sc.ra.degree), float(sc.dec.degree), frame="fk5", unit="deg")
|
|
heal = hp_plates.skycoord_to_healpix(crd)
|
|
try:
|
|
plate = SurveyHealpixPlate.objects.get(healpix=heal)
|
|
except:
|
|
print('Error: SurveyHealpixPlate not found, run ./manage.py init_survey_healpix_plates first')
|
|
return
|
|
subplate = SurveyHealpixSubPlate(healpix=heal, ra=float(sc.ra.degree), dec=float(sc.dec.degree), plate=plate)
|
|
subplate.save()
|
|
pass
|
|
|
|
class Command(BaseCommand):
|
|
|
|
def handle(self, *args, **options):
|
|
init_healpix_sub_plates(NSIDE_PLATES, NSIDE_SUBPLATES, ORDER)
|
|
|
|
|
|
|
|
|