21cmfast / 21cmFAST

Official repository for 21cmFAST: a code for generating fast simulations of the cosmological 21cm signal
MIT License
56 stars 37 forks source link

[BUG] I/O issues in the new Lightcones #372

Closed daviesje closed 1 month ago

daviesje commented 3 months ago

Describe the bug: There are a couple of small issues with loading lightcones since the "distances" field was added. The first is that lightcones generated from a previous version no longer load, since they cannot find this field. The second is that the units in the LightCone.lightcone_distances field don't seem to be saved, so that when you get lightcone_redshifts with a lightcone loaded from file it crashes when trying to call astropy.cosmology.z_at_value.

Solutions To fix the first problem, I think it would be a good idea to have an optional "compatibility" flag for reading which does not attempt the fields which would cause a crash across version, these include the global_parameters structure and any key used directly in the LightCone.read_particular method. In this case we may want to print warnings about missing fields and perhaps disallow further computation.

To fix the second, if we want lightcone_distances to have units, we should add them in read_particular, otherwise we can fix them to Mpc, and add the units when doing the lightcone_redshifts calculation.

daviesje commented 1 month ago

The important part of this issue was fixed by #392. While being able to load lightcones from previous versions would be nice in the future, it will be easier to regenerate lightcones in the vast majority of cases, so I'm closing this issue.