Skip to content

Commit

Permalink
WIP: NWBv2
Browse files Browse the repository at this point in the history
  • Loading branch information
t-b committed May 30, 2019
1 parent c72adc3 commit 1a17c89
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 113 deletions.
44 changes: 22 additions & 22 deletions Packages/MIES/MIES_AnalysisBrowser.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ End
static Function AB_LoadSweepsFromNWB(discLocation, dataFolder, device)
string discLocation, dataFolder, device

variable h5_fileID, h5_groupID
variable h5_fileID, h5_groupID, nwbVersion
string channelList

Wave/I sweeps = GetAnalysisChannelSweepWave(dataFolder, device)
Expand All @@ -588,33 +588,33 @@ static Function AB_LoadSweepsFromNWB(discLocation, dataFolder, device)
h5_fileID = IPNWB#H5_OpenFile(discLocation)

// load from /acquisition/timeseries
channelList = IPNWB#ReadAcquisition(h5_fileID)
h5_groupID = IPNWB#OpenAcquisition(h5_fileID)
nwbVersion = IPNWB#ReadNWBVersion(h5_fileID)
channelList = IPNWB#ReadAcquisition(h5_fileID, nwbVersion)
h5_groupID = IPNWB#OpenAcquisition(h5_fileID, nwbVersion)
Wave/T acquisition = GetAnalysisChannelAcqWave(dataFolder, device)
AB_StoreChannelsBySweep(h5_groupID, channelList, sweeps, acquisition)
AB_StoreChannelsBySweep(h5_groupID, nwbVersion, channelList, sweeps, acquisition)
HDF5CloseGroup/Z h5_groupID

// load from /stimulus/presentation
channelList = IPNWB#ReadStimulus(h5_fileID)
h5_groupID = IPNWB#OpenStimulus(h5_fileID)
Wave/T stimulus = GetAnalysisChannelStimWave(dataFolder, device)
AB_StoreChannelsBySweep(h5_groupID, channelList, sweeps, stimulus)
AB_StoreChannelsBySweep(h5_groupID, nwbVersion, channelList, sweeps, stimulus)
HDF5CloseGroup/Z h5_groupID

// close hdf5 file
IPNWB#H5_CloseFile(h5_fileID)
End

/// @brief Store channelList in storage wave according to index in sweeps wave
static Function AB_StoreChannelsBySweep(groupID, channelList, sweeps, storage)
variable groupID
static Function AB_StoreChannelsBySweep(groupID, nwbVersion, channelList, sweeps, storage)
variable groupID, nwbVersion
string channelList
Wave/I sweeps
Wave/T storage

variable numChannels, numSweeps, i
variable numChannels, numSweeps, i, sweepNo
string channelString
STRUCT IPNWB#ReadChannelParams channel

numChannels = ItemsInList(channelList)
numSweeps = GetNumberFromWaveNote(sweeps, NOTE_INDEX)
Expand All @@ -624,13 +624,13 @@ static Function AB_StoreChannelsBySweep(groupID, channelList, sweeps, storage)

for(i = 0; i < numChannels; i += 1)
channelString = StringFromList(i, channelList)
IPNWB#LoadSourceAttribute(groupID, channelString, channel)
FindValue/I=(channel.sweep)/S=0 sweeps
sweepNo = IPNWB#LoadSweepNumber(groupID, channelString, nwbVersion)
FindValue/I=(sweepNo)/S=0 sweeps
if(V_Value == -1)
numSweeps += 1
EnsureLargeEnoughWave(sweeps, minimumSize = numSweeps, dimension = ROWS, initialValue = -1)
EnsureLargeEnoughWave(storage, minimumSize = numSweeps, dimension = ROWS)
sweeps[numSweeps - 1] = channel.sweep
sweeps[numSweeps - 1] = sweepNo
storage[numSweeps - 1] = AddListItem(channelString, "")
else
storage[V_Value] = AddListItem(channelString, storage[V_Value])
Expand Down Expand Up @@ -1547,7 +1547,7 @@ static Function AB_LoadSweepFromNWB(discLocation, sweepDFR, device, sweep)
variable sweep

string channelList
variable h5_fileID, h5_groupID, numSweeps
variable h5_fileID, h5_groupID, numSweeps, version

Wave/T nwb = AB_GetMap(discLocation)

Expand All @@ -1573,20 +1573,21 @@ static Function AB_LoadSweepFromNWB(discLocation, sweepDFR, device, sweep)

// open NWB file
h5_fileID = IPNWB#H5_OpenFile(discLocation)
version = IPNWB#ReadNWBVersion(h5_fileID)

