File MIES_PulseAveraging.ipf

PA Routines for dealing with pulse averaging.

  • Averaging is done for all pulses in a set

  • Zeroing is done for all pulses

  • Deconvolution is done for the average wave only

  • See also PA_AutomaticTimeAlignment

Drawing layers:

  • ProgAxes: X=0 line for images

  • ProgFront: Scale bars

  • ProgBack: Failed pulses triangles

Unnamed Group

static const string PA_DRAWLAYER_XZEROLINE = "ProgAxes"
static const string PA_DRAWLAYER_SCALEBAR = "ProgFront"
static const string PA_DRAWLAYER_FAILED_PULSES = "ProgBack"

Pulse sort order

Popupmenu indizes for the PA plot controls

static const double PA_PULSE_SORTING_ORDER_SWEEP = 0x0
static const double PA_PULSE_SORTING_ORDER_PULSE = 0x1




static string PA_GetGraphs(string win, variable displayMode)

Return a list of all graphs.

static string PA_GetGraphName(string win, PulseAverageSettings *pa, variable displayMode, variable channelNumber, variable activeRegionCount)
static string PA_GetGraphPrefix(string win, variable displayMode)
string PA_GetColorScalePanel(string win)

Return the subwindow path to the panel which holds the graphs with the color scales.

Only present for PA_DISPLAYMODE_IMAGES graphs.

string PA_GetColorScaleGraph(string win)

Return the subwindow path to the graph which holds the color scales.

Only present for PA_DISPLAYMODE_IMAGES graphs.

static string PA_GetGraph(string mainWin, PulseAverageSettings *pa, variable displayMode, variable channelNumber, variable region, variable activeRegionCount, variable activeChanCount, variable numRegions)

Return the name of the pulse average graph.

This function takes care of creating a graph if it does not exist, and laying it out correctly

Layout scheme for multiple graphs turned on:

  • Positions the graphs right to mainWin in matrix form

  • Columns: Regions (aka headstages with pulse starting time information respecting region selection in GUI)

  • Rows: Active unique channels

static wave PA_GetAxes(PulseAverageSettings *pa, variable channel, variable region)

Return the names of the vertical and horizontal axes.

static wave PA_CalculatePulseInfos(wave DA, string fullPath, variable channelNumber, variable totalOnsetDelay)

Derive the pulse infos from a DA wave.

Uses plain FindLevels after the onset delay using 10% of the full range above the minimum as threshold


pulse info wave or if nothing could be found, an invalid wave reference

static wave PA_GetUniqueHeadstages(WaveText traceData)

Return a wave with headstage numbers, duplicates replaced with NaN so that the indizes still correspond the ones in traceData.

wave PA_GetPulseInfos(WaveText traceData, variable idx, variable region, string channelTypeStr)

Return pulse infos.

  • traceData – 2D wave with trace information, from GetTraceInfos()

  • idx – Index into traceData, used for determining sweep numbers, labnotebooks, etc.

  • region – Region (headstage) to get pulse starting times for

  • channelTypeStr – Type of the channel, one of XOP_CHANNEL_NAMES


invalid wave reference if no pulses could be found or 2D wave see GetPulseInfoWave()

static variable PA_DiffPulseInfos(wave numericalValues, variable sweepNo, WaveOrNull pulseInfosEpochs, WaveOrNull pulseInfosCalc)

Compare epoch and calculated pulse infos.

static wave PA_RetrievePulseInfosFromEpochs(string epochInfo)

Extracts the pulse info from the lab notebook and returns them as wave.


epochInfo[in] epoch data to extract pulse starting times


pulse info, see GetPulseInfoWave() or an invalid wave reference on error

static variable PA_GetPulseLength(wave pulseInfos, variable pulseIndex, variable overridePulseLength, variable fixedPulseLength)
static std::tuple<WAVE, WAVE> PA_CreateAndFillPulseWaveIfReq(WaveOrNull wv, dfref singleSweepFolder, variable channelType, variable channelNumber, variable clampMode, variable region, variable pulseIndex, variable first, variable length, wave pulseInfos)

Single pulse wave creator.

