Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance adaptive suprathreshold #2302

Draft
wants to merge 53 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
8b3f1f4
PSQ_DAScale (Adapt): Allow to look further back for passing adaptive …
t-b Nov 26, 2024
ac96bdd
PSQ_DAScale (Adapt): Round calculated DAscale to integer values
t-b Nov 27, 2024
ae01dde
PSQ_DS_GatherOvershootCorrection: Optimize execution
t-b Dec 3, 2024
ef9700f
PSQ_DAScale (Adapt): Add the type to the stored future DAScale values
t-b Nov 27, 2024
7b2d988
PSQ_DAScale (Adapt): Add negative fI slope QC entries
t-b Dec 3, 2024
6223765
tests: Add enableRegExp to RunWithOpts
t-b Jan 21, 2025
deb2ba8
EqualValuesOrBothNaN: Fix wording in documentation
t-b Jan 21, 2025
7c94d9b
Add LesserEqualValuesOrBothNaN and LargerEqualValuesOrBothNaN
t-b Jan 21, 2025
fdea37a
FindNeighbourDuplicates: Rename and add support for predicates
t-b Jan 21, 2025
1f65f8c
Packages/MIES/MIES_AnalysisFunctions_PatchSeq.ipf: Remove duplicated …
t-b Jan 21, 2025
6068d36
Tests/GenerateAnalysisFunctionTable: Update it
t-b Jan 14, 2025
2969178
PSQ_FMT_LBN_DA_AT_FI_SLOPE: Add it
t-b Jan 22, 2025
953e05b
PSQ_DS_StoreFitOffsetAndSlope: Factor it out
t-b Jan 22, 2025
220c955
PSQ_DS_ConsecutivePasses: Factor it out
t-b Jan 22, 2025
3d1ce15
PSQ_DAScale (Adaptive): Add new labnotebook entry being sweep QC with…
t-b Jan 22, 2025
d3618fb
MIES_AnalysisFunctions_PatchSeq.ipf: Add forgotten PSQ_FMT_LBN_DA_AT_…
t-b Jan 22, 2025
caa5dbf
PSQ_DAScale (Adapt): Enhance it
t-b Jan 22, 2025
a5a65bf
PSQ_DS_GetFutureDAScalesFromLBN: Factor it out
t-b Jan 22, 2025
89699e6
NumericWaveToList: Fix documentation
t-b Jan 22, 2025
8ec06c6
changes
t-b Jan 22, 2025
a267d36
changes
t-b Jan 22, 2025
0696448
changes
t-b Jan 22, 2025
dbc5824
cc
t-b Jan 22, 2025
4bf4c00
changes
t-b Jan 22, 2025
63ecb5d
changes
t-b Jan 22, 2025
5ab8c1c
changes
t-b Jan 22, 2025
3884ce4
changes
t-b Jan 22, 2025
9525e20
changes
t-b Jan 23, 2025
e8bea44
changes
t-b Jan 23, 2025
f709e4c
changes
t-b Jan 23, 2025
88cb00d
changes
t-b Jan 23, 2025
0a9e88c
changes
t-b Jan 23, 2025
8490acc
changes
t-b Jan 23, 2025
503d70d
changes
t-b Jan 23, 2025
4f5e2b8
changes
t-b Jan 23, 2025
cfd3d07
changes
t-b Jan 23, 2025
5bc66e7
changes
t-b Jan 23, 2025
59b74f0
changes
t-b Jan 23, 2025
418b6e1
changes
t-b Jan 24, 2025
7ad166f
changes
t-b Jan 24, 2025
8f19498
changes
t-b Jan 24, 2025
4c139ff
changes
t-b Jan 24, 2025
24df1dc
changes
t-b Jan 24, 2025
298e6fc
changes
t-b Jan 24, 2025
179bfd6
changes
t-b Jan 24, 2025
33e30d7
changes
t-b Jan 24, 2025
e9dc10f
changes
t-b Jan 24, 2025
eac69e6
changes
t-b Jan 24, 2025
f538b12
MergeSortStableInplace: Add it
t-b Jan 24, 2025
17327de
changes
t-b Jan 24, 2025
1e14749
SortKeyAndData: Add it
t-b Jan 24, 2025
7203f65
changes
t-b Jan 24, 2025
87bc99b
changes
t-b Jan 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
999 changes: 794 additions & 205 deletions Packages/MIES/MIES_AnalysisFunctions_PatchSeq.ipf

