diff --git a/.gitignore b/.gitignore index 5d381cc..8a614bb 100644 --- a/.gitignore +++ b/.gitignore @@ -160,3 +160,4 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +tutorial.ipynb diff --git a/management/commands/indexer.py b/management/commands/indexer.py index 06c906c..3e66cbd 100644 --- a/management/commands/indexer.py +++ b/management/commands/indexer.py @@ -1,9 +1,36 @@ from django.core.management.base import BaseCommand from GaiaDBInterface.models import GaiaSource, CatalogFile +from astropy.coordinates import SkyCoord +import astropy_healpix as ah +import numpy as np + + +def healpix(): + + NSIDE=2048 + ORDER='ring' + + for catalog_file in CatalogFile.objects.all(): + + sources = list(catalog_file.sources.all()) + + ra_list = np.array([source.ra for source in sources]) + dec_list = np.array([source.dec for source in sources]) + + skycoord = SkyCoord(ra=ra_list, dec=dec_list, unit='deg', frame="fk5") + + healpix = ah.HEALPix(nside=NSIDE, order=ORDER) + healpix_indices = healpix.skycoord_to_healpix(skycoord) + + for source, healpix_index in zip(sources, healpix_indices): + source.healpix_ring_index = healpix_index + + GaiaSource.objects.bulk_update(sources, ['healpix_ring_index']) + class Command(BaseCommand): help = 'Index sources using healpix.' def handle(self, *args, **options): - \ No newline at end of file + healpix() \ No newline at end of file diff --git a/migrations/0002_gaiasource_healpix_nested_index_and_more.py b/migrations/0002_gaiasource_healpix_nested_index_and_more.py new file mode 100644 index 0000000..24bc28c --- /dev/null +++ b/migrations/0002_gaiasource_healpix_nested_index_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 5.1.1 on 2024-09-11 11:13 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('GaiaDBInterface', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='gaiasource', + name='healpix_nested_index', + field=models.BigIntegerField(blank=True, null=True), + ), + migrations.AddField( + model_name='gaiasource', + name='healpix_ring_index', + field=models.BigIntegerField(blank=True, null=True), + ), + ] diff --git a/models.py b/models.py index 6bcf105..64a65bc 100644 --- a/models.py +++ b/models.py @@ -69,6 +69,10 @@ class GaiaSource(models.Model): phot_rp_mean_mag = models.FloatField(default=0.0, null=True) #mean rp magnitude, vega scale + healpix_ring_index = models.BigIntegerField(null=True, blank=True) + + healpix_nested_index = models.BigIntegerField(null=True, blank=True) +