Skip to content

Commit 7d1672f

Browse files
committed
changes
1 parent 9a5c3ef commit 7d1672f

2 files changed

Lines changed: 92 additions & 8 deletions

File tree

Packages/MIES/MIES_SweepFormula_PSX.ipf

Lines changed: 91 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4955,7 +4955,86 @@ End
49554955
// psx(id, [psxKernel(...), numSDs, psxSweepBPFilter(...), maxTauFactor, psxRiseTime(...), psxDeconvBPFilter(...)])
49564956
Function/WAVE PSX_Operation(variable jsonId, string jsonPath, string graph)
49574957

4958-
variable numberOfSDs, parameterJsonID, numCombos, i, readIndex, writeIndex, addedData, kernelAmp
4958+
variable kernelIterations = NaN
4959+
variable numCombos, medianAmp, medianDecayTau, avgRiseTau
4960+
4961+
for(;;)
4962+
if(IsFinite(kernelIterations))
4963+
kernelIterations -= 1
4964+
endif
4965+
4966+
[WAVE output, numCombos, kernelIterations] = PSX_OperationIterationImpl(jsonId, jsonPath, graph)
4967+
4968+
if(kernelIterations == 0)
4969+
return SFH_GetOutputForExecutor(output, graph, SF_OP_PSX)
4970+
endif
4971+
4972+
medianDecayTau = PSX_CalculateMedianFromEvents(output, numCombos, "weightedTau")
4973+
medianAmp = PSX_CalculateMedianFromEvents(output, numCombos, "amplitude")
4974+
avgRiseTau = PSX_CalculateAverageRiseTau(output, numCombos)
4975+
endfor
4976+
End
4977+
4978+
static Function PSX_CalculateAverageRiseTau(WAVE/WAVE output, variable numCombos)
4979+
4980+
variable i
4981+
string key
4982+
4983+
WAVE/ZZ result
4984+
4985+
for(i = 0; i < numCombos; i += 1)
4986+
key = PSX_GenerateKey("psxEvent", i)
4987+
WAVE psxEvent = output[%$key]
4988+
4989+
Make/FREE/N=(DimSize(psxEvent, ROWS))/D data
4990+
data = psxEvent[p][%$"Rise Time"]
4991+
4992+
WAVE/Z dataClean = ZapNaNs(data)
4993+
WaveClear data
4994+
4995+
if(WaveExists(dataClean))
4996+
Concatenate/FREE {dataClean}, result
4997+
endif
4998+
endfor
4999+
5000+
ASSERT(WaveExists(result), "Could not gather rise time data")
5001+
return mean(result)
5002+
End
5003+
5004+
static Function PSX_CalculateMedianFromEvents(WAVE/WAVE output, variable numCombos, string lbl)
5005+
5006+
variable i
5007+
string key
5008+
5009+
WAVE/ZZ result
5010+
5011+
for(i = 0; i < numCombos; i += 1)
5012+
key = PSX_GenerateKey("psxEvent", i)
5013+
WAVE psxEvent = output[%$key]
5014+
5015+
Make/FREE/N=(DimSize(psxEvent, ROWS))/D data
5016+
data = (psxEvent[p][%$"Fit Result"] == 1) ? psxEvent[p][%$lbl] : NaN
5017+
5018+
WAVE/Z dataClean = ZapNaNs(data)
5019+
WaveClear data
5020+
5021+
if(WaveExists(dataClean))
5022+
Concatenate/FREE {dataClean}, result
5023+
endif
5024+
endfor
5025+
5026+
ASSERT(WaveExists(result), "Could not gather data for " + lbl)
5027+
5028+
StatsQuantiles/Q/Z result
5029+
ASSERT(!V_flag, "Could not calculate median values for " + lbl)
5030+
MakeWaveFree($"W_StatsQuantiles")
5031+
5032+
return V_Median
5033+
End
5034+
5035+
Function [WAVE output, variable numCombos, variable kernelIterations] PSX_OperationIterationImpl(variable jsonId, string jsonPath, string graph)
5036+
5037+
variable numberOfSDs, parameterJsonID, i, readIndex, writeIndex, addedData, kernelAmp
49595038
variable maxTauFactor, peakThresh, success, kernelRiseTau, kernelDecayTau, constFilterOrderSweep, constFilterOrderDeconv
49605039
variable minFilterOrderSweep, minFilterOrderDeconv
49615040
string parameterPath, id, psxParameters, dataUnit, path, msg
@@ -5062,6 +5141,8 @@ Function/WAVE PSX_Operation(variable jsonId, string jsonPath, string graph)
50625141
ASSERT(IsFinite(kernelRiseTau), "riseTau must be finite")
50635142
kernelDecayTau = JWN_GetNumberFromWaveNote(psxKernelDataset, path + "/decayTau")
50645143
ASSERT(IsFinite(kernelDecayTau), "decayTau must be finite")
5144+
kernelIterations = JWN_GetNumberFromWaveNote(psxKernelDataset, path + "/iterations")
5145+
ASSERT(IsInteger(kernelIterations), "decayTau must be an integer")
50655146

