pypore.filetypes.event_database module¶
Created on Sep 13, 2013
@author: @parkin
- class pypore.filetypes.event_database.EventDatabase(filename, mode='r', title='', root_uep='/', filters=None, **kwargs)[source]¶
Bases: tables.file.File
PyTables HDF5 database storing events and corresponding 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 events and event data. Note that EventDatabase allows you to interact with this PyTables file in the usual PyTables file manner, so you can potentially mangle the data from the original EventDatabase format.
Automatically adds a group /events With table /events/eventTable and matrices /events/raw_data, /event/levels, and /event/levelLength
Must be instantiated by calling eventDatabase’s
>>> import pypore.eventDatabase as ed >>> database = ed.open_file('tests.h5',mode='w') >>> database.close() >>> os.remove('tests.h5')
- DEFAULT_MAX_EVENT_LENGTH = 100¶
- append_event(array_row, event_start, event_length, n_levels, raw_points_per_side, baseline, current_blockage, area, raw_data=None, levels=None, level_lengths=None)[source]¶
Appends an event with the specified values to the eventsTable. If raw_data, levels, or level_lengths are included, they are added to the corresponding matrices.
Parameters: - array_row (Int) – The row in the raw_data, levels, and level_lengths array that corresponds to this event.
- event_start – The starting index of this event in the data.
- event_length – Number of data points in the event.
- n_levels – Number of levels in the event.
- raw_points_per_side – Number of extra points kept on either side of the event in raw_data.
- baseline – Open-pore current at the time of the event.
- current_blockage – The mean current blockage of the event.
- area – The area of the event.
- raw_data – Numpy array of the raw data.
- levels – Numpy array of the levels.
- level_lengths – Numpy array of the level lengths.
- append_level_lengths(level_lengths)[source]¶
Appends a numpy matrix level_lengths to root.events.level_lengths
- 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.h5',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
- event_row = None¶
- get_event_count()[source]¶
Returns the number of rows in the /events/eventTable table. Note this will flush the table so the data is correct.
- get_event_data_at(i)[source]¶
Returns the event data portion of raw_data[i], ie excluding the raw buffer points kept on each side of an event.
- get_event_row(i)[source]¶
Returns the ith row in /events/eventTable. Throws IndexOutOfBounds or similar error if i out of bounds. Note this flushes the eventTable before returning.
- get_event_table_row()[source]¶
Gets the PyTables Row object of the eventTable. root.events.eventTable.row
If you need a specific row in eventTable, use getEventRow(i)
- get_level_lengths_at(i)[source]¶
Returns a numpy array of the level_lengths corresponding to the event in row ‘i’ of eventTable.
- get_levels_at(i)[source]¶
Returns a numpy array of the levels corresponding to the event in row ‘i’ of eventTable.
- initialize_database(**kargs)[source]¶
Initializes the EventDatabase. Adds a group ‘events’ with table ‘eventsTable’ and matrices ‘raw_data’, ‘levels’, and ‘level_lengths’.
Parameters: kargs – Dictionary - includes: -maxEventLength: Maximum number of datapoints for an event to be added.
- max_event_length = 100¶
- remove_event(i)[source]¶
Deletes event i from /events/eventTable. Does nothing if i < 0 or i >= eventCount. Note the table will be flushed. Note that deleting a row in a table of length 1 is not currently supported.
- remove_events(i, j)[source]¶
Deletes events [i,j) from /events/eventTable. Does nothing if deleting out of range events is requested. Note the table will be flushed. Note that deleting all the rows in a table is not currently supported. Refer to cleanDatabase for deleting everything.
- Args:
- i - First entry to delete. Must be within range
- 0 < i < eventCount
- j - 1 past last entry to delete. Must be within range
- i < j <= eventCount
- pypore.filetypes.event_database.open_file(*args, **kargs)[source]¶
Opens an EventDatabase by calling tables.openFile and then copying the __dict__ to a new EventDatabase instance.
Parameters: kargs – Pass in the following named parameters.
- maxEventLength: Maximum length of an event for the table. Default is 100.
- debug: boolean – If debug, an extra root.debug group will be created. If passing debug=True, then you need to also pass the following parameters. This mode is used by pypore.event_finder.find_events(), and only does anything if you are opening a new databse.
- n_points: number of points in the original data.
- n_channels: number of channels in the original data.
And optional parameters
- threshold_positive: boolean – True if you need an array allocated for positive threshold.
- threshold_negative: boolean – True if you need an array allocated to keep negative threshold data.