Skip to content

Commit 0a3efbb

Browse files
MichaelHutht-b
authored andcommitted
NWB: Insert recreated epoch data into LNB on NWB_ExportAllData
Epoch data is recreated for each sweep and inserted with the additional LNB column "PostProcessed" set to 1.
1 parent d10017f commit 0a3efbb

File tree

4 files changed

+69
-4
lines changed

4 files changed

+69
-4
lines changed

Packages/MIES/MIES_Epochs.ipf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ End
17781778
/// @param sweepDFR single sweep folder, e.g. for measurement with a device this wold be DFREF sweepDFR = GetSingleSweepFolder(deviceDFR, sweepNo)
17791779
/// @param sweepNo sweep number
17801780
/// @returns recreated 4D epoch wave
1781-
static Function/WAVE EP_RecreateEpochsFromLoadedData(WAVE numericalValues, WAVE/T textualValues, DFREF sweepDFR, variable sweepNo)
1781+
Function/WAVE EP_RecreateEpochsFromLoadedData(WAVE numericalValues, WAVE/T textualValues, DFREF sweepDFR, variable sweepNo)
17821782

17831783
STRUCT DataConfigurationResult s
17841784
variable channelNr, plannedTime, acquiredTime, adSize, firstUnacquiredIndex

Packages/MIES/MIES_ExperimentDocumentation.ipf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ static Function ED_InsertRowAfterSweepBlock(WAVE values, variable sweepNo, varia
125125
values[rowIndex][][] = NaN
126126
endif
127127
SetNumberInWaveNote(values, NOTE_INDEX, GetNumberFromWaveNote(values, NOTE_INDEX) + 1)
128+
InvalidateLBIndexAndRowCache(values)
128129

129130
return rowIndex
130131
End

Packages/MIES/MIES_MiesUtilities_Logbook.ipf

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,3 +1951,56 @@ Function/S StringifyLogbookMode(variable mode)
19511951
break
19521952
endswitch
19531953
End
1954+
1955+
Function InsertRecreatedEpochsIntoLBN(WAVE numericalValues, WAVE/T textualValues, string device, variable sweepNo)
1956+
1957+
string epochList
1958+
variable channelNumber, channelType, headstage, gotAssocValues
1959+
1960+
DFREF deviceDFR = GetDeviceDataPath(device)
1961+
DFREF sweepDFR = GetSingleSweepFolder(deviceDFR, sweepNo)
1962+
WAVE/Z recEpochs = EP_RecreateEpochsFromLoadedData(numericalValues, textualValues, sweepDFR, sweepNo)
1963+
if(!WaveExists(recEpochs))
1964+
print "Could not recreate Epochs."
1965+
return NaN
1966+
endif
1967+
1968+
Make/FREE/T/N=(1, 1) keys
1969+
Make/FREE/T/N=(1, 1, LABNOTEBOOK_LAYER_COUNT) values, unAssocValues
1970+
1971+
for(channelType = 0; channelType < XOP_CHANNEL_TYPE_COUNT; channelType += 1)
1972+
for(channelNumber = 0; channelNumber < NUM_DA_TTL_CHANNELS; channelNumber += 1)
1973+
// Currently only implemented for DAC channel type
1974+
if(channelType != XOP_CHANNEL_TYPE_DAC)
1975+
continue
1976+
endif
1977+
1978+
epochList = EP_EpochWaveToStr(recEpochs, channelNumber, channelType)
1979+
if(IsEmpty(epochList))
1980+
continue
1981+
endif
1982+
1983+
headstage = AFH_GetHeadstageFromChannelNumberAndType(device, channelType, channelNumber)
1984+
if(IsValidHeadstage(headstage))
1985+
values[0][0][headstage] = epochList
1986+
gotAssocValues = 1
1987+
continue
1988+
endif
1989+
// unassoc channel
1990+
unAssocValues[0][0][INDEP_HEADSTAGE] = epochList
1991+
keys[0][0] = CreateLBNUnassocKey(EPOCHS_ENTRY_KEY, channelNumber, channelType)
1992+
ED_AddEntriesToLabnotebook(unAssocValues, keys, sweepNo, device, DATA_ACQUISITION_MODE, insertAsPostProc = 1)
1993+
1994+
endfor
1995+
endfor
1996+
if(gotAssocValues)
1997+
keys[0][0] = EPOCHS_ENTRY_KEY
1998+
ED_AddEntriesToLabnotebook(values, keys, sweepNo, device, DATA_ACQUISITION_MODE, insertAsPostProc = 1)
1999+
endif
2000+
End
2001+
2002+
Function InvalidateLBIndexAndRowCache(WAVE values)
2003+
2004+
CA_DeleteCacheEntry(CA_CreateLBIndexCacheKey(values))
2005+
CA_DeleteCacheEntry(CA_CreateLBRowCacheKey(values))
2006+
End

Packages/MIES/MIES_NeuroDataWithoutBorders.ipf

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,6 @@ static Function NWB_AddDeviceSpecificData(STRUCT NWBAsyncParameters &s, variable
479479

480480
AddModificationTimeEntry(s.locationID, s.nwbVersion)
481481
NWB_AddDevice(s)
482-
NWB_WriteLabnotebooksAndComments(s)
483482
NWB_WriteTestpulseData(s, writeStoredTestPulses)
484483
End
485484

@@ -588,12 +587,13 @@ End
588587
/// @param overwrite [optional, defaults to false] overwrite any existing NWB file with the same name, only
589588
/// used when overrideFilePath is passed
590589
/// @param verbose [optional, defaults to true] get diagnostic output to the command line
590+
/// @param recreateEpochs [optional, defaults to false] when set to true, epoch information is recreated if the version of the data in the experiment is older than the latest version
591591
///
592592
/// @return 0 on success, non-zero on failure
593-
Function NWB_ExportAllData(variable nwbVersion, [string device, string overrideFullFilePath, string overrideFileTemplate, variable writeStoredTestPulses, variable writeIgorHistory, variable compressionMode, variable keepFileOpen, variable overwrite, variable verbose])
593+
Function NWB_ExportAllData(variable nwbVersion, [string device, string overrideFullFilePath, string overrideFileTemplate, variable writeStoredTestPulses, variable writeIgorHistory, variable compressionMode, variable keepFileOpen, variable overwrite, variable verbose, variable recreateEpochs])
594594

595595
string list, name, fileName
596-
variable locationID, sweep, createdNewNWBFile, argCheck
596+
variable locationID, sweep, createdNewNWBFile, argCheck, epochVersion
597597
string stimsetList = ""
598598

599599
if(ParamIsDefault(keepFileOpen))
@@ -630,6 +630,8 @@ Function NWB_ExportAllData(variable nwbVersion, [string device, string overrideF
630630
verbose = !!verbose
631631
endif
632632

633+
recreateEpochs = ParamIsDefault(recreateEpochs) ? 0 : !!recreateEpochs
634+
633635
argCheck = ParamIsDefault(overrideFullFilePath) + ParamIsDefault(overrideFileTemplate)
634636
ASSERT(argCheck >= 1 && argCheck <= 2, "Either arg overrideFullFilePath or arg overrideFileTemplate must be given or none (auto-gen)")
635637

@@ -736,6 +738,13 @@ Function NWB_ExportAllData(variable nwbVersion, [string device, string overrideF
736738
WAVE s.DAQDataWave = TextSweepToWaveRef(sweepWave)
737739
WAVE s.DAQConfigWave = configWave
738740

741+
if(recreateEpochs)
742+
epochVersion = GetLastSettingIndep(s.numericalValues, s.sweep, "Epochs Version", DATA_ACQUISITION_MODE, defValue = NaN)
743+
if(IsNaN(epochVersion) || epochVersion < SWEEP_EPOCH_VERSION)
744+
InsertRecreatedEpochsIntoLBN(s.numericalValues, s.textualValues, s.device, s.sweep)
745+
endif
746+
endif
747+
739748
NWB_AppendSweepLowLevel(s)
740749
stimsetList += AB_GetStimsetFromPanel(device, sweep)
741750

@@ -744,6 +753,8 @@ Function NWB_ExportAllData(variable nwbVersion, [string device, string overrideF
744753
endfor
745754
LOG_AddEntry(PACKAGE_MIES, "export", keys = {"size [MiB]"}, values = {num2str(NWB_GetExportedFileSize(device))})
746755

756+
NWB_WriteLabnotebooksAndComments(s)
757+
747758
NWB_AppendStimset(nwbVersion, s.locationID, stimsetList, compressionMode)
748759

749760
if(writeIgorHistory)

0 commit comments

Comments
 (0)