Skip to content

Commit

Permalink
Code_FPGA_DAC_ADC
Browse files Browse the repository at this point in the history
  • Loading branch information
soulsyrup committed Nov 30, 2023
1 parent 7b13d7b commit a0bdd66
Showing 1 changed file with 294 additions and 31 deletions.
325 changes: 294 additions & 31 deletions convert_nwb_to_npy_and_df.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,253 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "fbe7cf35-bc99-421d-bb1e-bc0938310a9a",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Acquisition Groups:\n",
" - ElectricalSeries: ElectricalSeries pynwb.ecephys.ElectricalSeries at 0x139943538298736\n",
"Fields:\n",
" comments: voltage data recorded from the amplifiers of an Intan Technologies chip\n",
" conversion: 1.0\n",
" data: <HDF5 dataset \"data\": shape (386048, 128), type \"<f4\">\n",
" description: voltage data recorded from the amplifiers of an Intan Technologies chip\n",
" electrodes: electrodes <class 'hdmf.common.table.DynamicTableRegion'>\n",
" filtering: Wideband data\n",
" interval: 1\n",
" offset: 0.0\n",
" resolution: 1.95e-07\n",
" timestamp_link: (\n",
" TimeSeries_analog_output <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_digital_input <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_amp_settle <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_charge_recovery <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_compliance_limit <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_stimulation <class 'pynwb.base.TimeSeries'>\n",
" )\n",
" timestamps: <HDF5 dataset \"timestamps\": shape (386048,), type \"<f8\">\n",
" timestamps_unit: seconds\n",
" unit: volts\n",
"\n",
" - TimeSeries_analog_output: TimeSeries_analog_output pynwb.base.TimeSeries at 0x139943538301472\n",
"Fields:\n",
" comments: analog output data recorded from an Intan Technologies system\n",
" conversion: 1.0\n",
" data: <HDF5 dataset \"data\": shape (386048, 8), type \"<f8\">\n",
" description: analog output data recorded from an Intan Technologies system\n",
" interval: 1\n",
" offset: 0.0\n",
" resolution: 0.0003125\n",
" timestamps: ElectricalSeries pynwb.ecephys.ElectricalSeries at 0x139943538298736\n",
"Fields:\n",
" comments: voltage data recorded from the amplifiers of an Intan Technologies chip\n",
" conversion: 1.0\n",
" data: <HDF5 dataset \"data\": shape (386048, 128), type \"<f4\">\n",
" description: voltage data recorded from the amplifiers of an Intan Technologies chip\n",
" electrodes: electrodes <class 'hdmf.common.table.DynamicTableRegion'>\n",
" filtering: Wideband data\n",
" interval: 1\n",
" offset: 0.0\n",
" resolution: 1.95e-07\n",
" timestamp_link: (\n",
" TimeSeries_analog_output <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_digital_input <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_amp_settle <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_charge_recovery <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_compliance_limit <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_stimulation <class 'pynwb.base.TimeSeries'>\n",
" )\n",
" timestamps: <HDF5 dataset \"timestamps\": shape (386048,), type \"<f8\">\n",
" timestamps_unit: seconds\n",
" unit: volts\n",
"\n",
" timestamps_unit: seconds\n",
" unit: volts\n",
"\n",
" - TimeSeries_digital_input: TimeSeries_digital_input pynwb.base.TimeSeries at 0x139943538302000\n",
"Fields:\n",
" comments: digital input data recorded from an Intan Technologies system\n",
" conversion: 1.0\n",
" data: <HDF5 dataset \"data\": shape (386048, 8), type \"<u8\">\n",
" description: digital input data recorded from an Intan Technologies system\n",
" interval: 1\n",
" offset: 0.0\n",
" resolution: -1.0\n",
" timestamps: ElectricalSeries pynwb.ecephys.ElectricalSeries at 0x139943538298736\n",
"Fields:\n",
" comments: voltage data recorded from the amplifiers of an Intan Technologies chip\n",
" conversion: 1.0\n",
" data: <HDF5 dataset \"data\": shape (386048, 128), type \"<f4\">\n",
" description: voltage data recorded from the amplifiers of an Intan Technologies chip\n",
" electrodes: electrodes <class 'hdmf.common.table.DynamicTableRegion'>\n",
" filtering: Wideband data\n",
" interval: 1\n",
" offset: 0.0\n",
" resolution: 1.95e-07\n",
" timestamp_link: (\n",
" TimeSeries_analog_output <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_digital_input <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_amp_settle <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_charge_recovery <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_compliance_limit <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_stimulation <class 'pynwb.base.TimeSeries'>\n",
" )\n",
" timestamps: <HDF5 dataset \"timestamps\": shape (386048,), type \"<f8\">\n",
" timestamps_unit: seconds\n",
" unit: volts\n",
"\n",
" timestamps_unit: seconds\n",
" unit: digital event\n",
"\n",
"\n",
"Stimulus Groups:\n",
" - TimeSeries_amp_settle: TimeSeries_amp_settle pynwb.base.TimeSeries at 0x139943538302576\n",
"Fields:\n",
" comments: amplifier settle activity of an Intan Technologies chip\n",
" conversion: 1.0\n",
" data: <HDF5 dataset \"data\": shape (386048, 128), type \"<i8\">\n",
" description: amplifier settle activity of an Intan Technologies chip\n",
" interval: 1\n",
" offset: 0.0\n",
" resolution: -1.0\n",
" timestamps: ElectricalSeries pynwb.ecephys.ElectricalSeries at 0x139943538298736\n",
"Fields:\n",
" comments: voltage data recorded from the amplifiers of an Intan Technologies chip\n",
" conversion: 1.0\n",
" data: <HDF5 dataset \"data\": shape (386048, 128), type \"<f4\">\n",
" description: voltage data recorded from the amplifiers of an Intan Technologies chip\n",
" electrodes: electrodes <class 'hdmf.common.table.DynamicTableRegion'>\n",
" filtering: Wideband data\n",
" interval: 1\n",
" offset: 0.0\n",
" resolution: 1.95e-07\n",
" timestamp_link: (\n",
" TimeSeries_analog_output <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_digital_input <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_amp_settle <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_charge_recovery <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_compliance_limit <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_stimulation <class 'pynwb.base.TimeSeries'>\n",
" )\n",
" timestamps: <HDF5 dataset \"timestamps\": shape (386048,), type \"<f8\">\n",
" timestamps_unit: seconds\n",
" unit: volts\n",
"\n",
" timestamps_unit: seconds\n",
" unit: digital event\n",
"\n",
" - TimeSeries_charge_recovery: TimeSeries_charge_recovery pynwb.base.TimeSeries at 0x139943538303104\n",
"Fields:\n",
" comments: charge recovery activity of an Intan Technologies chip\n",
" conversion: 1.0\n",
" data: <HDF5 dataset \"data\": shape (386048, 128), type \"<i8\">\n",
" description: charge recovery activity of an Intan Technologies chip\n",
" interval: 1\n",
" offset: 0.0\n",
" resolution: -1.0\n",
" timestamps: ElectricalSeries pynwb.ecephys.ElectricalSeries at 0x139943538298736\n",
"Fields:\n",
" comments: voltage data recorded from the amplifiers of an Intan Technologies chip\n",
" conversion: 1.0\n",
" data: <HDF5 dataset \"data\": shape (386048, 128), type \"<f4\">\n",
" description: voltage data recorded from the amplifiers of an Intan Technologies chip\n",
" electrodes: electrodes <class 'hdmf.common.table.DynamicTableRegion'>\n",
" filtering: Wideband data\n",
" interval: 1\n",
" offset: 0.0\n",
" resolution: 1.95e-07\n",
" timestamp_link: (\n",
" TimeSeries_analog_output <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_digital_input <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_amp_settle <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_charge_recovery <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_compliance_limit <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_stimulation <class 'pynwb.base.TimeSeries'>\n",
" )\n",
" timestamps: <HDF5 dataset \"timestamps\": shape (386048,), type \"<f8\">\n",
" timestamps_unit: seconds\n",
" unit: volts\n",
"\n",
" timestamps_unit: seconds\n",
" unit: digital event\n",
"\n",
" - TimeSeries_compliance_limit: TimeSeries_compliance_limit pynwb.base.TimeSeries at 0x139943538303632\n",
"Fields:\n",
" comments: compliance limit activity of an Intan Technologies chip\n",
" conversion: 1.0\n",
" data: <HDF5 dataset \"data\": shape (386048, 128), type \"<i8\">\n",
" description: compliance limit activity of an Intan Technologies chip\n",
" interval: 1\n",
" offset: 0.0\n",
" resolution: -1.0\n",
" timestamps: ElectricalSeries pynwb.ecephys.ElectricalSeries at 0x139943538298736\n",
"Fields:\n",
" comments: voltage data recorded from the amplifiers of an Intan Technologies chip\n",
" conversion: 1.0\n",
" data: <HDF5 dataset \"data\": shape (386048, 128), type \"<f4\">\n",
" description: voltage data recorded from the amplifiers of an Intan Technologies chip\n",
" electrodes: electrodes <class 'hdmf.common.table.DynamicTableRegion'>\n",
" filtering: Wideband data\n",
" interval: 1\n",
" offset: 0.0\n",
" resolution: 1.95e-07\n",
" timestamp_link: (\n",
" TimeSeries_analog_output <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_digital_input <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_amp_settle <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_charge_recovery <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_compliance_limit <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_stimulation <class 'pynwb.base.TimeSeries'>\n",
" )\n",
" timestamps: <HDF5 dataset \"timestamps\": shape (386048,), type \"<f8\">\n",
" timestamps_unit: seconds\n",
" unit: volts\n",
"\n",
" timestamps_unit: seconds\n",
" unit: digital event\n",
"\n",
" - TimeSeries_stimulation: TimeSeries_stimulation pynwb.base.TimeSeries at 0x139943538304160\n",
"Fields:\n",
" comments: current stimulation activity of an Intan Technologies chip\n",
" conversion: 1.0\n",
" data: <HDF5 dataset \"data\": shape (386048, 128), type \"<f8\">\n",
" description: current stimulation activity of an Intan Technologies chip\n",
" interval: 1\n",
" offset: 0.0\n",
" resolution: 1.0000000116860974e-07\n",
" timestamps: ElectricalSeries pynwb.ecephys.ElectricalSeries at 0x139943538298736\n",
"Fields:\n",
" comments: voltage data recorded from the amplifiers of an Intan Technologies chip\n",
" conversion: 1.0\n",
" data: <HDF5 dataset \"data\": shape (386048, 128), type \"<f4\">\n",
" description: voltage data recorded from the amplifiers of an Intan Technologies chip\n",
" electrodes: electrodes <class 'hdmf.common.table.DynamicTableRegion'>\n",
" filtering: Wideband data\n",
" interval: 1\n",
" offset: 0.0\n",
" resolution: 1.95e-07\n",
" timestamp_link: (\n",
" TimeSeries_analog_output <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_digital_input <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_amp_settle <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_charge_recovery <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_compliance_limit <class 'pynwb.base.TimeSeries'>,\n",
" TimeSeries_stimulation <class 'pynwb.base.TimeSeries'>\n",
" )\n",
" timestamps: <HDF5 dataset \"timestamps\": shape (386048,), type \"<f8\">\n",
" timestamps_unit: seconds\n",
" unit: volts\n",
"\n",
" timestamps_unit: seconds\n",
" unit: amps\n",
"\n"
]
}
],
"source": [
"from pynwb import NWBHDF5IO\n",
"\n",
Expand Down Expand Up @@ -50,7 +293,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "6a92f750-5b15-4deb-a902-583900418978",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -118,41 +361,61 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"id": "d6d160ab-6151-4e08-9fc5-60479f167514",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Saved: ElectricalSeries_acquisition.csv\n",
"Saved: TimeSeries_analog_output_acquisition.csv\n",
"Saved: TimeSeries_digital_input_acquisition.csv\n",
"Saved: TimeSeries_amp_settle_stimulus.csv\n",
"Saved: TimeSeries_charge_recovery_stimulus.csv\n",
"Saved: TimeSeries_compliance_limit_stimulus.csv\n",
"Saved: TimeSeries_stimulation_stimulus.csv\n"
]
}
],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"\n",
"for name, data in acquisition_data.items():\n",
" # Check if data is two-dimensional\n",
" if data['data'].ndim == 2:\n",
" # Create column names for each dimension\n",
" column_names = [f'{name}_dim_{i}' for i in range(data['data'].shape[1])]\n",
" else:\n",
" # For one-dimensional data, use a single column\n",
" column_names = [f'{name}_value']\n",
"\n",
" df = pd.DataFrame(data['data'], columns=column_names)\n",
" if data['timestamps'] is not None:\n",
" df['timestamps'] = data['timestamps']\n",
" df.to_csv(f'{name}_acquisition.csv', index=False)\n",
"\n",
"for name, data in stimulus_data.items():\n",
" # Check if data is two-dimensional\n",
" if data['data'].ndim == 2:\n",
" # Create column names for each dimension\n",
" column_names = [f'{name}_dim_{i}' for i in range(data['data'].shape[1])]\n",
" else:\n",
" # For one-dimensional data, use a single column\n",
" column_names = [f'{name}_value']\n",
"def save_to_csv(data_dict, file_suffix):\n",
" for name, data in data_dict.items():\n",
" # Create column names based on the shape of the data\n",
" column_names = [f'{name}_{i}' for i in range(data['data'].shape[1])]\n",
" \n",
" # Create a DataFrame\n",
" df = pd.DataFrame(data['data'], columns=column_names)\n",
" \n",
" # Drop columns where all values are zero\n",
" df = df.loc[:, (df != 0).any(axis=0)]\n",
" \n",
" # Add timestamps if available\n",
" if data['timestamps'] is not None:\n",
" df.insert(0, 'timestamps', data['timestamps'])\n",
" \n",
" # Save DataFrame to CSV\n",
" csv_filename = f'{name}_{file_suffix}.csv'\n",
" df.to_csv(csv_filename, index=False)\n",
" print(f'Saved: {csv_filename}')\n",
"\n",
" df = pd.DataFrame(data['data'], columns=column_names)\n",
" if data['timestamps'] is not None:\n",
" df['timestamps'] = data['timestamps']\n",
" df.to_csv(f'{name}_stimulus.csv', index=False)"
"# Assuming acquisition_data and stimulus_data are dictionaries \n",
"# containing your extracted data and timestamps:\n",
"save_to_csv(acquisition_data, 'acquisition')\n",
"save_to_csv(stimulus_data, 'stimulus')\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "87c4eecf-80ed-408c-8038-b5e8d9810703",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit a0bdd66

Please sign in to comment.