Large diffs are not rendered by default.

174 changes: 99 additions & 75 deletions Packages/MIES/MIES_Constants.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1138,81 +1138,90 @@ StrConstant PSQ_BASELINE_SELECTION_SHORT_NAME_RE_MATCHER = "^U_BLS[[:digit:]]+$"
///
/// @anchor PatchSeqLabnotebookFormatStrings
///@{
StrConstant PSQ_FMT_LBN_RB_DASCALE_EXC = "%s DAScale exceeded"
StrConstant PSQ_FMT_LBN_DASCALE_OOR = "%s DAScale out of range"
StrConstant PSQ_FMT_LBN_STEPSIZE = "%s step size"
StrConstant PSQ_FMT_LBN_STEPSIZE_FUTURE = "%s step size (fut.)"
StrConstant PSQ_FMT_LBN_SPIKE_DETECT = "%s spike detected"
StrConstant PSQ_FMT_LBN_SPIKE_POSITIONS = "%s spike positions"
StrConstant PSQ_FMT_LBN_SPIKE_COUNT = "%s spike count"
StrConstant PSQ_FMT_LBN_FINAL_SCALE = "%s final DAScale"
StrConstant PSQ_FMT_LBN_INITIAL_SCALE = "%s initial DAScale"
StrConstant PSQ_FMT_LBN_RMS_SHORT_PASS = "%s Chk%d S-RMS QC"
StrConstant PSQ_FMT_LBN_RMS_SHORT_THRESHOLD = "%s S-RMS Threshold"
StrConstant PSQ_FMT_LBN_RMS_LONG_PASS = "%s Chk%d L-RMS QC"
StrConstant PSQ_FMT_LBN_RMS_LONG_THRESHOLD = "%s L-RMS Threshold"
StrConstant PSQ_FMT_LBN_TARGETV = "%s Chk%d T-V BL"
StrConstant PSQ_FMT_LBN_TARGETV_THRESHOLD = "%s T-V Threshold"
StrConstant PSQ_FMT_LBN_TARGETV_PASS = "%s Chk%d T-V BL QC"
StrConstant PSQ_FMT_LBN_LEAKCUR = "%s Chk%d Leak Current BL"
StrConstant PSQ_FMT_LBN_LEAKCUR_PASS = "%s Chk%d Leak Current BL QC"
StrConstant PSQ_FMT_LBN_CHUNK_PASS = "%s Chk%d BL QC"
StrConstant PSQ_FMT_LBN_BL_QC_PASS = "%s BL QC"
StrConstant PSQ_FMT_LBN_SWEEP_PASS = "%s Sweep QC"
StrConstant PSQ_FMT_LBN_SET_PASS = "%s Set QC"
StrConstant PSQ_FMT_LBN_SAMPLING_PASS = "%s Sampling interval QC"
StrConstant PSQ_FMT_LBN_PULSE_DUR = "%s Pulse duration"
StrConstant PSQ_FMT_LBN_SPIKE_DASCALE_ZERO = "%s spike with zero"
StrConstant PSQ_FMT_LBN_RB_LIMITED_RES = "%s limited resolut."
StrConstant PSQ_FMT_LBN_DA_FI_SLOPE = "%s f-I slope"
StrConstant PSQ_FMT_LBN_DA_AT_FI_OFFSET = "%s f-I offset"
StrConstant PSQ_FMT_LBN_DA_FI_SLOPE_REACHED_PASS = "%s f-I slope QC"
StrConstant PSQ_FMT_LBN_DA_OPMODE = "%s operation mode"
StrConstant PSQ_FMT_LBN_DA_AT_ENOUGH_FI_POINTS_PASS = "%s enough f-I pairs for line fit QC"
StrConstant PSQ_FMT_LBN_DA_AT_FREQ = "%s AP frequency"
StrConstant PSQ_FMT_LBN_DA_AT_FUTURE_DASCALES = "%s DAScale values left"
StrConstant PSQ_FMT_LBN_DA_AT_FUTURE_DASCALES_PASS = "%s DAScale values left QC"
StrConstant PSQ_FMT_LBN_DA_AT_MAX_DASCALE_NORM = "%s Max. norm. DAScale step"
StrConstant PSQ_FMT_LBN_DA_AT_MAX_SLOPE = "%s f-I maximum slope"
StrConstant PSQ_FMT_LBN_DA_AT_MIN_DASCALE_NORM = "%s Min. norm. DAScale step"
StrConstant PSQ_FMT_LBN_DA_AT_RSA_DASCALE = "%s DAScale from rheobase, supra, adaptive"
StrConstant PSQ_FMT_LBN_DA_AT_RSA_FI_OFFSETS = "%s f-I offsets from rheobase, supra, adaptive"
StrConstant PSQ_FMT_LBN_DA_AT_RSA_FI_SLOPES = "%s f-I slopes from rheobase, supra, adaptive"
StrConstant PSQ_FMT_LBN_DA_AT_RSA_FI_SLOPES_PASS = "%s f-I slope QCs from rheobase, supra, adaptive"
StrConstant PSQ_FMT_LBN_DA_AT_RSA_FREQ = "%s AP frequency from rheobase, supra, adaptive"
StrConstant PSQ_FMT_LBN_DA_AT_RSA_SWEEPS = "%s passing sweep numbers from rheobase, supra, adaptive"
StrConstant PSQ_FMT_LBN_DA_AT_RSA_VALID_SLOPE_PASS = "%s f-I initial slope valid from rheobase, supra, adaptive QC"
StrConstant PSQ_FMT_LBN_DA_AT_VALID_SLOPE_PASS = "%s f-I slope valid QC"
StrConstant PSQ_FMT_LBN_CR_RESISTANCE = "%s input resistance"
StrConstant PSQ_FMT_LBN_CR_INSIDE_BOUNDS = "%s inside bounds"
StrConstant PSQ_FMT_LBN_CR_BOUNDS_ACTION = "%s bounds action"
StrConstant PSQ_FMT_LBN_CR_CYCLES = "%s cycle x values"
StrConstant PSQ_FMT_LBN_CR_BOUNDS_STATE = "%s bounds state"
StrConstant PSQ_FMT_LBN_CR_SPIKE_CHECK = "%s spike check"
StrConstant PSQ_FMT_LBN_CR_INIT_UOD = "%s initial user onset delay"
StrConstant PSQ_FMT_LBN_CR_INIT_LPF = "%s initial low pass filter"
StrConstant PSQ_FMT_LBN_CR_STIMSET_QC = "%s stimset QC"
StrConstant PSQ_FMT_LBN_SPIKE_PASS = "%s spike QC"
StrConstant PSQ_FMT_LBN_PB_RESISTANCE = "%s pipette resistance"
StrConstant PSQ_FMT_LBN_PB_RESISTANCE_PASS = "%s pipette resistance QC"
StrConstant PSQ_FMT_LBN_SE_RESISTANCE_A = "%s seal resistance A"
StrConstant PSQ_FMT_LBN_SE_RESISTANCE_B = "%s seal resistance B"
StrConstant PSQ_FMT_LBN_SE_RESISTANCE_MAX = "%s seal resistance max"
StrConstant PSQ_FMT_LBN_SE_RESISTANCE_PASS = "%s seal resistance QC"
StrConstant PSQ_FMT_LBN_SE_TESTPULSE_GROUP = "%s test pulse group"
StrConstant PSQ_FMT_LBN_AVERAGEV = "%s Chk%d Average"
StrConstant PSQ_FMT_LBN_VM_FULL_AVG = "%s Full Average"
StrConstant PSQ_FMT_LBN_VM_FULL_AVG_ADIFF = "%s Full Average absolute difference"
StrConstant PSQ_FMT_LBN_VM_FULL_AVG_ADIFF_PASS = "%s Full Average absolute difference QC"
StrConstant PSQ_FMT_LBN_VM_FULL_AVG_RDIFF = "%s Full Average relative difference"
StrConstant PSQ_FMT_LBN_VM_FULL_AVG_RDIFF_PASS = "%s Full Average relative difference QC"
StrConstant PSQ_FMT_LBN_VM_FULL_AVG_PASS = "%s Full Average QC"
StrConstant PSQ_FMT_LBN_AR_ACCESS_RESISTANCE = "%s access resistance"
StrConstant PSQ_FMT_LBN_AR_ACCESS_RESISTANCE_PASS = "%s access resistance QC"
StrConstant PSQ_FMT_LBN_AR_STEADY_STATE_RESISTANCE = "%s steady state resistance"
StrConstant PSQ_FMT_LBN_AR_RESISTANCE_RATIO = "%s access vs steady state ratio"
StrConstant PSQ_FMT_LBN_AR_RESISTANCE_RATIO_PASS = "%s access vs steady state ratio QC"
StrConstant PSQ_FMT_LBN_ASYNC_PASS = "%s async QC"
StrConstant PSQ_FMT_LBN_RB_DASCALE_EXC = "%s DAScale exceeded"
StrConstant PSQ_FMT_LBN_DASCALE_OOR = "%s DAScale out of range"
StrConstant PSQ_FMT_LBN_STEPSIZE = "%s step size"
StrConstant PSQ_FMT_LBN_STEPSIZE_FUTURE = "%s step size (fut.)"
StrConstant PSQ_FMT_LBN_SPIKE_DETECT = "%s spike detected"
StrConstant PSQ_FMT_LBN_SPIKE_POSITIONS = "%s spike positions"
StrConstant PSQ_FMT_LBN_SPIKE_COUNT = "%s spike count"
StrConstant PSQ_FMT_LBN_FINAL_SCALE = "%s final DAScale"
StrConstant PSQ_FMT_LBN_INITIAL_SCALE = "%s initial DAScale"
StrConstant PSQ_FMT_LBN_RMS_SHORT_PASS = "%s Chk%d S-RMS QC"
StrConstant PSQ_FMT_LBN_RMS_SHORT_THRESHOLD = "%s S-RMS Threshold"
StrConstant PSQ_FMT_LBN_RMS_LONG_PASS = "%s Chk%d L-RMS QC"
StrConstant PSQ_FMT_LBN_RMS_LONG_THRESHOLD = "%s L-RMS Threshold"
StrConstant PSQ_FMT_LBN_TARGETV = "%s Chk%d T-V BL"
StrConstant PSQ_FMT_LBN_TARGETV_THRESHOLD = "%s T-V Threshold"
StrConstant PSQ_FMT_LBN_TARGETV_PASS = "%s Chk%d T-V BL QC"
StrConstant PSQ_FMT_LBN_LEAKCUR = "%s Chk%d Leak Current BL"
StrConstant PSQ_FMT_LBN_LEAKCUR_PASS = "%s Chk%d Leak Current BL QC"
StrConstant PSQ_FMT_LBN_CHUNK_PASS = "%s Chk%d BL QC"
StrConstant PSQ_FMT_LBN_BL_QC_PASS = "%s BL QC"
StrConstant PSQ_FMT_LBN_SWEEP_PASS = "%s Sweep QC"
StrConstant PSQ_FMT_LBN_SET_PASS = "%s Set QC"
StrConstant PSQ_FMT_LBN_SAMPLING_PASS = "%s Sampling interval QC"
StrConstant PSQ_FMT_LBN_PULSE_DUR = "%s Pulse duration"
StrConstant PSQ_FMT_LBN_SPIKE_DASCALE_ZERO = "%s spike with zero"
StrConstant PSQ_FMT_LBN_SWEEP_EXCEPT_BL_PP_PASS = "%s sweep except baseline QC"
StrConstant PSQ_FMT_LBN_RB_LIMITED_RES = "%s limited resolut."
StrConstant PSQ_FMT_LBN_DA_FI_SLOPE = "%s f-I slope"
StrConstant PSQ_FMT_LBN_DA_AT_FI_NEG_SLOPE_PASS = "%s f-I neg. slope QC"
StrConstant PSQ_FMT_LBN_DA_AT_FI_OFFSET = "%s f-I offset"
StrConstant PSQ_FMT_LBN_DA_AT_FI_SLOPE = "%s f-I slope"
StrConstant PSQ_FMT_LBN_DA_AT_FI_OFFSET_DASCALE = "%s f-I offset for DAScale estimation"
StrConstant PSQ_FMT_LBN_DA_AT_FI_SLOPE_DASCALE = "%s f-I slope for DAScale estimation"
StrConstant PSQ_FMT_LBN_DA_FI_SLOPE_REACHED_PASS = "%s f-I slope QC"
StrConstant PSQ_FMT_LBN_DA_OPMODE = "%s operation mode"
StrConstant PSQ_FMT_LBN_DA_AT_ENOUGH_FI_POINTS_PASS = "%s enough f-I pairs for line fit QC"
StrConstant PSQ_FMT_LBN_DA_AT_FREQ = "%s AP frequency"
StrConstant PSQ_FMT_LBN_DA_AT_FUTURE_DASCALES = "%s DAScale values left"
StrConstant PSQ_FMT_LBN_DA_AT_FUTURE_DASCALES_PASS = "%s DAScale values left QC"
StrConstant PSQ_FMT_LBN_DA_AT_MAX_DASCALE_NORM = "%s Max. norm. DAScale step"
StrConstant PSQ_FMT_LBN_DA_AT_MAX_SLOPE = "%s f-I maximum slope"
StrConstant PSQ_FMT_LBN_DA_AT_MIN_DASCALE_NORM = "%s Min. norm. DAScale step"
StrConstant PSQ_FMT_LBN_DA_AT_RSA_DASCALE = "%s DAScale from rheobase, supra, adaptive"
StrConstant PSQ_FMT_LBN_DA_AT_RSA_FI_OFFSETS = "%s f-I offsets from rheobase, supra, adaptive"
StrConstant PSQ_FMT_LBN_DA_AT_RSA_FI_SLOPES = "%s f-I slopes from rheobase, supra, adaptive"
StrConstant PSQ_FMT_LBN_DA_AT_RSA_FI_OFFSETS_DASCALE = "%s f-I offsets for DAScale estimation from rheobase, supra, adaptive"
StrConstant PSQ_FMT_LBN_DA_AT_RSA_FI_SLOPES_DASCALE = "%s f-I slopes for DAScale estimation from rheobase, supra, adaptive"
StrConstant PSQ_FMT_LBN_DA_AT_RSA_FI_NEG_SLOPES_PASS = "%s f-I neg. slopes QC from rheobase, supra, adaptive"
StrConstant PSQ_FMT_LBN_DA_AT_RSA_FI_SLOPES_PASS = "%s f-I slope QCs from rheobase, supra, adaptive"
StrConstant PSQ_FMT_LBN_DA_AT_RSA_FREQ = "%s AP frequency from rheobase, supra, adaptive"
StrConstant PSQ_FMT_LBN_DA_AT_RSA_SWEEPS = "%s passing sweep numbers from rheobase, supra, adaptive"
StrConstant PSQ_FMT_LBN_DA_AT_RSA_VALID_SLOPE_PASS = "%s f-I initial slope valid from rheobase, supra, adaptive QC"
StrConstant PSQ_FMT_LBN_DA_AT_NEG_SLOPE_FILLIN = "%s fillin for neg slope criteria in progress"
StrConstant PSQ_FMT_LBN_DA_AT_VALID_SLOPE_PASS = "%s f-I slope valid QC"
StrConstant PSQ_FMT_LBN_CR_RESISTANCE = "%s input resistance"
StrConstant PSQ_FMT_LBN_CR_INSIDE_BOUNDS = "%s inside bounds"
StrConstant PSQ_FMT_LBN_CR_BOUNDS_ACTION = "%s bounds action"
StrConstant PSQ_FMT_LBN_CR_CYCLES = "%s cycle x values"
StrConstant PSQ_FMT_LBN_CR_BOUNDS_STATE = "%s bounds state"
StrConstant PSQ_FMT_LBN_CR_SPIKE_CHECK = "%s spike check"
StrConstant PSQ_FMT_LBN_CR_INIT_UOD = "%s initial user onset delay"
StrConstant PSQ_FMT_LBN_CR_INIT_LPF = "%s initial low pass filter"
StrConstant PSQ_FMT_LBN_CR_STIMSET_QC = "%s stimset QC"
StrConstant PSQ_FMT_LBN_SPIKE_PASS = "%s spike QC"
StrConstant PSQ_FMT_LBN_PB_RESISTANCE = "%s pipette resistance"
StrConstant PSQ_FMT_LBN_PB_RESISTANCE_PASS = "%s pipette resistance QC"
StrConstant PSQ_FMT_LBN_SE_RESISTANCE_A = "%s seal resistance A"
StrConstant PSQ_FMT_LBN_SE_RESISTANCE_B = "%s seal resistance B"
StrConstant PSQ_FMT_LBN_SE_RESISTANCE_MAX = "%s seal resistance max"
StrConstant PSQ_FMT_LBN_SE_RESISTANCE_PASS = "%s seal resistance QC"
StrConstant PSQ_FMT_LBN_SE_TESTPULSE_GROUP = "%s test pulse group"
StrConstant PSQ_FMT_LBN_AVERAGEV = "%s Chk%d Average"
StrConstant PSQ_FMT_LBN_VM_FULL_AVG = "%s Full Average"
StrConstant PSQ_FMT_LBN_VM_FULL_AVG_ADIFF = "%s Full Average absolute difference"
StrConstant PSQ_FMT_LBN_VM_FULL_AVG_ADIFF_PASS = "%s Full Average absolute difference QC"
StrConstant PSQ_FMT_LBN_VM_FULL_AVG_RDIFF = "%s Full Average relative difference"
StrConstant PSQ_FMT_LBN_VM_FULL_AVG_RDIFF_PASS = "%s Full Average relative difference QC"
StrConstant PSQ_FMT_LBN_VM_FULL_AVG_PASS = "%s Full Average QC"
StrConstant PSQ_FMT_LBN_AR_ACCESS_RESISTANCE = "%s access resistance"
StrConstant PSQ_FMT_LBN_AR_ACCESS_RESISTANCE_PASS = "%s access resistance QC"
StrConstant PSQ_FMT_LBN_AR_STEADY_STATE_RESISTANCE = "%s steady state resistance"
StrConstant PSQ_FMT_LBN_AR_RESISTANCE_RATIO = "%s access vs steady state ratio"
StrConstant PSQ_FMT_LBN_AR_RESISTANCE_RATIO_PASS = "%s access vs steady state ratio QC"
StrConstant PSQ_FMT_LBN_ASYNC_PASS = "%s async QC"
///@}

