Skip to content

Commit

Permalink
Merge pull request #2070 from AllenInstitute/bugfix/2070-fix_sort_epo…
Browse files Browse the repository at this point in the history
…chs-backport

EP: fix epoch sorting to be numerically correct
  • Loading branch information
t-b authored Mar 17, 2024
2 parents 1d38644 + 5cc0207 commit d57ec82
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Packages/MIES/MIES_Constants.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Constant ANALYSISBROWSER_PANEL_VERSION = 3
Constant STIMSET_NOTE_VERSION = 9

/// Version of the epoch information for DA+TTL data
Constant SWEEP_EPOCH_VERSION = 8
Constant SWEEP_EPOCH_VERSION = 9

/// Version of the labnotebooks and results (numerical and textual) waves
///
Expand Down
14 changes: 9 additions & 5 deletions Packages/MIES/MIES_Epochs.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -619,11 +619,13 @@ static Function EP_SortEpochs(string device)
endif

Duplicate/FREE/T/RMD=[, epochCnt - 1][][channel][channelType] epochWave, epochChannel
Redimension/N=(-1, -1, 0, 0) epochChannel
Redimension/N=(-1, -1) epochChannel

epochChannel[][%EndTime] = num2strHighPrec(-1 * str2num(epochChannel[p][%EndTime]), precision = EPOCHTIME_PRECISION)
SortColumns/DIML/KNDX={EPOCH_COL_STARTTIME, EPOCH_COL_ENDTIME, EPOCH_COL_TREELEVEL} sortWaves={epochChannel}
epochChannel[][%EndTime] = num2strHighPrec(-1 * str2num(epochChannel[p][%EndTime]), precision = EPOCHTIME_PRECISION)
Make/FREE/D/N=(DimSize(epochChannel, ROWS), DimSize(epochChannel, COLS)) epochSortColStartTime, epochSortColEndTime, epochSortColTreeLevel
epochSortColStartTime[] = str2numSafe(epochChannel[p][EPOCH_COL_STARTTIME])
epochSortColEndTime[] = -1 * str2numSafe(epochChannel[p][EPOCH_COL_ENDTIME])
epochSortColTreeLevel[] = str2numSafe(epochChannel[p][EPOCH_COL_TREELEVEL])
SortColumns/DIML keyWaves={epochSortColStartTime, epochSortColEndTime, epochSortColTreeLevel} sortWaves={epochChannel}

// remove epochs marked for removal
// first column needs to be StartTime
Expand All @@ -636,7 +638,9 @@ static Function EP_SortEpochs(string device)
epochWave[, epochCnt - 1][][channel][channelType] = epochChannel[p][q]
endif

epochWave[epochCnt, *][][channel][channelType] = ""
if(epochCnt < DimSize(epochWave, ROWS))
epochWave[epochCnt, *][][channel][channelType] = ""
endif
endfor
endfor
End
Expand Down
35 changes: 33 additions & 2 deletions Packages/tests/Basic/UTF_EpochswoHardware.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
#pragma rtFunctionErrors=1
#pragma ModuleName=EpochsTestwoHardware

static StrConstant EP_DUMMY_DEVICE = "dummy"

static Function [WAVE numericalValues, WAVE/T textualValues, WAVE/T epochsWave] PrepareEpochsTable_IGNORE()
variable DAC

string key, keyText
string device = "dummy"
string device = EP_DUMMY_DEVICE

WAVE/T/Z epochsWave = GetEpochsWave(DEVICE)
WAVE/T/Z epochsWave = GetEpochsWave(device)
CHECK_WAVE(epochsWave, TEXT_WAVE)

DAC = 2 // HS 0
Expand Down Expand Up @@ -258,3 +260,32 @@ static Function EP_CheckADCToDACMApping()
CHECK_EQUAL_STR(str, expected)
CHECK_EQUAL_VAR(str2num(result[0][%TreeLevel]), 1)
End

static Function EP_TestSortEpochs()

string refHash, orderHash, orderStr
variable numEpochs = 1000

[WAVE numericalValues, WAVE/T textualValues, WAVE/T epochsWave] = PrepareEpochsTable_IGNORE()

