Ejemplo n.º 1
0
 def add_scratch(self, **kwargs):
     '''Add data to the scratch space'''
     data, name, notes = getargs('data', 'name', 'notes', kwargs)
     if isinstance(data, (np.ndarray, pd.DataFrame, list, tuple)):
         if name is None:
             raise ValueError('please provide a name for scratch data')
         if isinstance(data, pd.DataFrame):
             table_description = getargs('table_description', kwargs)
             data = DynamicTable.from_dataframe(
                 df=data, name=name, table_description=table_description)
             if notes is not None:
                 warn(
                     'Notes argument is ignored when adding a pandas DataFrame to scratch'
                 )
         else:
             data = ScratchData(name=name, data=data, notes=notes)
     else:
         if notes is not None:
             warn(
                 'Notes argument is ignored when adding an NWBContainer to scratch'
             )
         if name is not None:
             warn(
                 'Name argument is ignored when adding an NWBContainer to scratch'
             )
     self._add_scratch(data)
Ejemplo n.º 2
0
 def add_scratch(self, **kwargs):
     '''Add data to the scratch space.'''
     data, name, description = getargs('data', 'name', 'description',
                                       kwargs)
     if isinstance(
             data,
         (str, int, float, bytes, np.ndarray, list, tuple, pd.DataFrame)):
         if name is None:
             msg = (
                 'A name is required for NWBFile.add_scratch when adding a scalar, numpy.ndarray, '
                 'list, tuple, or pandas.DataFrame as scratch data.')
             raise ValueError(msg)
         if description is None:
             msg = (
                 'A description is required for NWBFile.add_scratch when adding a scalar, numpy.ndarray, '
                 'list, tuple, or pandas.DataFrame as scratch data.')
             raise ValueError(msg)
         if isinstance(data, pd.DataFrame):
             data = DynamicTable.from_dataframe(
                 df=data, name=name, table_description=description)
         else:
             data = ScratchData(name=name,
                                data=data,
                                description=description)
     else:
         if name is not None:
             warn(
                 'The name argument is ignored when adding an NWBContainer, ScratchData, or '
                 'DynamicTable to scratch.')
         if description is not None:
             warn(
                 'The description argument is ignored when adding an NWBContainer, ScratchData, or '
                 'DynamicTable to scratch.')
     return self._add_scratch(data)
Ejemplo n.º 3
0
    def add_scratch(self, **kwargs):
        '''Add data to the scratch space'''
        data, name, notes, table_description, description = getargs('data', 'name', 'notes', 'table_description',
                                                                    'description', kwargs)
        if notes is not None or table_description != '':
            warn('Use of the `notes` or `table_description` argument will be removed in a future version of PyNWB. '
                 'Use the `description` argument instead.', PendingDeprecationWarning)
            if description is not None:
                raise ValueError('Cannot call add_scratch with (notes or table_description) and description')

        if isinstance(data, (str, int, float, bytes, np.ndarray, list, tuple, pd.DataFrame)):
            if name is None:
                msg = ('A name is required for NWBFile.add_scratch when adding a scalar, numpy.ndarray, '
                       'list, tuple, or pandas.DataFrame as scratch data.')
                raise ValueError(msg)
            if isinstance(data, pd.DataFrame):
                if table_description != '':
                    description = table_description  # remove after deprecation
                if description is None:
                    msg = ('A description is required for NWBFile.add_scratch when adding a scalar, numpy.ndarray, '
                           'list, tuple, or pandas.DataFrame as scratch data.')
                    raise ValueError(msg)
                data = DynamicTable.from_dataframe(df=data, name=name, table_description=description)
            else:
                if notes is not None:
                    description = notes  # remove after deprecation
                if description is None:
                    msg = ('A description is required for NWBFile.add_scratch when adding a scalar, numpy.ndarray, '
                           'list, tuple, or pandas.DataFrame as scratch data.')
                    raise ValueError(msg)
                data = ScratchData(name=name, data=data, description=description)
        else:
            if name is not None:
                warn('The name argument is ignored when adding an NWBContainer, ScratchData, or '
                     'DynamicTable to scratch.')
            if description is not None:
                warn('The description argument is ignored when adding an NWBContainer, ScratchData, or '
                     'DynamicTable to scratch.')
        return self._add_scratch(data)
Ejemplo n.º 4
0
 def setUpContainer(self):
     return DynamicTable.from_dataframe(
         pd.DataFrame({
             'a': [[1, 2, 3], [1, 2, 3], [1, 2, 3]],
             'b': ['4', '5', '6']
         }), 'test_table')
Ejemplo n.º 5
0
df = table.to_dataframe()

###############################################################################
# .. note::
#
#   Changes to the ``DataFrame`` will not be saved in the ``DynamicTable``.

###############################################################################
# Converting the table from a pandas ``DataFrame``
# ------------------------------------------------
# If your data is already in a :py:class:`~pandas.DataFrame`, you can convert the
# ``DataFrame`` to a :py:class:`~hdmf.common.table.DynamicTable` using the class method
# :py:meth:`DynamicTable.from_dataframe <hdmf.common.table.DynamicTable.from_dataframe>`.

table_from_df = DynamicTable.from_dataframe(
    name='my_table',
    df=df,
)

###############################################################################
# Accessing elements
# ------------------
# To access an element in the i-th row in the column with name "col_name" in a
# :py:class:`~hdmf.common.table.DynamicTable`, use square brackets notation:
# ``table[i, col_name]``. You can also use a tuple of row index and column
# name within the square brackets.

table[0, 'col1']  # returns 1
table[(0, 'col1')]  # returns 1

###############################################################################
# If the column is a ragged array, instead of a single value being returned,
Ejemplo n.º 6
0
 def create_module(self):
     waveform_module = ProcessingModule(name=self.name, description=self.description)
     waveform_module.add_container(
         DynamicTable.from_dataframe(self.waveform_analysis.transpose(), name=self.name))
     return waveform_module