From a0bdd66bf39f6722f70e40c62ffddfada3149d9a Mon Sep 17 00:00:00 2001 From: soulsyrup <121889618+soulsyrup@users.noreply.github.com> Date: Thu, 30 Nov 2023 15:42:32 -0300 Subject: [PATCH] Code_FPGA_DAC_ADC --- convert_nwb_to_npy_and_df.ipynb | 325 +++++++++++++++++++++++++++++--- 1 file changed, 294 insertions(+), 31 deletions(-) diff --git a/convert_nwb_to_npy_and_df.ipynb b/convert_nwb_to_npy_and_df.ipynb index df9563ef..83ad4721 100644 --- a/convert_nwb_to_npy_and_df.ipynb +++ b/convert_nwb_to_npy_and_df.ipynb @@ -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: \n", + " description: voltage data recorded from the amplifiers of an Intan Technologies chip\n", + " electrodes: electrodes \n", + " filtering: Wideband data\n", + " interval: 1\n", + " offset: 0.0\n", + " resolution: 1.95e-07\n", + " timestamp_link: (\n", + " TimeSeries_analog_output ,\n", + " TimeSeries_digital_input ,\n", + " TimeSeries_amp_settle ,\n", + " TimeSeries_charge_recovery ,\n", + " TimeSeries_compliance_limit ,\n", + " TimeSeries_stimulation \n", + " )\n", + " timestamps: \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: \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: \n", + " description: voltage data recorded from the amplifiers of an Intan Technologies chip\n", + " electrodes: electrodes \n", + " filtering: Wideband data\n", + " interval: 1\n", + " offset: 0.0\n", + " resolution: 1.95e-07\n", + " timestamp_link: (\n", + " TimeSeries_analog_output ,\n", + " TimeSeries_digital_input ,\n", + " TimeSeries_amp_settle ,\n", + " TimeSeries_charge_recovery ,\n", + " TimeSeries_compliance_limit ,\n", + " TimeSeries_stimulation \n", + " )\n", + " timestamps: \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: \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: \n", + " description: voltage data recorded from the amplifiers of an Intan Technologies chip\n", + " electrodes: electrodes \n", + " filtering: Wideband data\n", + " interval: 1\n", + " offset: 0.0\n", + " resolution: 1.95e-07\n", + " timestamp_link: (\n", + " TimeSeries_analog_output ,\n", + " TimeSeries_digital_input ,\n", + " TimeSeries_amp_settle ,\n", + " TimeSeries_charge_recovery ,\n", + " TimeSeries_compliance_limit ,\n", + " TimeSeries_stimulation \n", + " )\n", + " timestamps: \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: \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: \n", + " description: voltage data recorded from the amplifiers of an Intan Technologies chip\n", + " electrodes: electrodes \n", + " filtering: Wideband data\n", + " interval: 1\n", + " offset: 0.0\n", + " resolution: 1.95e-07\n", + " timestamp_link: (\n", + " TimeSeries_analog_output ,\n", + " TimeSeries_digital_input ,\n", + " TimeSeries_amp_settle ,\n", + " TimeSeries_charge_recovery ,\n", + " TimeSeries_compliance_limit ,\n", + " TimeSeries_stimulation \n", + " )\n", + " timestamps: \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: \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: \n", + " description: voltage data recorded from the amplifiers of an Intan Technologies chip\n", + " electrodes: electrodes \n", + " filtering: Wideband data\n", + " interval: 1\n", + " offset: 0.0\n", + " resolution: 1.95e-07\n", + " timestamp_link: (\n", + " TimeSeries_analog_output ,\n", + " TimeSeries_digital_input ,\n", + " TimeSeries_amp_settle ,\n", + " TimeSeries_charge_recovery ,\n", + " TimeSeries_compliance_limit ,\n", + " TimeSeries_stimulation \n", + " )\n", + " timestamps: \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: \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: \n", + " description: voltage data recorded from the amplifiers of an Intan Technologies chip\n", + " electrodes: electrodes \n", + " filtering: Wideband data\n", + " interval: 1\n", + " offset: 0.0\n", + " resolution: 1.95e-07\n", + " timestamp_link: (\n", + " TimeSeries_analog_output ,\n", + " TimeSeries_digital_input ,\n", + " TimeSeries_amp_settle ,\n", + " TimeSeries_charge_recovery ,\n", + " TimeSeries_compliance_limit ,\n", + " TimeSeries_stimulation \n", + " )\n", + " timestamps: \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: \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: \n", + " description: voltage data recorded from the amplifiers of an Intan Technologies chip\n", + " electrodes: electrodes \n", + " filtering: Wideband data\n", + " interval: 1\n", + " offset: 0.0\n", + " resolution: 1.95e-07\n", + " timestamp_link: (\n", + " TimeSeries_analog_output ,\n", + " TimeSeries_digital_input ,\n", + " TimeSeries_amp_settle ,\n", + " TimeSeries_charge_recovery ,\n", + " TimeSeries_compliance_limit ,\n", + " TimeSeries_stimulation \n", + " )\n", + " timestamps: \n", + " timestamps_unit: seconds\n", + " unit: volts\n", + "\n", + " timestamps_unit: seconds\n", + " unit: amps\n", + "\n" + ] + } + ], "source": [ "from pynwb import NWBHDF5IO\n", "\n", @@ -50,7 +293,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "6a92f750-5b15-4deb-a902-583900418978", "metadata": {}, "outputs": [], @@ -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": {