StrConstant FMT_LBN_ANA_FUNC_VERSION = "%s version"
Expand Down Expand Up @@ -1302,7 +1311,22 @@ Constant PSQ_DA_NUM_SWEEPS_SATURATION = 2
Constant PSQ_DA_NUM_INVALID_SLOPE_SWEEPS_ALLOWED = 3
Constant PSQ_DA_MAX_FREQUENCY_CHANGE_PERCENT = 20
Constant PSQ_DA_DASCALE_STEP_WITH_MIN_MAX_FACTOR = 3
Constant FAILING_ADAPTIVE_SCI_RANGE_DEFAULT = 1

/// @name Reason for adding a new DAScale value to the future wave
/// @anchor FutureDAScaleReason
///@{
StrConstant PSQ_DS_AD_REGULAR_RHSUAD = "RegRhSuAd"
StrConstant PSQ_DS_AD_REGULAR = "Reg"
StrConstant PSQ_DS_AD_REGULAR_POSNEG_SLOPE_RHSUAD = "RegPosNegSlopeRhSuAd"
StrConstant PSQ_DS_AD_REGULAR_POSNEG_SLOPE = "RegPosNegSlope"
StrConstant PSQ_DS_AD_FILLIN_RHSUAD = "FillinRhSuAd"
StrConstant PSQ_DS_AD_FILLIN = "Fillin"
StrConstant PSQ_DS_AD_FILLIN_POSNEG_SLOPE_RHSUAD = "FillinPosNegSlopeRhSuAd"
StrConstant PSQ_DS_AD_FILLIN_POSNEG_SLOPE = "FillinPosNegSlope"
///@}

