Skip to content

Commit

Permalink
Merge pull request #1879 from AllenInstitute/feature/1879-various-upd…
Browse files Browse the repository at this point in the history
…ates

Extracted parts from #1860
  • Loading branch information
t-b authored Sep 7, 2023
2 parents 7201e2e + b388d7d commit 0de9ec0
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 124 deletions.
24 changes: 22 additions & 2 deletions Packages/MIES/MIES_SweepFormula_Helpers.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,17 @@ End
/// Here `numBottles` is argument number 0 and mandatory as `defValue` is not present.
///
/// The second argument `size` is optional with 0.5 as default and also defines a list of valid values.
Function SFH_GetArgumentAsNumeric(variable jsonId, string jsonPath, string graph, string opShort, variable argNum, [variable defValue, WAVE/Z allowedValues, FUNCREF SFH_NumericChecker_Prototype checkFunc])
Function SFH_GetArgumentAsNumeric(variable jsonId, string jsonPath, string graph, string opShort, variable argNum, [variable defValue, WAVE/Z allowedValues, FUNCREF SFH_NumericChecker_Prototype checkFunc, variable checkDefault])

string msg, sep, allowedValuesAsStr
variable checkExist, numArgs, result, idx, ret

if(ParamIsDefault(checkDefault))
checkDefault = 1
else
checkDefault = !!checkDefault
endif

