Writing localisation tables with added Z column
mb1069 opened this issue · 1 comments
mb1069 commented
- Picasso version: latest
- Python version: 3.10.12
- Operating System: Ubuntu 22.04
Description
I am using an external application to assign Z positions to localisations, and would like to write a h5py file that can be read into Picasso Render to illustrate the results.
What I Did
I can read the hdf5 file from picasso localize as follows
df = pd.read_hdf(dirname+'storm_1_MMStack_Default.ome_locs_undrifted.hdf5', key='locs')
But writing a file as follow:
df.to_hdf('locs.hdf5', key='locs')
causes picasso render to fail silently. Editing the source code to throw the error yields:
[13:30, 01/11/2023] Miguel d'Arcangues Boland: Traceback (most recent call last):
File "/home/miguel/Projects/smlm_z/picasso/picasso/gui/render.py", line 11826, in open_file_dialog
self.view.add_multiple(paths)
File "/home/miguel/Projects/smlm_z/picasso/picasso/gui/render.py", line 5730, in add_multiple
raise e
File "/home/miguel/Projects/smlm_z/picasso/picasso/gui/render.py", line 5728, in add_multiple
self.add(path, render=False)
File "/home/miguel/Projects/smlm_z/picasso/picasso/gui/render.py", line 5613, in add
locs, info = io.load_locs(path, qt_parent=self)
File "/home/miguel/Projects/smlm_z/picasso/picasso/io.py", line 1244, in load_locs
print(locs_file['locs'][...])
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py/_objects.pyx", lin…
[13:30, 01/11/2023] Miguel d'Arcangues Boland: Traceback (most recent call last):
File "/home/miguel/Projects/smlm_z/picasso/picasso/gui/render.py", line 11826, in open_file_dialog
self.view.add_multiple(paths)
File "/home/miguel/Projects/smlm_z/picasso/picasso/gui/render.py", line 5730, in add_multiple
raise e
File "/home/miguel/Projects/smlm_z/picasso/picasso/gui/render.py", line 5728, in add_multiple
self.add(path, render=False)
File "/home/miguel/Projects/smlm_z/picasso/picasso/gui/render.py", line 5613, in add
locs, info = io.load_locs(path, qt_parent=self)
File "/home/miguel/Projects/smlm_z/picasso/picasso/io.py", line 1244, in load_locs
print(locs_file['locs'][...])
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "/home/miguel/anaconda3/envs/picasso/lib/python3.10/site-packages/h5py/hl/group.py", line 359, in __getitem_
raise TypeError("Accessing a group is done with bytes or str, "
TypeError: Accessing a group is done with bytes or str, not <class 'ellipsis'>
How can I write a file including the Z position which picasso can read correctly?
mb1069 commented
I found the solution
import h5py
with h5py.File('./locs_w_z.hdf5', "w") as locs_file:
locs_file.create_dataset("locs", data=locs.to_records())