The wave note for the pulse waves is stored in a separate empty wave. This speeds up the caching logic for the pulse waves a lot.

The wave note is used for documenting the applied operations:

  • $NOTE_KEY_FAILED_PULSE_LEVEL: Level used for failed pulse search

  • $NOTE_KEY_NUMBER_OF_SPIKES: Number of spikes used for failed pulse search

  • $NOTE_KEY_PULSE_LENGTH: Length in points of the pulse wave (before any operations)

  • $NOTE_KEY_SEARCH_FAILED_PULSE: Checkbox state of “Search failed pulses”

  • $NOTE_KEY_TIMEALIGN: Time alignment was active and applied

  • $NOTE_KEY_TIMEALIGN_TOTAL_OFFSET: Calculated offset from time alignment

  • $NOTE_KEY_ZEROED: Zeroing was active and applied

  • $NOTE_KEY_WAVE_MINIMUM: Minimum value of the data

  • $NOTE_KEY_WAVE_MAXIMUM: Maximum value of the data

  • $NOTE_KEY_TIMEALIGN_FEATURE_POS: Position where the feature for time alignment was found

  • $NOTE_KEY_PULSE_IS_DIAGONAL: Stores if pulse is shown in the diagonal of the output layout

  • $PA_SOURCE_WAVE_TIMESTAMP: Last modification time of the pulse wave before creation.

  • $NOTE_KEY_PULSE_START: ms coordinates where the pulse starts

  • $NOTE_KEY_PULSE_END: ms coordinates where the pulse ends

  • $NOTE_KEY_PULSE_CLAMPMODE: Clamp mode of the pulse data, one of AmplifierClampModes

Diagonal pulses only with failed pulse search enabled:

  • $NOTE_KEY_PULSE_HAS_FAILED: Pulse has failed

  • $NOTE_KEY_PULSE_SPIKE_POSITIONS: Comma separated list of spike positions in ms. 0 is the start of the pulse.

static variable PA_UpdateMinAndMax(wave wv, wave noteWave)
static string PA_GenerateFailedPulseKey(variable sweep, variable region, variable pulse)

Generate a key for a pulse.

All pulses with that key are either failing or passing.

static std::tuple<WaveDouble, WaveText> PA_GetSweepsAndExperimentsFromIndices(string win, WaveOrNull additionalData)
static std::tuple<PulseAverageSetIndices> PA_GenerateAllPulseWaves(string win, PulseAverageSettings *pa, variable mode, WaveOrNull additionalData)

Create all single pulse waves.

This function needs to be called when ever traces in the databrowser/sweepbrowser are removed or added.


  • Gather all AD sweep traces in the databrowser/sweepbrowser (skipping duplicates from oodDAQ)

  • Iterate over all regions (there are as many regions as unique headstages)

  • Now gather the pulse starting time from the region and create single pulse waves for all of them

The result is feed into GetPulseAverageProperties() and GetPulseAveragepropertiesWaves() for further consumption.

Fast path for incremental update:

  • The previous list of regions/channels is saved

  • We get the indizes of the new sweep (from additionalData)

  • Only these indizes are added to the properties wave, as well as the setIndice waves at the end

  • information is stored where the new data begins

  • The region/channels of the new Sweep(s) are merged with the old ones.

  • In case the layout changed compared to the old regions/channels it is calculated again.

static variable PA_SetDiagonalityNote(wave indices, variable startIndex, variable numEntries, WaveRefWave propertiesWaves, variable isDiagonal)
static std::tuple<PulseAverageSetIndices> PA_InitPASIInParts(PulseAverageSettings *pa, variable part, variable disableIncremental)

This function fills a structure with information we need in most further processing functions, e.g. PA DFs, references to properties, setIndice waves, regions, channels, axes, a.s.o. Since not every information might be available at the time this structure is filled there are two steps defined, that are enabled by setting ‘part’ with PA_PASIINIT_BASE and/or PA_PASIINIT_INDICEMETA.

  • paPulseAverageSettings structure

  • part – filling step for the returned structure, set depending on available data

  • disableIncremental – When set then the meta information for incremental updates is just initialized with zero.

