Skip to content

Commit 15e3a5e

Browse files
authored
Merge pull request #2418 from AllenInstitute/bugfix/2418-powerspectrum-average-sweepbrowser
SF_OperationPowerSpectrum: Fix average option with SweepBrowser data
2 parents 1c8fb8d + ef30c2d commit 15e3a5e

File tree

4 files changed

+61
-36
lines changed

4 files changed

+61
-36
lines changed

Packages/MIES/MIES_Constants.ipf

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,36 +2075,35 @@ StrConstant CO_AB_LOADHISTORYFROMPXP = "ABLoadHistoryFromPXP"
20752075
/// @name Constants for SweepFormula Meta data in JSON format
20762076
/// @anchor SFMetaDataConstants
20772077
///@{
2078-
StrConstant SF_META_DATATYPE = "/DataType" // string
2079-
StrConstant SF_META_SWEEPNO = "/SweepNumber" // number
2080-
StrConstant SF_META_RANGE = "/Range" // numeric wave
2081-
StrConstant SF_META_CHANNELTYPE = "/ChannelType" // number
2082-
StrConstant SF_META_CHANNELNUMBER = "/ChannelNumber" // number
2083-
StrConstant SF_META_DEVICE = "/Device" // string
2084-
StrConstant SF_META_EXPERIMENT = "/Experiment" // string
2085-
StrConstant SF_META_SWEEPMAPINDEX = "/SweepMapIndex" // number
2086-
StrConstant SF_META_ISAVERAGED = "/IsAveraged" // number
2087-
StrConstant SF_META_AVERAGED_FIRST_SWEEP = "/AveragedFirstSweep" // number
2088-
StrConstant SF_META_XVALUES = "/XValues" // numeric wave
2089-
StrConstant SF_META_XTICKLABELS = "/XTickLabels" // text wave
2090-
StrConstant SF_META_XTICKPOSITIONS = "/XTickPositions" // numeric wave
2091-
StrConstant SF_META_YTICKLABELS = "/YTickLabels" // text wave
2092-
StrConstant SF_META_YTICKPOSITIONS = "/YTickPositions" // numeric wave
2093-
StrConstant SF_META_XAXISLABEL = "/XAxisLabel" // string
2094-
StrConstant SF_META_YAXISLABEL = "/YAxisLabel" // string
2095-
StrConstant SF_META_LEGEND_LINE_PREFIX = "/LegendLinePrefix" // string
2096-
StrConstant SF_META_TAG_TEXT = "/TagText" // string
2097-
StrConstant SF_META_OPSTACK = "/OperationStack" // string
2098-
StrConstant SF_META_MOD_MARKER = "/Marker" // numeric wave (per point) or number (all points)
2099-
StrConstant SF_META_SHOW_LEGEND = "/ShowLegend" // numeric, boolean, defaults to true (1)
2100-
StrConstant SF_META_CUSTOM_LEGEND = "/CustomLegend" // string with custom legend text, honours /ShowLegend
2101-
StrConstant SF_META_ARGSETUPSTACK = "/ArgSetupStack" // string
2102-
StrConstant SF_META_TRACECOLOR = "/TraceColor" // numeric wave, applies to markers and lines
2103-
StrConstant SF_META_LINESTYLE = "/LineStyle" // number
2104-
StrConstant SF_META_TRACE_MODE = "/TraceMode" // number, one of @ref TraceDisplayTypes
2105-
StrConstant SF_META_TRACETOFRONT = "/TraceToFront" // number, boolean, defaults to false (0)
2106-
StrConstant SF_META_DONOTPLOT = "/DoNotPlot" // number, boolean, defaults to false (0)
2107-
StrConstant SF_META_WINDOW_HOOK = "/WindowHook" // string
2078+
StrConstant SF_META_DATATYPE = "/DataType" // string
2079+
StrConstant SF_META_SWEEPNO = "/SweepNumber" // number
2080+
StrConstant SF_META_RANGE = "/Range" // numeric wave
2081+
StrConstant SF_META_CHANNELTYPE = "/ChannelType" // number
2082+
StrConstant SF_META_CHANNELNUMBER = "/ChannelNumber" // number
2083+
StrConstant SF_META_DEVICE = "/Device" // string
2084+
StrConstant SF_META_EXPERIMENT = "/Experiment" // string
2085+
StrConstant SF_META_SWEEPMAPINDEX = "/SweepMapIndex" // number
2086+
StrConstant SF_META_ISAVERAGED = "/IsAveraged" // number
2087+
StrConstant SF_META_XVALUES = "/XValues" // numeric wave
2088+
StrConstant SF_META_XTICKLABELS = "/XTickLabels" // text wave
2089+
StrConstant SF_META_XTICKPOSITIONS = "/XTickPositions" // numeric wave
2090+
StrConstant SF_META_YTICKLABELS = "/YTickLabels" // text wave
2091+
StrConstant SF_META_YTICKPOSITIONS = "/YTickPositions" // numeric wave
2092+
StrConstant SF_META_XAXISLABEL = "/XAxisLabel" // string
2093+
StrConstant SF_META_YAXISLABEL = "/YAxisLabel" // string
2094+
StrConstant SF_META_LEGEND_LINE_PREFIX = "/LegendLinePrefix" // string
2095+
StrConstant SF_META_TAG_TEXT = "/TagText" // string
2096+
StrConstant SF_META_OPSTACK = "/OperationStack" // string
2097+
StrConstant SF_META_MOD_MARKER = "/Marker" // numeric wave (per point) or number (all points)
2098+
StrConstant SF_META_SHOW_LEGEND = "/ShowLegend" // numeric, boolean, defaults to true (1)
2099+
StrConstant SF_META_CUSTOM_LEGEND = "/CustomLegend" // string with custom legend text, honours /ShowLegend
2100+
StrConstant SF_META_ARGSETUPSTACK = "/ArgSetupStack" // string
2101+
StrConstant SF_META_TRACECOLOR = "/TraceColor" // numeric wave, applies to markers and lines
2102+
StrConstant SF_META_LINESTYLE = "/LineStyle" // number
2103+
StrConstant SF_META_TRACE_MODE = "/TraceMode" // number, one of @ref TraceDisplayTypes
2104+
StrConstant SF_META_TRACETOFRONT = "/TraceToFront" // number, boolean, defaults to false (0)
2105+
StrConstant SF_META_DONOTPLOT = "/DoNotPlot" // number, boolean, defaults to false (0)
2106+
StrConstant SF_META_WINDOW_HOOK = "/WindowHook" // string
21082107

