Skip to content

Commit 4b88fa7

Browse files
authored
Merge pull request #1200 from AllenInstitute/feature/1200-mh_extend_developers_docu
Extend developers documentation for headstage vs channel from LBN functions
2 parents a836146 + a0eb80b commit 4b88fa7

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

Packages/doc/developers.rst

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,92 @@ The programmer might consider evaluating ``V_AbortCode`` after catch.
400400
It is recommended to comment in the code before the try what the construct is
401401
intended to handle (RTE, Abort or both).
402402

403+
Retrieving Headstage / Channel Information from the LBN
404+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
405+
406+
If you would like to retrieve the settings from the last acquisition then look up function like ``AFH_GetHeadstageFromDAC``.
407+
It retrieves the correct information under the following conditions:
408+
409+
- Data Acquisition is ongoing or
410+
- Data Acquisition has finished and DAEphys panel was not changed.
411+
412+
This function returns NaN if the active DAC had no associated headstage.
413+
The same applies for ``AFH_GetHeadstageFromADC``.
414+
415+
In contrast the functions AFH_GetDACFromHeadstage and AFH_GetADCFromHeadstage return DAC/ADC numbers only for active headstages.
416+
417+
One of the most used functions to retrieve specific information from the LBN is
418+
``GetLastSettingChannel``. The returned wave has NUM_HEADSTAGES + 1 entries.
419+
The first NUM_HEADSTAGES entries refer to the headstages whereas the last entry contains
420+
all headstage independent data.
421+
This is related to the general layout of the LBN, where the headstage is an index of the wave.
422+
In the numerical LBN (``GetLBNumericalValues``) there are columns with DAC/ADC channel information identified by their respective dimension label.
423+
For associated DAC <-> ADC channels the number of the DAC and ADC is present in the layers. The first NUM_HEADSTAGES layers refer to the headstages.
424+
425+
Thus, if headstage 3 uses DAC channel 5 and ADC channel 1 for a sweep then in the LBN
426+
at index 3 in the DAC column a 3 is present and in the ADC column a 1.
427+
Details of the internal data format of the LBN are not required for correct retrieval
428+
of that information as MIES provides functions for that:
429+
430+
.. code-block:: igorpro
431+
432+
WAVE/Z numericalValues = BSP_GetLBNWave(graph, LBN_NUMERICAL_VALUES, sweepNumber = sweep)
433+
if(!WaveExists(numericalValues))
434+
// fitting handling code
435+
endif
436+
WAVE/Z settings
437+
[settings, index] = GetLastSettingChannel(numericalValues, $"", sweep, "Indexing", channelNumber, channelType, entrySourceType)
438+
439+
This call specifies a sweep number, a channel type and a channel number and asks for information from the "Indexing" field.
440+
It returns a 1D wave settings and an index, where settings[index] is a Boolean entry telling if indexing was off or on.
441+
The value index itself is the headstage number. The index value can also equal NUM_HEADSTAGES when it refers to a headstage independent value.
442+
443+
To find the ``ADC`` channel from a ``DAC`` channel, the example above can also be setup with channelType = XOP_CHANNEL_TYPE_DAC and LBN entry name "ADC".
444+
This works the same for finding the ``DAC`` channel from a ``ADC`` channel.
445+
446+
If one just wants the headstage number there is an utility function ``GetHeadstageForChannel`` that returns the active headstage for a channel.
447+
448+
The LBN entry ``Headstage Active`` is a Boolean entry and marks which headstage was active in a sweep.
449+
The ``Headstage Active`` can only be set (1) for a headstage that has an associated ``DAC`` and ``ADC`` channel.
450+
451+
Creating LBN entries for tests
452+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
453+
454+
.. code-block:: igorpro
455+
456+
Make/FREE/N=(1, 1, LABNOTEBOOK_LAYER_COUNT) valuesHSA, valuesDAC, valuesADC
457+
Make/T/FREE/N=(1, 1, 1) keys
458+
459+
sweepNo = 0
460+
461+
// HS 0: DAC 2 and ADC 6
462+
// HS 1: DAC 3 and ADC 7
463+
// HS 2+: No DAC/ADC set
464+
valuesDAC[] = NaN
465+
valuesDAC[0][0][0] = 2 // The layer refers to the headstage number
466+
valuesDAC[0][0][1] = 3
467+
keys[] = "DAC"
468+
ED_AddEntriesToLabnotebook(valuesDAC, keys, sweepNo, device, DATA_ACQUISITION_MODE)
469+
470+
valuesADC[] = NaN
471+
valuesADC[0][0][0] = 6
472+
valuesADC[0][0][1] = 7
473+
keys[] = "ADC"
474+
ED_AddEntriesToLabnotebook(valuesADC, keys, sweepNo, device, DATA_ACQUISITION_MODE)
475+
476+
valuesHSA[] = 0
477+
valuesHSA[0][0][0] = 1 // the only valid option here is to set HS 0 and 1 active
478+
valuesHSA[0][0][1] = 1 // because we did not set ADC/DAC channels for the other HS.
479+
keys[] = "Headstage Active"
480+
ED_AddEntriesToLabnotebook(valuesHSA, keys, sweepNo, device, DATA_ACQUISITION_MODE)
481+
482+
The key function here is ``ED_AddEntriesToLabnotebook``. There are no checks applied for this
483+
way of creating LBN entries for tests that guarantee a consistent LBN. e.g. setting headstage 2 to active
484+
in the upper code would violate LBN format schema.
485+
Note that in contrast ``ED_AddEntryToLabnotebook`` is used to add specific user entries to the LBN
486+
and **is not suited** for setting up generic test LBN entries.
487+
More example code can be found in ``PrepareLBN_IGNORE`` in UTF_Labnotebook.ipf.
488+
403489
Original Developer Docu on SweepFormula
404490
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
405491

0 commit comments

Comments
 (0)