Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
24c6d11
PSX_RestoreGuiState: Prefer GUI control setter over PGC
t-b Apr 1, 2025
467c867
PSX_GetEventIndexAndComboIndex: Handle vs in keyboard navigation
t-b Apr 4, 2025
419ef3e
PSX: Tweak detection algorithm
timjarsky Mar 18, 2025
b5b49a1
PSX: Calculate the starting point for the average fit better
t-b Mar 19, 2025
61d1645
PSX_GetEventFitRange: Change starting position
t-b Mar 19, 2025
44b93c8
PSX_CalculateEventProperties: Tweak baseline calculation
t-b Mar 19, 2025
40f45a7
UTF_SweepFormula_PSX.ipf: Fix tests
t-b Mar 19, 2025
969f4ba
PSX_GetGoodTau: Handle edge case
t-b Mar 25, 2025
796ca00
PSX_PlotStartupSettings: Handle no userdata properly
t-b Mar 25, 2025
bce4b84
MIES_SweepFormula_PSX.ipf: Tweak PSX_TAU_CALC_FACTOR
timjarsky Mar 19, 2025
c2629d7
MIES_SweepFormula_PSX.ipf: Tweak peak and baseline calculation
t-b Apr 7, 2025
80971bb
PSX_CalculateRiseTime: Factor it out
t-b Mar 25, 2025
3da8142
PSX_CalculateRiseTime: Return error when xStart is NaN
t-b Mar 26, 2025
1a80379
PSX_UpdateDisplayedFit: Remove yOffset
t-b Apr 7, 2025
0b8b612
PSX_FitAcceptAverage: Use different method for calculating start posi…
t-b Mar 25, 2025
111fccf
MIES_SweepFormula_PSX.ipf: Revise event peak and baseline calculation
t-b Apr 7, 2025
ed7cbe3
PSX_GetEventFitRange/PSX_FitEventDecay: Revise them
t-b Apr 7, 2025
dfbebf0
PSX_FitEventDecay: Switch from single exponential to double exponenti…
timjarsky Apr 2, 2025
c04798e
PSX_FitAcceptAverage: Multiple simultaneous fits to the accepted all …
timjarsky Apr 2, 2025
31e9eb8
PSX_FilterEventsKernelAmpSign: Ignore events with non-finite deconv v…
t-b Apr 7, 2025
c977b8f
PSX: Add more vertical lines for peak_t and baseline_t
t-b Apr 7, 2025
c3b950a
PSX_FitEventDecay: Support three tau instead of one
t-b Apr 2, 2025
76ee433
PSX_AppendTracesToAllEventGraph: Fix function comment
t-b Apr 7, 2025
57b1b6d
stopping the collapse of the universe by filtering out negative time …
timjarsky Apr 10, 2025
d45b953
another tau filter
timjarsky Apr 10, 2025
3f82efa
BandPassWithRingingDetection: Add it
timjarsky Apr 23, 2025
c1f58e7
psxDeconvFilter: Rework it
t-b May 9, 2025
ea04883
MIES_SweepFormula_PSX.ipf: Document SweepFormula operation signatures
t-b May 9, 2025
ca6d2ed
psxSweepBPFilter: Add it
t-b May 9, 2025
51541ed
PSX_FilterSweepData/PSX_DeconvoluteSweepData: Always make order even
t-b May 12, 2025
cbf2ccc
SFH_GetArgumentAsNumeric: Add assertion
t-b May 12, 2025
43ab30a
BandPassWithRingingDetection: Minor cleanup
t-b May 12, 2025
6f3bf66
BandPassWithRingingDetection: Remove the offset for every iteration
t-b May 12, 2025
97d1ae5
BandPassWithRingingDetection: Reorganize the code
t-b May 12, 2025
351502f
PSX_Operation: Fix data gathering after failure
t-b May 13, 2025
b8b30da
PSX_Operation: Backdown filtering order
t-b May 14, 2025
954e30d
MIES_SweepFormula_PSX.ipf: Check number of arguments in all operations
t-b May 14, 2025
a7462db
SF_CheckInputCode: Preprocess code
t-b May 14, 2025
0ef1eb2
Packages/doc/SweepFormula.rst: Update it
t-b May 28, 2025
1b5d868
PSX: Use 2^x padding for FFT input
t-b May 30, 2025
f123986
PSX: Prefer odd number of historgram bins
timjarsky May 30, 2025
c165ceb
Revert "PSX: Use 2^x padding for FFT input"
timjarsky May 30, 2025
bf5f6dd
PSX_FitAcceptAverage: Calculate maximum of it as well
t-b Jun 4, 2025
7aa2be6
PSX: Add average fit for all states
t-b Jun 4, 2025
b16326f
MakeWaveFree: Make it threadsafe
t-b Jun 6, 2025
0a85d57
tools/check-code.sh: Teach the test assertion check support for NOLINT
t-b Jun 10, 2025
8313a73
MIES_Utilities_Algorithm.ipf: Add helper routines for DoFFT
t-b Jun 5, 2025
a2ad471
SF_SetStatusDisplay: Make it available for all
t-b Jun 6, 2025
5ddd976
PSX: Implement sweep data shortening for faster FFT
t-b Jun 6, 2025
c9e7854
PSX: Supply default values for filtering derived from the kernel
t-b Jun 10, 2025
80451b5
GetInterpolatedYValue: Add it with tests
t-b Jun 10, 2025
8114257
PSX: Add Onset and Rise y values to psxEvent
t-b Jun 10, 2025
5c317af
PSX_FitAverage: Store fit results in datafolder hierarchy
t-b Jun 10, 2025
f98435d
Packages/doc/SweepFormula.rst: Add units for rise and decay tau
t-b Jun 10, 2025
8fe2f53
PSX_UpdateBlockIndizes: Remove unused restrictCurrentCombo variable
t-b Jun 11, 2025
79100a9
PSX_Operation: Add peakThreshold to parameter JSON
t-b Jun 25, 2025
17506ee
JSONToWave/WaveTypeStringToNumber: Add support for unsigned integer w…
t-b Jul 9, 2025
91f34bc
PSX_OperationStatsImpl: Output more entries for stats postprocessing
t-b Jul 9, 2025
3b74672
Tim's questionable changes :)
timjarsky Jul 28, 2025
bb473f3
PSX_UpdateAverageTraces: Fix indexing confusion
t-b Jul 29, 2025
d94a574
new function to determine the fit end time for the decay to the avera…
timjarsky Aug 5, 2025
ab66bfc
Update Packages/MIES/MIES_SweepFormula_PSX.ipf
timjarsky Aug 6, 2025
f7489e2
Update Packages/MIES/MIES_SweepFormula_PSX.ipf
timjarsky Aug 6, 2025
df910ad
stand alone function to get kernel decay tau
timjarsky Aug 8, 2025
76b5943
PSX fixes
timjarsky Aug 13, 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
9 changes: 7 additions & 2 deletions Packages/MIES/MIES_Cache.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ End
/// @param psxParameters JSON dump of the psx/psxKernel operation parameters
Function/S CA_PSXEventsKey(string comboKey, string psxParameters)