// load acquisition
Wave/T acquisition = GetAnalysisChannelAcqWave(nwb[%DataFolder], device)
channelList = acquisition[V_Value]
h5_groupID = IPNWB#OpenAcquisition(h5_fileID)
if(AB_LoadSweepFromNWBgeneric(h5_groupID, channelList, sweepDFR, configSweep))
h5_groupID = IPNWB#OpenAcquisition(h5_fileID, version)
if(AB_LoadSweepFromNWBgeneric(h5_groupID, version, channelList, sweepDFR, configSweep))
return 1
endif

// load stimulus
Wave/T stimulus = GetAnalysisChannelStimWave(nwb[%DataFolder], device)
channelList = stimulus[V_Value]
h5_groupID = IPNWB#OpenStimulus(h5_fileID)
if(AB_LoadSweepFromNWBgeneric(h5_groupID, channelList, sweepDFR, configSweep))
if(AB_LoadSweepFromNWBgeneric(h5_groupID, version, channelList, sweepDFR, configSweep))
return 1
endif

Expand All @@ -1596,8 +1597,9 @@ static Function AB_LoadSweepFromNWB(discLocation, sweepDFR, device, sweep)
return 0
End

static Function AB_LoadSweepFromNWBgeneric(h5_groupID, channelList, sweepDFR, configSweep)
variable h5_groupID
/// @todo nwbVersion
static Function AB_LoadSweepFromNWBgeneric(h5_groupID, version, channelList, sweepDFR, configSweep)
variable h5_groupID, version
string channelList
DFREF sweepDFR
Wave/I configSweep
Expand All @@ -1611,10 +1613,7 @@ static Function AB_LoadSweepFromNWBgeneric(h5_groupID, channelList, sweepDFR, co

for(i = 0; i < numChannels; i += 1)
channel = StringFromList(i, channelList)

// use AnalyseChannelName as a fallback if properties from the source attribute are missing
IPNWB#AnalyseChannelName(channel, p)
IPNWB#LoadSourceAttribute(h5_groupID, channel, p)

switch(p.channelType)
case ITC_XOP_CHANNEL_TYPE_DAC:
Expand All @@ -1625,7 +1624,7 @@ static Function AB_LoadSweepFromNWBgeneric(h5_groupID, channelList, sweepDFR, co
break
case ITC_XOP_CHANNEL_TYPE_ADC:
channelName = "AD"
wave loaded = IPNWB#LoadTimeseries(h5_groupID, channel)
wave loaded = IPNWB#LoadTimeseries(h5_groupID, channel, version)
channelName += "_" + num2str(p.channelNumber)
fakeConfigWave = 1
break
Expand Down Expand Up @@ -1661,6 +1660,7 @@ static Function AB_LoadSweepFromNWBgeneric(h5_groupID, channelList, sweepDFR, co
default:
ASSERT(0, "unknown channel type " + num2str(p.channelType))
endswitch
ASSERT(WaveExists(loaded), "No Wave loaded")

if(waveNoteLoaded == 0)
SVAR/Z test = sweepDFR:note
Expand Down
1 change: 1 addition & 0 deletions Packages/MIES/MIES_Constants.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@ StrConstant PRESSURE_STARTSEAL = "Initial Seal Pressure (psi)"
StrConstant PRESSURE_MAXSEAL = "Maximum Seal Pressure (psi)"
StrConstant TP_AFTER_DAQ = "Activate TP after DAQ"
StrConstant EXPORT_NWB = "Export to NWB"
StrConstant NWB_VERSION = "NWB Version"
StrConstant APPEND_ASYNC = "Append Asynchronous reading to wave note"
StrConstant SYNC_MIES_MCC = "Sync MIES to MCC"
StrConstant ENABLE_I_EQUAL_ZERO = "Switch clamp modes via I equal zero"
Expand Down
3 changes: 2 additions & 1 deletion Packages/MIES/MIES_DAEphys.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ Function DAP_EphysPanelStartUpSettings()
CheckBox check_Settings_TPAfterDAQ WIN = $panelTitle, value= 0

CheckBox Check_Settings_NwbExport WIN = $panelTitle,value= 0
PopupMenu Popup_Settings_NwbVersion WIN = $panelTitle, mode=2, popvalue="2"

SetVariable min_AsyncAD_00 WIN = $panelTitle,value= _NUM:0
SetVariable max_AsyncAD_00 WIN = $panelTitle,value= _NUM:0
Expand Down Expand Up @@ -2347,7 +2348,7 @@ Function DAP_CheckSettings(panelTitle, mode)
endfor

if(DAG_GetNumericalValue(panelTitle, "Check_Settings_NwbExport"))
NWB_PrepareExport()
NWB_PrepareExport(DAG_GetNumericalValue(panelTitle, "Popup_Settings_NwbVersion"))
endif

return 0
Expand Down
5 changes: 5 additions & 0 deletions Packages/MIES/MIES_DAEphys_Macro.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -3217,6 +3217,11 @@ Window DA_Ephys() : Panel
CheckBox Check_Settings_NwbExport,userdata(ResizeControlsInfo) += A"zzzzzzzzzzzz!!#u:Du]k<zzzzzzzzzzz"
CheckBox Check_Settings_NwbExport,userdata(ResizeControlsInfo) += A"zzz!!#u:Du]k<zzzzzzzzzzzzzz!!!"
CheckBox Check_Settings_NwbExport,value= 0
PopupMenu Popup_Settings_NwbVersion,pos={139.00,231.00},size={69.00,19.00},proc=DAP_PopMenuProc_UpdateGuiState,title="version"
PopupMenu Popup_Settings_NwbVersion,help={"Set the NWB Version of the export when using triggered export from DA_Ephys"}
PopupMenu Popup_Settings_NwbVersion,userdata(tabcontrol)= "ADC"
PopupMenu Popup_Settings_NwbVersion,userdata(tabnum)= "5"
PopupMenu Popup_Settings_NwbVersion,mode=2,popvalue="2",value= #"\"1;2\""
SetVariable setvar_DataAcq_OnsetDelayUser,pos={289.00,636.00},size={167.00,18.00},bodyWidth=50,disable=1,proc=DAP_SetVar_UpdateGuiState,title="User onset delay (ms)"
SetVariable setvar_DataAcq_OnsetDelayUser,help={"A global parameter that delays the onset time of a set after the initiation of data acquistion. Data acquisition start time is NOT delayed. Useful when set(s) have insufficient baseline epoch."}
SetVariable setvar_DataAcq_OnsetDelayUser,userdata(tabnum)= "0"
Expand Down
22 changes: 22 additions & 0 deletions Packages/MIES/MIES_Debugging.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -560,3 +560,25 @@ Function GetSizeOfAllWavesInExperiment()

Edit/K=1 root:list
End

// see tools/functionprofiling.sh
Function DEBUG_STOREFUNCTION()
string funcName = GetRTStackInfo(2)
string callchain = GetRTStackInfo(0)
string caller = StringFromList(0, callchain)

WAVE/Z wv = root:functionids
if(!WaveExists(wv))
WAVE/T functionids = ListToTextWave(FunctionList("*", ";", "KIND:18,WIN:"), ";")
Duplicate functionids root:functionids/WAVE=wv
endif
WAVE/Z count = root:functioncount
if(!WaveExists(count))
Make/U/L/N=(DimSize(wv, 0)) root:functioncount = 0
WAVE count = root:functioncount
endif
FindValue/TEXT=(funcName) wv
if(V_Value != -1)
count[V_Value] += 1
endif
End
2 changes: 2 additions & 0 deletions Packages/MIES/MIES_ExperimentConfig.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ static Function ExpConfig_DAEphysSettings(panelTitle, UserSettings)
PGC_SetAndActivateControl(panelTitle,"check_Settings_TP_SaveTP", val = str2numSafe(UserSettings[V_value][%SettingValue]))
FindValue /TXOP = 4 /TEXT = EXPORT_NWB UserSettings
PGC_SetAndActivateControl(panelTitle,"Check_Settings_NwbExport", val = str2numSafe(UserSettings[V_value][%SettingValue]))
FindValue /TXOP = 4 /TEXT = NWB_VERSION UserSettings
PGC_SetAndActivateControl(panelTitle,"Popup_Settings_NwbVersion", val = str2numSafe(UserSettings[V_value][%SettingValue]))
FindValue /TXOP = 4 /TEXT = APPEND_ASYNC UserSettings
PGC_SetAndActivateControl(panelTitle,"Check_Settings_Append", val = str2numSafe(UserSettings[V_value][%SettingValue]))
FindValue /TXOP = 4 /TEXT = SYNC_MIES_MCC UserSettings
Expand Down
4 changes: 3 additions & 1 deletion Packages/MIES/MIES_Menu.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ Menu "Mies Panels"
"-"
SubMenu "Neurodata Without Borders (NWB)"
"Export all data into NWB" , /Q, NWB_ExportWithDialog(NWB_EXPORT_DATA)
"-"
"Export all data into NWBv1 (legacy)" , /Q, NWB_ExportWithDialog(NWB_EXPORT_DATA, nwbVersion = 1)
"-"
"Export all stimsets into NWB" , /Q, NWB_ExportWithDialog(NWB_EXPORT_STIMSETS)
"Load Stimsets from NWB" , /Q, NWB_LoadAllStimsets()
"-"
End
"-"
"About MIES" , /Q, OpenAboutDialog()
Expand Down
Loading

0 comments on commit 1a17c89

Please sign in to comment.