{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%reload_ext autoreload\n", "%autoreload 2\n", "%matplotlib inline\n", "\n", "import warnings\n", "warnings.filterwarnings('ignore')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Handle imports" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from exact_sync.v1.api.annotations_api import AnnotationsApi\n", "from exact_sync.v1.api.images_api import ImagesApi\n", "from exact_sync.v1.api.image_sets_api import ImageSetsApi\n", "from exact_sync.v1.api.annotation_types_api import AnnotationTypesApi\n", "from exact_sync.v1.api.products_api import ProductsApi\n", "from exact_sync.v1.api.teams_api import TeamsApi\n", "\n", "from exact_sync.v1.models import ImageSet, Team, Product, AnnotationType, Image, Annotation, AnnotationMediaFile\n", "from exact_sync.v1.rest import ApiException\n", "from exact_sync.v1.configuration import Configuration\n", "from exact_sync.v1.api_client import ApiClient" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Connect to EXACT" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "configuration = Configuration()\n", "configuration.username = 'exact'\n", "configuration.password = 'exact'\n", "configuration.host = \"http://127.0.0.1:1337\"\n", "\n", "client = ApiClient(configuration)\n", "\n", "image_sets_api = ImageSetsApi(client)\n", "annotations_api = AnnotationsApi(client)\n", "annotation_types_api = AnnotationTypesApi(client)\n", "images_api = ImagesApi(client)\n", "product_api = ProductsApi(client)\n", "team_api = TeamsApi(client)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Donwload all annotaions from one imageset" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on method list_image_sets in module exact_sync.v1.api.image_sets_api:\n", "\n", "list_image_sets(pagination:bool=True, **kwargs) method of exact_sync.v1.api.image_sets_api.ImageSetsApi instance\n", " list_image_sets # noqa: E501\n", " \n", " This method makes a synchronous HTTP request by default. To make an\n", " asynchronous HTTP request, please pass async_req=True\n", " >>> thread = api.list_image_sets(async_req=True)\n", " >>> result = thread.get()\n", " \n", " :param bool pagination: active or deactive\n", " :param async_req bool\n", " :param int limit: Number of results to return per page.\n", " :param int offset: The initial index from which to return the results.\n", " :param str id: id\n", " :param str path: path\n", " :param str path__contains: path__contains\n", " :param str name: name\n", " :param str name__contains: name__contains\n", " :param str location: location\n", " :param str location__contains: location__contains\n", " :param str description: description\n", " :param str description__contains: description__contains\n", " :param str time: time\n", " :param str time__range: time__range\n", " :param str team: team\n", " :param str creator: creator\n", " :param str public: public\n", " :param str main_annotation_type: main_annotation_type\n", " :param str set_tags: set_tags\n", " :param str product: product\n", " :param str collaboration_type: collaboration_type\n", " :param str priority: priority\n", " :param str zip_state: zip_state\n", " :param str images: images\n", " :return: ImageSets\n", " If the method is called asynchronously,\n", " returns the request thread.\n", "\n" ] } ], "source": [ "help(image_sets_api.list_image_sets)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'count': 1,\n", " 'next': None,\n", " 'previous': None,\n", " 'results': [{'creator': 1,\n", " 'description': '',\n", " 'id': 161,\n", " 'images': [1436,\n", " 1437,\n", " 1438,\n", " 1439,\n", " 1440,\n", " 1441,\n", " 1442,\n", " 1443,\n", " 1444,\n", " 1445,\n", " 1446,\n", " 1447,\n", " 1448,\n", " 1449,\n", " 1450,\n", " 1451,\n", " 1452,\n", " 1453,\n", " 1454,\n", " 1455],\n", " 'location': None,\n", " 'main_annotation_type': 266,\n", " 'name': 'MICCAI Mitotic Figure Study',\n", " 'path': 'exact_166_161',\n", " 'product_set': [130],\n", " 'set_tags': [],\n", " 'team': 166}]}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "image_set = image_sets_api.list_image_sets(name__contains=\"MICCAI Mitotic Figure Study\")\n", "image_set" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "annos = []\n", "for image_id in image_set.results[0].images:\n", " \n", " for anno in annotations_api.list_annotations(image=image_id, deleted=False,pagination=False,expand=\"user,annotation_type\",fields=\"id,user,time,unique_identifier,annotation_type,vector\").results:\n", " annos.append([anno.id, anno.user[\"username\"], anno.time, anno.unique_identifier, anno.annotation_type[\"name\"], anno.vector])" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'annotation_type': {'area_hit_test': True,\n", " 'closed': True,\n", " 'color_code': '#0000FF',\n", " 'default_height': 50,\n", " 'default_width': 50,\n", " 'enable_blurred': True,\n", " 'enable_concealed': True,\n", " 'id': 266,\n", " 'name': 'mitotic figure',\n", " 'node_count': 0,\n", " 'product': 130,\n", " 'sort_order': 0,\n", " 'vector_type': 1},\n", " 'annotationversion_set': [],\n", " 'blurred': None,\n", " 'concealed': None,\n", " 'deleted': None,\n", " 'description': None,\n", " 'id': 1310601,\n", " 'image': None,\n", " 'last_edit_time': None,\n", " 'last_editor': None,\n", " 'meta_data': None,\n", " 'time': datetime.datetime(2020, 10, 23, 18, 2, 12, 170203),\n", " 'unique_identifier': 'd4adb89f-f080-4287-9854-f75bc65faba1',\n", " 'uploaded_media_files': [],\n", " 'user': {'id': 55,\n", " 'is_active': True,\n", " 'is_staff': False,\n", " 'is_superuser': False,\n", " 'last_login': None,\n", " 'team_set': [166],\n", " 'username': 'Participant_9'},\n", " 'vector': {'x1': 3690, 'x2': 3740, 'y1': 3801, 'y2': 3851},\n", " 'verified_by_user': None}" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "anno" ] }, { "cell_type": "code", "execution_count": 17, "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", " \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", " \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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idusertimeunique_identifiertypevector
01292457exact2020-10-20 16:29:55.210182842fb8c3-0de7-40f4-ae56-b5248df9f60emitotic figure{'x1': 4425, 'x2': 4475, 'y1': 3416, 'y2': 3466}
11304465Participant_102020-10-23 17:49:07.29459105345076-582f-4cc7-885e-1b81a0a8307emitotic figure{'x1': 2213, 'x2': 2263, 'y1': 4335, 'y2': 4385}
21304466Participant_102020-10-23 18:00:39.16380956b1124e-7ba7-40dc-808c-64495fee9cf2mitotic figure{'x1': 2213, 'x2': 2263, 'y1': 4335, 'y2': 4385}
31304467Participant_102020-10-23 18:00:39.1638095146dc65-7887-4994-9b4f-69b104cd643fmitotic figure{'x1': 4426, 'x2': 4476, 'y1': 3417, 'y2': 3467}
41305447Participant_132020-10-23 18:01:09.98694662632382-8a52-43aa-96c7-185b1e810390mitotic figure{'x1': 4426, 'x2': 4476, 'y1': 3418, 'y2': 3468}
.....................
68771310597Participant_92020-10-23 18:02:12.168202db139eea-0c22-41a7-be28-034b9f030859mitotic figure{'x1': 1112, 'x2': 1162, 'y1': 341, 'y2': 391}
68781310598Participant_92020-10-23 18:02:12.169204eeba4467-55e2-40ad-b57e-a9d9017871b0mitotic figure{'x1': 4499, 'x2': 4549, 'y1': 4028, 'y2': 4078}
68791310599Participant_92020-10-23 18:02:12.16920471c53fdf-4f44-40f6-ae94-611c5ada7650mitotic figure{'x1': 4277, 'x2': 4327, 'y1': 3889, 'y2': 3939}
68801310600Participant_92020-10-23 18:02:12.16920440951d62-9f68-4ab1-948a-644e16de8273mitotic figure{'x1': 3705, 'x2': 3755, 'y1': 3834, 'y2': 3884}
68811310601Participant_92020-10-23 18:02:12.170203d4adb89f-f080-4287-9854-f75bc65faba1mitotic figure{'x1': 3690, 'x2': 3740, 'y1': 3801, 'y2': 3851}
\n", "

6882 rows × 6 columns

\n", "
" ], "text/plain": [ " id user time \\\n", "0 1292457 exact 2020-10-20 16:29:55.210182 \n", "1 1304465 Participant_10 2020-10-23 17:49:07.294591 \n", "2 1304466 Participant_10 2020-10-23 18:00:39.163809 \n", "3 1304467 Participant_10 2020-10-23 18:00:39.163809 \n", "4 1305447 Participant_13 2020-10-23 18:01:09.986946 \n", "... ... ... ... \n", "6877 1310597 Participant_9 2020-10-23 18:02:12.168202 \n", "6878 1310598 Participant_9 2020-10-23 18:02:12.169204 \n", "6879 1310599 Participant_9 2020-10-23 18:02:12.169204 \n", "6880 1310600 Participant_9 2020-10-23 18:02:12.169204 \n", "6881 1310601 Participant_9 2020-10-23 18:02:12.170203 \n", "\n", " unique_identifier type \\\n", "0 842fb8c3-0de7-40f4-ae56-b5248df9f60e mitotic figure \n", "1 05345076-582f-4cc7-885e-1b81a0a8307e mitotic figure \n", "2 56b1124e-7ba7-40dc-808c-64495fee9cf2 mitotic figure \n", "3 5146dc65-7887-4994-9b4f-69b104cd643f mitotic figure \n", "4 62632382-8a52-43aa-96c7-185b1e810390 mitotic figure \n", "... ... ... \n", "6877 db139eea-0c22-41a7-be28-034b9f030859 mitotic figure \n", "6878 eeba4467-55e2-40ad-b57e-a9d9017871b0 mitotic figure \n", "6879 71c53fdf-4f44-40f6-ae94-611c5ada7650 mitotic figure \n", "6880 40951d62-9f68-4ab1-948a-644e16de8273 mitotic figure \n", "6881 d4adb89f-f080-4287-9854-f75bc65faba1 mitotic figure \n", "\n", " vector \n", "0 {'x1': 4425, 'x2': 4475, 'y1': 3416, 'y2': 3466} \n", "1 {'x1': 2213, 'x2': 2263, 'y1': 4335, 'y2': 4385} \n", "2 {'x1': 2213, 'x2': 2263, 'y1': 4335, 'y2': 4385} \n", "3 {'x1': 4426, 'x2': 4476, 'y1': 3417, 'y2': 3467} \n", "4 {'x1': 4426, 'x2': 4476, 'y1': 3418, 'y2': 3468} \n", "... ... \n", "6877 {'x1': 1112, 'x2': 1162, 'y1': 341, 'y2': 391} \n", "6878 {'x1': 4499, 'x2': 4549, 'y1': 4028, 'y2': 4078} \n", "6879 {'x1': 4277, 'x2': 4327, 'y1': 3889, 'y2': 3939} \n", "6880 {'x1': 3705, 'x2': 3755, 'y1': 3834, 'y2': 3884} \n", "6881 {'x1': 3690, 'x2': 3740, 'y1': 3801, 'y2': 3851} \n", "\n", "[6882 rows x 6 columns]" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "annos = pd.DataFrame(annos, columns=[\"id\", \"user\", \"time\", \"unique_identifier\", \"type\", \"vector\"])\n", "annos" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.6.10" } }, "nbformat": 4, "nbformat_minor": 4 }