static variable PA_CopySetIndiceSizeDispRestart(WaveRefWave setIndices)

For incremental display update copy current size of of setIndices to new display start.

static std::tuple<WaveRefWave, WAVE, WAVE, WAVE> PA_GetSetIndicesHelper(dfref pulseAverageHelperDFR, variable prevIndices)

Retrieve setIndices, channels and regions of the current or the previous layout, as is saved in the properties wave wave note.

  • pulseAverageHelperDFR[in] Reference to pulse average helper DF

  • prevIndices[in] When set then the indices, channels and regions of the previous layout are returned, otherwise the current layout is returned. Note that only the layout is considered, the returned indices always contain the current indices for each channel/region at the time of calling this function.

static variable PA_UpdateIndiceNotes(wave currentDisplayMapping, wave prevDisplayMapping, PulseAverageSetIndices *pasi, variable layoutChanged)

Updates the setIndices notes with information about the layout and layout changes. Therefore the function compares the previous display mapping and the current display mapping for each region/channel in the layout and determines if the setIndices at this region/channel are added as new/moved/stayed at the same position or were removed. In the setIndices wave note the following keys are set: ‘$PA_SETINDICES_KEY_DISPCHANGE’: change in the layout for this set ‘$PA_SETINDICES_KEY_ACTIVEREGIONCOUNT’: grid location on the vertical where this set is displayed ‘$PA_SETINDICES_KEY_ACTIVECHANCOUNT’: grid location on the horizontal where this set is displayed (this data is currently not used, but created for further PA plot extension)

  • currentDisplayMapping[in] 3D wave, rows and columns map the region/channels, in the two layers the associated activeRegion and activeChannel are stored. The layer information is the position in the grid of the layout.

  • prevDisplayMapping[in] Technically the same wave as currentDisplayMapping, but it stores the information about the previous layout.

  • pasi[in] Pulse Average structure storing PA information

  • layoutChanged[in] when set then the layout has changed compared to the previous one displayed. This is directly related to a region/channel change.

static variable PA_UpdateIndiceNotesImpl(wave indices, wave currentMap, wave oldMap, variable channel, variable region, variable layoutChanged, variable indiceType)

Evaluate the previous and current mapping and set the display change in the wave note of the indice sets as well as activeChanCount, activeRegionCount. IMPORTANT: To have a consistent state for the case the layout changed the function must be called with the current and the previous indices. Otherwise removed sets wont be flagged properly.

static variable PA_ApplyPulseSortingOrder(wave setIndices, variable channelNumber, variable region, wave properties, PulseAverageSettings *pa)
static variable PA_GatherSettings(string win, PulseAverageSettings *s)

Populates pps.pulseAverSett with the user selection from the panel.

static variable PA_DeconvGatherSettings(string win, PulseAverageDeconvSettings *deconvolution)

gather deconvolution settings from PA section in BSP

variable PA_Update(string win, variable mode, WaveOrNull additionalData = defaultValue)

Update the PA plot to accomodate changed settings.

static wave PA_GetSetWaves(dfref dfr, variable channelNumber, variable region, variable removeFailedPulses = defaultValue)

Returns the two column setWave with pulse/pulsenote.

static wave PA_GetSetWaves_TS(wave properties, WaveRefWave propertiesWaves, wave setIndizes, variable getMode, variable removeFailedPulses)

Returns a 1D wave ref wave containing the refs to the setwave2 refs of {all, new, old} sets, depending on the mode constant given in getModes. For mode constants.

See also

PAGetSetWavesModes, they can be combined by ORing the bits. Each setWave2 component wave entry in the returned wave is a 2D wave ref wave that refrences the pulse data in col 0, and the pulse note in col 1. The rows count the pulses.

static variable PA_MarkFailedPulses(PulseAverageSettings *pa, PulseAverageSetIndices *pasi)

Handle marking pulses as failed/passed if required.

static variable PA_TagSearchedPulses(PulseAverageSettings *pa, wave wv)
static variable PA_GetTraceCountFromGraphData(string graph, variable clear = defaultValue)

This function returns data from the light-weight data storage for PA graph data.

  • graph[in] name of PA graph

  • clear[in] [optional, default = 0] when set reinitializes the data for the given graph


row index of the wave where the graph data is stored

static string PA_ShowPulses(string win, PulseAverageSettings *pa, PA_ConstantSettings *cs, PulseAverageSetIndices *pasi, variable mode)
static variable PA_ClearGraphs(string graphs)

Remove all traces, image and annotations from the graph and clears its trace user data.

static std::tuple<PA_ConstantSettings> PA_DetermineConstantSettings(PulseAverageSettings *pa, PulseAverageSettings *paOld, variable mode)

Returns a filled structure PA_ConstantSettings which has 1 for all constant entries of the given category.

static std::tuple<PulseAverageSetIndices, variable> PA_PreProcessPulses(string win, PulseAverageSettings *pa, PA_ConstantSettings *cs, variable mode, WaveOrNull additionalData)

Gather and pre-process the single pulses for display.

This function is display-type agnostic and only does preparational steps. No graphs are created or killed.

The work with pulses is done in the following order:

  • Gather pulses

  • Sort pulses (in setIndizes)

  • Reset pulses to backup

  • Failed pulse marking

  • Zeroing

  • Time alignment

  • Averaging

Return values:
  • pasi – structure keeping references to current PA data set

  • needsPlotting – dest boolean denoting if there are pulses to plot

static variable PA_CalculateAllAverages(PulseAverageSettings *pa, PulseAverageSetIndices *pasi, variable mode)
static variable PA_TAAdaptAverageWave(WaveOrNull avg, WaveRefWave set)
static variable PA_MakeAverageWavePermanent(dfref dfr, WaveOrNull avg, variable channel, variable region)
static wave PA_ExtractPulseSetFromSetWaves2(WaveRefWaveOrNull setWave2)
static variable PA_StoreMaxAndUnitsInWaveNote(WaveOrNull w, WaveOrNull unitSource)

Stores the WaveMaximum in the wave note of the given wave and sets the wave unit to the same as from unitSource.

  • w[in] Wave where the maximum is determined and written to the wave note, the wave unit determiend from unitSource is also set for w

  • unitSource[in] a source wave for wave unit information for w

static wave PA_ExtractSumsCountsOnly(WaveRefWave w)
variable PA_UpdateScaleBars(string win, variable resetToUserLength)

Update the scale bars of the passed plot.

This functions is non-statc as it is called from the operation queue. This is necessary as the window hooks listen to the mouse wheel event, and we want to update only after the mouse wheel triggered the axis range change. And that is only possible with the operation queue.

  • win – PA trace or image plot

  • resetToUserLength – Reset the scale bars to the user upplied values

static variable PA_DrawScaleBars(string win, PulseAverageSettings *pa, PulseAverageSetIndices *pasi, variable displayMode, variable axisMode, variable resetToUserLength = defaultValue)
static std::tuple<variable, variable, variable, variable> PA_GetMinAndMax(WaveRefWave setWaves2)
static std::tuple<variable, variable> PA_NeedsForcedScaleBar(string win, string userDataName, variable physicalLength, variable axisMinimum, variable axisMaximum, variable userLength = defaultValue, string userLengthName = defaultValue, variable resetToUserLength = defaultValue)

Determine if we need a scale bar label.

Without any optional parameters we always need a label if we have a stored entry userDataName and that differs from physicalLength.

With the optional parameters we prioritize userLength if it has changed compared to the stored value userLengthName or if it needs resetting on a new plot. Otherwise we use the same approach as above.

static variable PA_DrawScaleBarsHelper(string win, variable axisMode, variable displayMode, WaveRefWave setWaves2, string vertAxis, string horizAxis, variable ylength, string xUnit, string yUnit, variable activeChanCount, variable activeRegionCount, variable numActive, variable resetToUserLength)
wave PA_SpikePositionsForNonVC(wave wv, variable failedPulsesLevel)

Calculate the number of spikes in the given wave for IC and I=0 data.

static variable PA_PulseHasFailed(wave pulseWave, wave noteWave, PulseAverageSettings *s)
string PA_GeneratePulseWaveName(variable channelType, variable channelNumber, variable region, variable pulseIndex)

Generate the wave name for a single pulse.

string PA_BaseName(variable channelNumber, variable headStage)

Generate a static base name for objects in the current averaging folder.

static variable PA_ZeroPulses(WaveOrNull setWave2)

Zero single pulses using ZeroWave.

static variable PA_ZeroWave(wave wv, wave noteWave)

Zero the wave using differentiation and integration.

Overwrites the input wave Preserves the WaveNote and adds the entry NOTE_KEY_ZEROED

2D waves are zeroed along each row

static wave PA_SmoothDeconv(wave input, PulseAverageDeconvSettings *deconvolution)
static wave PA_Deconvolution(wave average, dfref outputDFR, string outputWaveName, PulseAverageDeconvSettings *deconvolution)
variable PA_CheckProc_Common(WMCheckboxAction *cba)
variable PA_SetVarProc_Common(WMSetVariableAction *sva)
variable PA_PopMenuProc_ColorScale(WMPopupAction *pa)
variable PA_PopMenuProc_Common(WMPopupAction *pa)
static variable PA_AutomaticTimeAlignment(PulseAverageSetIndices *pasi)

Time alignment for PA single pulses.

See Time Alignment for an explanation of the algorithm.

static variable PA_GetFeaturePosition(wave wv, wave noteWave)
static variable PA_SetFeaturePosition(wave wv, wave noteWave, variable featurePos)
static variable PA_ResetWavesIfRequired(WaveOrNull setWave2, PulseAverageSettings *pa, variable mode)

Reset All pulse and pulse note waves from a set to its original state if they are outdated.

static variable PA_LayoutGraphs(string win, PulseAverageSettings *pa, PulseAverageSetIndices *pasi, variable displayMode)
static variable PA_GetSetXAxisUserData(string graph, string horizAxis)
static variable PA_AddColorScales(string win, PulseAverageSettings *pa, PulseAverageSetIndices *pasi)
static variable PA_AddColorScale(string graph, string colorScaleGraph, string name, string text, variable index, variable numSlots, string traceName)
static variable PA_SerializeSettings(string win, PulseAverageSettings *pa)

Write the PA settings pa to the panel user data and return a JSON id with the settings.


Valid JSON id, caller must release memory.

static variable PA_DeserializeSettings(string win, PulseAverageSettings *pa)

Read the PA settings from the panel user data into pa and return a JSON id with the settings.


Valid JSON id, caller must release memory, or NaN on error/incompatible struct

static string PA_ShowImage(string win, PulseAverageSettings *pa, PA_ConstantSettings *cs, PulseAverageSetIndices *pasi, variable mode, WaveOrNull additionalData)
static variable PA_HighligthFailedPulsesInImage(string graph, PulseAverageSettings *pa, string vertAxis, string horizAxis, wave img, wave properties, wave setIndizes, variable numPulses)
static variable PA_SetColorScale(string win, string colScale)

Apply the given color scale to all PA plot images.

static variable PA_ResizeColorScalePanel(string imageGraph)

Adjust the size of the panel with the color scale graph.

variable PA_TraceWindowHook(WMWinHookStruct *s)
variable PA_ImageWindowHook(WMWinHookStruct *s)
static variable PA_IsDataOnSubPlot(PulseAverageSettings *pa, PulseAverageSetIndices *pasi, variable xLoc, variable yLoc, variable displayMode)

Returns 1 if data is displayed on the given layout grid location. When data is displayed in PA_ShowPulses and PA_ShowImage then in PulseAverageSetIndices this is tagged.

  • pa[in] Pulse Average Setting information

  • pasi[in] Pulse Average Set Indices information

  • xLoc[in] x location on display grid, typically the channel index

  • yLoc[in] y location on display grid, typically the region index

  • displayMode[in] Return data for either trace plot (PA_DISPLAYMODE_TRACES) or image plot (PA_DISPLAYMODE_IMAGES)


1 if data is displayed on this grid location, 0 if no data is displayed

static variable PA_DrawXZeroLines(string win, PulseAverageSettings *pa, PulseAverageSetIndices *pasi, variable displayMode)
static variable PA_AccelerateAppendTraces(variable jsonID, WaveRefWave plotWaves)

Runs through all graph groups in the json and appends them to the graph.

static variable PA_AccelerateAppendTracesImpl(string w, string v, string h, variable r, variable g, variable b, variable a, variable s, wave y, WaveText t, WaveRefWave d)

Appends a group of traces to a graph, properties v to s must be constant for the group.

  • w[in] name of graph window

  • v[in] name of vertical axis

  • h[in] name of horizontal axis

  • r[in] red color component

  • g[in] green color component

  • b[in] blue color component

  • a[in] alpha component

  • s[in] step width of graph display

  • y[in] 1D wave with indices into wave d for the actual plot data

  • t[in] 1D wave with trace names, same size as y

  • d[in] wave reference wave with plot data


static const string PA_GRAPH_PREFIX = "PulseAverage"
static const string PA_SETTINGS = "PulseAverageSettings"
static const string PA_USER_DATA_X_START_RELATIVE_PREFIX = "XAxisStartPlotRelative_"
static const string PA_USER_DATA_CALC_XLENGTH = "CalculatedXBarLength"
static const string PA_USER_DATA_CALC_YLENGTH = "CalculatedYBarLength"
static const string PA_USER_DATA_USER_YLENGTH = "UserYBarLength"
static const double PA_USE_WAVE_SCALES = 0x01
static const double PA_USE_AXIS_SCALES = 0x02
static const double PA_X_AXIS_OFFSET = 0.01
static const double PA_PLOT_STEPPING = 16
static const double PA_DISPLAYMODE_TRACES = 0x01
static const double PA_DISPLAYMODE_IMAGES = 0x02
static const double PA_DISPLAYMODE_ALL = 0xFF
static const double PA_COLORSCALE_PANEL_WIDTH = 150
static const double PA_PEAK_BOX_AVERAGE = 5
static const double PA_AVGERAGE_PLOT_LSIZE = 1.5
static const double PA_DECONVOLUTION_PLOT_LSIZE = 2
static const string PA_PROPERTIES_KEY_REGIONS = "Regions"
static const string PA_PROPERTIES_KEY_CHANNELS = "Channels"
static const string PA_PROPERTIES_KEY_PREVREGIONS = "PreviousRegions"
static const string PA_PROPERTIES_KEY_PREVCHANNELS = "PreviousChannels"
static const string PA_PROPERTIES_KEY_SWEEPS = "Sweeps"
static const string PA_PROPERTIES_KEY_LAYOUTCHANGE = "LayoutChanged"
static const string PA_PROPERTIES_STRLIST_SEP = ","
static const string PA_SETINDICES_KEY_ACTIVECHANCOUNT = "ActiveChanCount"
static const string PA_SETINDICES_KEY_ACTIVEREGIONCOUNT = "ActiveRegionCount"
static const string PA_SETINDICES_KEY_DISPCHANGE = "DisplayChange"
static const string PA_SETINDICES_KEY_DISPSTART = "DisplayStart"
static const double PA_UPDATEINDICES_TYPE_PREV = 1
static const double PA_UPDATEINDICES_TYPE_CURR = 2
static const double PA_INDICESCHANGE_NONE = 0
static const double PA_INDICESCHANGE_MOVED = 1
static const double PA_INDICESCHANGE_REMOVED = 2
static const double PA_INDICESCHANGE_ADDED = 3
static const double PA_PASIINIT_BASE = 0x01
static const double PA_PASIINIT_INDICEMETA = 0x02
static const double PA_MINIMUM_SPIKE_WIDTH = 0.2
struct PA_ConstantSettings

Helper structure to store the constantness of various categories of settings.

Public Members

variable singlePulse
variable traces
variable images
variable failedPulses
variable dontResetWaves
variable multipleGraphs
variable showAverage
variable deconvolution
variable hideFailedPulses
variable showIndividualPulses
variable showTraces