Skip to content

Commit

Permalink
add to_csv method to Electrodes
Browse files Browse the repository at this point in the history
  • Loading branch information
TomDonoghue committed May 25, 2024
1 parent a772b57 commit fab0489
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
18 changes: 18 additions & 0 deletions convnwb/objects/electrodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from copy import deepcopy

from convnwb.io.utils import get_files, check_ext, check_folder
from convnwb.modutils.dependencies import safe_import, check_dependency

pd = safe_import('pandas')
Expand Down Expand Up @@ -168,3 +169,20 @@ def to_dataframe(self):
"""Return object data as a dataframe."""

return pd.DataFrame(self.to_dict())


@check_dependency(pd, 'pandas')
def to_csv(self, file_name, folder=None, **kwargs):
"""Save out the electrode information as a CSV file.
Parameters
----------
file_name : str
The file name to save.
folder : str
The folder to save the file to.
**kwargs
Additional keyword arguments to pass to pd.DataFrame.to_csv().
"""

self.to_dataframe().to_csv(check_ext(check_folder(file_name, folder), '.csv'), **kwargs)
10 changes: 10 additions & 0 deletions convnwb/tests/objects/test_electrodes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"""Tests for convnwb.objects.electrodes"""

import os

import pandas as pd

from convnwb.tests.tsettings import TEST_FILE_PATH

from convnwb.objects.electrodes import *

###################################################################################################
Expand Down Expand Up @@ -79,3 +83,9 @@ def test_electrodes_to_dataframe(telectrodes):
df = telectrodes.to_dataframe()
assert isinstance(df, pd.DataFrame)
assert len(df) == telectrodes.n_bundles * telectrodes.n_electrodes_per_bundle

def test_electrodes_to_csv(telectrodes):

test_fname = 'test_electrodes_csv'
telectrodes.to_csv(test_fname, TEST_FILE_PATH)
assert os.path.exists(TEST_FILE_PATH / (test_fname + '.csv'))

0 comments on commit fab0489

Please sign in to comment.