added ORDER and NSIDE as arguments for the indexer script
This commit is contained in:
parent
3acef66a89
commit
84f373d590
@ -8,12 +8,17 @@ from datetime import datetime, timedelta
|
|||||||
def current_time():
|
def current_time():
|
||||||
return (datetime.now() + timedelta(hours=3)).strftime("%H:%M:%S")
|
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
|
def healpix(nside, order):
|
||||||
ORDER='ring'
|
|
||||||
|
#NSIDE=2048
|
||||||
|
#ORDER='ring'
|
||||||
|
|
||||||
for catalog_file in CatalogFile.objects.all():
|
for catalog_file in CatalogFile.objects.all():
|
||||||
|
|
||||||
print(f'[{current_time()}] Loading sources from the database...')
|
print(f'[{current_time()}] Loading sources from the database...')
|
||||||
sources = list(catalog_file.sources.all())
|
sources = list(catalog_file.sources.all())
|
||||||
print(f'[{current_time()}] Sources ready. Forming ra & dec arrays...')
|
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')
|
skycoord = SkyCoord(ra=ra_list, dec=dec_list, unit='deg', frame='fk5')
|
||||||
print(f'[{current_time()}] SkyCoord objects ready. Calculating healpix indices...')
|
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)
|
healpix_indices = healpix.skycoord_to_healpix(skycoord)
|
||||||
print(f'[{current_time()}] Indices ready. Assigning indices to source instances...')
|
print(f'[{current_time()}] Indices ready. Assigning indices to source instances...')
|
||||||
|
|
||||||
@ -33,13 +38,28 @@ def healpix():
|
|||||||
source.healpix_ring_index = healpix_index
|
source.healpix_ring_index = healpix_index
|
||||||
print(f'[{current_time()}] Instances ready. Bulk updating the database...')
|
print(f'[{current_time()}] Instances ready. Bulk updating the database...')
|
||||||
|
|
||||||
|
if order == "ring":
|
||||||
GaiaSource.objects.bulk_update(sources, ['healpix_ring_index'])
|
GaiaSource.objects.bulk_update(sources, ['healpix_ring_index'])
|
||||||
print(f'[{current_time()}] Database updated, sources indexed successfully.')
|
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):
|
class Command(BaseCommand):
|
||||||
help = 'Index sources using healpix.'
|
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)
|
||||||
|
|
18
migrations/0003_alter_catalogfile_status.py
Normal file
18
migrations/0003_alter_catalogfile_status.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.1 on 2024-09-12 11:40
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('GaiaDBInterface', '0002_gaiasource_healpix_nested_index_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='catalogfile',
|
||||||
|
name='status',
|
||||||
|
field=models.CharField(choices=[('PENDING', 'Pending'), ('IN_PROGRESS', 'In Progress'), ('INGESTED', 'Ingested'), ('INDEX_IN_PROGRESS', 'Index in progress'), ('INDEXED', 'Indexed')], default='PENDING', max_length=17),
|
||||||
|
),
|
||||||
|
]
|
@ -11,10 +11,11 @@ class CatalogFile(models.Model):
|
|||||||
('PENDING', 'Pending'),
|
('PENDING', 'Pending'),
|
||||||
('IN_PROGRESS', 'In Progress'),
|
('IN_PROGRESS', 'In Progress'),
|
||||||
('INGESTED', 'Ingested'),
|
('INGESTED', 'Ingested'),
|
||||||
|
('INDEX_IN_PROGRESS', 'Index in progress'),
|
||||||
('INDEXED', 'Indexed')
|
('INDEXED', 'Indexed')
|
||||||
]
|
]
|
||||||
|
|
||||||
status = models.CharField(max_length=11, choices=STATUS_CHOICES, default='PENDING')
|
status = models.CharField(max_length=17, choices=STATUS_CHOICES, default='PENDING')
|
||||||
|
|
||||||
class GaiaSource(models.Model):
|
class GaiaSource(models.Model):
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user