prototype indexer implementation
This commit is contained in:
parent
6df8af77df
commit
5fe96c3b86
1
.gitignore
vendored
1
.gitignore
vendored
@ -160,3 +160,4 @@ cython_debug/
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
tutorial.ipynb
|
||||
|
@ -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):
|
||||
|
||||
|
||||
healpix()
|
23
migrations/0002_gaiasource_healpix_nested_index_and_more.py
Normal file
23
migrations/0002_gaiasource_healpix_nested_index_and_more.py
Normal file
@ -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),
|
||||
),
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user