File MIES_Utilities_Algorithm.ipf¶
utility functions for common algorithms
Functions
-
variable Downsample(WaveOrNull wv, variable downsampleFactor, variable upsampleFactor, variable mode, string winFunction = defaultValue)¶
Downsample data.
Downsampling is performed on each column of the input wave. Edge-points of the output wave are by default set to zero.
- Parameters:
wv – numeric wave, its row must hold more points than downsampleFactor. Will hold the downsampled data on successfull return, in the error case the contents are undetermined
downsampleFactor – positive non-zero integer by which the wave should be downsampled
upsampleFactor – positive non-zero integer by which the wave should be upsampled
mode – decimation mode, one of DECIMATION_BY_OMISSION, DECIMATION_BY_AVERAGING or DECIMATION_BY_SMOOTHING.
winFunction – Windowing function for DECIMATION_BY_SMOOTHING mode, must be one of FFT_WINF.
- Returns:
One on error, zero otherwise
-
variable CalculateLCMOfWave(wave wv)¶
Compute the least common multiplier of all entries in the 1D-wave.
-
wave GetUniqueEntries(wave wv, variable caseSensitive = defaultValue, variable dontDuplicate = defaultValue)¶
Returns an unsorted free wave with all unique entries from wv If dontDuplicate is set, then for a single element input wave no new free wave is created but the input wave is returned.
uses built-in igor function FindDuplicates. Entries are deleted from left to right.
- Parameters:
wv – wave reference, can be numeric or text
caseSensitive – [optional, default = 1] Indicates whether comparison should be case sensitive. Applies only if the input wave is a text wave
dontDuplicate – [optional, default = 0] for a single element input wave no new free wave is created but the input wave is returned.
-
string GetUniqueTextEntriesFromList(string list, string sep = defaultValue, variable caseSensitive = defaultValue)
Convenience wrapper around GetUniqueTextEntries() for string lists.
-
static wave GetUniqueTextEntries(WaveText wv, variable caseSensitive = defaultValue, variable dontDuplicate = defaultValue)¶
Search and Remove Duplicates from Text Wave wv.
Duplicates are removed from left to right
- Parameters:
wv – text wave reference
caseSensitive – [optional, default = 1] Indicates whether comparison should be case sensitive.
dontDuplicate – [optional, default = 0] for a single element input wave no new free wave is created but the input wave is returned.
- Returns:
free wave with unique entries
-
variable CALL_FUNCTION_LIST_PROTOTYPE(string str)¶
Function prototype for use with CallFunctionForEachListItem.
-
variable CALL_FUNCTION_LIST_PROTOTYPE_TS(string str)¶
Function prototype for use with CallFunctionForEachListItem.
-
variable CallFunctionForEachListItem(CALL_FUNCTION_LIST_PROTOTYPE f, string list, string sep = defaultValue)¶
Convenience function to call the function f with each list item.
The function’s type must be CALL_FUNCTION_LIST_PROTOTYPE where the return type is ignored.
-
variable CallFunctionForEachListItem_TS(CALL_FUNCTION_LIST_PROTOTYPE_TS f, string list, string sep = defaultValue)¶
Compatibility wrapper for threadsafe functions
f
See also
-
variable GetRowIndex(wave wv, variable val = defaultValue, string str = defaultValue, WaveOrNull refWave = defaultValue, variable reverseSearch = defaultValue, variable textOp = defaultValue)¶
Return the row index of the given value, string converted to a variable, or wv.
Assumes wv being one dimensional and does not use any tolerance for numerical values.
-
string GetListDifference(string list1, string list2, variable caseSensitive = defaultValue)¶
calculates the relative complement of list2 in list1
Every list item of
list2
must be inlist1
.also called the set-theoretic difference of list1 and list2
- Returns:
difference as list
-
variable InPlaceRandomShuffle(wave inwave, variable noiseGenMode = defaultValue)¶
Random shuffle of the wave contents.
Function was taken from: http://www.igorexchange.com/node/1614 author s.r.chinn
- Parameters:
inwave – The wave that will have its rows shuffled.
noiseGenMode – [optional, defaults to NOISE_GEN_XOSHIRO] type of RNG to use
-
wave ExtractFromSubrange(string listOfRanges, variable dim)¶
Extract the values of a list of subrange specifications See also DisplayHelpTopic “Subrange Display”.
Example invocations:
WAVE ranges = ExtractFromSubrange("[3,4]_[*]_[1, *;4]_[]_[5][]", 0)
- Parameters:
listOfRanges – list of subrange specifications separated by **_**
dim – dimension to extract
- Returns:
2-dim wave with the start, stop, step as columns and rows as number of elements. Returns -1 instead of
*
or(empty)
. An invalid wave reference is returned on parsing errors.
-
wave GetSetUnion(wave wave1, wave wave2)¶
Return a wave of the union of all entries from both waves with duplicates removed.
Given {1, 2, 10} and {2, 5, 11} this will return {1, 2, 5, 10, 11}. The order of the returned entries is not defined.
-
wave GetSetDifference(wave wave1, wave wave2, variable getIndices = defaultValue)¶
Return a wave were all elements which are in both wave1 and wave2 have been removed from wave1.
The text comparison is case insensitive. wave1 must be 1d, the returned wave is 1d. Waves can be text or numeric, both waves must have the same type
See also
GetListDifference for string lists
- Parameters:
wave1 – first wave
wave2 – second wave
getIndices – [optional, default 0] when this flag is set instead of the values the indices in wave1 are returned
- Returns:
Wave with partial values from wave1 or numeric wave with indices of elements in wave1
-
static std::tuple<WAVE, variable> GetSetDifferenceNumeric(wave wave1, wave wave2, variable getIndices)¶
-
static std::tuple<WAVE, variable> GetSetDifferenceText(WaveText wave1, WaveText wave2, variable getIndices)¶
-
wave GetSetIntersection(wave wave1, wave wave2, variable getIndices = defaultValue)¶
Return a wave with the set theory style intersection of wave1 and wave2.
Given {1, 2, 4, 10} and {2, 5, 11} this will return {2}. Given {10, 2, 4, 2, 1} and {11, 5, 2} with getIndices = 1 this will return {1, 3}.
Inspired by http://www.igorexchange.com/node/366 but adapted to modern Igor Pro It does work with text waves as well, there it performs case sensitive comparisons
For wave1 and wave2 numerical and text waves are allowed, wave1 and wave2 must have the same type.
- Parameters:
wave1 – first wave
wave2 – second wave
getIndices – [optional, default 0] when this flag is set then the index positions of the intersecting elements in the first wave are returned.
- Returns:
free wave with the set intersection or an null wave reference if the intersection is an empty set
-
static variable FindLevelSingle(wave data, variable level, variable edge, variable first, variable last)¶
-
static wave FindLevelsMult(wave data, variable level, variable edge, variable first, variable last, variable maxNumLevels)¶
-
wave FindLevelWrapper(wave data, variable level, variable edge, variable mode, variable maxNumLevels = defaultValue)¶
FindLevel wrapper which handles 2D data without copying data.
The returned levels are in the wave’s row units.
FINDLEVEL_MODE_SINGLE:
Return a 1D wave with as many rows as columns in the input data
Contents are the x values of the first level or NaN if none could be found
FINDLEVEL_MODE_MULTI:
Returns a 2D WAVE rows being the number of columns in the input data and columns holding all found x values of the levels per data column.
In both cases the dimension label of the each column holds the number of found levels in each data colum. This will be always 1 for FINDLEVEL_MODE_SINGLE.
- Parameters:
data – input data, can be either 1D or 2D
level – level to search
edge – type of the edge, one of FindLevelEdgeTypes
mode – mode, one of FindLevelModes
maxNumLevels – [optional, defaults to number of points/rows] maximum number of levels to find
-
wave GrepWave(WaveText wv, string regex)¶
Wrapper for
Grep
which uses a textwave for input and ouput.
-
wave GrepTextWave(WaveText in, string regexp, variable invert = defaultValue)¶
Grep the given regular expression in the text wave.
-
std::tuple<WaveDouble, WaveDouble> DistributeElements(variable numElements, variable offset = defaultValue)¶
Distribute N elements over a range from 0.0 to 1.0 with spacing.
-
variable CalculateNiceLength(variable range, variable multiple)¶
Calculate a nice length which is an integer number of
multiple
long.For small values \( 10^{-x} \) times
multiple
are returned
-
variable BinarySearchText(WaveText theWave, string theText, variable caseSensitive = defaultValue, variable startPos = defaultValue, variable endPos = defaultValue)¶
Finds the first occurrence of a text within a range of points in a SORTED text wave.
From https://www.wavemetrics.com/code-snippet/binary-search-pre-sorted-text-waves by Jamie Boyd Completely reworked, fixed and removed unused features
-
variable DoPowerSpectrum(wave input, wave output, variable col)¶
Calculate PowerSpectrum on a per column basis on each input[][col] and write the result into output[][col]. The result is capped to the output rows. No window function is applied.
-
wave DoFFT(wave input, string winFunc = defaultValue, variable padSize = defaultValue)¶
Perform FFT on input with optionally given window function.
- Parameters:
input – Wave to perform FFT on
winFunc – [optional, defaults to NONE] FFT window function
padSize – [optional, defaults to the next power of 2 of the input wave row size] Target size used for padding
-
string CompressNumericalList(string list, string sepChar)¶
Convert a numerical integer list seperated by sepChar to a list including a range sign (“-”) e. g. 1,2,3,4 -> 1-4 1,2,4,5,6 -> 1-2,4-6 1,1,1,2 -> 1-2 the input list does not have to be sorted.
-
wave SplitLogDataBySize(WaveText logData, string sep, variable lim, variable lastIndex = defaultValue, variable firstPartSize = defaultValue)¶
Splits a text wave (with e.g. log entries) into parts. The parts are limited by a size in bytes such that each part contains only complete lines and is smaller than the given size limit. A possible separator for line endings is considered in the size calculation.
- Parameters:
logData – text wave
sep – separator string that is considered in the length calculation. This is useful if the resulting waves are later converted to strings with TextWaveToList, where the size grows by lines * separatorLength.
lim – size limit for each part in bytes
lastIndex – [optional, default DimSize(logData, ROWS) - 1] When set, only elements in logData from index 0 to lastIndex are considered. lastIndex is included. lastIndex is limited between 0 and DimSize(logData, ROWS) - 1.
firstPartSize – [optional, default lim] When set then the first parts size limit is firstPartSize instead of lim
- Returns:
wave reference wave containing text waves that are consecutive and sequential parts of logdata