removed boolean types for ring and nested indices. Made the indexer create both indexes at once as it is faster.
This commit is contained in:
parent
84f373d590
commit
e5663e3c30
@ -12,17 +12,17 @@ def update_catalog_file_status(catalog_file, status): #catalog file
|
|||||||
catalog_file.status = status
|
catalog_file.status = status
|
||||||
catalog_file.save()
|
catalog_file.save()
|
||||||
|
|
||||||
def healpix(nside, order):
|
def healpix(nside): #NSIDE 2048, ORDER ring or nested
|
||||||
|
|
||||||
#NSIDE=2048
|
for catalog_file in CatalogFile.objects.filter(status='INGESTED'):
|
||||||
#ORDER='ring'
|
|
||||||
|
|
||||||
for catalog_file in CatalogFile.objects.all():
|
print(f'[{current_time()}] Loading sources from {catalog_file.name}...')
|
||||||
|
|
||||||
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...')
|
||||||
|
|
||||||
|
if catalog_file.status == 'INDEX_IN_PROGRESS':
|
||||||
|
sources.update(healpix_ring_index=None, healpix_nested_index=None)
|
||||||
|
|
||||||
ra_list = np.array([source.ra for source in sources])
|
ra_list = np.array([source.ra for source in sources])
|
||||||
dec_list = np.array([source.dec for source in sources])
|
dec_list = np.array([source.dec for source in sources])
|
||||||
print(f'[{current_time()}] ra & dec arrays ready. Creating SkyCoord objects...')
|
print(f'[{current_time()}] ra & dec arrays ready. Creating SkyCoord objects...')
|
||||||
@ -30,24 +30,33 @@ def healpix(nside, order):
|
|||||||
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_indices = healpix.skycoord_to_healpix(skycoord)
|
|
||||||
print(f'[{current_time()}] Indices ready. Assigning indices to source instances...')
|
ring_healpix = ah.HEALPix(nside=nside, order=ring, frame='fk5')
|
||||||
|
ring_healpix_indices = healpix.skycoord_to_healpix(skycoord)
|
||||||
|
print(f'[{current_time()}] Ring indices ready. Assigning indices to source instances...')
|
||||||
|
|
||||||
|
for source, healpix_index in zip(sources, ring_healpix_indices):
|
||||||
|
source.healpix_ring_index = healpix_index
|
||||||
|
print(f'[{current_time()}] Instances ready.')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
nested_healpix = ah.HEALPix(nside=nside, order=nested, frame='fk5')
|
||||||
|
nested_healpix_indices = healpix.skycoord_to_healpix(skycoord)
|
||||||
|
print(f'[{current_time()}] Nested indices ready. Assigning indices to source instances...')
|
||||||
|
|
||||||
for source, healpix_index in zip(sources, healpix_indices):
|
for source, healpix_index in zip(sources, healpix_indices):
|
||||||
source.healpix_ring_index = healpix_index
|
source.healpix_nested_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'])
|
update_catalog_file_status(catalog_file, 'INDEX_IN_PROGRESS')
|
||||||
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, ['healpix_ring_index', 'healpix_nested_index'])
|
||||||
GaiaSource.objects.bulk_update(sources, ['helpix_nested_index'])
|
|
||||||
print(f'[{current_time()}] Database updated, sources nested-indexed successfully.')
|
print(f'[{current_time()}] Database updated, sources nested-indexed successfully.')
|
||||||
update_catalog_file_status(catalog_file, 'INDEXED')
|
update_catalog_file_status(catalog_file, 'INDEXED')
|
||||||
else:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
@ -56,10 +65,10 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
parser.add_argument('nside', type=int, help='NSIDE parameter for HEALPix')
|
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):
|
def handle(self, *args, **options):
|
||||||
nside = options['nside']
|
nside = options['nside']
|
||||||
order = options['order']
|
|
||||||
healpix(nside, order)
|
healpix(nside)
|
||||||
|
|
@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 5.1.1 on 2024-09-12 13:24
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('GaiaDBInterface', '0003_alter_catalogfile_status'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='catalogfile',
|
||||||
|
name='nested_indexed',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='catalogfile',
|
||||||
|
name='ring_indexed',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
]
|
@ -0,0 +1,21 @@
|
|||||||
|
# Generated by Django 5.1.1 on 2024-09-12 13:42
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('GaiaDBInterface', '0004_catalogfile_nested_indexed_catalogfile_ring_indexed'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='catalogfile',
|
||||||
|
name='nested_indexed',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='catalogfile',
|
||||||
|
name='ring_indexed',
|
||||||
|
),
|
||||||
|
]
|
@ -17,6 +17,7 @@ class CatalogFile(models.Model):
|
|||||||
|
|
||||||
status = models.CharField(max_length=17, choices=STATUS_CHOICES, default='PENDING')
|
status = models.CharField(max_length=17, choices=STATUS_CHOICES, default='PENDING')
|
||||||
|
|
||||||
|
|
||||||
class GaiaSource(models.Model):
|
class GaiaSource(models.Model):
|
||||||
|
|
||||||
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user