Skip to content

Commit

Permalink
Merge pull request #2339 from AllenInstitute/bugfix/2339-add-power-sp…
Browse files Browse the repository at this point in the history
…ectrum-setting-to-labnotebook

DA_Ephys: Add power spectrum to labnotebook
  • Loading branch information
t-b authored Jan 30, 2025
2 parents 00e925e + 02e67da commit 4187bf1
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Packages/MIES/MIES_Constants.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Constant SWEEP_EPOCH_VERSION = 9
/// - New/Changed layers of entries
///
///@{
Constant LABNOTEBOOK_VERSION = 78
Constant LABNOTEBOOK_VERSION = 79
Constant RESULTS_VERSION = 3
///@}

Expand Down
1 change: 1 addition & 0 deletions Packages/MIES/MIES_DataConfigurator.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,7 @@ static Function DC_PrepareLBNEntries(string device, STRUCT DataConfigurationResu
DC_DocumentChannelProperty(device, "Repeat sweep on async alarm", INDEP_HEADSTAGE, NaN, NaN, var = DAG_GetNumericalValue(device, "Check_Settings_AlarmAutoRepeat"))
DC_DocumentChannelProperty(device, AUTOBIAS_PERC_KEY, INDEP_HEADSTAGE, NaN, NaN, var = DAG_GetNumericalValue(device, "setvar_Settings_AutoBiasPerc"))
DC_DocumentChannelProperty(device, "Autobias interval", INDEP_HEADSTAGE, NaN, NaN, var = DAG_GetNumericalValue(device, "setvar_Settings_AutoBiasInt"))
DC_DocumentChannelProperty(device, "TP power spectrum", INDEP_HEADSTAGE, NaN, NaN, var = DAG_GetNumericalValue(device, "check_settings_show_power"))

DC_DocumentHardwareProperties(device, s.hardwareType)

Expand Down
8 changes: 6 additions & 2 deletions Packages/MIES/MIES_ExperimentDocumentation.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,8 @@ Function ED_TPDocumentation(string device)
WAVE TPResults = GetTPResults(device)
WAVE statusHS = DAG_GetChannelState(device, CHANNEL_TYPE_HEADSTAGE)

Make/FREE/T/N=(3, 12) TPKeyWave
Make/FREE/N=(1, 12, LABNOTEBOOK_LAYER_COUNT) TPSettingsWave = NaN
Make/FREE/T/N=(3, 13) TPKeyWave
Make/FREE/N=(1, 13, LABNOTEBOOK_LAYER_COUNT) TPSettingsWave = NaN

// add data to TPKeyWave
TPKeyWave[0][0] = "TP Baseline Vm" // current clamp
Expand All @@ -818,6 +818,7 @@ Function ED_TPDocumentation(string device)
TPKeyWave[0][9] = "DAC"
TPKeyWave[0][10] = "ADC"
TPKeyWave[0][11] = CLAMPMODE_ENTRY_KEY
TPKeyWave[0][12] = "TP power spectrum"

TPKeyWave[1][0] = "mV"
TPKeyWave[1][1] = "pA"
Expand All @@ -831,6 +832,7 @@ Function ED_TPDocumentation(string device)
TPKeyWave[1][9] = ""
TPKeyWave[1][10] = ""
TPKeyWave[1][11] = ""
TPKeyWave[1][12] = LABNOTEBOOK_BINARY_UNIT

RTolerance = TPSettings[%resistanceTol][INDEP_HEADSTAGE]
TPKeyWave[2][0] = "1" // Assume a tolerance of 1 mV for V rest
Expand All @@ -845,6 +847,7 @@ Function ED_TPDocumentation(string device)
TPKeyWave[2][9] = "0.1"
TPKeyWave[2][10] = "0.1"
TPKeyWave[2][11] = LABNOTEBOOK_NO_TOLERANCE
TPKeyWave[2][12] = LABNOTEBOOK_NO_TOLERANCE

TPSettingsWave[0][2][0, NUM_HEADSTAGES - 1] = TPResults[%ResistanceInst][r]
TPSettingsWave[0][3][0, NUM_HEADSTAGES - 1] = TPResults[%ResistanceSteadyState][r]
Expand Down Expand Up @@ -877,6 +880,7 @@ Function ED_TPDocumentation(string device)
TPSettingsWave[0][9][0, NUM_HEADSTAGES - 1] = hsProp[r][%DAC]
TPSettingsWave[0][10][0, NUM_HEADSTAGES - 1] = hsProp[r][%ADC]
TPSettingsWave[0][11][0, NUM_HEADSTAGES - 1] = hsProp[r][%ClampMode]
TPSettingsWave[0][12][INDEP_HEADSTAGE] = DAG_GetNumericalValue(device, "check_settings_show_power")

sweepNo = AFH_GetLastSweepAcquired(device)
ED_AddEntriesToLabnotebook(TPSettingsWave, TPKeyWave, sweepNo, device, TEST_PULSE_MODE)
Expand Down
11 changes: 6 additions & 5 deletions Packages/MIES/MIES_MiesUtilities_Logbook.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1347,11 +1347,12 @@ threadsafe static Function FindRange(WAVE wv, variable col, variable val, variab

if(WaveExists(indizesSourceType)) // entrySourceType could be found
WAVE/Z indizes = GetSetIntersection(indizesSetting, indizesSourceType)
if(!WaveExists(indizes))
return NaN
endif
else
WAVE indizes = indizesSetting
WAVE/Z indizes = indizesSetting
endif

if(!WaveExists(indizes))
return NaN
endif

numRows = DimSize(indizes, ROWS)
Expand All @@ -1372,7 +1373,7 @@ threadsafe static Function FindRange(WAVE wv, variable col, variable val, variab
for(i = numRows - 2; i >= 0; i -= 1)
index = indizes[i]
// a backward search stops when the beginning of the last sequence was found
if(index < first - 1)
if(index < first - 1 && sourceTypeCol >= 0)
if(IsNumeric)
for(j = index + 1; j < first; j += 1)
if(!IsNaN(wv[j][sourceTypeCol][0]))
Expand Down
11 changes: 8 additions & 3 deletions Packages/MIES/MIES_WaveDataFolderGetters.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -2367,7 +2367,7 @@ threadsafe Function/WAVE GetLBNidCache(WAVE numericalValues)
return wv
End

static Constant SWEEP_SETTINGS_WAVE_VERSION = 39
static Constant SWEEP_SETTINGS_WAVE_VERSION = 40

/// @brief Uses the parameter names from the `sourceKey` columns and
/// write them as dimension into the columns of dest.
Expand Down Expand Up @@ -2513,6 +2513,7 @@ End
/// - 59: Save amplifier settings
/// - 60: Require amplifier
/// - 61: Skip Ahead
/// - 62: TP power spectrum
Function/WAVE GetSweepSettingsKeyWave(string device)

variable versionOfNewWave = SWEEP_SETTINGS_WAVE_VERSION
Expand All @@ -2530,9 +2531,9 @@ Function/WAVE GetSweepSettingsKeyWave(string device)
if(ExistsWithCorrectLayoutVersion(wv, versionOfNewWave))
return wv
elseif(WaveExists(wv))
Redimension/N=(-1, 62) wv
Redimension/N=(-1, 63) wv
else
Make/T/N=(3, 62) newDFR:$newName/WAVE=wv
Make/T/N=(3, 63) newDFR:$newName/WAVE=wv
endif

wv = ""
Expand Down Expand Up @@ -2789,6 +2790,10 @@ Function/WAVE GetSweepSettingsKeyWave(string device)
wv[%Units][61] = ""
wv[%Tolerance][61] = "1"

wv[%Parameter][62] = "TP power spectrum"
wv[%Units][62] = LABNOTEBOOK_BINARY_UNIT
wv[%Tolerance][62] = LABNOTEBOOK_NO_TOLERANCE

SetSweepSettingsDimLabels(wv, wv)
SetWaveVersion(wv, versionOfNewWave)

Expand Down
3 changes: 2 additions & 1 deletion Packages/MIES/labnotebook_numerical_description.itx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
IGOR
WAVES/T/N=(195,6) labnotebook_numerical_description
WAVES/T/N=(196,6) labnotebook_numerical_description
BEGIN
"Name" "Unit" "Tolerance" "Description" "Headstage Contingency" "ClampMode"
"SweepNum" "" "-" "Sweep number: Non-repeating non-negative numeric identifier for sweep time series. Increments in the order of acquisition. Starts at zero." "ALL" ""
Expand Down Expand Up @@ -123,6 +123,7 @@ BEGIN
"Autobias" "On/Off" "-" "During the inter trial interval (\"ITI\") autobias adjusts the holding current to maintain the user defined \"Autobias Vcom\" within \"Autobias Vcom variance\". The autobias evaluates a user defined part (\"Autobias (%)\") of the Testpulse baseline at the \"Autobias Interval\" (DaEphys->Settings->Amplifier)." "DEPEND" "IC"
"Sweep Rollback" "" "0.1" "Sweep rollback allows to remove existing sweeps by decreasing the device sweep counter. This entry documents that sweep rollback has happened and the new target sweep number. (removed)" "INDEP" ""
"Skip Sweeps" "" "0.1" "Whenever the user issues a \"Skip Sweeps\" command this entry documents the new and to be jumped to sweep number." "INDEP" ""
"TP power spectrum" "On/Off" "-" "Instead of the Testpulse the power spectrum is displayed/saved during TP and TP during ITI" "INDEP" ""
"Async 0 On/Off" "On/Off" "-" "Single AD channel read at the end of the sweep. Commonly used for reading experimental hardware states. From temperature controllers, for example.\r\rAlarm is triggered when enabled and minimum or maximum is exceeded.\r\rThe value is stored in a new labnotebook column called \"Async AD$X: $Name\" where X is the asynchronous channel and $Name the title of the entry." "INDEP" "IC;VC;I=0"
"Async 1 On/Off" "On/Off" "-" "Single AD channel read at the end of the sweep. Commonly used for reading experimental hardware states. From temperature controllers, for example.\r\rAlarm is triggered when enabled and minimum or maximum is exceeded.\r\rThe value is stored in a new labnotebook column called \"Async AD$X: $Name\" where X is the asynchronous channel and $Name the title of the entry." "INDEP" "IC;VC;I=0"
"Async 2 On/Off" "On/Off" "-" "Single AD channel read at the end of the sweep. Commonly used for reading experimental hardware states. From temperature controllers, for example.\r\rAlarm is triggered when enabled and minimum or maximum is exceeded.\r\rThe value is stored in a new labnotebook column called \"Async AD$X: $Name\" where X is the asynchronous channel and $Name the title of the entry." "INDEP" "IC;VC;I=0"
Expand Down
Binary file modified Packages/tests/Basic/Basic.pxp
Binary file not shown.
25 changes: 25 additions & 0 deletions Packages/tests/Basic/UTF_Labnotebook.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ Function GetLastSettingEntrySourceTypes()
CHECK_EQUAL_WAVES(DAQSettings, {0, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(TPSettings, {1, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN}, mode = WAVE_DATA)

// no entry source otherwise the same labnotebook as above
WAVE/SDFR=dfr numericalValues_with_sweep_rb_no_type
WAVE numericalValues = PrepareLBNNumericalValues(numericalValues_with_sweep_rb_no_type)
WAVE/Z DAQSettings = GetLastSetting(numericalValues, 0, "DAC", DATA_ACQUISITION_MODE)
WAVE/Z TPSettings = GetLastSetting(numericalValues, 0, "DAC", TEST_PULSE_MODE)

CHECK_EQUAL_WAVES(DAQSettings, {0, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN}, mode = WAVE_DATA)
CHECK_EQUAL_WAVES(TPSettings, {1, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN}, mode = WAVE_DATA)

// contains two times sweep 73, created with sweep rollback and a trailing TP
// and does not have entry source type information
WAVE/SDFR=dfr numericalValues_no_type_with_sweep_rb_with_tp
Expand Down Expand Up @@ -222,6 +231,22 @@ Function GetLastSettingFindsNaNSweep()
CHECK_EQUAL_WAVES(settings, settingsRef, mode = WAVE_DATA, tol = 1e-13)
End

Function GetLastSettingOnlyTPData()

DFREF dfr = root:Labnotebook_misc:

// check that we can find the first entries of the testpulse which have sweepNo == NaN
WAVE/SDFR=dfr numericalValues_only_TP
WAVE numericalValues = PrepareLBNNumericalValues(numericalValues_only_TP)

WAVE/Z settings = GetLastSetting(numericalValues, NaN, "TP power spectrum", TEST_PULSE_MODE)
Make/D/FREE settingsRef = {NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 1}
CHECK_EQUAL_WAVES(settings, settingsRef, mode = WAVE_DATA)

WAVE/Z settings = GetLastSetting(numericalValues, NaN, "TP power spectrum", DATA_ACQUISITION_MODE)
CHECK_WAVE(settings, NULL_WAVE)
End

static Function GetLastSettingFindsWithinNonConsecutiveSweepOrder()

string key
Expand Down
10 changes: 10 additions & 0 deletions Packages/tests/HardwareBasic/UTF_TestPulseAndTPDuringDAQ.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,13 @@ static Function RunPowerSpectrum_REENTRY([string str])
CHECK_EQUAL_VAR(0, sweepDataLNB[0][%$STIMSET_SCALE_FACTOR_KEY][0])
CHECK_EQUAL_VAR(0, sweepDataLNB[0][%$STIMSET_SCALE_FACTOR_KEY][1])

WAVE numericalValues = GetLBNumericalValues(str)

WAVE/Z powerSpectrum = GetLastSetting(numericalValues, sweepNo, "TP power spectrum", DATA_ACQUISITION_MODE)
CHECK_WAVE(powerSpectrum, NULL_WAVE)

WAVE/Z powerSpectrum = GetLastSetting(numericalValues, sweepNo, "TP power spectrum", TEST_PULSE_MODE)
CHECK_EQUAL_WAVES(powerSpectrum, {NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 1}, mode = WAVE_DATA)
End

// UTF_TD_GENERATOR DeviceNameGeneratorMD1
Expand Down Expand Up @@ -1266,6 +1273,9 @@ static Function TPDuringDAQwithPS_REENTRY([string str])
daGain = DAG_GetNumericalValue(str, GetSpecialControlLabel(CHANNEL_TYPE_DAC, CHANNEL_CONTROL_SCALE), index = 0)

CHECK_EQUAL_WAVES(stimScale, {tpAmp, daGain, NaN, NaN, NaN, NaN, NaN, NaN, NaN}, mode = WAVE_DATA)

WAVE/Z powerSpectrum = GetLastSetting(numericalValues, sweepNo, "TP power spectrum", DATA_ACQUISITION_MODE)
CHECK_EQUAL_WAVES(powerSpectrum, {NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 1}, mode = WAVE_DATA)
End

// UTF_TD_GENERATOR v0:SingleMultiDeviceDAQ
Expand Down

0 comments on commit 4187bf1

Please sign in to comment.