Skip to content

Commit

Permalink
Comply with detector type update on SVO website (#44)
Browse files Browse the repository at this point in the history
* Detector type update on SVO website, convert list of bytes to strings in ReadIsochrone

* Minor change in the accuracy of a unit test with Monte Carlo
  • Loading branch information
tomasstolker committed Apr 7, 2021
1 parent 962fba9 commit 4bfb210
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 18 deletions.
5 changes: 5 additions & 0 deletions README.rst
Expand Up @@ -34,6 +34,11 @@ Documentation

Documentation can be found at `http://species.readthedocs.io <http://species.readthedocs.io>`_.

Tutorials
---------

There are several `Jupyter notebooks <https://species.readthedocs.io/en/latest/tutorials.html>`_ with tutorials that showcase the workflow and available tools. They can also be executed on `Binder <https://mybinder.org/v2/gh/tomasstolker/species/HEAD>`_ by navigating to the *docs/tutorials* folder.

Attribution
-----------

Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/fitting_model_spectra.ipynb
Expand Up @@ -11,7 +11,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"In this tutorial, we will fit spectra and photometric fluxes of [beta Pic b](http://exoplanet.eu/catalog/beta_pic_b/) with the synthetic spectra from a radiative-convective equilibrium atmosphere model. Here we will use [DRIFT-PHOENIX](https://leap2010blog.wordpress.com/2014/07/03/drift-phoenix-atmosphere-models-creating-new-worlds/) but there are also several [other models supported by *species*](https://species.readthedocs.io/en/latest/overview.html#supported-data)."
"In this tutorial, we will fit spectra and photometric fluxes of [beta Pic b](http://exoplanet.eu/catalog/beta_pic_b/) with the synthetic spectra from a radiative-convective equilibrium atmosphere model. Here we will use [DRIFT-PHOENIX](https://leap2010blog.wordpress.com/2014/07/03/drift-phoenix-atmosphere-models-creating-new-worlds/) but there are also [several other models](https://species.readthedocs.io/en/latest/overview.html#supported-data) supported by *species*."
]
},
{
Expand Down
18 changes: 8 additions & 10 deletions species/data/filters.py
Expand Up @@ -132,20 +132,18 @@ def download_filter(filter_id: str) -> Tuple[Optional[np.ndarray],
f'available?')

if transmission is not None:
try:
det_type = table.get_field_by_id('DetectorType').value
det_type = table.get_field_by_id('DetectorType').value

# For backward compatibility
if not isinstance(det_type, str):
det_type = det_type.decode('utf-8')
# For backward compatibility
if not isinstance(det_type, str):
det_type = det_type.decode('utf-8')

if int(det_type) == 1:
det_type = 'photon'

except KeyError:
# Energy-counting detector if the DetectorType key is not present
if int(det_type) == 0:
det_type = 'energy'

elif int(det_type) == 1:
det_type = 'photon'

wavelength *= 1e-4 # (um)

os.remove('filter.xml')
Expand Down
11 changes: 6 additions & 5 deletions species/data/isochrones.py
Expand Up @@ -12,10 +12,9 @@ def add_baraffe(database,
tag,
filename):
"""
Function for adding the Baraffe et al. isochrone data to the database. Any of the isochrones
from https://phoenix.ens-lyon.fr/Grids/ can be used as input.
https://ui.adsabs.harvard.edu/abs/2003A%26A...402..701B/
Function for adding the `Baraffe et al. (2003)
<https://ui.adsabs.harvard.edu/abs/2003A%26A...402..701B/>`_ isochrone data to the database.
Any of the isochrones from https://phoenix.ens-lyon.fr/Grids/ can be used as input.
Parameters
----------
Expand All @@ -32,8 +31,10 @@ def add_baraffe(database,
None
"""

# read in all the data, ignoring empty lines or lines with '---'
# Read in all the data, ignoring empty lines or lines with '---'

data = []

with open(filename) as data_file:
for line in data_file:
if '---' in line or line == '\n':
Expand Down
9 changes: 8 additions & 1 deletion species/read/read_isochrone.py
Expand Up @@ -75,14 +75,16 @@ def get_isochrone(self,
Box with the isochrone.
"""

age_points = np.repeat(age, masses.shape[0]) # (Myr)
age_points = np.full(masses.shape[0], age) # (Myr)

color = None
mag_abs = None

index_teff = 2
index_logg = 4

# Read isochrone data

with h5py.File(self.database, 'r') as h5_file:
model = h5_file[f'isochrones/{self.tag}/evolution'].attrs['model']
evolution = np.asarray(h5_file[f'isochrones/{self.tag}/evolution'])
Expand All @@ -91,6 +93,11 @@ def get_isochrone(self,
filters = list(h5_file[f'isochrones/{self.tag}/filters'])
magnitudes = np.asarray(h5_file[f'isochrones/{self.tag}/magnitudes'])

# Convert the h5py list of filters from bytes to strings
for i, item in enumerate(filters):
if isinstance(item, bytes):
filters[i] = item.decode('utf-8')

if model == 'baraffe':
if filters_color is not None:
index_color_1 = filters.index(filters_color[0])
Expand Down
2 changes: 1 addition & 1 deletion test/test_analysis/test_photometry.py
Expand Up @@ -115,5 +115,5 @@ def test_spectrum_to_magnitude(self):
assert abs_mag[0] == pytest.approx(5.59000700894101, rel=self.limit, abs=0.)

# The error is estimated with Monte Carlo sampling
assert app_mag[1] == pytest.approx(5.368048545366946e-05, rel=0., abs=1e-5)
assert app_mag[1] == pytest.approx(5.368048545366946e-05, rel=0., abs=2e-5)
assert abs_mag[1] == pytest.approx(0.021714790446227043, rel=0., abs=1e-2)

0 comments on commit 4bfb210

Please sign in to comment.