Skip to content

Commit

Permalink
Improve linting and consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey committed Dec 1, 2023
1 parent bbb91e2 commit 26a8788
Show file tree
Hide file tree
Showing 116 changed files with 694 additions and 564 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ jobs:
name: Install dependencies
command: sudo apt-get update -yq && sudo apt install -yq pandoc
- tox:
env: docs,flake8
env: docs,lint
- store_artifacts:
path: docs/_build/html
- persist_to_workspace:
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,10 @@ repos:
rev: 6.1.0
hooks:
- id: flake8
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.3
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
types_or: [python, pyi]
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@
man_pages = [
('index', 'HistomicsTK',
'HistomicsTK Documentation',
['Kitware, Inc.'], 1)
['Kitware, Inc.'], 1),
]

# If true, show URL addresses after external links.
Expand Down
20 changes: 10 additions & 10 deletions docs/examples/annotation_database_backup_and_sql_parser.ipynb

Large diffs are not rendered by default.

56 changes: 28 additions & 28 deletions docs/examples/annotations_to_object_segmentation_masks.ipynb

Large diffs are not rendered by default.

58 changes: 29 additions & 29 deletions docs/examples/annotations_to_semantic_segmentation_masks.ipynb

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions docs/examples/color_deconvolution.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@
"import histomicstk as htk\n",
"\n",
"import numpy as np\n",
"import scipy as sp\n",
"\n",
"import skimage.io\n",
"import skimage.measure\n",
"import skimage.color\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib.patches as mpatches\n",
"%matplotlib inline\n",
"\n",
"#Some nice default configuration for plots\n",
Expand Down Expand Up @@ -230,7 +228,7 @@
"\n",
"# perform sparse color deconvolution\n",
"imDeconvolved = htk.preprocessing.color_deconvolution.color_deconvolution(\n",
" imInput, \n",
" imInput,\n",
" htk.preprocessing.color_deconvolution.complement_stain_matrix(W_est),\n",
" I_0,\n",
")\n",
Expand Down
14 changes: 7 additions & 7 deletions docs/examples/color_normalization_and_augmentation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"outputs": [],
"source": [
"APIURL = 'http://candygram.neurology.emory.edu:8080/api/v1/'\n",
"SAMPLE_SLIDE_ID = \"5d817f5abd4404c6b1f744bb\"\n",
"SAMPLE_SLIDE_ID = '5d817f5abd4404c6b1f744bb'\n",
"\n",
"gc = girder_client.GirderClient(apiUrl=APIURL)\n",
"# gc.authenticate(interactive=True)\n",
Expand All @@ -75,7 +75,7 @@
"W_target = np.array([\n",
" [0.5807549, 0.08314027, 0.08213795],\n",
" [0.71681094, 0.90081588, 0.41999816],\n",
" [0.38588316, 0.42616716, -0.90380025]\n",
" [0.38588316, 0.42616716, -0.90380025],\n",
"])\n",
"\n",
"# visualization color map\n",
Expand Down Expand Up @@ -105,9 +105,9 @@
"source": [
"# get RGB image at a small magnification\n",
"slide_info = gc.get('item/%s/tiles' % SAMPLE_SLIDE_ID)\n",
"getStr = \"/item/%s/tiles/region?left=%d&right=%d&top=%d&bottom=%d\" % (\n",
" SAMPLE_SLIDE_ID, 0, slide_info['sizeX'], 0, slide_info['sizeY']\n",
" ) + \"&magnification=%.2f\" % MAG\n",
"getStr = '/item/%s/tiles/region?left=%d&right=%d&top=%d&bottom=%d' % (\n",
" SAMPLE_SLIDE_ID, 0, slide_info['sizeX'], 0, slide_info['sizeY'],\n",
" ) + '&magnification=%.2f' % MAG\n",
"tissue_rgb = get_image_from_htk_response(\n",
" gc.get(getStr, jsonResp=False))\n",
"\n",
Expand Down Expand Up @@ -317,7 +317,7 @@
" ax[0].imshow(tissue_rgb[ymin:ymax, xmin:xmax, :])\n",
" ax[1].imshow(tissue_rgb_normalized[ymin:ymax, xmin:xmax, :])\n",
" plt.show()\n",
" \n",
"\n",
"vis_result()"
]
},
Expand Down Expand Up @@ -854,7 +854,7 @@
" ax[0].imshow(rgb)\n",
" ax[1].imshow(augmented_rgb)\n",
" plt.show()\n",
" \n",
"\n",
"vis_augmentation()"
]
},
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/creating_gallery_images_review.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@
"SAMPLE_FOLDER_ID = '5e2a2da8ddda5f83986d18a2'\n",
"\n",
"# This is the girder folder where galleries will be visualized\n",
"POST_FOLDERID = \"5e3ce440ddda5f839875b33e\"\n",
"POST_FOLDERID = '5e3ce440ddda5f839875b33e'\n",
"\n",
"# Connect to an authenticated girder API. You \n",
"# Connect to an authenticated girder API. You\n",
"gc = girder_client.GirderClient(apiUrl=APIURL)\n",
"gc.authenticate(interactive=True) # need this to post!\n",
"# gc.authenticate(apiKey='kri19nTIGOkWH01TbzRqfohaaDWb6kPecRqGmemb')\n",
Expand Down
18 changes: 9 additions & 9 deletions docs/examples/nuclei_segmentation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
" 'hematoxylin': [0.65, 0.70, 0.29],\n",
" 'eosin': [0.07, 0.99, 0.11],\n",
" 'dab': [0.27, 0.57, 0.78],\n",
" 'null': [0.0, 0.0, 0.0]\n",
" 'null': [0.0, 0.0, 0.0],\n",
"}\n",
"\n",
"# specify stains of input image\n",
Expand All @@ -160,8 +160,8 @@
"stain_3 = 'null' # set to null of input contains only two stains\n",
"\n",
"# create stain matrix\n",
"W = np.array([stainColorMap[stain_1], \n",
" stainColorMap[stain_2], \n",
"W = np.array([stainColorMap[stain_1],\n",
" stainColorMap[stain_2],\n",
" stainColorMap[stain_3]]).T\n",
"\n",
"# perform standard color deconvolution\n",
Expand Down Expand Up @@ -226,7 +226,7 @@
"im_log_max, im_sigma_max = htk.filters.shape.cdog(\n",
" im_nuclei_stain, im_fgnd_mask,\n",
" sigma_min=min_radius * np.sqrt(2),\n",
" sigma_max=max_radius * np.sqrt(2)\n",
" sigma_max=max_radius * np.sqrt(2),\n",
")\n",
"\n",
"# detect and segment nuclei using local maximum clustering\n",
Expand Down Expand Up @@ -266,14 +266,14 @@
" height = objProps[i].bbox[2] - objProps[i].bbox[0] + 1\n",
"\n",
" cur_bbox = {\n",
" \"type\": \"rectangle\",\n",
" \"center\": c,\n",
" \"width\": width,\n",
" \"height\": height,\n",
" 'type': 'rectangle',\n",
" 'center': c,\n",
" 'width': width,\n",
" 'height': height,\n",
" }\n",
"\n",
" plt.plot(c[0], c[1], 'g+')\n",
" mrect = mpatches.Rectangle([c[0] - 0.5 * width, c[1] - 0.5 * height] , \n",
" mrect = mpatches.Rectangle([c[0] - 0.5 * width, c[1] - 0.5 * height] ,\n",
" width, height, fill=False, ec='g', linewidth=2)\n",
" plt.gca().add_patch(mrect)"
]
Expand Down
14 changes: 7 additions & 7 deletions docs/examples/polygon_merger_from_tiled_masks.ipynb

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions docs/examples/polygon_merger_using_rtree.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,20 @@
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"**Implementation summary**\n",
"\n",
Expand All @@ -66,14 +69,17 @@
" |_tests/\n",
" |_ test_polygon_merger.py\n",
"```"
],
"metadata": {
"collapsed": false
}
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"import os\n",
Expand All @@ -85,13 +91,7 @@
"from histomicstk.annotations_and_masks.masks_to_annotations_handler import (\n",
" get_annotation_documents_from_contours, _discard_nonenclosed_background_group)\n",
"from histomicstk.annotations_and_masks.annotation_and_mask_utils import parse_slide_annotations_into_tables"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
]
},
{
"cell_type": "code",
Expand Down Expand Up @@ -439,7 +439,7 @@
"source": [
"# init & run polygon merger\n",
"pm = Polygon_merger_v2(contours_df, verbose=1)\n",
"pm.unique_groups.remove(\"roi\")\n",
"pm.unique_groups.remove('roi')\n",
"pm.run()"
]
},
Expand All @@ -460,13 +460,13 @@
"source": [
"# add colors (aesthetic)\n",
"for group in pm.unique_groups:\n",
" cs = contours_df.loc[contours_df.loc[:, \"group\"] == group, \"color\"]\n",
" cs = contours_df.loc[contours_df.loc[:, 'group'] == group, 'color']\n",
" pm.new_contours.loc[\n",
" pm.new_contours.loc[:, \"group\"] == group, \"color\"] = cs.iloc[0]\n",
" pm.new_contours.loc[:, 'group'] == group, 'color'] = cs.iloc[0]\n",
"\n",
"# get rid of nonenclosed stroma (aesthetic)\n",
"pm.new_contours = _discard_nonenclosed_background_group(\n",
" pm.new_contours, background_group=\"mostly_stroma\")"
" pm.new_contours, background_group='mostly_stroma')"
]
},
{
Expand Down Expand Up @@ -663,12 +663,12 @@
"annotation_docs = get_annotation_documents_from_contours(\n",
" pm.new_contours.copy(), separate_docs_by_group=True,\n",
" docnamePrefix='test',\n",
" verbose=False, monitorPrefix=POST_SLIDE_ID + \": annotation docs\")\n",
" verbose=False, monitorPrefix=POST_SLIDE_ID + ': annotation docs')\n",
"\n",
"# post annotations to slide -- make sure it posts without errors\n",
"for annotation_doc in annotation_docs:\n",
" resp = gc.post(\n",
" \"/annotation?itemId=\" + POST_SLIDE_ID, json=annotation_doc)"
" '/annotation?itemId=' + POST_SLIDE_ID, json=annotation_doc)"
]
},
{
Expand Down
12 changes: 6 additions & 6 deletions docs/examples/positive_pixel_count.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,19 @@
"import ipywidgets as widgets\n",
"from ipywidgets import interactive\n",
"\n",
"params= { \n",
"params= {\n",
" 'hue_value': widgets.FloatSlider(min=0.0,max=1.0,step=0.004,style = {'description_width': 'initial'}, value=0.05),\n",
" 'hue_width':widgets.FloatSlider(min=0.0,max=1.0,step=0.05,style = {'description_width': 'initial'}, value=0.15), \n",
" 'hue_width':widgets.FloatSlider(min=0.0,max=1.0,step=0.05,style = {'description_width': 'initial'}, value=0.15),\n",
" 'saturation_minimum': widgets.FloatSlider(min=0.0,max=1.0,step=0.05,style = {'description_width': 'initial'}, value=0.05),\n",
" 'intensity_upper_limit': widgets.FloatSlider(min=0.0,max=1.0,step=0.05,style = {'description_width': 'initial'}, value=0.95),\n",
" 'intensity_weak_threshold': widgets.FloatSlider(min=0.0,max=1.0,step=0.05,style = {'description_width': 'initial'}, value=0.65),\n",
" 'intensity_strong_threshold':widgets.FloatSlider(min=0.0,max=1.0,step=0.05,style = {'description_width': 'initial'}, value=0.35),\n",
" 'intensity_lower_limit':widgets.FloatSlider(min=0.0,max=1.0,step=0.05,style = {'description_width': 'initial'}, value=0.05)\n",
" 'intensity_lower_limit':widgets.FloatSlider(min=0.0,max=1.0,step=0.05,style = {'description_width': 'initial'}, value=0.05),\n",
" }\n",
"\n",
"def g(**params):\n",
" count_and_label(ppc.Parameters(**params))\n",
" \n",
"\n",
"w = interactive(g,**params)\n",
"display(w)\n",
"\n",
Expand Down Expand Up @@ -679,7 +679,7 @@
"ts = large_image.getTileSource(slide_path)\n",
"im_region = ts.getRegion(region=region, format=large_image.tilesource.TILE_FORMAT_NUMPY)[0]\n",
"\n",
"print(\"The region\")\n",
"print('The region')\n",
"plt.imshow(im_region)\n",
"plt.show()"
]
Expand Down Expand Up @@ -817,7 +817,7 @@
}
],
"source": [
"print(\"stats_dask - stats:\")\n",
"print('stats_dask - stats:')\n",
"pp_namedtuple(ppc.Output(**{f: getattr(stats_dask, f) - getattr(stats, f) for f in ppc.Output._fields}))"
]
},
Expand Down
26 changes: 13 additions & 13 deletions docs/examples/segmentation_masks_to_annotations.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"outputs": [],
"source": [
"APIURL = 'http://candygram.neurology.emory.edu:8080/api/v1/'\n",
"SAMPLE_SLIDE_ID = \"5d8c296cbd4404c6b1fa5572\"\n",
"SAMPLE_SLIDE_ID = '5d8c296cbd4404c6b1fa5572'\n",
"\n",
"gc = girder_client.GirderClient(apiUrl=APIURL)\n",
"gc.authenticate(apiKey='kri19nTIGOkWH01TbzRqfohaaDWb6kPecRqGmemb')\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/semantic_segmentation_superpixel_approach.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"outputs": [],
"source": [
"APIURL = 'http://candygram.neurology.emory.edu:8080/api/v1/'\n",
"SAMPLE_SLIDE_ID = \"5d586d76bd4404c6b1f286ae\"\n",
"SAMPLE_SLIDE_ID = '5d586d76bd4404c6b1f286ae'\n",
"# SAMPLE_SLIDE_ID = \"5d8c296cbd4404c6b1fa5572\"\n",
"\n",
"gc = girder_client.GirderClient(apiUrl=APIURL)\n",
Expand Down Expand Up @@ -248,7 +248,7 @@
" 'deconvolve_first': False,\n",
" 'n_thresholding_steps': 2,\n",
" 'sigma': 1.5,\n",
" 'min_size': 500, },\n",
" 'min_size': 500 },\n",
" verbose=2, monitorPrefix='test',\n",
" logging_savepath=logging_savepath)"
]
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/simple_tissue_detection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"source": [
"APIURL = 'http://candygram.neurology.emory.edu:8080/api/v1/'\n",
"# SAMPLE_SLIDE_ID = '5d586d57bd4404c6b1f28640'\n",
"SAMPLE_SLIDE_ID = \"5d817f5abd4404c6b1f744bb\"\n",
"SAMPLE_SLIDE_ID = '5d817f5abd4404c6b1f744bb'\n",
"\n",
"gc = girder_client.GirderClient(apiUrl=APIURL)\n",
"# gc.authenticate(interactive=True)\n",
Expand Down Expand Up @@ -311,7 +311,7 @@
" ax[0].imshow(thumbnail_rgb)\n",
" ax[1].imshow(labeled, cmap=cMap)\n",
" ax[2].imshow(mask, cmap=cMap)\n",
" plt.suptitle(\"deconvolve = %s, n_thresholding_steps = %d\" % (deconvolve_first, n_thresholding_steps), fontsize=20)\n",
" plt.suptitle('deconvolve = %s, n_thresholding_steps = %d' % (deconvolve_first, n_thresholding_steps), fontsize=20)\n",
" plt.show()"
]
}
Expand Down
Loading

0 comments on commit 26a8788

Please sign in to comment.