code changes for release 2.2.0

This commit is contained in:
2021-09-09 12:45:39 +02:00
parent c50ca2e577
commit e3e80f5796
25 changed files with 3519 additions and 238 deletions

View File

@ -1,12 +1,14 @@
#pragma TextEncoding = "UTF-8"
#pragma rtGlobals=3 // Use modern global access method and strict wave access.
#pragma IgorVersion = 6.36
#pragma ModuleName = PearlPShellImport
#pragma version = 1.11
#include <HDF5 Browser>
#include "pearl-compat"
#include "pearl-gui-tools"
#include "pearl-area-import"
// copyright (c) 2013-18 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.
@ -50,7 +52,7 @@
///
/// @author matthias muntwiler, matthias.muntwiler@psi.ch
///
/// @copyright 2013-18 Paul Scherrer Institut @n
/// @copyright 2013-21 Paul Scherrer Institut @n
/// Licensed under the Apache License, Version 2.0 (the "License"); @n
/// you may not use this file except in compliance with the License. @n
/// You may obtain a copy of the License at
@ -75,7 +77,7 @@ strconstant kScanDimLabel = "scan"
strconstant kDataDimLabel = "data"
/// List of preferred datasets to load for preview
strconstant kPreviewDatasets = "ScientaImage;ScientaSpectrum;ImageAngleDistribution;ImageEnergyDistribution;Counts;SampleCurrent;"
strconstant kPreviewDatasets = "ImageEnergyDistribution;ScientaSpectrum;ScientaImage;Counts;SampleCurrent;"
/// List of datasets that must be loaded to determine the axis scaling of a Scienta image
strconstant kScientaScalingDatasets = "LensMode;ScientaChannelBegin;ScientaChannelEnd;ScientaSliceBegin;ScientaSliceEnd;"
@ -336,6 +338,81 @@ function /s psh5_load_preview(APathName, AFileName, [load_data, load_attr, pref_
return dataname
end
/// load organizational metadata from the general group.
///
/// the general group contains the following datasets:
/// authors, pgroup, proposal, proposer, sample.
///
/// data is loaded into the current data folder.
/// all items are loaded into strings, authors is a comma-separated list.
/// missing items default to empty strings.
///
/// @param APathName igor symbolic path name. can be empty if the path is specified in FileName or a dialog box should be displayed
///
/// @param AFileName if empty a dialog box shows up
///
/// @return semicolon-separated list of the objects.
///
function /s psh5_load_general_group(APathName, AFileName)
string APathName
string AFileName
variable fileID
HDF5OpenFile /P=$APathName /R /Z fileID as AFileName
if (v_flag == 0)
string obj_names = "authors;pgroup;proposal;proposer;sample;"
variable nn = ItemsInList(obj_names, ";")
variable ii
string name
for (ii = 0; ii < nn; ii += 1)
name = StringFromList(ii, obj_names, ";")
psh_load_general_string(fileID, name)
endfor
return obj_names
else
return ""
endif
end
/// load a string from the general group.
///
/// the general group contains the following datasets:
/// authors, pgroup, proposal, proposer, sample.
///
/// data is loaded into a global string in the current data folder.
/// arrays with multiple items are loaded into a comma-separated list.
/// a missing item defaults to the empty string.
///
/// @param fileID ID of open HDF5 file from psh5_open_file().
///
/// @return comma-separated list of values.
///
function /s psh_load_general_string(fileID, name)
variable fileID
string name
string path = "/general/" + name
HDF5LoadData /O /Q /Z /N=wt_load_general /TYPE=1 fileID, path
string values = ""
if (!v_flag)
wave /t wt_load_general
variable nn = numpnts(wt_load_general)
variable ii
for (ii = 0; ii < nn; ii += 1)
values = AddListItem(wt_load_general[ii], values, ",", inf)
endfor
killwaves /z wt_load_general
if (strlen(values) >= 1)
values = values[0,strlen(values)-2]
endif
endif
string /g $name = values
return values
end
/// load all data of a selected scan from a PShell data file.
///
/// data is loaded into the current data folder.
@ -1667,13 +1744,13 @@ function ps_detect_scale(ax, lo, hi, un)
case "Angular45":
lo[%$kAngleDimLabel] = -45/2
hi[%$kAngleDimLabel] = +45/2
un[%$kAngleDimLabel] = "<EFBFBD>"
un[%$kAngleDimLabel] = "°"
ax[%$kAngleDimLabel] = "angle"
break
case "Angular60":
lo[%$kAngleDimLabel] = -60/2
hi[%$kAngleDimLabel] = +60/2
un[%$kAngleDimLabel] = "<EFBFBD>"
un[%$kAngleDimLabel] = "°"
ax[%$kAngleDimLabel] = "angle"
break
case "Transmission":
@ -1719,12 +1796,12 @@ function ps_detect_scale(ax, lo, hi, un)
un[%$kScanDimLabel] = "mm"
break
case "ExitSlit":
un[%$kScanDimLabel] = "<EFBFBD>m"
un[%$kScanDimLabel] = "µm"
break
case "ManipulatorTheta":
case "ManipulatorTilt":
case "ManipulatorPhi":
un[%$kScanDimLabel] = "<EFBFBD>"
un[%$kScanDimLabel] = "°"
break
case "FocusXRot":
case "FocusYRot":
@ -1890,6 +1967,11 @@ end
///
/// @param reduction_param parameter string for the reduction function.
///
/// @param dataset name of dataset to load, optionally including group path relative to scan (scan 1).
/// by default, the function looks for a ScientaImage dataset.
/// in a multi-region scan, this will be region 1.
/// to select region 2, e.g., use `dataset="region2/ScientaImage"`.
///
/// @param progress progress window.
/// @arg 1 (default) show progress window
/// @arg 0 do not show progress window
@ -1908,12 +1990,13 @@ end
///
/// @return global string s_scanpaths in new data folder contains a list of scan groups inside the file.
///
function /s psh5_load_reduced(ANickName, APathName, AFileName, reduction_func, reduction_param, [progress, nthreads])
function /s psh5_load_reduced(ANickName, APathName, AFileName, reduction_func, reduction_param, [dataset, progress, nthreads])
string ANickName
string APathName
string AFileName
funcref adh5_default_reduction reduction_func
string reduction_param
string dataset
variable progress
variable nthreads
@ -1972,7 +2055,9 @@ function /s psh5_load_reduced(ANickName, APathName, AFileName, reduction_func, r
setdatafolder dataDF
string datasets = psh5_list_scan_datasets(fileID, scanpath, include_regions=1)
string dataset = select_dataset(datasets, "ScientaImage")
if (ParamIsDefault(dataset))
dataset = select_dataset(datasets, "ScientaImage")
endif
wavenames = psh5_load_dataset_reduced(fileID, scanpath, dataset, reduction_func, reduction_param, progress=progress, nthreads=nthreads)
psh5_close_file(fileID)
@ -2503,3 +2588,48 @@ static function /s wave2list(w, format, sep)
return list
end
/// kill any waves matching a pattern in the experiment
///
/// this may be used to kill big waves of original data before saving
///
function /s kill_matching_waves(dfr, pattern, recurse, [killed])
DFREF dfr
string pattern
variable recurse
string killed
if (ParamIsDefault(killed))
killed = ""
endif
string s
string r
variable index = 0
do
Wave/Z w = WaveRefIndexedDFR(dfr, index)
if (!WaveExists(w))
break
endif
s = NameOfWave(w)
if (stringmatch(s, pattern))
killwaves /z w
killed = AddListItem(s, killed, ";", Inf)
endif
index += 1
while(1)
if (recurse)
Variable numChildDataFolders = CountObjectsDFR(dfr, 4)
Variable i
for(i=0; i<numChildDataFolders; i+=1)
String childDFName = GetIndexedObjNameDFR(dfr, 4, i)
DFREF childDFR = dfr:$childDFName
killed = kill_matching_waves(childDFR, pattern, 1, killed=killed)
endfor
endif
return killed
End