mtex-toolbox / mtex

MTEX is a free Matlab toolbox for quantitative texture analysis. Homepage:
http://mtex-toolbox.github.io/
GNU General Public License v2.0
281 stars 185 forks source link

ebsd.export('myfile.h5') creates an h5 file that EBSD.load cannot read #1365

Open argerlt opened 2 years ago

argerlt commented 2 years ago

What is the problem This is the simplest version of the code I could write to reproduce the problem:

===================== ebsd = EBSD.load([mtexEBSDPath filesep 'martensite.cpr'],'convertEuler2SpatialReferenceFrame') ebsd.export('test.h5') ebsd_from_h5 = EBSD.load('test.h5')

and it produces the error:

Output argument "ebsd" (and possibly others) not assigned a value in the execution with "loadEBSD_h5" function.

Error in EBSD.load (line 86) ebsd{k} = feval(['loadEBSD_',char(interface)],...

===================== It also happens with my own ebsd data as well, so I don't think it's a problem with the datasets itself. I also tried remaning to h5, hf5, and hdf5, none of which seemed to work. I also tried fixing loadEBSD_h5.m myself, but with little luck. If I do get it to work, I will add it as a pull request What do you want to do? change loadEBSD_h5 so it will successfully import data generated by the MTEX export

What MTEX version do you use? 5.7.0

YJoyce commented 11 months ago

Hi, I am experiencing the same problem. May I ask if you solved it and what should be done about it?

argerlt commented 11 months ago

Sort of. I actually sidestepped the problem after posting this in 2022, but I came up with a better solution just now. I'll list both here.

Quick background first though, I THINK(@ralfHielscher or someone knowledgeable, correct me if I'm wrong) this problem persists in part because TSL, Bruker, DREAM3D, and MTEX all use .h5 to store EBSD data, but all have vastly different methods for storing identical datasets. This makes sense; there is no way DREAM3D, which handles correlated FEM meshes and voxel data simultaneously, would use the same format as TSL, which allows for the storing of per-pixel Kikuchi patterns. However, this means any reader trying to read all three inputs is going to have to parse the difference on the fly from clues in the file layout, which is even more challenging because all 4 formats listed above keep changing slightly, yet all call themselves ".h5".

Which is all to say, fixing this function would be hard, and any fix would probably break again quickly, so not a lot of incentive to work on it when there are other lower hanging fruit.

My solution in 2022:

ORIX is a python package that does some (but definitely not all) of what MTEX can do. If you can do your processing entirely in ORIX, it has some very robust to/from hdf5 functions with a comprehensive tutorial. (I suggest you read the whole page, but this links directly to the saving part). Be warned though, this is YET ANOTHER .h5 format, different from MTEX, DREAM3D, Bruker, or TSL.

My solution just now:

Most people just want *.h5 files because they are space-efficient. If this is your case, try .crc instead:

ebsd = EBSD.load([mtexEBSDPath filesep 'martensite.cpr'],'convertEuler2SpatialReferenceFrame');
ebsd.export('test.crc');
ebsd_from_crc = EBSD.load('test.crc')

It takes up about 50% more space than .h5, but its still way better and much faster read/write than the %1500 bloat seen from saving as ASCII text files.

Possible solution using h5

Messing around, it looks like loadEBSD_h5 is searching for additional input variables. Here is my best shot so far:

ebsd_from_h5 = EBSD.load('mtex_eqport_test.crch5','interface','h5','/ebsd')

this at least seems to load the file, but then it doesn't know where to save it, which make me think there is some additional variable like 'export_as' or write_to that I haven't found

hope this helps.

YJoyce commented 11 months ago

Thanks for the detailed reply, it gave me some inspiration!! Thank you again! I'll come back later if I've solved the problem.