if(ParamIsDefault(defValue))
checkExist = 1
else
Expand All @@ -68,6 +74,10 @@ Function SFH_GetArgumentAsNumeric(variable jsonId, string jsonPath, string graph
SFH_ASSERT(!checkExist, msg)

result = defValue

if(!checkDefault)
return result
endif
endif

if(!ParamIsDefault(allowedValues))
Expand Down Expand Up @@ -112,11 +122,17 @@ End
/// The second argument `type` is optional with `steam train` as default and a list of allowed values.
///
/// The text argument can be abbreviated as long as it is unique, the unabbreviated result is returned in all cases.
Function/S SFH_GetArgumentAsText(variable jsonId, string jsonPath, string graph, string opShort, variable argNum, [string defValue, WAVE/T/Z allowedValues, FUNCREF SFH_StringChecker_Prototype checkFunc])
Function/S SFH_GetArgumentAsText(variable jsonId, string jsonPath, string graph, string opShort, variable argNum, [string defValue, WAVE/T/Z allowedValues, FUNCREF SFH_StringChecker_Prototype checkFunc, variable checkDefault])

string msg, result, sep, allowedValuesAsStr
variable checkExist, numArgs, idx, ret

if(ParamIsDefault(checkDefault))
checkDefault = 1
else
checkDefault = !!checkDefault
endif

if(ParamIsDefault(defValue))
checkExist = 1
else
Expand Down Expand Up @@ -150,6 +166,10 @@ Function/S SFH_GetArgumentAsText(variable jsonId, string jsonPath, string graph,
SFH_ASSERT(!checkExist, msg)

result = defValue

if(!checkDefault)
return result
endif
endif

if(!ParamIsDefault(allowedValues))
Expand Down
20 changes: 10 additions & 10 deletions Packages/MIES/MIES_SweepFormula_PSX.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,11 @@ end
/// - deconvolution
/// - histogram of deconvolution
/// - gaussian fit of histogram
static Function [WAVE sweepDataFiltOff, WAVE sweepDataFiltOffDeconv] PSX_Analysis(WAVE sweepData, WAVE psxKernelFFT, variable filterLow, variable filterHigh)
static Function [WAVE sweepDataFiltOff, WAVE sweepDataFiltOffDeconv] PSX_Analysis(WAVE sweepData, WAVE psxKernelFFT, variable sweepFilterLow, variable sweepFilterHigh)

variable offset

WAVE sweepDataFilt = PSX_FilterSweepData(sweepData, filterLow, filterHigh)
WAVE sweepDataFilt = PSX_FilterSweepData(sweepData, sweepFilterLow, sweepFilterHigh)

WAVE/ZZ sweepDataFiltOff
[sweepDataFiltOff, offset] = PSX_OffsetSweepData(sweepDataFilt)
Expand Down Expand Up @@ -696,7 +696,7 @@ static Function/WAVE PSX_CreateOverrideResults(variable numEvents, WAVE/T combos
return wv
End

static Function PSX_OperationSweepGathering(string graph, WAVE/WAVE psxKernelDataset, variable parameterJsonID, variable filterLow, variable filterHigh, variable index, WAVE/WAVE output)
static Function PSX_OperationSweepGathering(string graph, WAVE/WAVE psxKernelDataset, variable parameterJsonID, variable sweepFilterLow, variable sweepFilterHigh, variable index, WAVE/WAVE output)

string key, comboKey, psxParametersAnalyzePeaks, cacheKey

Expand All @@ -717,7 +717,7 @@ static Function PSX_OperationSweepGathering(string graph, WAVE/WAVE psxKernelDat
WAVE sweepDataFiltOff = psxAnalyzePeaksFromCache[%sweepDataFiltOff]
WAVE sweepDataFiltOffDeconv = psxAnalyzePeaksFromCache[%sweepDataFiltOffDeconv]
else
[WAVE sweepDataFiltOff, WAVE sweepDataFiltOffDeconv] = PSX_Analysis(sweepData, psxKernelFFT, filterLow, filterHigh)
[WAVE sweepDataFiltOff, WAVE sweepDataFiltOffDeconv] = PSX_Analysis(sweepData, psxKernelFFT, sweepFilterLow, sweepFilterHigh)

Make/FREE/WAVE/N=(2) psxAnalyzePeaks
SetDimensionLabels(psxAnalyzePeaks, "sweepDataFiltOff;sweepDataFiltOffDeconv", ROWS)
Expand Down Expand Up @@ -4090,7 +4090,7 @@ End
// ...
Function/WAVE PSX_Operation(variable jsonId, string jsonPath, string graph)
variable numberOfSDs, filterLow, filterHigh, parameterJsonID, numCombos, i, addedData, kernelAmp
variable numberOfSDs, sweepFilterLow, sweepFilterHigh, parameterJsonID, numCombos, i, addedData, kernelAmp
variable maxTauFactor, peakThresh
string parameterPath, id, psxParameters, dataUnit
Expand All @@ -4100,8 +4100,8 @@ Function/WAVE PSX_Operation(variable jsonId, string jsonPath, string graph)
try
numberOfSDs = SFH_GetArgumentAsNumeric(jsonID, jsonPath, graph, SF_OP_PSX, 2, defValue = PSX_NUMBER_OF_SDS_DEFAULT, checkFunc = IsStrictlyPositiveAndFinite)
filterLow = SFH_GetArgumentAsNumeric(jsonID, jsonPath, graph, SF_OP_PSX, 3, defValue = PSX_DEFAULT_FILTER_LOW)
filterHigh = SFH_GetArgumentAsNumeric(jsonID, jsonPath, graph, SF_OP_PSX, 4, defValue = PSX_DEFAULT_FILTER_HIGH)
sweepFilterLow = SFH_GetArgumentAsNumeric(jsonID, jsonPath, graph, SF_OP_PSX, 3, defValue = PSX_DEFAULT_FILTER_LOW)
sweepFilterHigh = SFH_GetArgumentAsNumeric(jsonID, jsonPath, graph, SF_OP_PSX, 4, defValue = PSX_DEFAULT_FILTER_HIGH)
maxTauFactor = SFH_GetArgumentAsNumeric(jsonID, jsonPath, graph, SF_OP_PSX, 5, defValue = PSX_DEFAULT_MAX_TAU_FACTOR, checkFunc = IsStrictlyPositiveAndFinite)
WAVE riseTime = SFH_GetArgumentAsWave(jsonID, jsonPath, graph, SF_OP_PSX, 6, defOp = "psxRiseTime()", singleResult = 1)
ASSERT(IsNumericWave(riseTime), "Invalid return from psxRiseTime")
Expand All @@ -4111,8 +4111,8 @@ Function/WAVE PSX_Operation(variable jsonId, string jsonPath, string graph)
JSON_AddTreeObject(parameterJsonID, parameterPath)
JSON_AddString(parameterJsonID, parameterPath + "/id", id)
JSON_AddVariable(parameterJsonID, parameterPath + "/numberOfSDs", numberOfSDs)
JSON_AddVariable(parameterJsonID, parameterPath + "/filterLow", filterLow)
JSON_AddVariable(parameterJsonID, parameterPath + "/filterHigh", filterHigh)
JSON_AddVariable(parameterJsonID, parameterPath + "/sweepFilterLow", sweepFilterLow)
JSON_AddVariable(parameterJsonID, parameterPath + "/sweepFilterHigh", sweepFilterHigh)
JSON_AddVariable(parameterJsonID, parameterPath + "/maxTauFactor", maxTauFactor)
parameterPath = SF_META_USER_GROUP + PSX_JWN_PARAMETERS + "/" + SF_OP_PSX_RISETIME
JSON_AddTreeObject(parameterJsonID, parameterPath)
Expand All @@ -4138,7 +4138,7 @@ Function/WAVE PSX_Operation(variable jsonId, string jsonPath, string graph)
endfor
for(i = 0; i < numCombos; i += 1)
PSX_OperationSweepGathering(graph, psxKernelDataset, parameterJsonID, filterLow, filterHigh, i, output)
PSX_OperationSweepGathering(graph, psxKernelDataset, parameterJsonID, sweepFilterLow, sweepFilterHigh, i, output)
endfor
[WAVE hist, WAVE fit, peakThresh, dataUnit] = PSX_CalculatePeakThreshold(output, numCombos, numberOfSDs)
Expand Down
49 changes: 0 additions & 49 deletions Packages/MIES/MIES_Utilities.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -3424,35 +3424,6 @@ Function/WAVE ExtractFromSubrange(listOfRanges, dim)
return ranges
End

/// @brief Check if a name for an object adheres to the strict naming rules
///
/// @see `DisplayHelpTopic "Standard Object Names"`
///
/// UTF_NOINSTRUMENTATION
threadsafe Function IsValidObjectName(string name)
return NameChecker(name, 0)
End

/// UTF_NOINSTRUMENTATION
threadsafe Function IsStrictlyPositiveAndFinite(variable var)

return var > 0 && var < inf
End

/// @brief Check if a name for an object adheres to the liberal naming rules
///
/// @see `DisplayHelpTopic "Liberal Object Names"`
///
/// UTF_NOINSTRUMENTATION
threadsafe Function IsValidLiberalObjectName(string name)
return NameChecker(name, 1)
End

/// UTF_NOINSTRUMENTATION
threadsafe static Function NameChecker(string name, variable liberal)
return !cmpstr(name, CleanupName(name, !!liberal, MAX_OBJECT_NAME_LENGTH_IN_BYTES))
End

/// @brief Find an integer `x` which is larger than `a` but the
/// smallest possible power of `p`.
///
Expand Down Expand Up @@ -6770,26 +6741,6 @@ Function GetDayOfWeek(variable seconds)
return str2num(dayOfWeek)
End

/// @brief Return the truth if `val` is in the range `]0, 1[`
threadsafe Function BetweenZeroAndOneExc(variable val)
return val > 0.0 && val < 1.0
End

/// @brief Return the truth if `val` is in the range `[0, 1]`
threadsafe Function BetweenZeroAndOne(variable val)
return val >= 0.0 && val <= 1.0
End

/// @brief Return the truth if `val` is in the range `]0, 100[`
threadsafe Function BetweenZeroAndOneHoundredExc(variable val)
return val > 0.0 && val < 100.0
End

/// @brief Return the truth if `val` is in the range `[0, 100]`
threadsafe Function BetweenZeroAndOneHoundred(variable val)
return val >= 0.0 && val <= 100.0
End

/// @brief Upper case the first character in an ASCII string
threadsafe Function/S UpperCaseFirstChar(string str)

Expand Down
73 changes: 73 additions & 0 deletions Packages/MIES/MIES_Utilities_Checks.ipf
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#pragma TextEncoding = "UTF-8"
#pragma rtGlobals=3 // Use modern global access method and strict wave access.
#pragma rtFunctionErrors=1

#ifdef AUTOMATED_TESTING
#pragma ModuleName=MIES_Checks
#endif

/// @file MIES_Utilities_Checks.ipf
/// @brief Threadsafe check functions which comply with either SFH_NumericChecker_Prototype or SFH_StringChecker_Prototype

/// @brief Check if a name for an object adheres to the strict naming rules
///
/// @see `DisplayHelpTopic "Standard Object Names"`
///
/// UTF_NOINSTRUMENTATION
threadsafe Function IsValidObjectName(string name)
return NameChecker(name, 0)
End

/// @brief Check if a name for an object adheres to the liberal naming rules
///
/// @see `DisplayHelpTopic "Liberal Object Names"`
///
/// UTF_NOINSTRUMENTATION
threadsafe Function IsValidLiberalObjectName(string name)
return NameChecker(name, 1)
End

/// UTF_NOINSTRUMENTATION
threadsafe static Function NameChecker(string name, variable liberal)
return !cmpstr(name, CleanupName(name, !!liberal, MAX_OBJECT_NAME_LENGTH_IN_BYTES))
End

/// UTF_NOINSTRUMENTATION
threadsafe Function IsStrictlyPositiveAndFinite(variable var)

return var > 0 && var < inf
End

/// UTF_NOINSTRUMENTATION
threadsafe Function IsNullOrPositiveAndFinite(variable var)

return var >= 0 && var < inf
End

/// @brief Return the truth if `val` is in the range `]0, 1[`
///
/// UTF_NOINSTRUMENTATION
threadsafe Function BetweenZeroAndOneExc(variable val)
return val > 0.0 && val < 1.0
End

/// @brief Return the truth if `val` is in the range `[0, 1]`
///
/// UTF_NOINSTRUMENTATION
threadsafe Function BetweenZeroAndOne(variable val)
return val >= 0.0 && val <= 1.0
End

/// @brief Return the truth if `val` is in the range `]0, 100[`
///
/// UTF_NOINSTRUMENTATION
threadsafe Function BetweenZeroAndOneHoundredExc(variable val)
return val > 0.0 && val < 100.0
End

/// @brief Return the truth if `val` is in the range `[0, 100]`
///
/// UTF_NOINSTRUMENTATION
threadsafe Function BetweenZeroAndOneHoundred(variable val)
return val >= 0.0 && val <= 100.0
End
1 change: 1 addition & 0 deletions Packages/MIES_Include.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ End
#include "MIES_TestPulse_Multi"
#include "MIES_TraceUserData"
#include "MIES_Utilities"
#include "MIES_Utilities_Checks"
#include "MIES_WaveBuilder"
#include "MIES_WaveBuilderPanel"
#include "MIES_WaveBuilder_Macro"
Expand Down
2 changes: 2 additions & 0 deletions Packages/tests/Basic/UTF_Basic.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "UTF_UpgradeDataFolderLocation"
#include "UTF_UpgradeWaveLocationAndGetIt"
#include "UTF_Utils"
#include "UTF_UtilsChecks"
#include "UTF_WaveAveraging"
#include "UTF_WaveBuilder"
#include "UTF_WaveBuilderRegression"
Expand Down Expand Up @@ -115,6 +116,7 @@ Function RunWithOpts([string testcase, string testsuite, variable allowdebug, va
list = AddListItem("UTF_UpgradeDataFolderLocation.ipf", list, ";", inf)
list = AddListItem("UTF_UpgradeWaveLocationAndGetIt.ipf", list, ";", inf)
list = AddListItem("UTF_Utils.ipf", list, ";", inf)
list = AddListItem("UTF_UtilsChecks.ipf", list, ";", inf)
list = AddListItem("UTF_WaveAveraging.ipf", list, ";", inf)
list = AddListItem("UTF_WaveBuilder.ipf", list, ";", inf)
list = AddListItem("UTF_WaveBuilderRegression.ipf", list, ";", inf)
Expand Down
63 changes: 0 additions & 63 deletions Packages/tests/Basic/UTF_Utils.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -3690,17 +3690,6 @@ Function FLW_RequiresNumericWave()
endtry
End

Function/WAVE InfiniteValues()

Make/FREE wv = {NaN, Inf, -Inf}

SetDimLabel ROWS, 0, $"NaN", wv
SetDimLabel ROWS, 1, $"Inf", wv
SetDimLabel ROWS, 2, $"-Inf", wv

return wv
End

// UTF_TD_GENERATOR InfiniteValues
Function FLW_RequiresFiniteLevel([var])
variable var
Expand Down Expand Up @@ -7142,58 +7131,6 @@ static Function GetDayOfWeekTest()
endtry
End

static Function BetweenZeroAndOneX()

FUNCREF SFH_NumericChecker_Prototype f = BetweenZeroAndOne
CHECK(FuncRefIsAssigned(FuncRefInfo(f)))

CHECK_EQUAL_VAR(BetweenZeroAndOne(-2.0), 0)
CHECK_EQUAL_VAR(BetweenZeroAndOne(0.0), 1)
CHECK_EQUAL_VAR(BetweenZeroAndOneExc(0 + 1e-15), 1)
CHECK_EQUAL_VAR(BetweenZeroAndOne(0.1), 1)
CHECK_EQUAL_VAR(BetweenZeroAndOneExc(1.0 - 1e-14), 1)
CHECK_EQUAL_VAR(BetweenZeroAndOne(1.0), 1)
CHECK_EQUAL_VAR(BetweenZeroAndOne(2.0), 0)

FUNCREF SFH_NumericChecker_Prototype f = BetweenZeroAndOneExc
CHECK(FuncRefIsAssigned(FuncRefInfo(f)))

// excluding the borders
CHECK_EQUAL_VAR(BetweenZeroAndOneExc(-2.0), 0)
CHECK_EQUAL_VAR(BetweenZeroAndOneExc(0), 0)
CHECK_EQUAL_VAR(BetweenZeroAndOneExc(0 + 1e-15), 1)
CHECK_EQUAL_VAR(BetweenZeroAndOneExc(0.1), 1)
CHECK_EQUAL_VAR(BetweenZeroAndOneExc(1.0 - 1e-14), 1)
CHECK_EQUAL_VAR(BetweenZeroAndOneExc(1.0), 0)
CHECK_EQUAL_VAR(BetweenZeroAndOneExc(2.0), 0)
End

static Function BetweenZeroAndOneHoundredX()

FUNCREF SFH_NumericChecker_Prototype f = BetweenZeroAndOneHoundred
CHECK(FuncRefIsAssigned(FuncRefInfo(f)))

CHECK_EQUAL_VAR(BetweenZeroAndOneHoundred(-2.0), 0)
CHECK_EQUAL_VAR(BetweenZeroAndOneHoundred(0.0), 1)
CHECK_EQUAL_VAR(BetweenZeroAndOneHoundredExc(0 + 1e-15), 1)
CHECK_EQUAL_VAR(BetweenZeroAndOneHoundred(0.1), 1)
CHECK_EQUAL_VAR(BetweenZeroAndOneHoundredExc(100.0 - 1e-14), 1)
CHECK_EQUAL_VAR(BetweenZeroAndOneHoundred(1.0), 1)
CHECK_EQUAL_VAR(BetweenZeroAndOneHoundred(102.0), 0)

FUNCREF SFH_NumericChecker_Prototype f = BetweenZeroAndOneHoundredExc
CHECK(FuncRefIsAssigned(FuncRefInfo(f)))

// excluding the borders
CHECK_EQUAL_VAR(BetweenZeroAndOneHoundredExc(-2.0), 0)
CHECK_EQUAL_VAR(BetweenZeroAndOneHoundredExc(0), 0)
CHECK_EQUAL_VAR(BetweenZeroAndOneHoundredExc(0 + 1e-15), 1)
CHECK_EQUAL_VAR(BetweenZeroAndOneHoundredExc(0.1), 1)
CHECK_EQUAL_VAR(BetweenZeroAndOneHoundredExc(100.0 - 1e-14), 1)
CHECK_EQUAL_VAR(BetweenZeroAndOneHoundredExc(100.0), 0)
CHECK_EQUAL_VAR(BetweenZeroAndOneHoundredExc(102.0), 0)
End

static Function TestUpperCaseFirstChar()

string ret = UpperCaseFirstChar("")
Expand Down
Loading

0 comments on commit 0de9ec0

Please sign in to comment.