Mapping exoplanets in our region of the galaxy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
3.0 KiB

import astropy
import json
import numpy
import pyvo
from enum import Enum
class FieldSet(Enum):
ID = ('pl_name', 'hostname', 'pl_letter', 'gaia_id', 'hip_name', 'hd_name')
SYSTEM = ('sy_snum', 'sy_pnum', 'sy_mnum', 'cb_flag')
LOCATION = ('sy_dist', 'ra', 'dec', 'glat', 'glon')
STELLAR_DATA = ('st_mass', 'st_rad', 'st_dens', 'st_teff', 'st_age', 'st_met', 'st_lum')
PLANETARY_DATA = ('pl_bmasse', 'pl_rade', 'pl_bmassj', 'pl_radj', 'pl_dens')
ORBIT = ('pl_orbper', 'pl_orbsmax', 'pl_orbeccen', 'pl_orbincl')
MAGNITUDE = ('sy_bmag', 'sy_vmag')
class Catalog:
archive_url = ''
def __init__(self, max_distance, spacing=12.0):
max_distance: maximum distance, in parsecs, of stars to include in query
spacing: distance, in parsecs, between concentric groups
self.max_distance = max_distance
self.spacing = spacing
def create_query(self, *field_sets):
fields = []
for field_set in field_sets:
fields.extend([field for field in field_set.value])
query = [
', '.join(fields),
'from PSCompPars',
f'where sy_dist between 0 and {self.max_distance}',
'order by',
', '.join(FieldSet.LOCATION.value)
return ' '.join(query)
def fetch(self, *field_sets):
service = pyvo.dal.TAPService(self.archive_url)
query = service.create_query(self.create_query(*field_sets)) = query.execute().to_table()
def lookup_index(self, planet_name):
if hasattr(self, 'data'):
name =['pl_name']
return numpy.where(name == planet_name)
def lookup_row(self, planet_name):
if hasattr(self, 'data'):
def distance_group(data, spacing=12.0):
return numpy.trunc(data['sy_dist'] / spacing)
def latitude_subgroup(data, spacing=12.0):
ring = Catalog.distance_group(data, spacing)
latitude = numpy.pi * data['glat'] / 180.0
subgroup = numpy.zeros(ring.shape)
for i in range(len(subgroup)):
crit_angle = numpy.arcsin(ring[i] / (ring[i] + 1))
if crit_angle > 0.0:
bins = [numpy.pi, crit_angle, 0.0, -crit_angle, -numpy.pi]
subgroup[i] = numpy.digitize(latitude[i], bins)
subgroup[i] = 0.0
return subgroup
def group_regions(self):
if hasattr(self, 'data'):
rings = self.distance_group(, self.spacing)
def subgroup_regions(self):
if hasattr(self, 'data'):
rings = self.distance_group(, self.spacing)
tiers = self.latitude_subgroup(, self.spacing)
key_table = astropy.table.Table([rings, tiers], names=('ring_group', 'tier_subgroup'))