pypore.filetypes.data_file module

Created on Jan 28, 2014

@author: @parkin

class pypore.filetypes.data_file.DataFile(filename, mode='r', title='', root_uep='/', filters=None, **kwargs)[source]

Bases: tables.file.File

PyTables HDF5 database storing raw data. Inherits from tables.file.File, so you can interact with this just as you would a PyTables File object. However, this contains some extra convenience methods for storing/reading data. Note that DataFile allows you to interact with this PyTables file in the usual PyTables file manner, so you can potentially mangle the data from the original DataFile format.

Automatically adds matrix /data

Must be instantiated by calling pypore.filetypes.data_file.open_file()

>>> import pypore.dataFile as df
>>> database = df.open_file(tests,mode='w')
>>> # Now do stuff with the DataFile
>>> # ...
>>> # Close and remove the DataFile
>>> database.close()
>>> os.remove(tests)
clean_database()[source]

Removes /events and then re-initializes the /events group. Note that any references to any table/matrix in this group will be broken and need to be refreshed.

>>> h5 = open_file(tests,mode='a')
>>> table = h5.get_event_table()
>>> h5.clean_database() // table is now refers to deleted table
>>> table = h5.get_event_table() // table now refers to live table
get_data_length()[source]

Note this will flush the table so the data is correct. :returns: The number of rows in the data matrix.

get_sample_rate()[source]
Returns:The sample rate at root.attrs.sample_rate
initialize_database(**kargs)[source]

Initializes the data_file.

Parameters:kargs – Can pass in ‘n_points’: Maximum number of data points for an event to be added.
pypore.filetypes.data_file.open_file(*args, **kargs)[source]

Opens a DataFile, which is a subclass of tables.file.File and can be treated as such.

Parameters:
  • args – Arguments that get passed to tables.openFile().
  • kargs

    Arguments that get passed to tables.openFile(). Should additionally include:

    • n_points: Number of points that should be in the array.
    • sample_rate: Sample rate of the data.
Returns:

pypore.filetypes.data_file.DataFile – an already opened pypore.filetypes.data_file.DataFile.

>>> import pypore.filetypes.data_file as df
>>> df.open_file('tests.h5', mode='w')