added ORDER and NSIDE as arguments for the indexer script
This commit is contained in:
@@ -8,12 +8,17 @@ from datetime import datetime, timedelta
|
||||
def current_time():
|
||||
return (datetime.now() + timedelta(hours=3)).strftime("%H:%M:%S")
|
||||
|
||||
def healpix():
|
||||
def update_catalog_file_status(catalog_file, status): #catalog file status updater
|
||||
catalog_file.status = status
|
||||
catalog_file.save()
|
||||
|
||||
NSIDE=2048
|
||||
ORDER='ring'
|
||||
def healpix(nside, order):
|
||||
|
||||
#NSIDE=2048
|
||||
#ORDER='ring'
|
||||
|
||||
for catalog_file in CatalogFile.objects.all():
|
||||
|
||||
print(f'[{current_time()}] Loading sources from the database...')
|
||||
sources = list(catalog_file.sources.all())
|
||||
print(f'[{current_time()}] Sources ready. Forming ra & dec arrays...')
|
||||
@@ -25,7 +30,7 @@ def healpix():
|
||||
skycoord = SkyCoord(ra=ra_list, dec=dec_list, unit='deg', frame='fk5')
|
||||
print(f'[{current_time()}] SkyCoord objects ready. Calculating healpix indices...')
|
||||
|
||||
healpix = ah.HEALPix(nside=NSIDE, order=ORDER, frame='fk5')
|
||||
healpix = ah.HEALPix(nside=nside, order=order, frame='fk5')
|
||||
healpix_indices = healpix.skycoord_to_healpix(skycoord)
|
||||
print(f'[{current_time()}] Indices ready. Assigning indices to source instances...')
|
||||
|
||||
@@ -33,13 +38,28 @@ def healpix():
|
||||
source.healpix_ring_index = healpix_index
|
||||
print(f'[{current_time()}] Instances ready. Bulk updating the database...')
|
||||
|
||||
GaiaSource.objects.bulk_update(sources, ['healpix_ring_index'])
|
||||
print(f'[{current_time()}] Database updated, sources indexed successfully.')
|
||||
|
||||
if order == "ring":
|
||||
GaiaSource.objects.bulk_update(sources, ['healpix_ring_index'])
|
||||
print(f'[{current_time()}] Database updated, sources ring-indexed successfully.')
|
||||
update_catalog_file_status(catalog_file, 'INDEXED')
|
||||
elif order == "nested":
|
||||
GaiaSource.objects.bulk_update(sources, ['helpix_nested_index'])
|
||||
print(f'[{current_time()}] Database updated, sources nested-indexed successfully.')
|
||||
update_catalog_file_status(catalog_file, 'INDEXED')
|
||||
else:
|
||||
pass
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Index sources using healpix.'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
|
||||
healpix()
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('nside', type=int, help='NSIDE parameter for HEALPix')
|
||||
parser.add_argument('order', type=str, help='ORDER parameter for HEALPix')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
nside = options['nside']
|
||||
order = options['order']
|
||||
healpix(nside, order)
|
||||
|
Reference in New Issue
Block a user