nvladimus / npy2bdv

Fast writing of numpy 3d-arrays into HDF5 Fiji/BigDataViewer files.
GNU General Public License v3.0
34 stars 11 forks source link

Fix shape broadcast error when input image has odd number in shape #15

Closed pr4deepr closed 9 months ago

pr4deepr commented 9 months ago

https://github.com/nvladimus/npy2bdv/issues/14

Fix shape broadcast error when images with odd shapes are used with subsampling

pr4deepr commented 9 months ago

I know this may be separate, but we should also add an optional argument for read only: https://github.com/nvladimus/npy2bdv/blob/4d1ffd356b0ec99f45e26fe8327275602fd12095/npy2bdv/npy2bdv.py#L693

Currently, BDVEditor opens it as read/write, but I cannot access it as read only. Is it possible to add optional:

def __init__(self, filename,mode='r+'): and follow that up with: self._file_object_h5 = h5py.File(self.filename_h5, mode)

This may affect functions such as crop_view and finalize..

Cheers Pradeep

pr4deepr commented 9 months ago

I took a stab at it. Instead of changing BDVEditor, I added a BDVReader class. Also added the option to read individual z planes as well

https://github.com/nvladimus/npy2bdv/blob/582218114da76950f9cea2fb8428872c39e5bc07/npy2bdv/npy2bdv.py#L888

nvladimus commented 8 months ago

Hi, Pradeep, Many thanks for the thoughtful PR. I wrote a couple of tests and it worked perfectly (the downsampling of odd-shaped arrays part). Regarding the BdvReader class, thanks for proposing it. I found it almost fully duplicating the BDVEditor, except the read-only part. So I incorporated the mode= parameter into the BdvEditor constructor, and removed the duplicate BdvReader class altogether. I hope this makes sense. I merged your PR to master branch, and updated the CHANGELOG.md with your contribution. Last thing, if you can, could you possibly write a unit test in the test_h5.py for reading the single plane using BdvEditor.read_view(..., z=...) option? This would be great to make sure there are no bugs. Many thanks for your contribution! 🥇