dangilman / pyHalo

A python toolkit for rendering populations of dark matter halos for gravitational lensing simulations
MIT License
25 stars 13 forks source link

Value of z_lens with too much precision causes error #51

Open cgannonucm opened 9 months ago

cgannonucm commented 9 months ago

Description

Unexpected error when creating a CDM realization using the pyHalo.preset_models.CDM method. I was tabulating properties of CDM realizations across different host halo masses / lens redshifts and came across an unexpected error. It appears that including too many decimal places when specifying a z_lens value causes a crash.

For example: realization = CDM(z_lens=0.333,z_source=2, sigma_sub=0.3,log_mlow=8,log_mhigh=9,LOS_normalization=0.0,log_m_host=13.18888) crashes

But realization = CDM(z_lens=0.33,z_source=2, sigma_sub=0.3,log_mlow=8,log_mhigh=9,LOS_normalization=0.0,log_m_host=13.18888)

executes fine

traceback Exception Traceback.txt

This problem can be worked around by using np.round to round the value of z_lens before passing to CDM, but I figured this issue could be quite confusing to encounter.

dangilman commented 9 months ago

Hi @cgannonucm, yes thanks for pointing this out. It's true that due to some settings hard-coded in pyHalo there can be rounding errors that cause division by zero if one specifies lens redshifts to more than two decimal places of precision. I plan on fixing this issue in the next pypi release