{ "cells": [ { "cell_type": "markdown", "id": "486f2bc8", "metadata": {}, "source": [ "# Create a Pattern Set" ] }, { "cell_type": "markdown", "id": "59cb72d9", "metadata": {}, "source": [ "## Note" ] }, { "cell_type": "markdown", "id": "c4ddbe4b", "metadata": {}, "source": [ "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." ] }, { "cell_type": "markdown", "id": "cf44e459", "metadata": {}, "source": [ "## Load AUViewer API" ] }, { "cell_type": "code", "execution_count": 1, "id": "527fcaec", "metadata": {}, "outputs": [], "source": [ "# Import the AUViewer API and set the data path\n", "import auviewer.api as api\n", "api.setDataPath('~/myproject')" ] }, { "cell_type": "markdown", "id": "18ce4dcf", "metadata": {}, "source": [ "## Load Project" ] }, { "cell_type": "code", "execution_count": 2, "id": "b5395b9f", "metadata": {}, "outputs": [], "source": [ "# Load project\n", "p = api.loadProject(1)" ] }, { "cell_type": "markdown", "id": "9555d176", "metadata": {}, "source": [ "## Create a New Pattern Set" ] }, { "cell_type": "code", "execution_count": 3, "id": "08c2bcb1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# No pattern sets exist yet.\n", "p.listPatternSets()" ] }, { "cell_type": "code", "execution_count": 4, "id": "1bdad2a6", "metadata": {}, "outputs": [], "source": [ "# Create a new pattern set\n", "ps = p.createPatternSet(name='Interesting Alerts', description='These are some interesting alerts I wanted to share.')" ] }, { "cell_type": "code", "execution_count": 5, "id": "a810a031", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[[1, 'Interesting Alerts']]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# There it is!\n", "p.listPatternSets()" ] }, { "cell_type": "markdown", "id": "e0c1cbee", "metadata": {}, "source": [ "## Get & Populate the Patterns DataFrame" ] }, { "cell_type": "code", "execution_count": 6, "id": "c548e76b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on PatternSet in module auviewer.patternset object:\n", "\n", "class PatternSet(builtins.object)\n", " | PatternSet(projparent, dbmodel)\n", " | \n", " | Represents a pattern set.\n", " | \n", " | Methods defined here:\n", " | \n", " | __init__(self, projparent, dbmodel)\n", " | Initialize self. See help(type(self)) for accurate signature.\n", " | \n", " | addPatterns(self, df, validate=True)\n", " | Add patterns to the pattern set. By default, the rows will be validated (e.g. for matching file ID & filename).\n", " | This may be skipped in the case of extremely high volume, but it may lead to database integrity issues to do so.\n", " | \n", " | During validation, if filename is present and file_id is not, then file_id will be populated according to the\n", " | filename. If both are populated, then the file_id will be validated to match the filename. The provided pattern\n", " | set must contain 'file_id' and/or 'filename' columns as well as ['series', 'left', 'right', 'label'].\n", " | :return: None\n", " | \n", " | assignToUsers(self, user_ids: Union[int, List[int]]) -> None\n", " | Assign the pattern set to user(s).\n", " | :param user_ids: May be single user ID or list of user IDs.\n", " | :return: None\n", " | \n", " | delete(self, deletePatterns=False)\n", " | Deletes the pattern set from the database and the parent project\n", " | instance. If the pattern set has patterns, the deletion will fail,\n", " | unless the deletePatterns flag is True, in which case it will first\n", " | delete the child patterns.\n", " | \n", " | deletePatterns(self) -> int\n", " | Delete the patterns belonging to this pattern set.\n", " | :return: number of deleted patterns\n", " | \n", " | deleteUnannotatedPatterns(self) -> int\n", " | Delete all patterns which have not yet been annotated from the set.\n", " | :return: number of deleted patterns\n", " | \n", " | getAnnotationCount(self) -> int\n", " | Returns a count of annotations which annotate any pattern in this set.\n", " | \n", " | getAnnotations(self) -> pandas.core.frame.DataFrame\n", " | Returns a DataFrame of the annotations in this set.\n", " | \n", " | getPatternCount(self) -> int\n", " | Returns a count of the patterns in this set.\n", " | \n", " | getPatterns(self) -> pandas.core.frame.DataFrame\n", " | Returns a DataFrame of the patterns in this set.\n", " | \n", " | refresh(self)\n", " | Refresh model & update the count of patterns belonging to this set\n", " | (this is normally an internally-used method).\n", " | \n", " | setDescription(self, description: str)\n", " | Set the pattern set's description.\n", " | \n", " | setName(self, name: str)\n", " | Set the pattern set's name.\n", " | \n", " | setShowByDefault(self, show: bool)\n", " | Set whether a pattern set should show by default.\n", " | \n", " | ----------------------------------------------------------------------\n", " | Data descriptors defined here:\n", " | \n", " | __dict__\n", " | dictionary for instance variables (if defined)\n", " | \n", " | __weakref__\n", " | list of weak references to the object (if defined)\n", "\n" ] } ], "source": [ "# Let's see what pattern set API methods are available\n", "help(ps)" ] }, { "cell_type": "code", "execution_count": 7, "id": "ad36987f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
file_idfilenameseriesleftrighttopbottomlabelpattern_identifier
\n", "
" ], "text/plain": [ "Empty DataFrame\n", "Columns: [file_id, filename, series, left, right, top, bottom, label, pattern_identifier]\n", "Index: []" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Get the patterns DataFrame (will be empty)\n", "patterns = ps.getPatterns()\n", "patterns" ] }, { "cell_type": "code", "execution_count": 8, "id": "47d3ee50", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
file_idfilenameseriesleftrighttopbottomlabelpattern_identifier
0NaNsample_patient.h5/numerics/HR.HR:value1.537603e+091.537604e+09NaNNaNafibNaN
\n", "
" ], "text/plain": [ " file_id filename series left \\\n", "0 NaN sample_patient.h5 /numerics/HR.HR:value 1.537603e+09 \n", "\n", " right top bottom label pattern_identifier \n", "0 1.537604e+09 NaN NaN afib NaN " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Add a pattern to the DataFrame\n", "patterns = patterns.append({\n", " 'filename': 'sample_patient.h5',\n", " 'series': '/numerics/HR.HR:value',\n", " 'left': 1537603200.0,\n", " 'right': 1537603500.0,\n", " 'label': 'afib'\n", "}, ignore_index=True)\n", "patterns" ] }, { "cell_type": "markdown", "id": "7c9c70a3", "metadata": {}, "source": [ "## Add the Patterns to the Pattern Set" ] }, { "cell_type": "code", "execution_count": 9, "id": "cf0737c6", "metadata": {}, "outputs": [], "source": [ "# Add the new pattern(s) to the pattern set\n", "ps.addPatterns(patterns)" ] }, { "cell_type": "markdown", "id": "042d2661", "metadata": {}, "source": [ "## We can confirm it's added!" ] }, { "cell_type": "code", "execution_count": 10, "id": "d5d034c2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
file_idfilenameseriesleftrighttopbottomlabelpattern_identifier
01sample_patient.h5/numerics/HR.HR:value1.537603e+091.537604e+09NoneNoneafib1_1_/numerics/HR.HR:value_1537603200.0_1537603...
\n", "
" ], "text/plain": [ " file_id filename series left \\\n", "0 1 sample_patient.h5 /numerics/HR.HR:value 1.537603e+09 \n", "\n", " right top bottom label \\\n", "0 1.537604e+09 None None afib \n", "\n", " pattern_identifier \n", "0 1_1_/numerics/HR.HR:value_1537603200.0_1537603... " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ps.getPatterns()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.11" } }, "nbformat": 4, "nbformat_minor": 5 }