This is from a Jupyter Notebook. View & download the notebook here.


Create a Pattern Set

Note

Note that API documentation is available at https://auviewer.readthedocs.io/ and via the help() Python method (see the “Getting Documentation via Help()” example notebook.

Load AUViewer API

[1]:
# Import the AUViewer API and set the data path
import auviewer.api as api
api.setDataPath('~/myproject')

Load Project

[2]:
# Load project
p = api.loadProject(1)

Create a New Pattern Set

[3]:
# No pattern sets exist yet.
p.listPatternSets()
[3]:
[]
[4]:
# Create a new pattern set
ps = p.createPatternSet(name='Interesting Alerts', description='These are some interesting alerts I wanted to share.')
[5]:
# There it is!
p.listPatternSets()
[5]:
[[1, 'Interesting Alerts']]

Get & Populate the Patterns DataFrame

[6]:
# Let's see what pattern set API methods are available
help(ps)
Help on PatternSet in module auviewer.patternset object:

class PatternSet(builtins.object)
 |  PatternSet(projparent, dbmodel)
 |
 |  Represents a pattern set.
 |
 |  Methods defined here:
 |
 |  __init__(self, projparent, dbmodel)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |
 |  addPatterns(self, df, validate=True)
 |      Add patterns to the pattern set. By default, the rows will be validated (e.g. for matching file ID & filename).
 |      This may be skipped in the case of extremely high volume, but it may lead to database integrity issues to do so.
 |
 |      During validation, if filename is present and file_id is not, then file_id will be populated according to the
 |      filename. If both are populated, then the file_id will be validated to match the filename. The provided pattern
 |      set must contain 'file_id' and/or 'filename' columns as well as ['series', 'left', 'right', 'label'].
 |      :return: None
 |
 |  assignToUsers(self, user_ids: Union[int, List[int]]) -> None
 |      Assign the pattern set to user(s).
 |      :param user_ids: May be single user ID or list of user IDs.
 |      :return: None
 |
 |  delete(self, deletePatterns=False)
 |      Deletes the pattern set from the database and the parent project
 |      instance. If the pattern set has patterns, the deletion will fail,
 |      unless the deletePatterns flag is True, in which case it will first
 |      delete the child patterns.
 |
 |  deletePatterns(self) -> int
 |      Delete the patterns belonging to this pattern set.
 |      :return: number of deleted patterns
 |
 |  deleteUnannotatedPatterns(self) -> int
 |      Delete all patterns which have not yet been annotated from the set.
 |      :return: number of deleted patterns
 |
 |  getAnnotationCount(self) -> int
 |      Returns a count of annotations which annotate any pattern in this set.
 |
 |  getAnnotations(self) -> pandas.core.frame.DataFrame
 |      Returns a DataFrame of the annotations in this set.
 |
 |  getPatternCount(self) -> int
 |      Returns a count of the patterns in this set.
 |
 |  getPatterns(self) -> pandas.core.frame.DataFrame
 |      Returns a DataFrame of the patterns in this set.
 |
 |  refresh(self)
 |      Refresh model & update the count of patterns belonging to this set
 |      (this is normally an internally-used method).
 |
 |  setDescription(self, description: str)
 |      Set the pattern set's description.
 |
 |  setName(self, name: str)
 |      Set the pattern set's name.
 |
 |  setShowByDefault(self, show: bool)
 |      Set whether a pattern set should show by default.
 |
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |
 |  __dict__
 |      dictionary for instance variables (if defined)
 |
 |  __weakref__
 |      list of weak references to the object (if defined)

[7]:
# Get the patterns DataFrame (will be empty)
patterns = ps.getPatterns()
patterns
[7]:
file_id filename series left right top bottom label pattern_identifier
[8]:
# Add a pattern to the DataFrame
patterns = patterns.append({
    'filename': 'sample_patient.h5',
    'series': '/numerics/HR.HR:value',
    'left': 1537603200.0,
    'right': 1537603500.0,
    'label': 'afib'
}, ignore_index=True)
patterns
[8]:
file_id filename series left right top bottom label pattern_identifier
0 NaN sample_patient.h5 /numerics/HR.HR:value 1.537603e+09 1.537604e+09 NaN NaN afib NaN

Add the Patterns to the Pattern Set

[9]:
# Add the new pattern(s) to the pattern set
ps.addPatterns(patterns)

We can confirm it’s added!

[10]:
ps.getPatterns()
[10]:
file_id filename series left right top bottom label pattern_identifier
0 1 sample_patient.h5 /numerics/HR.HR:value 1.537603e+09 1.537604e+09 None None afib 1_1_/numerics/HR.HR:value_1537603200.0_1537603...