From 84f373d5902e686c5ad5724fca3d3654597ba544 Mon Sep 17 00:00:00 2001 From: tyrin Date: Thu, 12 Sep 2024 15:52:38 +0300 Subject: [PATCH] added ORDER and NSIDE as arguments for the indexer script --- management/commands/indexer.py | 38 ++++++++++++++++----- migrations/0003_alter_catalogfile_status.py | 18 ++++++++++ models.py | 3 +- 3 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 migrations/0003_alter_catalogfile_status.py diff --git a/management/commands/indexer.py b/management/commands/indexer.py index 73afa2c..aa1b04f 100644 --- a/management/commands/indexer.py +++ b/management/commands/indexer.py @@ -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() \ No newline at end of file + 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) + \ No newline at end of file diff --git a/migrations/0003_alter_catalogfile_status.py b/migrations/0003_alter_catalogfile_status.py new file mode 100644 index 0000000..be30339 --- /dev/null +++ b/migrations/0003_alter_catalogfile_status.py @@ -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), + ), + ] diff --git a/models.py b/models.py index 64a65bc..0db89c2 100644 --- a/models.py +++ b/models.py @@ -11,10 +11,11 @@ class CatalogFile(models.Model): ('PENDING', 'Pending'), ('IN_PROGRESS', 'In Progress'), ('INGESTED', 'Ingested'), + ('INDEX_IN_PROGRESS', 'Index in progress'), ('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):