21092108
/// A color group allows to have matching colors for sweep data with the same channel type/number and sweep.
21102109
/// It is applied before the matching headstage/average colors in #SF_GetTraceColor().

Packages/MIES/MIES_SweepFormula.ipf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,11 +1514,16 @@ Function [STRUCT RGBColor s] SF_GetTraceColor(string graph, string opStack, WAVE
15141514
return [s]
15151515
endif
15161516

1517+
isAveraged = JWN_GetNumberFromWaveNote(data, SF_META_ISAVERAGED)
1518+
if(isAveraged)
1519+
[s] = GetTraceColorForAverage()
1520+
return [s]
1521+
endif
1522+
15171523
channelNumber = JWN_GetNumberFromWaveNote(data, SF_META_CHANNELNUMBER)
15181524
channelType = JWN_GetNumberFromWaveNote(data, SF_META_CHANNELTYPE)
1519-
isAveraged = JWN_GetNumberFromWaveNote(data, SF_META_ISAVERAGED)
15201525
mapIndex = JWN_GetNumberFromWaveNote(data, SF_META_SWEEPMAPINDEX)
1521-
sweepNo = (isAveraged == 1) ? JWN_GetNumberFromWaveNote(data, SF_META_AVERAGED_FIRST_SWEEP) : JWN_GetNumberFromWaveNote(data, SF_META_SWEEPNO)
1526+
sweepNo = JWN_GetNumberFromWaveNote(data, SF_META_SWEEPNO)
15221527
if(!IsValidSweepNumber(sweepNo))
15231528
return [s]
15241529
endif
@@ -6976,7 +6981,6 @@ static Function/WAVE SF_AverageDataOverSweeps(WAVE/WAVE input)
69766981
if(isSweepData)
69776982
JWN_SetNumberInWaveNote(group, SF_META_CHANNELNUMBER, channelNumber)
69786983
JWN_SetNumberInWaveNote(group, SF_META_CHANNELTYPE, channelType)
6979-
JWN_SetNumberInWaveNote(group, SF_META_AVERAGED_FIRST_SWEEP, sweepNo)
69806984
endif
69816985
groupWaves[pos] = group
69826986

@@ -7000,11 +7004,11 @@ static Function/WAVE SF_AverageDataOverSweeps(WAVE/WAVE input)
70007004
for(i = 0; i < numGroups; i += 1)
70017005
WAVE wData = output[i]
70027006
JWN_SetNumberInWaveNote(wData, SF_META_ISAVERAGED, 1)
7007+
JWN_SetNumberInWaveNote(wData, SF_META_TRACE_MODE, TRACE_DISPLAY_MODE_LINES)
70037008
if(CmpStr(GetDimLabel(groupWaves, ROWS, i), SF_AVERAGING_NONSWEEPDATA_LBL))
70047009
WAVE group = groupWaves[i]
70057010
JWN_SetNumberInWaveNote(wData, SF_META_CHANNELNUMBER, JWN_GetNumberFromWaveNote(group, SF_META_CHANNELNUMBER))
70067011
JWN_SetNumberInWaveNote(wData, SF_META_CHANNELTYPE, JWN_GetNumberFromWaveNote(group, SF_META_CHANNELTYPE))
7007-
JWN_SetNumberInWaveNote(wData, SF_META_AVERAGED_FIRST_SWEEP, JWN_GetNumberFromWaveNote(group, SF_META_AVERAGED_FIRST_SWEEP))
70087012
endif
70097013
endfor
70107014

Packages/tests/Basic/UTF_SweepFormula.ipf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,8 +1081,6 @@ static Function/WAVE TestAverageOverSweeps_CheckMeta(WAVE data, variable channel
10811081
CHECK_EQUAL_VAR(channelNumber, val)
10821082
val = JWN_GetNumberFromWaveNote(data, SF_META_CHANNELTYPE)
10831083
CHECK_EQUAL_VAR(channelType, val)
1084-
val = JWN_GetNumberFromWaveNote(data, SF_META_AVERAGED_FIRST_SWEEP)
1085-
CHECK_EQUAL_VAR(firstSweep, val)
10861084
val = JWN_GetNumberFromWaveNote(data, SF_META_ISAVERAGED)
10871085
CHECK_EQUAL_VAR(1, val)
10881086

Packages/tests/HistoricData/UTF_HistoricSweepBrowser.ipf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,27 @@ static Function TestTTLDisplayWithNoEpochInfo([string str])
2323

2424
CHECK_NO_RTE()
2525
End
26+
27+
Function TestSweepFormulaPowerSpectrumAverage()
28+
29+
string abWin, sweepBrowsers, file, sweepBrowser, bsPanel, scPanel, code
30+
31+
WAVE/T files = GetHistoricDataFiles()
32+
file = "input:" + files[0]
33+
34+
[abWin, sweepBrowsers] = OpenAnalysisBrowser({file}, loadSweeps = 1)
35+
sweepBrowser = StringFromList(0, sweepBrowsers)
36+
37+
bsPanel = BSP_GetPanel(sweepBrowser)
38+
CHECK(WindowExists(bsPanel))
39+
40+
scPanel = BSP_GetSweepControlsPanel(sweepBrowser)
41+
CHECK(WindowExists(scPanel))
42+
43+
code = "trange = [0, inf]\r" + \
44+
"sel = select(selrange($trange),selchannels(AD), selsweeps())\r" + \
45+
"dat = data($sel)\r" + \
46+
"powerspectrum($dat, default, avg)"
47+
48+
ExecuteSweepFormulaCode(sweepBrowser, code)
49+
End

0 commit comments

Comments
 (0)