manoharan-lab / holopy

Hologram processing and light scattering in python
GNU General Public License v3.0
134 stars 50 forks source link

Error displaying reconstruction slice #367

Closed barkls closed 3 years ago

barkls commented 4 years ago

The following code should display only the second slice (z=1) of a reconstruction stack, but it gives an error

import holopy as hp
holo = hp.core.io.get_example_data('image0001')
recon = hp.propagate(holo, [0, 1])
one_slice = recon.sel(z=1)
hp.show(one_slice)

The code works when replacing the second last line with one_slice = recon.sel(z=[1]) (note z is a list).

The problem is that xr.DataArray.sel() keeps z as a coord but not a dim. Line 228 of hp/core/io/vis.py checks if z is an attribute and then tries to take its length but this fails here since it's just a single value. That line of code should probably check if 'z' is in im.dims instead of the hasattr. We should also add a test.