code changes for release 3.0.0: new PShell import
This commit is contained in:
@ -1,12 +1,15 @@
|
||||
#pragma TextEncoding = "Windows-1252"
|
||||
#pragma TextEncoding = "UTF-8"
|
||||
#pragma rtGlobals=3 // Use modern global access method and strict wave access.
|
||||
#pragma IgorVersion = 6.2
|
||||
#pragma IgorVersion = 6.36
|
||||
#pragma ModuleName = PearlAreaImport
|
||||
#pragma version = 1.13
|
||||
#if IgorVersion() < 9.00
|
||||
#include <HDF5 Browser>
|
||||
#endif
|
||||
#include "pearl-compat"
|
||||
#include "pearl-gui-tools"
|
||||
|
||||
// copyright (c) 2013-20 Paul Scherrer Institut
|
||||
// copyright (c) 2013-21 Paul Scherrer Institut
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@ -1195,6 +1198,7 @@ end
|
||||
/// a numeric index is appended to distinguish the results.
|
||||
/// the index starts at 1. existing waves are overwritten.
|
||||
///
|
||||
/// @return result code: 0 for success, < 0 for error
|
||||
///
|
||||
function adh5_reduce_brick(source, reduction_func, reduction_param, result_prefix, [progress, nthreads])
|
||||
wave source
|
||||
@ -1211,7 +1215,10 @@ function adh5_reduce_brick(source, reduction_func, reduction_param, result_prefi
|
||||
if (ParamIsDefault(nthreads))
|
||||
nthreads = -1
|
||||
endif
|
||||
|
||||
dfref base_df = GetDataFolderDFR()
|
||||
variable result = 0
|
||||
string wavenames = ""
|
||||
|
||||
// nx and nz are the image dimensions
|
||||
variable nx, ny, nz, nt
|
||||
@ -1219,10 +1226,9 @@ function adh5_reduce_brick(source, reduction_func, reduction_param, result_prefi
|
||||
ny = dimsize(source, 1)
|
||||
nz = dimsize(source, 2)
|
||||
// force 4th dimension to singleton (ad_extract_slab handles 3 dimensions only)
|
||||
nt = 0
|
||||
nt = 1
|
||||
|
||||
variable nzt = max(nz, 1) * max(nt, 1)
|
||||
variable izt
|
||||
|
||||
// set up multi threading
|
||||
if (nthreads < 0)
|
||||
@ -1239,133 +1245,159 @@ function adh5_reduce_brick(source, reduction_func, reduction_param, result_prefi
|
||||
endif
|
||||
|
||||
if (progress)
|
||||
display_progress_panel("data reduction", "extracting data (step 1 of 2)...", nzt)
|
||||
display_progress_panel("Reduction", "Processing data...", nzt)
|
||||
endif
|
||||
|
||||
variable iz, it
|
||||
variable n_sent = 0
|
||||
variable n_recvd = 0
|
||||
variable tmo = 0
|
||||
string dfname
|
||||
dfref dfr
|
||||
variable iw, nw
|
||||
string sw
|
||||
make /n=0 /free /wave result_waves
|
||||
|
||||
iz = 0
|
||||
it = 0
|
||||
|
||||
izt = 0
|
||||
for (iz = 0; iz < max(nz, 1); iz += 1)
|
||||
for (it = 0; it < max(nt, 1); it += 1)
|
||||
dfname = "processing_" + num2str(izt)
|
||||
newdatafolder /s $dfname
|
||||
ad_extract_slab(source, nan, nan, nan, nan, iz, iz, "image", pscale=1)
|
||||
wave image
|
||||
do
|
||||
// fill the processing queue up to a maximum number of folders
|
||||
if (n_sent < max(1, nthreads) * 10 + n_recvd)
|
||||
if (iz < nz)
|
||||
if (it < nt)
|
||||
// load a slab into a temporary folder
|
||||
dfname = "processing_" + num2str(n_sent)
|
||||
NewDataFolder /s $dfname
|
||||
ad_extract_slab(source, nan, nan, nan, nan, iz, iz, "image", pscale=1)
|
||||
wave image
|
||||
variable /g r_index = iz
|
||||
variable /g s_index = it
|
||||
string /g func_param = reduction_param
|
||||
|
||||
// send to processing queue
|
||||
variable /g r_index = iz
|
||||
variable /g s_index = it
|
||||
string /g func_param = reduction_param
|
||||
|
||||
if (nthreads > 0)
|
||||
WaveClear image
|
||||
ThreadGroupPutDF threadGroupID, :
|
||||
else
|
||||
processing_folders[izt] = GetDataFolderDFR()
|
||||
string param = reduction_param
|
||||
wave /wave reduced_waves = reduction_func(image, param)
|
||||
variable /g func_result = numpnts(reduced_waves)
|
||||
adh5_get_result_waves(reduced_waves, "redw_", 0)
|
||||
WaveClear image, reduced_waves
|
||||
setdatafolder ::
|
||||
endif
|
||||
|
||||
izt += 1
|
||||
// progress window
|
||||
if (progress)
|
||||
if (update_progress_panel(izt))
|
||||
result = -4 // user abort
|
||||
break
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
|
||||
if (progress)
|
||||
update_progress_panel(0, message="processing data (step 2 of 2)...")
|
||||
endif
|
||||
|
||||
dfref dfr
|
||||
for (izt = 0; (izt < nzt) && (result == 0); izt += 1)
|
||||
if (nthreads > 0)
|
||||
do
|
||||
dfr = ThreadGroupGetDFR(threadGroupID, 1000)
|
||||
if (DatafolderRefStatus(dfr) != 0)
|
||||
break
|
||||
endif
|
||||
if (progress)
|
||||
if (update_progress_panel(izt))
|
||||
result = -4 // user abort
|
||||
break
|
||||
if (nthreads > 0)
|
||||
// send to thread group
|
||||
WaveClear image
|
||||
ThreadGroupPutDF threadGroupID, :
|
||||
else
|
||||
// process immediately in single-thread mode
|
||||
processing_folders[n_sent] = GetDataFolderDFR()
|
||||
string param = func_param
|
||||
wave /wave reduced_waves = reduction_func(image, param)
|
||||
variable /g func_result = numpnts(reduced_waves)
|
||||
adh5_get_result_waves(reduced_waves, "redw_", 0)
|
||||
WaveClear image, reduced_waves
|
||||
setdatafolder ::
|
||||
endif
|
||||
endif
|
||||
while (1)
|
||||
else
|
||||
dfr = processing_folders[izt]
|
||||
if (progress)
|
||||
if (update_progress_panel(izt))
|
||||
result = -4 // user abort
|
||||
break
|
||||
|
||||
iz += 1
|
||||
n_sent += 1
|
||||
tmo = 0
|
||||
else
|
||||
iz += 1
|
||||
it = 0
|
||||
endif
|
||||
endif
|
||||
else
|
||||
// throttle the loop if processing is slow
|
||||
tmo = min(100, tmo + 10)
|
||||
endif
|
||||
|
||||
if (result != 0)
|
||||
break
|
||||
endif
|
||||
|
||||
nvar rr = dfr:r_index
|
||||
nvar ss = dfr:s_index
|
||||
nvar func_result = dfr:func_result
|
||||
|
||||
if (func_result < 1)
|
||||
result = -3 // dimension reduction error
|
||||
// receive a slab from the processing queue
|
||||
if (n_recvd < nzt)
|
||||
if (nthreads > 0)
|
||||
dfr = ThreadGroupGetDFR(threadGroupID, tmo)
|
||||
else
|
||||
dfr = processing_folders[n_recvd]
|
||||
processing_folders[n_recvd] = $""
|
||||
endif
|
||||
|
||||
if (DatafolderRefStatus(dfr) != 0)
|
||||
// access results folder
|
||||
nvar rr = dfr:r_index
|
||||
nvar ss = dfr:s_index
|
||||
nvar func_result = dfr:func_result
|
||||
|
||||
if (func_result < 1)
|
||||
print "error during data reduction."
|
||||
result = -3
|
||||
break
|
||||
endif
|
||||
|
||||
// initialize result waves just once
|
||||
if (numpnts(result_waves) == 0)
|
||||
redimension /n=(func_result) result_waves
|
||||
for (iw = 0; iw < func_result; iw += 1)
|
||||
sw = "redw_" + num2str(iw)
|
||||
wave profile = dfr:$sw
|
||||
sw = "ReducedData" + num2str(iw+1)
|
||||
make /n=(dimsize(profile, 0), nz, nt) /d /o $sw
|
||||
wave data = $sw
|
||||
setdimlabel 0, -1, $getdimlabel(profile, 0, -1), data
|
||||
setscale /p x dimoffset(profile, 0), dimdelta(profile, 0), waveunits(profile, 0), data
|
||||
setscale /p y dimoffset(source, 2), dimdelta(source, 2), waveunits(source, 2), data
|
||||
setscale /p z dimoffset(source, 3), dimdelta(source, 3), waveunits(source, 3), data
|
||||
setscale d 0, 0, waveunits(profile, -1), data
|
||||
note data, note(profile)
|
||||
result_waves[iw] = data
|
||||
endfor
|
||||
endif
|
||||
|
||||
// copy results
|
||||
for (iw = 0; iw < func_result; iw += 1)
|
||||
sw = "redw_" + num2str(iw)
|
||||
wave profile = dfr:$sw
|
||||
wave data = result_waves[iw]
|
||||
data[][rr][ss] = profile[p]
|
||||
endfor
|
||||
|
||||
n_recvd += 1
|
||||
KillDataFolder /Z dfr
|
||||
endif
|
||||
else
|
||||
// processing complete
|
||||
break
|
||||
endif
|
||||
|
||||
if (numpnts(result_waves) == 0)
|
||||
redimension /n=(func_result) result_waves
|
||||
for (iw = 0; iw < func_result; iw += 1)
|
||||
sw = "redw_" + num2str(iw)
|
||||
wave profile = dfr:$sw
|
||||
sw = result_prefix + num2str(iw+1)
|
||||
make /n=(dimsize(profile, 0), nz, nt) /d /o $sw
|
||||
wave data = $sw
|
||||
setdimlabel 0, -1, $getdimlabel(profile, 0, -1), data
|
||||
setscale /p x dimoffset(profile, 0), dimdelta(profile, 0), waveunits(profile, 0), data
|
||||
setscale /p y dimoffset(source, 2), dimdelta(source, 2), waveunits(source, 2), data
|
||||
setscale /p z dimoffset(source, 3), dimdelta(source, 3), waveunits(source, 3), data
|
||||
setscale d 0, 0, waveunits(profile, -1), data
|
||||
result_waves[iw] = data
|
||||
endfor
|
||||
// update progress window
|
||||
if (progress)
|
||||
if (update_progress_panel(n_recvd))
|
||||
print "user abort"
|
||||
result = -4
|
||||
break
|
||||
endif
|
||||
endif
|
||||
for (iw = 0; iw < func_result; iw += 1)
|
||||
sw = "redw_" + num2str(iw)
|
||||
wave profile = dfr:$sw
|
||||
wave data = result_waves[iw]
|
||||
data[][rr][ss] = profile[p]
|
||||
endfor
|
||||
endfor
|
||||
|
||||
while ((n_recvd < nzt) && (result == 0))
|
||||
|
||||
// clean up
|
||||
if (nthreads > 0)
|
||||
variable tstatus = ThreadGroupRelease(threadGroupID)
|
||||
if (tstatus == -2)
|
||||
result = -5 // thread did not terminate properly
|
||||
print "error: thread did not terminate properly."
|
||||
result = -5
|
||||
endif
|
||||
else
|
||||
for (izt = 0; izt < nzt; izt += 1)
|
||||
KillDataFolder /Z processing_folders[izt]
|
||||
endfor
|
||||
endif
|
||||
|
||||
// finalize results
|
||||
nw = numpnts(result_waves)
|
||||
wavenames = ""
|
||||
for (iw = 0; iw < nw; iw += 1)
|
||||
wave /z data = result_waves[iw]
|
||||
if (WaveExists(data))
|
||||
if (nz == 1)
|
||||
redimension /n=(-1, 0, 0) data
|
||||
elseif (nt == 1)
|
||||
redimension /n=(-1, nz, 0) data
|
||||
endif
|
||||
wavenames += nameofwave(data) + ";"
|
||||
endif
|
||||
endfor
|
||||
|
||||
if (progress)
|
||||
kill_progress_panel()
|
||||
endif
|
||||
|
||||
setdatafolder base_df
|
||||
return result
|
||||
end
|
||||
|
||||
@ -1979,12 +2011,12 @@ function adh5_scale_scienta(data)
|
||||
case 1: // Angular45
|
||||
ALow = -45/2
|
||||
AHigh = +45/2
|
||||
AUnit = "<EFBFBD>"
|
||||
AUnit = "°"
|
||||
break
|
||||
case 2: // Angular60
|
||||
ALow = -60/2
|
||||
AHigh = +60/2
|
||||
AUnit = "<EFBFBD>"
|
||||
AUnit = "°"
|
||||
break
|
||||
endswitch
|
||||
endif
|
||||
|
Reference in New Issue
Block a user