Skip to content

Commit

Permalink
Clean up a variety of warnings and deprecations.
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey committed Nov 13, 2024
1 parent 4bfc643 commit 1c9d840
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 23 deletions.
2 changes: 1 addition & 1 deletion histomicstk/annotations_and_masks/polygon_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os

import numpy as np
from imageio import imread
from imageio.v2 import imread
from PIL import Image
# import cv2
from shapely.geometry.polygon import Polygon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ def test_get_scale_factor_and_appendStr(self):
[(None, 10.), (0.25, '&magnification=10.00000000')],
[(None, None), (1.0, '')],
]
for (MPP, MAG), (sftrue, apstr) in in_out:
sf, appendStr = get_scale_factor_and_appendStr(
gc=cfg.gc, slide_id=cfg.iteminfo['_id'], MPP=MPP, MAG=MAG)
assert sf == sftrue
assert appendStr == apstr
with pytest.warns(RuntimeWarning):
for (MPP, MAG), (sftrue, apstr) in in_out:
sf, appendStr = get_scale_factor_and_appendStr(
gc=cfg.gc, slide_id=cfg.iteminfo['_id'], MPP=MPP, MAG=MAG)
assert sf == sftrue
assert appendStr == apstr
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ def test_dump_annotations_locally_1(self):
dbcon = sql_engine.connect()

result = pd.read_sql_query(text("""SELECT count(*) FROM 'folders';"""), dbcon)
assert int(result.loc[0, :]) == 2
assert int(result.iloc[0, 0]) == 2

result = pd.read_sql_query(text("""SELECT count(*) FROM 'items';"""), dbcon)
assert int(result.loc[0, :]) == 4
assert int(result.iloc[0, 0]) == 4

# cleanup
shutil.rmtree(savepath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import numpy as np
import pytest
from imageio import imread
from imageio.v2 import imread
from pandas import read_csv

from histomicstk.annotations_and_masks.annotation_and_mask_utils import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import pandas as pd
import pytest
from imageio import imread
from imageio.v2 import imread
from pandas import read_csv

from histomicstk.annotations_and_masks.annotation_and_mask_utils import \
Expand Down
10 changes: 8 additions & 2 deletions histomicstk/features/compute_global_cell_graph_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,14 @@ def _pop_stats(pop):
if mask.all():
break
pop = pop[mask]
minmaxr = pop.min() / pop.max()
disorder = stddev / (mean + stddev)
if pop.max():
minmaxr = pop.min() / pop.max()
else:
minmaxr = 0.0
if mean + stddev:
disorder = stddev / (mean + stddev)
else:
disorder = 0.0
return PopStats(mean, stddev, minmaxr, disorder)


Expand Down
6 changes: 4 additions & 2 deletions histomicstk/features/compute_haralick_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,10 @@ def compute_haralick_features(im_label, im_intensity, offsets=None,
meanx = np.dot(n_Minus, px)
variance = np.dot(px, np.square(n_Minus)) - np.square(meanx)
nGLCMr = np.ravel(nGLCM)
Correlation = (np.dot(np.ravel(xy), nGLCMr) - np.square(meanx)) / variance

if variance:
Correlation = (np.dot(np.ravel(xy), nGLCMr) - np.square(meanx)) / variance
else:
Correlation = 0.0
# computes sum of squares : variance
SumOfSquares = variance

Expand Down
2 changes: 1 addition & 1 deletion histomicstk/saliency/cellularity_detection_superpixels.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ def set_color_normalization_values(
assert what in ('thumbnail', 'main')

if ref_image_path is not None:
from imageio import imread
from imageio.v2 import imread

ref_im = np.array(imread(ref_image_path, pilmode='RGB'))
mu, sigma = lab_mean_std(ref_im)
Expand Down
6 changes: 3 additions & 3 deletions histomicstk/saliency/cellularity_detection_thresholding.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def find_potentially_cellular_regions(self):
# Second, low-pass filter to dilate and smooth a bit
self.maybe_cellular = gaussian(
0 + (self.maybe_cellular > 0), sigma=self.cdt.cellular_step2_sigma,
output=None, mode='nearest', preserve_range=True)
out=None, mode='nearest', preserve_range=True)

# find connected components
self.maybe_cellular, _ = ndimage.label(self.maybe_cellular)
Expand Down Expand Up @@ -224,7 +224,7 @@ def find_top_cellular_regions(self):
# get top n brightest regions from the largest areas
intensity_feats.sort_values('Intensity.Mean', axis=0, inplace=True)
discard = np.array(intensity_feats.index[:-self.cdt.cellular_top_n])
discard = np.in1d(top_cellular, discard).reshape(top_cellular.shape)
discard = np.isin(top_cellular, discard).reshape(top_cellular.shape)
top_cellular[discard] = 0

# integrate into labeled mask
Expand Down Expand Up @@ -614,7 +614,7 @@ def set_color_normalization_target(
> reinhard and macenko_pca are accepted.
"""
from imageio import imread
from imageioi.v2 import imread

# read input image
ref_im = np.array(imread(ref_image_path, pilmode='RGB'))
Expand Down
6 changes: 3 additions & 3 deletions histomicstk/saliency/tissue_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def get_tissue_mask(
if sigma > 0.0:
thumbnail = gaussian(
thumbnail, sigma=sigma,
output=None, mode='nearest', preserve_range=True)
out=None, mode='nearest', preserve_range=True)

# get threshold to keep analysis region
try:
Expand All @@ -124,7 +124,7 @@ def get_tissue_mask(

# only keep
unique, counts = np.unique(labeled[labeled > 0], return_counts=True)
discard = np.in1d(labeled, unique[counts < min_size])
discard = np.isin(labeled, unique[counts < min_size])
discard = discard.reshape(labeled.shape)
labeled[discard] = 0

Expand Down Expand Up @@ -265,7 +265,7 @@ def _get_largest_regions(labeled, top_n=10):
keep = unique[np.argsort(counts)[-top_n:]]

mask = np.zeros(labeled_im.shape)
keep_pixels = np.in1d(labeled_im, keep)
keep_pixels = np.isin(labeled_im, keep)
keep_pixels = keep_pixels.reshape(labeled_im.shape)
mask[keep_pixels] = 1
labeled_im[mask == 0] = 0
Expand Down
4 changes: 2 additions & 2 deletions tests/test_global_cell_graph_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def testSimple(self):
density_distance_for_neighbors_1_mean=2.59272486435,
density_distance_for_neighbors_1_min_max_ratio=0.75,
density_distance_for_neighbors_1_stddev=0.333333333333,
density_neighbors_in_distance_0_disorder=np.nan,
density_neighbors_in_distance_0_disorder=0.0,
density_neighbors_in_distance_0_mean=0.0,
density_neighbors_in_distance_0_min_max_ratio=np.nan,
density_neighbors_in_distance_0_min_max_ratio=0.0,
density_neighbors_in_distance_0_stddev=0.0,
density_neighbors_in_distance_1_disorder=0.414213562373,
density_neighbors_in_distance_1_mean=0.666666666667,
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ passenv =
DOCKER_*
GENERATE_GROUNDTRUTH
PYTEST_*
DASK_*
# This adds the tests directory to the python path so we can import the test
# utilities as needed.
setenv =
Expand Down

0 comments on commit 1c9d840

Please sign in to comment.