50665147
for(i = 0; i < numCombos; i += 1)
50675148
PSX_OperationImpl(graph, parameterJsonID, id, peakThresh, maxTauFactor, riseTime, kernelAmp, kernelRiseTau, kernelDecayTau, i, output)
@@ -5084,7 +5165,7 @@ Function/WAVE PSX_Operation(variable jsonId, string jsonPath, string graph)
50845165

50855166
SFH_CleanUpInput(psxKernelDataset)
50865167

5087-
return SFH_GetOutputForExecutor(output, graph, SF_OP_PSX)
5168+
return [output, numCombos, kernelIterations]
50885169
End
50895170

50905171
Function [variable constFilterOrder, variable minFilterOrder] PSX_HasConstantFilterOrder(WAVE/WAVE output, variable numCombos, variable type)
@@ -5132,20 +5213,21 @@ End
51325213
// Output[3] = psx_kernel(1)
51335214
// ...
51345215
//
5135-
// psxKernel([select(...), riseTau, decayTau, amp])
5216+
// psxKernel([select(...), riseTau, decayTau, amp, iterations])
51365217
Function/WAVE PSX_OperationKernel(variable jsonId, string jsonPath, string graph)
51375218

5138-
variable riseTau, decayTau, amp, dt, numPoints, numCombos, i, offset, idx
5219+
variable riseTau, decayTau, amp, dt, numPoints, numCombos, i, offset, idx, iterations
51395220
string parameterPath, key
51405221

5141-
SFH_CheckArgumentCount(jsonId, jsonPath, SF_OP_PSX_KERNEL, 0, maxArgs = 4)
5222+
SFH_CheckArgumentCount(jsonId, jsonPath, SF_OP_PSX_KERNEL, 0, maxArgs = 5)
51425223

51435224
WAVE/Z/WAVE selectDataCompArray = SFH_GetArgumentSelect(jsonID, jsonPath, graph, SF_OP_PSX_KERNEL, 0)
51445225
SFH_ASSERT(WaveExists(selectDataCompArray), "Could not gather sweep data from select statement")
51455226

5146-
riseTau = SFH_GetArgumentAsNumeric(jsonID, jsonPath, graph, SF_OP_PSX_KERNEL, 1, defValue = 1, checkFunc = IsStrictlyPositiveAndFinite)
5147-
decayTau = SFH_GetArgumentAsNumeric(jsonID, jsonPath, graph, SF_OP_PSX_KERNEL, 2, defValue = 15, checkFunc = IsStrictlyPositiveAndFinite)
5148-
amp = SFH_GetArgumentAsNumeric(jsonID, jsonPath, graph, SF_OP_PSX_KERNEL, 3, defValue = -5, checkFunc = IsFinite)
5227+
riseTau = SFH_GetArgumentAsNumeric(jsonID, jsonPath, graph, SF_OP_PSX_KERNEL, 1, defValue = 1, checkFunc = IsStrictlyPositiveAndFinite)
5228+
decayTau = SFH_GetArgumentAsNumeric(jsonID, jsonPath, graph, SF_OP_PSX_KERNEL, 2, defValue = 15, checkFunc = IsStrictlyPositiveAndFinite)
5229+
amp = SFH_GetArgumentAsNumeric(jsonID, jsonPath, graph, SF_OP_PSX_KERNEL, 3, defValue = -5, checkFunc = IsFinite)
5230+
iterations = SFH_GetArgumentAsNumeric(jsonID, jsonPath, graph, SF_OP_PSX_KERNEL, 4, defValue = 0, checkFunc = IsInteger)
51495231

51505232
SFH_ASSERT(decayTau > riseTau, "decay tau must be strictly larger than the rise tau")
51515233

@@ -5218,6 +5300,7 @@ Function/WAVE PSX_OperationKernel(variable jsonId, string jsonPath, string graph
52185300
JWN_SetNumberInWaveNote(output, parameterPath + "/riseTau", riseTau)
52195301
JWN_SetNumberInWaveNote(output, parameterPath + "/decayTau", decayTau)
52205302
JWN_SetNumberInWaveNote(output, parameterPath + "/amp", amp)
5303+
JWN_SetNumberInWaveNote(output, parameterPath + "/iterations", iterations)
52215304

52225305
JWN_SetStringInWaveNote(output, SF_META_OPSTACK, AddListItem(SF_OP_PSX_KERNEL, ""))
52235306

Packages/tests/Basic/UTF_SweepFormula.ipf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,3 +2185,4 @@ static Function TestAxisLabelGathering()
21852185

21862186
KillWaves/Z data1, data2, data3
21872187
End
2188+

0 commit comments

Comments
 (0)