Skip to content
Snippets Groups Projects
Commit ab088a0f authored by Eric Wait's avatar Eric Wait
Browse files

Added explicit thread count to klb reader / writer

parent f8f9d2bd
Branches
No related tags found
No related merge requests found
...@@ -70,8 +70,8 @@ function [im, imD] = ReaderKLB(varargin) ...@@ -70,8 +70,8 @@ function [im, imD] = ReaderKLB(varargin)
try try
inType = class(MicroscopeData.KLB.readKLBroi(fullfile(imPath,klbList(1).name),ones(2,5))); inType = class(MicroscopeData.KLB.readKLBroi(fullfile(imPath,klbList(1).name),ones(2,5)));
catch catch err
warning('No images with at this data field!'); warning(err.identifier,'%s\nNo images with at this data field!',err.message);
return return
end end
...@@ -173,6 +173,9 @@ end ...@@ -173,6 +173,9 @@ end
function im = readKLBChunk(imD,outType,roi_xyz,filePerC,filePerT,prgs) function im = readKLBChunk(imD,outType,roi_xyz,filePerC,filePerT,prgs)
im = zeros(Utils.SwapXY_RC(roi_xyz(2,:)-roi_xyz(1,:))+1,outType); im = zeros(Utils.SwapXY_RC(roi_xyz(2,:)-roi_xyz(1,:))+1,outType);
myCluster = parcluster('local');
threads = myCluster.NumWorkers;
if (filePerC) if (filePerC)
if (filePerT) if (filePerT)
% individual image per c and t % individual image per c and t
...@@ -180,7 +183,7 @@ function im = readKLBChunk(imD,outType,roi_xyz,filePerC,filePerT,prgs) ...@@ -180,7 +183,7 @@ function im = readKLBChunk(imD,outType,roi_xyz,filePerC,filePerT,prgs)
for t=roi_xyz(1,5):roi_xyz(2,5) for t=roi_xyz(1,5):roi_xyz(2,5)
for c=roi_xyz(1,4):roi_xyz(2,4) for c=roi_xyz(1,4):roi_xyz(2,4)
fileName = sprintf('%s_c%d_t%04d.klb',imD.DatasetName,c,t); fileName = sprintf('%s_c%d_t%04d.klb',imD.DatasetName,c,t);
im(:,:,:,c,t) = MicroscopeData.KLB.readKLBroi(fullfile(imD.imageDir,fileName), Utils.SwapXY_RC([[roi_xyz(1,1:3),1,1]; [roi_xyz(2,1:3),1,1]])); im(:,:,:,c,t) = MicroscopeData.KLB.readKLBroi(fullfile(imD.imageDir,fileName), Utils.SwapXY_RC([[roi_xyz(1,1:3),1,1]; [roi_xyz(2,1:3),1,1]]),threads);
i = i +1; i = i +1;
if (~isempty(prgs)) if (~isempty(prgs))
prgs.PrintProgress(i); prgs.PrintProgress(i);
...@@ -192,7 +195,7 @@ function im = readKLBChunk(imD,outType,roi_xyz,filePerC,filePerT,prgs) ...@@ -192,7 +195,7 @@ function im = readKLBChunk(imD,outType,roi_xyz,filePerC,filePerT,prgs)
i=0; i=0;
for c=roi_xyz(1,4):roi_xyz(2,4) for c=roi_xyz(1,4):roi_xyz(2,4)
fileName = sprintf('%s_c%d.klb',imD.DatasetName,c); fileName = sprintf('%s_c%d.klb',imD.DatasetName,c);
im(:,:,:,c,:) = MicroscopeData.KLB.readKLBroi(fullfile(imD.imageDir,fileName), Utils.SwapXY_RC([[roi_xyz(1,1:3),1,roi_xyz(1,5)]; [roi_xyz(2,1:3),1,roi_xyz(2,5)]])); im(:,:,:,c,:) = MicroscopeData.KLB.readKLBroi(fullfile(imD.imageDir,fileName), Utils.SwapXY_RC([[roi_xyz(1,1:3),1,roi_xyz(1,5)]; [roi_xyz(2,1:3),1,roi_xyz(2,5)]]),threads);
i = i +1; i = i +1;
if (~isempty(prgs)) if (~isempty(prgs))
prgs.PrintProgress(i*imD.NumberOfFrames); prgs.PrintProgress(i*imD.NumberOfFrames);
...@@ -204,7 +207,7 @@ function im = readKLBChunk(imD,outType,roi_xyz,filePerC,filePerT,prgs) ...@@ -204,7 +207,7 @@ function im = readKLBChunk(imD,outType,roi_xyz,filePerC,filePerT,prgs)
i = 0; i = 0;
for t=roi_xyz(1,5):roi_xyz(2,5) for t=roi_xyz(1,5):roi_xyz(2,5)
fileName = sprintf('%s_t%04d.klb',imD.DatasetName,t); fileName = sprintf('%s_t%04d.klb',imD.DatasetName,t);
im(:,:,:,:,t) = MicroscopeData.KLB.readKLBroi(fullfile(imD.imageDir,fileName), Utils.SwapXY_RC([[roi_xyz(1,1:4),1]; [roi_xyz(2,1:4),1]])); im(:,:,:,:,t) = MicroscopeData.KLB.readKLBroi(fullfile(imD.imageDir,fileName), Utils.SwapXY_RC([[roi_xyz(1,1:4),1]; [roi_xyz(2,1:4),1]]),threads);
i = i +1; i = i +1;
if (~isempty(prgs)) if (~isempty(prgs))
prgs.PrintProgress(i*imD.NumberOfChannels); prgs.PrintProgress(i*imD.NumberOfChannels);
...@@ -212,6 +215,6 @@ function im = readKLBChunk(imD,outType,roi_xyz,filePerC,filePerT,prgs) ...@@ -212,6 +215,6 @@ function im = readKLBChunk(imD,outType,roi_xyz,filePerC,filePerT,prgs)
end end
else else
% only one file % only one file
im = MicroscopeData.KLB.readKLBroi(fullfile(imD.imageDir,[imD.DatasetName '.klb']),Utils.SwapXY_RC(roi_xyz)); im = MicroscopeData.KLB.readKLBroi(fullfile(imD.imageDir,[imD.DatasetName '.klb']),Utils.SwapXY_RC(roi_xyz),threads);
end end
end end
...@@ -133,32 +133,35 @@ function WriterKLB(im, varargin) ...@@ -133,32 +133,35 @@ function WriterKLB(im, varargin)
blockMem = prod(blockSize_xyzct)*bytes; blockMem = prod(blockSize_xyzct)*bytes;
blockSize_xyzct(5) = max(1,floor((1024^2)/blockMem)); % try to get close to 1MB block size blockSize_xyzct(5) = max(1,floor((1024^2)/blockMem)); % try to get close to 1MB block size
myCluster = parcluster('local');
threads = myCluster.NumWorkers;
fileName = fullfile(outDir,args.imageData.DatasetName); fileName = fullfile(outDir,args.imageData.DatasetName);
prgs = Utils.CmdlnProgress(args.imageData.NumberOfChannels*args.imageData.NumberOfFrames,true); prgs = Utils.CmdlnProgress(args.imageData.NumberOfChannels*args.imageData.NumberOfFrames,true);
if (args.filePerT) if (args.filePerT)
if (args.filePerC) if (args.filePerC)
for t=1:args.imageData.NumberOfFrames for t=1:args.imageData.NumberOfFrames
for c=1:args.imageData.NumberOfChannels for c=1:args.chanList
fileNameCT = sprintf('%s_c%d_t%04d',fileName,c,t); fileNameCT = sprintf('%s_c%d_t%04d',fileName,args.chanList(c),t);
MicroscopeData.KLB.writeKLBstack(im(:,:,:,c,t), [fileNameCT,'.klb'], -1, [args.imageData.PixelPhysicalSize,1,1], blockSize_xyzct); MicroscopeData.KLB.writeKLBstack(im(:,:,:,c,t), [fileNameCT,'.klb'], threads, [args.imageData.PixelPhysicalSize,1,1], blockSize_xyzct);
prgs.PrintProgress(c+(t-1)*args.imageData.NumberOfChannels); prgs.PrintProgress(c+(t-1)*args.imageData.NumberOfChannels);
end end
end end
else else
for t=1:args.imageData.NumberOfFrames for t=1:args.imageData.NumberOfFrames
fileNameT = sprintf('%s_t%04d',fileName,t); fileNameT = sprintf('%s_t%04d',fileName,t);
MicroscopeData.KLB.writeKLBstack(im(:,:,:,:,t), [fileNameT,'.klb'], -1, [args.imageData.PixelPhysicalSize,1,1], blockSize_xyzct); MicroscopeData.KLB.writeKLBstack(im(:,:,:,:,t), [fileNameT,'.klb'], threads, [args.imageData.PixelPhysicalSize,1,1], blockSize_xyzct);
prgs.PrintProgress(t*args.imageData.NumberOfChannels); prgs.PrintProgress(t*args.imageData.NumberOfChannels);
end end
end end
elseif (args.filePerC) elseif (args.filePerC)
for c=1:args.imageData.NumberOfChannels for c=1:length(args.chanList)
fileNameC = sprintf('%s_c%d',fileName,c); fileNameC = sprintf('%s_c%d',fileName,args.chanList(c));
MicroscopeData.KLB.writeKLBstack(squeeze(im(:,:,:,c,:)), [fileNameC,'.klb'], -1, [args.imageData.PixelPhysicalSize,1,1], blockSize_xyzct); MicroscopeData.KLB.writeKLBstack(squeeze(im(:,:,:,c,:)), [fileNameC,'.klb'], threads, [args.imageData.PixelPhysicalSize,1,1], blockSize_xyzct);
prgs.PrintProgress(c*args.imageData.NumberOfFrames); prgs.PrintProgress(c*args.imageData.NumberOfFrames);
end end
else else
MicroscopeData.KLB.writeKLBstack(im, [fileName,'.klb'], -1, [args.imageData.PixelPhysicalSize,1,1], blockSize_xyzct); MicroscopeData.KLB.writeKLBstack(im, [fileName,'.klb'], threads, [args.imageData.PixelPhysicalSize,1,1], blockSize_xyzct);
end end
if (args.verbose) if (args.verbose)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment