File MIES_AnalysisFunctions.ipf

AF Analysis functions to be called during data acquisition

Users can implement functions which are called at certain events for each data acquisition cycle. See TestAnalysisFunction_V3() for an example.

See also

MIES_AnalysisFunctionPrototypes.ipf

Event

Description

Specialities

User epochs

Pre DAQ

Before any DAQ occurs

Called before the settings are validated completely, only the analysis parameters are validated if present. With Indexing ON, only the analysis function of the first stimset will receive that event.

No

Pre Sweep Config

Before the sweep is configured

None

Write

Pre Set

Before a new set starts

None

Write

Mid Sweep

Each time when new data is polled

Available for background DAQ only. Will always be called at least once and also with the full stimset acquired.

Write

Post Sweep

After each sweep (before possible ITI pause)

None

Read/Write

Post Set

After a full set has been acquired

This event is not always reached as the user might not acquire all steps of a set. With indexing, locked and unlocked, only the post set events for fully acquired stimsets are reached.

Read/Write

Post DAQ

After DAQ has finished and before potential “TP after DAQ”

None

No

User epochs will only be recorded in events which support them, see User epochs for more information about user epochs.

Useful helper functions are defined in MIES_AnalysisFunctionHelpers.ipf.

The Post/Pre Sweep/Set/DAQ functions are not executed if a currently running sweep is aborted. Changing the stimset in the Post DAQ event is only possible without indexing active.

Analysis function return types

Some event types support a range of different return types which let the user decide what should happen next. See also AnalysisFuncReturnTypesConstants. The first analysis function returning with a special value requesting a DAQ stop or preventing it from starting will immediately do so, thus subsequent analysis functions for other active headstage will not run.

Value

Event Types

Action

NaN

All

Nothing

0

All

Nothing

1

Pre DAQ

DAQ is prevented to start

1

Pre Set

DAQ is stopped

1

Pre Sweep Config

DAQ is stopped

ANALYSIS_FUNC_RET_REPURP_TIME

Mid Sweep

Current sweep is immediately stopped. Left over time is repurposed for ITI.

ANALYSIS_FUNC_RET_EARLY_STOP

Mid Sweep

Current sweep is immediately stopped without honouring the left over time in a special way.

Analysis function user parameters (V3 only)

For some analysis functions it is beneficial to send in additional data depending on the stimset. This is supported by adding parameters and their values via AFH_AddAnalysisParameter() to the stimset, or using the Wavebuilder GUI, and then querying them with the help of Analysis Helper functions for dealing with user parameters. The parameters are stored serialized in the WPT wave, see GetWaveBuilderWaveTextParam() for the exact format. See TestAnalysisFunction_V3() for an example implementation.

If you want to propose a list of parameters which should/must be present, define an additional function named like your analysis function but suffixed with _GetParams and return a comma separated list of names. Adding the type is also possible via $name:$type syntax. The list of parameter names and types is then checked before DAQ. The supplied names are taken to be required by default, optional parameters, and their types, must be enclosed with []. The list at ANALYSIS_FUNCTION_PARAMS_TYPES holds all valid types.

The optional function _CheckParam allows you to validate passed parameters. In case of a valid parameter it must return an emtpy string and an error message in case of failure. Parameters which don’t pass can neither be added to stimsets nor can they be used for data acquisition. Optional parameters are only checked if they are present in the stimulus set so you don’t need to handle that case special.

The optional function _GetHelp allows you to create per parameter help text which is shown in the Wavebuilder.

Example:

Function MyAnalysisFunction(string device, struct AnalysisFunction_V3& s)
    // ...
End

Function/S MyAnalysisFunction_GetParams()
    return "param1:variable,[optParam1:wave]"
End

Function/S MyAnalysisFunction_CheckParam(string name, struct CheckParametersStruct& s)
    variable value

    strswitch(name)
        case "param1":
            value = AFH_GetAnalysisParamNumerical(name, s.params)
            if(!IsFinite(value) || !(value >= 0 && value <= 100))
                return "Needs to be between 0 and 100."
            endif
            break
        case "optParam1":
            WAVE/Z wv = AFH_GetAnalysisParamWave(name, s.params)
            if(!WaveExists(wv) || !IsFloatingPointWave(wv))
                return "Needs to be an existing floating point wave."
            endif
            break
    endswitch

    // default to passing for other parameters
    return ""
End

Function/S MyAnalysisFunction_GetHelp(string name)

    strswitch(name)
        case "param1":
             return "This parameter helps in finding pink unicorns"
             break
        case "optParam1":
             return "This parameter delivers food right to your door"
             break
        default:
             ASSERT(0, "Unimplemented for parameter " + name)
             break
    endswitch
End

Initial parameters for stimulation

static const string DEFAULT_DEVICE = "ITC18USB_Dev_0"

device device

static const string STIM_SET_LOCAL = "PulseTrain_150Hz_DA_0"

Initial stimulus set.

static const double VM1_LOCAL = -55

Initial holding potential.

static const double VM2_LOCAL = -85

Second holding potential to switch to.

static const double SCALE_LOCAL = 70

Stimulus amplitude.

static const double NUM_SWEEPS_LOCAL = 6

Number of sweeps to acquire.

static const double ITI_LOCAL = 15

Inter-trial-interval.

Initial settings for oodDAQ stimulation

static const double POST_DELAY = 150

Delay after stimulation event in which no other event can occur in ms.

Functions

variable TestAnalysisFunction_V1(string device, variable eventType, wave DAQDataWave, variable headStage)
variable TestAnalysisFunction_V2(string device, variable eventType, wave DAQDataWave, variable headStage, variable realDataLength)
variable TestAnalysisFunction_V3(string device, AnalysisFunction_V3 *s)
variable MeasureMidSweepTiming_V3(string device, AnalysisFunction_V3 *s)

Measure the time between mid sweep calls.

Used mainly for debugging.

variable Enforce_VC(string device, variable eventType, wave DAQDataWave, variable headStage, variable realDataLength)
variable Enforce_IC(string device, variable eventType, wave DAQDataWave, variable headStage, variable realDataLength)
variable SetStimConfig_Vclamp(string device, variable eventType, wave DAQDataWave, variable headStage)

Force active headstages into voltage clamp.

variable SetStimConfig_Iclamp(string device, variable eventType, wave DAQDataWave, variable headStage)

Force active headstages into current clamp.

variable ChangeHoldingPotential(string device, variable eventType, wave DAQDataWave, variable headStage)

Change holding potential midway through stim set.

variable LastStimSet(string device, variable eventType, wave DAQDataWave, variable headStage)

Print last Stim Set run and headstage mode and holding potential.

variable StimParamGUI()

GUI to set initial stimulus parameters using SetStimParam() and begin data acquisition. NOTE: DATA ACQUISITION IS INTIATED AT THE END OF FUNCTION!

variable SetStimParam(string stimSet, variable Vm1, variable Scale, variable Sweeps, variable ITI)

Called by StimParamGUI to set initial stimulus parameters.

Parameters
  • stimSet – Stimulus set to run

  • Vm1 – Holding potential

  • Scale – Stimulus amplitude in mV

  • Sweeps – Number of sweeps

  • ITI – Inter-trial-interval

variable setHolding(variable Vm1)

Set holding potential for active headstages.

Parameters

Vm1 – Holding potential

variable setVClampMode()

Set active headstages into V-clamp.

variable setIClampMode()

Set active headstages into I-clamp.

variable switchHolding(variable Vm2)

Change holding potential on active headstages to Vm2. Switch occurs after X/2 number of data sweeps. If X!/2 switchSweep = floor(X/2)

Parameters

Vm2 – Holding potential to switch to

variable InitoodDAQ()

Initialize oodDAQ settings.

variable LastStimSetRun()

Print last full stim set aqcuired.

variable TestPrematureSweepStop(string device, variable eventType, wave DAQDataWave, variable headStage, variable realDataLength)

Mid sweep analysis function which stops the sweeps and repurposes the left over time at the 20th call.

This function needs to be set for Pre DAQ, Mid Sweep and Post Sweep Event.

variable preDAQ_MP_mainConfig(string device, variable eventType, wave DAQDataWave, variable headStage, variable realDataLength)
variable preDAQ_MP_IfMixed(string device, variable eventType, wave DAQDataWave, variable headStage, variable realDataLength)
variable preDAQ_MP_ChirpBlowout(string device, variable eventType, wave DAQDataWave, variable headStage, variable realDataLength)
variable AdjustDAScale(string device, variable eventType, wave DAQDataWave, variable headStage, variable realDataLength)

Analysis function to set different “DA Scale” values for a sweep.

Prerequisites:

  • Stimset with multiple but identical sweeps and testpulse-like shape. The number of sweeps must be larger than the number of rows in the DAScales wave below.

  • This stimset must have this analysis function set for the “Pre DAQ” and the “Post Sweep” Event

  • Does currently nothing for “Mid Sweep” Event

  • Does not support DA/AD channels not associated with a MIES headstage (aka unassociated DA/AD Channels)

  • All active headstages must be in “Current Clamp”

variable FitResistance(string device, variable headstage, variable showPlot = defaultValue, variable anaFuncType = defaultValue)

Plot the resistance of the sweeps of the same SCI

Usually called by PSQ_AdjustDAScale().

variable SetDAScaleModOp(string device, variable headstage, variable modifier, string operator, variable invert = defaultValue, variable roundTopA = defaultValue)

Helper for setting the DAScale.

variable SetDAScale(string device, variable headstage, variable absolute = defaultValue, variable relative = defaultValue, variable offset = defaultValue, variable roundTopA = defaultValue)

Set the DAScale value of the given headstage.

Parameters
  • device – device

  • headstage – MIES headstage

  • absolute – (optional) DAScale value in A (Amperes)

  • relative – (optional) relative DAScale modifier

  • offset – (optional) offset DAScale value

  • roundTopA – (optional, defaults to false) round the set DAScale to integer pA values

string ReachTargetVoltage_GetParams()

Return a list of required parameters.

string ReachTargetVoltage_GetHelp(string name)
string ReachTargetVoltage_CheckParam(string name, CheckParametersStruct *s)
variable ReachTargetVoltage(string device, AnalysisFunction_V3 *s)

Analysis function to experimentally determine the cell resistance by sweeping through a wave of target voltages.

Prerequisites:

  • Stimset with multiple but identical sweeps and testpulse-like shape. The number of sweeps must be larger than the number of rows in the targetVoltages wave below.

  • Does not support DA/AD channels not associated with a MIES headstage (aka unassociated DA/AD Channels)

  • All active headstages must be in “Current Clamp”

  • All active IC headstages must run this analysis function

  • An inital DAScale of -20pA is used, a fixup value of -100pA is used on the next sweep if the measured resistance is smaller than 20MΩ

variable SetControlInEvent(string device, AnalysisFunction_V3 *s)

Analysis function to set GUI controls or notebooks in the events.

Usage:

  • Add analysis parameters named like the control/notebook

  • Their value must be a textwave with at least one tuple of event type and data.

  • Valid number of rows are therefore 2, 4, 6, …

  • The first tuple element is the event type, one of EVENT_NAME_LIST without “Mid Sweep” and “Generic”, and the second element the value to set

  • For PopupMenus the passed value is the menu item and not its index

  • The controls are searched in all open panels and graphs. The notebook can be a toplevel or subwindow notebook. For multiple matching panels or graphs we prefer the corresponding DAEphys panel and Databrowser.

Examples:

setvar_DataAcq_OnsetDelayUser -> Pre DAQ|20|
Popup_Settings_FixedFreq -> Pre Sweep|100|Post Sweep|Maximum|
sweepFormula_formula -> Pre Set|data(cursors(A,B), select(channels(AD), sweeps()))