Skip to content

Commit

Permalink
Added warnings when calculating magnitudes for evolutionary tracks an…
Browse files Browse the repository at this point in the history
…d parameters are outside the grid boundaries
  • Loading branch information
Tomas Stolker committed Oct 13, 2020
1 parent 486ec60 commit 99c3509
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions species/read/read_isochrone.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
Module with reading functionalities for isochrones.
"""

import os
import configparser
import os
import warnings

from typing import Optional, Tuple

Expand Down Expand Up @@ -205,16 +206,31 @@ def get_color_magnitude(self,
mag1[i] = np.nan
mag2[i] = np.nan

warnings.warn(f'The value of Teff is NaN for the following isochrone sample: '
f'{model_param}. Setting the magnitudes to NaN.')

else:
for item_bounds in model1.get_bounds():
if model_param[item_bounds] <= model1.get_bounds()[item_bounds][0]:
mag1[i] = np.nan
mag2[i] = np.nan

warnings.warn(f'The value of {item_bounds} is {model_param[item_bounds]}, '
f'which is below the lower bound of the model grid '
f'({model1.get_bounds()[item_bounds][0]}). Setting the '
f'magnitudes to NaN for the following isochrone sample: '
f'{model_param}.')

elif model_param[item_bounds] >= model1.get_bounds()[item_bounds][1]:
mag1[i] = np.nan
mag2[i] = np.nan

warnings.warn(f'The value of {item_bounds} is {model_param[item_bounds]}, '
f'which is above the upper bound of the model grid '
f'({model1.get_bounds()[item_bounds][1]}). Setting the '
f'magnitudes to NaN for the following isochrone sample: '
f'{model_param}.')

if not np.isnan(mag1[i]):
mag1[i], _ = model1.get_magnitude(model_param)
mag2[i], _ = model2.get_magnitude(model_param)
Expand All @@ -226,7 +242,7 @@ def get_color_magnitude(self,
abs_mag = mag2

else:
raise ValueError('The filter_mag argument should be equal to one of the two filter '
raise ValueError('The argument of filter_mag should be equal to one of the two filter '
'values of filters_color.')

return box.create_box(boxtype='colormag',
Expand Down Expand Up @@ -300,6 +316,9 @@ def get_color_color(self,
mag3[i] = np.nan
mag4[i] = np.nan

warnings.warn(f'The value of Teff is NaN for the following isochrone sample: '
f'{model_param}. Setting the magnitudes to NaN.')

else:
for item_bounds in model1.get_bounds():
if model_param[item_bounds] <= model1.get_bounds()[item_bounds][0]:
Expand All @@ -308,12 +327,24 @@ def get_color_color(self,
mag3[i] = np.nan
mag4[i] = np.nan

warnings.warn(f'The value of {item_bounds} is {model_param[item_bounds]}, '
f'which is below the lower bound of the model grid '
f'({model1.get_bounds()[item_bounds][0]}). Setting the '
f'magnitudes to NaN for the following isochrone sample: '
f'{model_param}.')

elif model_param[item_bounds] >= model1.get_bounds()[item_bounds][1]:
mag1[i] = np.nan
mag2[i] = np.nan
mag3[i] = np.nan
mag4[i] = np.nan

warnings.warn(f'The value of {item_bounds} is {model_param[item_bounds]}, '
f'which is above the upper bound of the model grid '
f'({model1.get_bounds()[item_bounds][1]}). Setting the '
f'magnitudes to NaN for the following isochrone sample: '
f'{model_param}.')

if not np.isnan(mag1[i]) and not np.isnan(mag2[i]) and\
not np.isnan(mag3[i]) and not np.isnan(mag4[i]):
mag1[i], _ = model1.get_magnitude(model_param)
Expand Down

0 comments on commit 99c3509

Please sign in to comment.