py4dstem/py4DSTEM

Error importing .mib data

yining2260878 opened this issue · 1 comments

With Python 3.19.6 and py4DSTEM 0.13.17

Hi, I was using py4DSTEM.io.import_file to load .mib files. When importing data acquired from a single chip (256X256 in the diffraction plane), that works very well.
Then I want to import a .mib file acquired from combined 4 chips (514X514 in the diffraction plane), and it comes to an error like this:

KeyError Traceback (most recent call last)
Cell In[5], line 3
-> 3 dataset_vac = py4DSTEM.io.import_file(filepath = vac_file_path, scan = (300,301))
File ~\anaconda3\envs\yining4dstem\lib\site-packages\py4DSTEM\io\import_file.py:75, in import_file(filepath, mem, binfactor, filetype, **kwargs)
72 # elif filetype == "kitware_counted":
73 # data = read_kitware_counted(filepath, mem, binfactor, metadata=metadata, **kwargs)
74 elif filetype == "mib":
-> 75 data = load_mib(filepath, mem=mem, binfactor=binfactor,**kwargs)
76 else:
77 raise Exception("Bad filetype!")

File ~\anaconda3\envs\yining4dstem\lib\site-packages\py4DSTEM\io\nonnative\read_mib.py:28, in load_mib(file_path, mem, binfactor, reshape, flip, scan, **kwargs)
26 # Get scan info from kwargs
27 header = parse_hdr(file_path)
-> 28 width = header["width"]
29 height = header["height"]
30 width_height = width * height

KeyError: 'width'

I think I've figured this problem out:

1st our Merlin detector saves the chip configuration as '2X2G' rather than '2X2', so adding '2X2G' as an acceptable option in the if statements in read_mib.py fixes that issue. A different work around would be to change the headers in the .mib file directly but the .mib is too large to open in a text editor. The Merlin detector does generate a .hdr file with the headers in the same folder as the .mib, it might be a good idea to add an optional keyword argument called hdr e.g. load_mib(hdr = 'file_data.hdr') so that it reads the header from the accompanying .hdr file instead of the mib and if you wanted to change headers you can just open the .hdr in a text editor.

2nd, in our configuration the gap between chips is apparently 2 pixels wide so the diffraction pattern has a cross in the middle dividing the pattern into quadrants where the pixel intensity is zero and giving a width and height of the DP as 514 X 514 not 512 X 512. So this has to be changed when defining width and height and the dictionary 'mib_file_size_dict' in get_mib_depth now needs to be updated for 514 X 514 file size.

Diffraction Pattern