StrConstant PSQ_DS_AD_TYPE_SEP = ":"
///@}

/// @name PatchSeq Ramp
Expand Down
82 changes: 82 additions & 0 deletions Packages/MIES/MIES_Utilities_Algorithm.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1168,3 +1168,85 @@ Function/WAVE SplitLogDataBySize(WAVE/T logData, string sep, variable lim, [vari

return result
End

Function [WAVE keySorted, WAVE dataSorted] SortKeyAndData(WAVE key, WAVE data)

Concatenate/FREE {key, data}, comb
MergeSortStableInplace(comb, col = 0)

/// @todo workaround IP issue 4979 (singleWaves is not a free wave)
Make/FREE/WAVE/N=0 singleWaves
SplitWave/FREE/OREF=singleWaves/SDIM=(COLS) comb
return [singleWaves[0], singleWaves[1]]
End

/// Sort the given wave in ascending order
/// Passing in a 2D wave also to sort all columns according to `col`
///
/// Straight from wikipedia, top-down implementation, https://en.wikipedia.org/wiki/Merge_sort
/// with the addition of `col`
Function MergeSortStableInplace(WAVE A, [variable col])

/// Array A[] has the items to sort; array B[] is a work array.
variable numRows, numCols

numRows = DimSize(A, ROWS)
numCols = DimSize(A, COLS)

if(ParamIsDefault(col))
col = 0
else
ASSERT(col >= 0 && col < numCols, "col is out of range")
endif

if(numRows <= 1)
return NaN
endif

Duplicate/FREE A, B // one time copy of A[] to B[]

TopDownSplitMerge(A, 0, numRows, B, col) // sort data from B[] into A[]
End

// Split A[] into 2 runs, sort both runs into B[], merge both runs from B[] to A[]
// iBegin is inclusive iEnd is exclusive (A[iEnd] is not in the set).
static Function TopDownSplitMerge(WAVE B, variable iBegin, variable iEnd, WAVE A, variable col)

variable iMiddle

if(iEnd - iBegin <= 1) // if run size == 1
return NaN // consider it sorted
endif

// split the run longer than 1 item into halves
iMiddle = ceil((iEnd + iBegin) / 2) // iMiddle = mid point

// recursively sort both runs from array A[] into B[]
TopDownSplitMerge(A, iBegin, iMiddle, B, col) // sort the left run
TopDownSplitMerge(A, iMiddle, iEnd, B, col) // sort the right run
// merge the resulting runs from array B[] into A[]
TopDownMerge(B, iBegin, iMiddle, iEnd, A, col)
End

// Left source half is A[ iBegin:iMiddle-1].
// Right source half is A[iMiddle:iEnd-1 ].
// Result is B[ iBegin:iEnd-1 ].
static Function TopDownMerge(WAVE B, variable iBegin, variable iMiddle, variable iEnd, WAVE A, variable col)

variable i, j, k

i = iBegin
j = iMiddle

// While there are elements in the left or right runs...
for(k = iBegin; k < iEnd; k++)
// If left run head exists and is <= existing right run head.
if(i < iMiddle && (j >= iEnd || A[i][col] <= A[j][col]))
B[k][] = A[i][q]
i = i + 1
else
B[k][] = A[j][q]
j = j + 1
endif
endfor
End
18 changes: 17 additions & 1 deletion Packages/MIES/MIES_Utilities_Checks.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,30 @@ Function StringEndsWith(string str, string suffix)
return 0
End

/// @brief Check wether `val1` and `val2` are equal or both NaN
/// @brief Check wether `val1` and `val2` are equal or both are NaN
///
/// UTF_NOINSTRUMENTATION
threadsafe Function EqualValuesOrBothNaN(variable left, variable right)

return (IsNaN(left) && IsNaN(right)) || (left == right)
End

/// @brief Check wether `val1` <= `val2` holds or both are NaN
///
/// UTF_NOINSTRUMENTATION
threadsafe Function LesserEqualValuesOrBothNaN(variable left, variable right)

return (IsNaN(left) && IsNaN(right)) || (left <= right)
End

/// @brief Check wether `val1` >= `val2` holds or both are NaN
///
/// UTF_NOINSTRUMENTATION
threadsafe Function LargerEqualValuesOrBothNaN(variable left, variable right)

return (IsNaN(left) && IsNaN(right)) || (left >= right)
End

/// @brief Checks wether `wv` is constant and has the value `val`
///
/// @param wv wave to check
Expand Down
2 changes: 1 addition & 1 deletion Packages/MIES/MIES_Utilities_Conversions.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ End
/// @param sep separator
/// @param colSep [optional, default = `,`] separator for column entries
/// @param format [optional, defaults to `%g`] sprintf conversion specifier
/// @param trailSep [optional, defaults to false] don't add a row separator after the last row
/// @param trailSep [optional, defaults to true] don't add a row separator after the last row
threadsafe Function/S NumericWaveToList(WAVE/Z wv, string sep, [string format, string colSep, variable trailSep])

if(!WaveExists(wv))
Expand Down
12 changes: 9 additions & 3 deletions Packages/MIES/MIES_Utilities_WaveHandling.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1248,8 +1248,14 @@ Function SearchForDuplicates(WAVE wv)
return WaveExists(idx) && DimSize(idx, ROWS) > 0
End

/// @brief Return the indizes of elements which need to be dropped so that no two neighbouring points are equal/both NaN
Function/WAVE FindNeighbourDuplicates(WAVE wv)
threadsafe Function FindNeighbourPrototype(variable var1, variable var2)

ASSERT_TS(0, "Can't call prototype function")
End

/// @brief Return the indizes of elements which need to be dropped so that no
/// two neighbouring points fullfil the predicate `f`
threadsafe Function/WAVE FindNeighbourWithPredicate(WAVE wv, FUNCREF FindNeighbourPrototype pred)

variable numPoints, i, numDuplicates, idx

Expand All @@ -1265,7 +1271,7 @@ Function/WAVE FindNeighbourDuplicates(WAVE wv)
FastOp indizes = (NaN)

for(i = 1; i < numPoints; i += 1)
if(EqualValuesOrBothNaN(wv[i - 1], wv[i]))
if(pred(wv[i - 1], wv[i]))
indizes[idx++] = i
endif
endfor
Expand Down
Loading
Loading