Skip to content

Commit

Permalink
Change starcat to use cspyce
Browse files Browse the repository at this point in the history
  • Loading branch information
astrocfi committed Feb 15, 2018
1 parent 37125bf commit 7677285
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions starcat/spice.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@
from starcatalog import *
import numpy as np
import os.path
import cspice
import cspyce

class SpiceStar(Star):
"""A holder for star attributes.
This class includes attributes unique to the SPICE catalogs."""

def __init__(self):
# Initialize the standard fields
Star.__init__(self)

# Initialize the SPICE-specific fields
self.spectral_class = None
"""The spectral class"""


class SpiceStarCatalog(StarCatalog):
def __init__(self, name):
self.filename = os.path.join(os.environ["SPICE_PATH"], "Stars", name+'.bdb')
self.catalog = cspice.stcl01(self.filename)[0]
self.catalog = cspyce.stcl01(self.filename)[0]
self.debug_level = 0

# (ra, dec, ra_uncertainty, dec_uncertainty,
# catalog_number, spectral_type, v_magnitude)

Expand All @@ -35,11 +35,11 @@ def _find_stars(self, ra_min, ra_max, dec_min, dec_max, **kwargs):
vmag_min = kwargs.get('vmag_min', None)
vmag_max = kwargs.get('vmag_max', None)

nstars = cspice.stcf01(self.catalog, ra_min, ra_max, dec_min, dec_max)
nstars = cspyce.stcf01(self.catalog, ra_min, ra_max, dec_min, dec_max)

for i in range(nstars):
star = SpiceStar()
result = tuple(cspice.stcg01(i))
result = tuple(cspyce.stcg01(i))
(star.ra, star.dec, star.ra_sigma, star.dec_sigma,
star.unique_number, star.spectral_class, star.vmag) = result
if vmag_min is not None and star.vmag < vmag_min:
Expand All @@ -50,16 +50,16 @@ def _find_stars(self, ra_min, ra_max, dec_min, dec_max, **kwargs):
if self.debug_level:
print 'SKIPPED VMAG', star.vmag
continue

star.temperature = self.temperature_from_sclass(star.spectral_class)
if self.debug_level:
print 'OK!'
yield star



#===============================================================================
# UNIT TESTS
# UNIT TESTS
#===============================================================================

import unittest
Expand All @@ -74,7 +74,7 @@ def runTest(self):

num_vmag_lim = cat.count_stars(vmag_max=10)
self.assertGreater(num_all, num_vmag_lim)

# Compare slicing directions
num_dec = 0
for idec in xrange(20):
Expand All @@ -86,8 +86,7 @@ def runTest(self):
num_ra += cat.count_stars(dec_min=0., dec_max=4.*RPD,
ra_min=(ira+60)*RPD, ra_max=((ira+1)+60)*RPD)
self.assertEqual(num_dec, num_ra)


if __name__ == '__main__':
unittest.main(verbosity=2)

0 comments on commit 7677285

Please sign in to comment.