HeloiseS / hoki

Bridging the gap between observation and theory
https://heloises.github.io/hoki/intro.html
BSD 3-Clause "New" or "Revised" License
47 stars 8 forks source link

[BUG] Error message in hrdiagrams.stack is incorrect. #77

Closed Krytic closed 2 years ago

Krytic commented 2 years ago

Describe the bug The error message for an invalid age_range in hrdiagrams.stack is incorrect. For the file hrs-bin-imf135_300.z020.dat, requesting an age_range of [6.0, 11.0] produces an error:

Traceback (most recent call last):
  File "testhoki.py", line 11, in <module>
    my_plot = hr.plot(age_range=age_range)
  File "/home/sean/Desktop/hoki/hoki/hrdiagrams.py", line 319, in plot
    self.stack(age_range[0], age_range[1])
  File "/home/sean/Desktop/hoki/hoki/hrdiagrams.py", line 188, in stack
    raise HokiFatalError("The age range requested is outside the valid range"
hoki.utils.exceptions.HokiFatalError: The age range requested is outside the valid range(6.0 to 11.1 inclusive)6.0 11.0

To Reproduce Download the hrs-bin-imf135_300.z020.dat file from BPASS,

Simple reproducing code:

from hoki import load
import matplotlib.pyplot as plt
import numpy as np

file = 'hrs-bin-imf135_300.z020.dat'
hr_type = 'TL'
age_range = [6.0, 11.0]

hr = load.model_output(file, hr_type=hr_type)

my_plot = hr.plot(age_range=age_range)

plt.xlim(5, 3.3)
plt.axvline(3.5)
my_plot.set_title(f"{file} -- type: {hr_type} (stacked ages from {age_range[0]} to {age_range[1]})")
plt.show()

Expected behavior Either a consistent error message, or the stack to be created.

Screenshots n/a

Desktop (please complete the following information):

Additional context n/a

Krytic commented 2 years ago

After testing, it appears that BPASS_TIME_BINS[-1] is suspect to a floating point roundoff error on my system. It is being represented as 10.999999999999982 instead of 11 which it should. I have a fix in the works.