Redimension/N=(numEpochs, -1, -1, -1) epochsWave
epochsWave[][EPOCH_COL_STARTTIME][][] = num2strHighPrec(-trunc(p / 3), precision = EPOCHTIME_PRECISION)
epochsWave[][EPOCH_COL_ENDTIME][][] = num2strHighPrec(trunc(p / 2), precision = EPOCHTIME_PRECISION)
epochsWave[][EPOCH_COL_TAGS][][] = num2istr(p)
epochsWave[][EPOCH_COL_TREELEVEL][][] = num2strHighPrec(p, precision = EPOCHTIME_PRECISION)
Make/FREE/D/N=(numEpochs) mixRandom = enoise(1, NOISE_GEN_XOSHIRO)

SortColumns/DIML keyWaves={mixRandom} sortWaves={epochsWave}
Make/FREE/D/N=(numEpochs) order = str2num(epochsWave[p][EPOCH_COL_TAGS][0][0])
wfprintf orderStr, "%d\r", order

MIES_EP#EP_SortEpochs(EP_DUMMY_DEVICE)

WAVE/T epochWave = GetEpochsWave(EP_DUMMY_DEVICE)

Make/FREE/D/N=(numEpochs) order = str2num(epochWave[p][EPOCH_COL_TAGS][0][0])
refHash = "e234059bf5dcf332577b1459e4f30e28a01103eeb598499322840378d86d69e5"
orderHash = WaveHash(order, HASH_SHA2_256)
INFO("mixed order = %s", s0 = orderStr)
CHECK_EQUAL_STR(refHash, orderHash)
End
15 changes: 10 additions & 5 deletions Packages/tests/HardwareBasic/UTF_Epochs.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -996,11 +996,16 @@ static Function EP_EpochTestTTL_REENTRY([STRUCT IUTF_mData &mData])
Duplicate/FREE/T epochTags, epochShortNames
epochShortNames[] = EP_GetShortName(epochTags[p])

Make/FREE/T nameRef = {"E0_PT_P0_P", "E0_PT_P0", "ST", "E0", "E0_PT_P0_B", "E0_PT_P1_P", "E0_PT_P1", \
"E0_PT_P1_B", "E0_PT_P2_P", "E0_PT_P2", "E0_PT_P2_B", "E0_PT_P3_P", "E0_PT_P3", "E0_PT_P3_B", \
"E0_PT_P4_P", "E0_PT_P4", "E0_PT_P4_B", "E0_PT_P5_P", "E0_PT_P5", "E0_PT_P5_B", "E0_PT_P6_P", \
"E0_PT_P6", "E0_PT_P6_B", "E0_PT_P7_P", "E0_PT_P7", "E0_PT_P7_B", "E0_PT_P8_P", "E0_PT_P8", \
"E0_PT_P8_B", "E0_PT_P9", "E0_PT_P9_P"}
Make/FREE/T nameRef = {"ST", "E0", "E0_PT_P0", "E0_PT_P0_P", "E0_PT_P0_B", \
"E0_PT_P1", "E0_PT_P1_P", "E0_PT_P1_B", \
"E0_PT_P2", "E0_PT_P2_P", "E0_PT_P2_B", \
"E0_PT_P3", "E0_PT_P3_P", "E0_PT_P3_B", \
"E0_PT_P4", "E0_PT_P4_P", "E0_PT_P4_B", \
"E0_PT_P5", "E0_PT_P5_P", "E0_PT_P5_B", \
"E0_PT_P6", "E0_PT_P6_P", "E0_PT_P6_B", \
"E0_PT_P7", "E0_PT_P7_P", "E0_PT_P7_B", \
"E0_PT_P8", "E0_PT_P8_P", "E0_PT_P8_B", \
"E0_PT_P9", "E0_PT_P9_P" }
if(mData.v2)
InsertPoints/M=(ROWS) 0, 1, nameRef
nameref[0] = "B0_OD"
Expand Down
2 changes: 1 addition & 1 deletion Packages/tests/HardwareBasic/UTF_SweepFormulaHardware.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -810,5 +810,5 @@ static Function SF_UnassociatedDATTL_Epochs_REENTRY([string str])
CHECK_EQUAL_VAR(DimSize(data, ROWS), 29)
WAVE/T epochDataT = data[0]
CHECK_WAVE(epochDataT, TEXT_WAVE)
CHECK_EQUAL_STR(epochDataT[0], "E0_PT_P0_P")
CHECK_EQUAL_STR(epochDataT[0], "E0_PT_P0")
End

0 comments on commit d57ec82

Please sign in to comment.