BYU-MicrostructureOfMaterials / OpenXY

Other
35 stars 14 forks source link

Can Open XY read .ebsp files? #24

Open anastasiavr opened 3 years ago

anastasiavr commented 3 years ago

Hello, I am currently using Aztec software for ebsp acquisition, which stores the kikuchi patterns in an .ebsp file. One can then export the patterns in .tiff file types but this is a very very long process. Is there a way open xy can work directly with the .ebsp file instead of the tiffs? Thank you in advance!

eretnek commented 3 years ago

Unfortunately, not at this time. Newer versions of AZtec can output hdf5 files, but as far as I can tell, they only includes the information and not the patterns themselves. Edax's hdf5 format does include pattern data, and saves a lot of time. Hopefully, AZtec will follow suit someday.

-Tim

On Wed, Feb 10, 2021, 5:23 AM anastasiavr notifications@github.com wrote:

Hello, I am currently using Aztec software for ebsp acquisition, which stores the kikuchi patterns in an .ebsp file. One can then export the patterns in .tiff file types but this is a very very long process. Is there a way open xy can work directly with the .ebsp file instead of the tiffs? Thank you in advance!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/BYU-MicrostructureOfMaterials/OpenXY/issues/24, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACWHJDKCN5D3CAPNGTXNLSLS6J3EVANCNFSM4XM3MQ6A .

mikesmic commented 3 years ago

Hi, just to add that it is possible to read uncompressed .ebsp files. I wrote some code to read them in EMsoft a few years back (EMsoft-org/EMsoft@ef30487abfd14e825370ad73bc41afc215719f0a EMsoft-org/EMsoft@c3bce54af0a45fd50f4fca5a8fffc2f96d826af0) because I was having a similar nightmare with 100,000+ files in a single directory.

Let me know if you want to implement this here, I haven't coded in matlab in a good while but I can run you through the structure of an .ebsp file.

anastasiavr commented 3 years ago

Hello, I took some time to look at your codes, but unfortunately I am not familiar with Fortran. I am using MATLAB for some time now (I definitely am not an expert) but I think understanding the structure of the .ebsp files would be very useful as a first step and interesting for other users as well. Thank you for taking the time to help.

dtfullwood commented 3 years ago

Mike is going to help us figure out the structure, so hopefully we'll have a go at it in the near future...

dtfullwood commented 3 years ago

anastasiavr - do you have small scan with the relevant .cpr/.crc/.ctf/.ebsp files that we could use to develop this capability? If so, email me on dfullwood@byu.edu. Mike has sent us some python code to help with this. Thanks David

anastasiavr commented 3 years ago

@dtfullwood Yes, I will have a look for a small scan, otherwise I will have to compress a larger one. I will get back you via email. Thank you! Anastasia

hakonanes commented 3 years ago

Mike has sent us some python code to help with this.

@mikesmic, could you share this Python code with me (hakon.w.anes@ntnu.no) as well? We would like to read from and write to .ebsp files in the kikuchipy Python package. We can read and write some formats, but would like to expand our IO capabilities.

dtfullwood commented 3 years ago

I just sent you some matlab code that will read an image from an .EBSP file. it is just rough code for playing with but has the essential information:

% Read EBSP file [file,path]=uigetfile; ftoopen=fopen([path,file]); fseek(ftoopen,8,'bof'); %move to start of offset data xCells=37; %number of points in x direction from .cpr or .crc file – need to automate this yCells=40; Offset=fread(ftoopen,xCellsyCells,'uint64'); % start point of each pattern in file Offset=reshape(Offset,[yCells,xCells]); % I’m not 100% sure about the order here – need to check against OpenXY i=1; %pick number of pattern desired in y direction j=1; %pick number of pattern desired in x direction fseek(ftoopen,Offset(i,j),'bof'); patdims=fread(ftoopen,8,'uint16'); patdims=[patdims(5),patdims(3)]; % size of EBSP patsize=patdims(1)patdims(2); pat=fread(ftoopen,patsize,'uint8'); pat=reshape(pat,patdims); imagesc(pat) colormap gray fclose(ftopen);

Here is the original python code, but the pattern dimension and scan size are hard coded in. The matlab code shows how to read the pattern dimensions; and scan size (xCells, yCells) can be read from the .crc or .cpr file very easily (note that github reads the comment symbol '#' as a header command and bolds the line...):

Script to load a single EBSD pattern from a .ebsp file at

a specified location in the EBSD map.

Format of the .ebsp file

- Header of 8 bytes

- Block of 1 8-byte integer per pattern in the map - these

are the position of each pattern block in the file in the

order they appear in the map (I think row by row)

- Pattern blocks, each consisting of

- 16 bytes - 4 4-byte ints. I think the middle 2 are the

pattern dimensions, not sure about the others

- 1-byte unsigned int per pixel in the pattern

- 18 bytes - not sure what this is

import numpy as np import matplotlib.pyplot as plt

def load_pat(offset, pat_file, pat_dims): """Read a single EBSD pattern image from file.

Parameters
----------
offset: int
    Position of the start of the pattern block.

pat_file: str
    Path to the .ebsp file.

pat_dims : tuple of int
    Dimensions of the pattern image.

Returns
-------
np.ndarray
    Loaded pattern image

"""
pat = np.fromfile(
    pat_file,
    offset=offset + 16,
    count=pat_dims[0] * pat_dims[1],
    dtype=np.uint8
).reshape(pat_dims)

return pat

pat_file = "7aafe81e-f69a-4ec8-b952-e4df78f04d7d.ebsp"

Dimensions of the EBSD map and patterns

y, x for both

map_dims = (70, 70) pat_dims = (512, 622)

Create map of pattern positions in file

pat_offsets = np.fromfile( pat_file, offset=8, count=map_dims[0] * map_dims[1], dtype=np.int64 ).reshape(map_dims)

Load a single pattern from the file

pat = load_pat(pat_offsets[0, 0], pat_file, pat_dims)

plt.figure() plt.imshow(pat)

hakonanes commented 3 years ago

Thanks a lot @dtfullwood (and @mikesmic?)!

mikesmic commented 3 years ago

Thanks for sharing that on! @hakonanes looks like a very nice package, I can see that being very useful