return CA_PSXBaseKey(comboKey, psxParameters) + " Events " + ":Version 2"
return CA_PSXBaseKey(comboKey, psxParameters) + " Events " + ":Version 3"
End

Function/S CA_PSXOperationKey(string comboKey, string psxParameters)
Expand All @@ -472,7 +472,7 @@ End

Function/S CA_PSXAnalyzePeaks(string comboKey, string psxParameters)

return CA_PSXBaseKey(comboKey, psxParameters) + " Analyze Peaks " + ":Version 2"
return CA_PSXBaseKey(comboKey, psxParameters) + " Analyze Peaks " + ":Version 3"
End

/// @brief Return the key for the igor info entries
Expand Down Expand Up @@ -512,6 +512,11 @@ Function/S CA_GetLabnotebookNamesKey(WAVE/Z/T textualValues, WAVE/Z/T numericalV
return "Version 1:" + Hash(key, HASH_SHA2_256)
End

Function/S CA_GetGoodFFTSizesKeys()

return "GetGoodFFTSizes Version 1"
End

///@}

/// @brief Make space for one new entry in the cache waves
Expand Down
32 changes: 21 additions & 11 deletions Packages/MIES/MIES_Constants.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,14 @@ Constant SF_DM_NORMAL = 1
Constant SF_DM_SUBWINDOWS = 2
///@}

/// @name Constants for SF_SetStatusDisplay
/// @anchor SweepFormulaStatusDisplayModes
///@{
Constant SF_MSG_OK = 1
Constant SF_MSG_ERROR = 0
Constant SF_MSG_WARN = -1
///@}

/// @name Parameters for GetTTLLabnotebookEntry()
/// @anchor LabnotebookTTLNames
///
Expand Down Expand Up @@ -2343,12 +2351,13 @@ Constant SECONDS_PER_DAY = 86400
StrConstant DB_AXIS_PART_EPOCHS = "_EP"
///@}

StrConstant SF_OP_PSX = "psx"
StrConstant SF_OP_PSX_KERNEL = "psxKernel"
StrConstant SF_OP_PSX_STATS = "psxStats"
StrConstant SF_OP_PSX_RISETIME = "psxRiseTime"
StrConstant SF_OP_PSX_PREP = "psxPrep"
StrConstant SF_OP_PSX_DECONV_FILTER = "psxDeconvFilter"
StrConstant SF_OP_PSX = "psx"
StrConstant SF_OP_PSX_KERNEL = "psxKernel"
StrConstant SF_OP_PSX_STATS = "psxStats"
StrConstant SF_OP_PSX_RISETIME = "psxRiseTime"
StrConstant SF_OP_PSX_PREP = "psxPrep"
StrConstant SF_OP_PSX_DECONV_BP_FILTER = "psxDeconvBPFilter"
StrConstant SF_OP_PSX_SWEEP_BP_FILTER = "psxSweepBPFilter"

/// @name Available PSX states
/// @anchor PSXStates
Expand Down Expand Up @@ -2377,10 +2386,12 @@ Constant PSX_MARKER_UNDET = 18
/// @name Custom error codes for PSX_FitEventDecay()
/// @anchor FitEventDecayCustomErrors
///@{
Constant PSX_DECAY_FIT_ERROR = -10000
Constant PSX_DECAY_FIT_ERROR = -10000
Constant PSX_DECAY_FIT_INVALID_RANGE_ERROR = -10001

///@}

StrConstant PSX_STATS_LABELS = "Average;Median;Average Deviation;Standard deviation;Skewness;Kurtosis"
StrConstant PSX_STATS_LABELS = "Average;Median;Average Deviation;Standard deviation;Skewness;Kurtosis;Lower quartile;Upper quartile;Inter-quartile range;Median absolute deviation;Most frequent value"

/// @name Horizontal offset modes in all event graph
///
Expand All @@ -2393,9 +2404,8 @@ Constant PSX_HORIZ_OFFSET_PEAK = 1
Constant PSX_HORIZ_OFFSET_SLEW = 2
///@}

Constant PSX_DECONV_FILTER_DEF_LOW = 500
Constant PSX_DECONV_FILTER_DEF_HIGH = 50
Constant PSX_DECONV_FILTER_DEF_ORDER = 7
Constant PSX_SWEEP_FILTER_DEF_ORDER = 4
Constant PSX_DECONV_FILTER_DEF_ORDER = 4

StrConstant PSX_JWN_COMBO_KEYS_NAME = "ComboKeys"

Expand Down
77 changes: 77 additions & 0 deletions Packages/MIES/MIES_MiesUtilities_Algorithm.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -641,3 +641,80 @@ threadsafe Function/WAVE FindIndizes(WAVE numericOrTextWave, [variable col, stri

return result
End

/// @brief Band‑pass filters a wave while automatically reducing IIR filter
/// order until the output contains no NaNs/Infs and its SEM is not larger than
/// the original (simple ringing detection).
///
/// @param src – input wave
/// @param fHigh – pass‑band edge frequencies in Hz (Igor’s band‑pass requires fLow > fHigh; the routine swaps them if needed)
/// @param fLow – low part
/// @param maxOrder – starting (maximum) IIR filter order to try (>0)
///
/// Logic: iteratively lowers the filter order until three conditions are met:
/// 1. FilterIIR executes without error.
/// 2. WaveStats reports V_numNaNs = 0 and V_numInfs = 0.
/// 3. SEM(filtered) ≤ SEM(original).
///
/// @retval realOrder filter order that finally succeeded (NaN if every order failed)
/// @retval filtered filtered data
Function [variable realOrder, WAVE filtered] BandPassWithRingingDetection(WAVE src, variable fHigh, variable fLow, variable maxOrder)

variable err, samp, semOrig, offset, i
string msg

ASSERT(IsInteger(maxOrder) && maxOrder > 0 && isEven(maxOrder), "maxOrder must be a positive and even integer")
Copy link

Copilot AI Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion uses compound logical operators (&&) which the test framework check was designed to flag. Consider breaking this into separate assertions for each condition to improve clarity and debugging.

Suggested change
ASSERT(IsInteger(maxOrder) && maxOrder > 0 && isEven(maxOrder), "maxOrder must be a positive and even integer")
ASSERT(IsInteger(maxOrder), "maxOrder must be an integer")
ASSERT(maxOrder > 0, "maxOrder must be positive")
ASSERT(isEven(maxOrder), "maxOrder must be even")

Copilot uses AI. Check for mistakes.


// Igor band-pass expects fLow > fHigh
[fHigh, fLow] = MinMax(fLow, fHigh)

// Sampling rate (Hz) – assumes X scaling is in milliseconds
samp = 1 / (DeltaX(src) * MILLI_TO_ONE)

// Pre-compute SEM(original) once
WaveStats/Q src
semOrig = V_sem
offset = v_avg
ASSERT(V_numNaNs == 0 && V_numInfs == 0, "Expected only finite value in input data")

// Prepare destination wave
Duplicate/FREE src, filtered

for(i = maxOrder; i > 0; i -= 2)
Multithread filtered = src - offset

FilterIIR/LO=(fLow / samp)/HI=(fHigh / samp)/DIM=(ROWS)/ORD=(i) filtered; err = GetRTError(1)
if(err)
continue
endif

WaveStats/Q filtered
if(V_numNaNs > 0 || V_numInfs > 0)
sprintf msg, "V_numNaNs: %g, V_numInfs: %g", V_numNaNs, V_numInfs
DEBUGPRINT(msg)

// bad numerical output → lower order
continue
endif

if(V_sem > semOrig)
sprintf msg, "V_sem: %g,semOrig: %g", V_sem, semOrig
DEBUGPRINT(msg)

// noisier than original → ringing
continue
endif

Multithread filtered += offset

sprintf msg, "maxOrder: %g, realOrder: %g", maxOrder, i
DEBUGPRINT(msg)

return [i, filtered]
endfor

sprintf msg, "maxOrder: %g, realOrder: NaN", maxOrder
DEBUGPRINT(msg)

return [NaN, $""]
End
24 changes: 13 additions & 11 deletions Packages/MIES/MIES_SweepFormula.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ static StrConstant SF_PLOTTER_GUIDENAME = "HOR"

static StrConstant SF_XLABEL_USER = ""

static Constant SF_MSG_OK = 1
static Constant SF_MSG_ERROR = 0
static Constant SF_MSG_WARN = -1

static Constant SF_NUMTRACES_ERROR_THRESHOLD = 10000
static Constant SF_NUMTRACES_WARN_THRESHOLD = 1000

Expand Down Expand Up @@ -252,7 +248,8 @@ Function/WAVE SF_GetNamedOperations()
SF_OP_LOG10, SF_OP_APFREQUENCY, SF_OP_CURSORS, SF_OP_SELECTSWEEPS, SF_OP_AREA, SF_OP_SETSCALE, SF_OP_BUTTERWORTH, \
SF_OP_SELECTCHANNELS, SF_OP_DATA, SF_OP_LABNOTEBOOK, SF_OP_WAVE, SF_OP_FINDLEVEL, SF_OP_EPOCHS, SF_OP_TP, \
SF_OP_STORE, SF_OP_SELECT, SF_OP_POWERSPECTRUM, SF_OP_TPSS, SF_OP_TPBASE, SF_OP_TPINST, SF_OP_TPFIT, \
SF_OP_PSX, SF_OP_PSX_KERNEL, SF_OP_PSX_STATS, SF_OP_PSX_RISETIME, SF_OP_PSX_PREP, SF_OP_PSX_DECONV_FILTER, \
SF_OP_PSX, SF_OP_PSX_KERNEL, SF_OP_PSX_STATS, SF_OP_PSX_RISETIME, SF_OP_PSX_PREP, SF_OP_PSX_DECONV_BP_FILTER, \
SF_OP_PSX_SWEEP_BP_FILTER, \
SF_OP_MERGE, SF_OP_FIT, SF_OP_FITLINE, SF_OP_DATASET, SF_OP_SELECTVIS, SF_OP_SELECTCM, SF_OP_SELECTSTIMSET, \
SF_OP_SELECTIVSCCSWEEPQC, SF_OP_SELECTIVSCCSETQC, SF_OP_SELECTRANGE, SF_OP_SELECTEXP, SF_OP_SELECTDEV, \
SF_OP_SELECTEXPANDSCI, SF_OP_SELECTEXPANDRAC, SF_OP_SELECTSETCYCLECOUNT, SF_OP_SELECTSETSWEEPCOUNT, \
Expand Down Expand Up @@ -1164,8 +1161,11 @@ static Function/WAVE SF_FormulaExecutor(string graph, variable jsonID, [string j
case SF_OP_PSX_PREP:
WAVE out = PSX_OperationPrep(jsonId, jsonPath, graph)
break
case SF_OP_PSX_DECONV_FILTER:
WAVE out = PSX_OperationDeconvFilter(jsonId, jsonPath, graph)
case SF_OP_PSX_DECONV_BP_FILTER:
WAVE out = PSX_OperationDeconvBPFilter(jsonId, jsonPath, graph)
break
case SF_OP_PSX_SWEEP_BP_FILTER:
WAVE out = PSX_OperationSweepBPFilter(jsonId, jsonPath, graph)
break
case SF_OP_MERGE:
WAVE out = SF_OperationMerge(jsonId, jsonPath, graph)
Expand Down Expand Up @@ -2857,7 +2857,7 @@ static Function/S SF_PreprocessInput(string formula)
return formula
End

static Function SF_SetStatusDisplay(string bsPanel, string errMsg, variable errState)
Function SF_SetStatusDisplay(string bsPanel, string errMsg, variable errState)

ASSERT(errState == SF_MSG_ERROR || errState == SF_MSG_OK || errState == SF_MSG_WARN, "Unknown error state for SF status")
SetValDisplay(bsPanel, "status_sweepFormula_parser", var = errState)
Expand Down Expand Up @@ -2916,16 +2916,18 @@ End
static Function SF_CheckInputCode(string code, string graph)

variable i, numGraphs, jsonIDy, jsonIDx, subFormulaCnt
string jsonPath, xFormula, yFormula, formulasRemain, subPath, yAndXFormula
string jsonPath, xFormula, yFormula, formulasRemain, subPath, yAndXFormula, codeWithoutVariables, preProcCode

NVAR jsonID = $GetSweepFormulaJSONid(SF_GetBrowserDF(graph))
JSON_Release(jsonID, ignoreErr = 1)
jsonID = JSON_New()
JSON_AddObjects(jsonID, "")

code = SF_CheckVariableAssignments(code, jsonID)
preProcCode = SF_PreprocessInput(code)

codeWithoutVariables = SF_CheckVariableAssignments(preProcCode, jsonID)

WAVE/T graphCode = SF_SplitCodeToGraphs(SF_PreprocessInput(code))
WAVE/T graphCode = SF_SplitCodeToGraphs(codeWithoutVariables)

numGraphs = DimSize(graphCode, ROWS)
for(i = 0; i < numGraphs; i += 1)
Expand Down
1 change: 1 addition & 0 deletions Packages/MIES/MIES_SweepFormula_Helpers.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Function SFH_GetArgumentAsNumeric(variable jsonId, string jsonPath, string graph
endif

if(ParamIsDefault(defValue))
ASSERT(ParamIsDefault(checkDefault), "Without defValue passing checkDefault does not make sense")
checkExist = 1
else
checkExist = 0
Expand Down
Loading
Loading