mtex icon indicating copy to clipboard operation
mtex copied to clipboard

EBSD.load comes with large time penalty

Open kilir opened this issue 2 years ago • 1 comments

Comparing the following,

tic
ebsd = loadEBSD_h5oina("testdata.h5oina")
toc

Elapsed time is 1.599104 seconds.

tic
ebsd = EBSD.load("testdata.h5oina")
toc

Elapsed time is 22.712014 seconds. where the latter spends lots of time on file2cell if I'm not mistaken.

Maybe we should just mention in the documentation that "guessing" the file type may come with a penalty.

Rüdiger

kilir avatar Jun 07 '22 10:06 kilir

Personally I have written an EBBSD loader which checks the extension and compares to the available loaders in the interfaces dir. Currently calling

ext_f = getMTEXpref('EBSDExtensions'); 

does not return all extensions for the loader. This function simply parses the function names and returns them for loading, they are called by feval(...). As you see I only check for ebsd loaders: regexp(listing(i).name,'loadEBSD_\w+.m' and I call 'convertEuler2...' due to my data. This canb e changed

function [ebsd,filenames]=loadallEBSD(fname,varargin)
%LOADALLEBSD loads all supplied ebsd-maps supplied in the fname pathname variable.
%   If fname is a cell containing paths to ebsd-files, the output will also
%   be a cell containing corresponding loaded ebsd-maps. If fname is a
%   string, the output will be a single loaded ebsd-map.

%If cell, load all files into cell
if iscell(fname)
    ebsd=cell(0);
    filenames=cell(0);

    for i=1:length(fname)
        [output,fnames] = loadallEBSD(fname{i},varargin{:});
        if isa(output,'EBSD')
            ebsd{end+1} = output;
            filenames{end+1}=fnames;
        end
    end
else
    %Get all file extensions for which load functions exist
    [mtex_dir,~,~] = fileparts(which('startup_mtex'));
    listing = dir([mtex_dir,filesep,'interfaces']);
    ext_f = cell(0);
    k=0;

    for i  =  1:length(listing)
        if regexp(listing(i).name,'loadEBSD_\w+.m') 
            k = k + 1;
            substr = split(listing(i).name,["_","."]);
            ext_f{k} = substr{2};
        end
    end
    
    % ext_f = getMTEXpref('EBSDExtensions'); %Does not contain all extensions!
    %load single file
    [~,filenames,ext]=fileparts(fname);
    ext = char(ext);

    if any(strcmp(ext_f,ext(2:end)))
        funcname = strcat('loadEBSD_',ext(2:end));
        ebsd = feval(funcname,fname,'convertEuler2SpatialReferenceFrame',varargin{:});
    else
        warning(['Loader for extension ', ext ,' not found'])
        ebsd = [];
        filenames = [];
        return 
    end

end
end

vedadb avatar Nov 22 '23 08:11 vedadb