pyxem / pyxem-demos

Examples and tutorials of multi-dimensional diffraction microscopy workflows using pyxem.
30 stars 38 forks source link

mib to h5 conversion #77

Closed adriente closed 3 years ago

adriente commented 3 years ago

Hi,

We have an issue with the mib_to_h5stack conversion function is throwing the following error :

>>> pxm.utils.io_utils.mib_to_h5stack(data_path, h5_path)
---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_26584/236218266.py in <module>
      1 h5_path = 'Z:\\user\\Pixelated detector\\21-09-09 First test\\STEM mode\\02-test\\20210909 155051\\default.h5'
      2 
----> 3 pxm.utils.io_utils.mib_to_h5stack(data_path, h5_path)

~\Anaconda3\envs\user4dstem\lib\site-packages\pyxem\utils\io_utils.py in mib_to_h5stack(fp, save_path, mmap_mode)
    222                     _stack_h5dump(data, hdr_info, save_path)
    223         elif hdr_info["raw"] == "MIB":
--> 224             _stack_h5dump(data, hdr_info, save_path)
    225     return
    226 

~\Anaconda3\envs\user4dstem\lib\site-packages\pyxem\utils\io_utils.py in _stack_h5dump(data, hdr_info, saving_path, raw_binary, stack_num)
    901                     )
    902                 else:
--> 903                     data_dump1 = _untangle_raw(
    904                         data_dump0, hdr_info, data_dump0.shape[0]
    905                     )

~\Anaconda3\envs\user4dstem\lib\site-packages\pyxem\utils\io_utils.py in _untangle_raw(data, hdr_info, stack_size)
   1029             (da.concatenate((det1, det3), 1), da.concatenate((det2, det4), 1)), 2
   1030         )
-> 1031     return untangled_data
   1032 
   1033 

UnboundLocalError: local variable 'untangled_data' referenced before assignment

Searching a little bit in the source code it seems that there is an issue with the hdr associated with the mib file. When we run :

>>> _parse_hdr(data_path)
{'width': 256,
 'height': 256,
 'Assembly Size': '1x1',
 'offset': 384,
 'data-type': 'unsigned',
 'data-length': '8',
 'Counter Depth (number)': 6,
 'raw': 'MIB',
 'byte-order': 'dont-care',
 'record-by': 'image',
 'title': 'Z:\\user\\Pixelated detector\\21-09-09 First test\\STEM mode\\02-test\\20210909 155051\\default',
 'date': '20210909',
 'time': '15:50:57.107038',
 'data offset': 384}

It seems to us that in the source code this "Assembly Size" : "1x1" is not well taken into account. Only the "Assembly Size" : "2x2" should be working. It is not clear for us if this is the intented behavior. How can we make the conversion to h5 then ?

adriente commented 3 years ago

I have posted this issue at the wrong place. I didn't see I was in pyxem_demos. I have seen that there is an issue opened about the issue here. I am then closing the issue.

pc494 commented 3 years ago

I have posted this issue at the wrong place. I didn't see I was in pyxem_demos. I have seen that there is an issue opened about the issue here. I am then closing the issue.

This equivalent issue is https://github.com/pyxem/pyxem/issues/748?

adriente commented 3 years ago

Yes, exactly.