timothydmorton / isochrones

Pythonic stellar model grid access; easy MCMC fitting of stellar properties
http://isochrones.readthedocs.org
MIT License
117 stars 63 forks source link

KeyError when calculating magnitudes for binary stars in isochrones package #184

Open rafe-sh opened 8 months ago

rafe-sh commented 8 months ago

I encountered a KeyError when attempting to calculate magnitudes for binary stars using the isochrones package. The error occurs specifically when accessing the key 'J' in the props_A or props_B dictionaries. This KeyError prevents the successful calculation of magnitudes for the J-band.

Steps to Reproduce:

Expected Behavior:

The isochrones package should generate the synthetic magnitudes for the specified bands without any KeyError.

Actual Behavior:

A KeyError is raised for the key 'J' when trying to access the props_A['J'] or props_B['J'] values.

Additional Information:

I have verified that the MIST evolutionary tracks are properly installed and up to date. I have also confirmed that the 'J' band is included in the bands list, matching the available bands in the MIST tracks.

PS: Here is the code snippet I am using:

from isochrones import BinaryStarModel
from isochrones.utils import addmags

distance = 500  # pc
AV = 0.2
mass_A = 1.0
mass_B = 0.5
age = 9.6
feh = 0.0

# Synthetic 2MASS and Gaia magnitudes
bands = ['J', 'H', 'K', 'BP', 'RP', 'G']
props_A = mist.track.generate(mass_A, age, feh, distance=distance, AV=AV,
                              bands=bands, return_dict=True, accurate=True)
props_B = mist.track.generate(mass_B, age, feh, distance=distance, AV=AV,
                              bands=bands, return_dict=True, accurate=True)

unc = dict(J=0.02, H=0.02, K=0.02, BP=0.002, RP=0.002, G=0.001)
mags_tot = {b: (addmags(props_A[b], props_B[b]), unc[b]) for b in bands}

# Gaia parallax in mas for a system at 500 pc
parallax = (2, 0.05)

mod_binary = BinaryStarModel(mist, **mags_tot, parallax=parallax, name='demo_binary')

Please let me know if you need any further information or if there are any suggested workarounds for this issue. Thank you for your attention to this matter

BS-astronomer commented 6 months ago

Hi, I replaced mags_tot = {b: (addmags(props_A[b], props_B[b]), unc[b]) for b in bands} with mags_tot = {b: (addmags(props_A[b+'_mag'], props_B[b'_mag']), unc[b]) for b in bands}

the DataFrame returned by mist.track.generate() has such keys as 'J_mag', 'G_mag', etc.