zkbt / chromatic

Tools for visualizing spectrosopic light curves, with flux as a function of wavelength and time.
MIT License
14 stars 4 forks source link

Rainbow()._create_copy() changes boolean arrays in core_dictionaries to binary #250

Open gmduvvuri opened 2 months ago

gmduvvuri commented 2 months ago

For reasons I can probably get around with some work, I have been saving some wavelike and timelike masks as booleans so I can flip True/False within certain functions. What I ran into after copying a rainbow is that those boolean masks changed to integer 0/1 values and I can't find what deepcopy step is behind it. This problem occurs with Python bool and np.bool_. Niche but an unexpected behavior for an important function that it would be nice to figure out.

from chromatic import Rainbow
import numpy as np
from astropy import units

wave = np.arange(4) * units.micron
time = np.arange(3) * units.day
flux = np.ones((4, 3))

wave_bool = np.array([True, False, True, True])
time_bool = np.array([True] * len(time), dtype=np.bool_)

r = Rainbow(time=time, wavelength=wave, flux=flux)

r.wavelike["wave_bool"] = wave_bool
r.timelike["time_bool"] = time_bool

print(r.wavelike["wave_bool"])
print(r.timelike["time_bool"])

r_copy = r._create_copy()

print(r_copy.wavelike["wave_bool"])
print(r_copy.timelike["time_bool"])
zkbt commented 2 months ago

Weird, fascinating. There's a slight possibility this is related to some of the weird @propertys that I set up, or some weird type management in __getattr__, or something else, but I need to look a little more closely to see.

gmduvvuri commented 1 month ago

Finally got around to this extra little test but the metadata dictionary preserves the original array so the differences between metadata + similarities between wavelike/timelike should help hunt this down (I will not be doing this anytime soon, going to plough ahead with this workaround for now, sorry).