Skip to content

Commit

Permalink
optimize imports
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldoucet committed Nov 5, 2024
1 parent a5aea93 commit 345ceea
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/hest/io/seg_readers.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from collections import defaultdict
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor, as_completed
from concurrent.futures import ProcessPoolExecutor, as_completed
import json
import time
import warnings
from abc import abstractmethod

import geopandas as gpd
from loguru import logger
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from shapely.geometry.polygon import Point, Polygon
from tqdm import tqdm

Expand Down Expand Up @@ -240,6 +238,7 @@ def write_geojson(gdf: gpd.GeoDataFrame, path: str, category_key: str, extra_pro


def generate_colors(names):
from matplotlib import pyplot as plt
colors = plt.get_cmap('hsv', len(names))
color_dict = {}
for i in range(len(names)):
Expand Down
2 changes: 1 addition & 1 deletion src/hest/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from hestcore.segmentation import get_path_relative
from loguru import logger

from hest.autoalign import autoalign_visium
from hest.custom_readers import ADT_to_adata, GSE144239_to_adata, colon_atlas_to_adata, heart_atlas_to_adata
from hest.HESTData import (HESTData, STHESTData, VisiumHDHESTData,
VisiumHESTData, XeniumHESTData)
Expand Down Expand Up @@ -457,6 +456,7 @@ def read(self,
if (not tissue_position_exists and alignment_file_path is None):
print('no tissue_positions_list.csv/tissue_positions.csv or alignment file found')
print('attempt fiducial auto alignment...')
from hest.autoalign import autoalign_visium

os.makedirs(os.path.join(os.path.dirname(img_path), 'spatial'), exist_ok=True)
autoalign_save_dir = None
Expand Down
3 changes: 2 additions & 1 deletion src/hest/segmentation/TissueMask.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pickle
from typing import List

import cv2
import numpy as np
from PIL import Image

Expand All @@ -27,6 +26,8 @@ def load_tissue_mask(pkl_path: str, jpg_path: str, width: int, height: int) -> T
with Image.open(jpg_path) as img:
tissue_mask = np.array(img).copy()


import cv2
tissue_mask = cv2.resize(tissue_mask, (width, height))

mask = TissueMask(tissue_mask, contours_tissue, contours_holes)
Expand Down
7 changes: 2 additions & 5 deletions src/hest/segmentation/cell_segmenters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

import os
import sys
import time
import traceback
import warnings
from abc import abstractmethod
from concurrent.futures import ThreadPoolExecutor, as_completed
from multiprocessing import Pool, cpu_count
from time import sleep
from concurrent.futures import ThreadPoolExecutor
from typing import Tuple, Union

import geopandas as gpd
import matplotlib.pyplot as plt
import numpy as np
import openslide
import pandas as pd
Expand Down Expand Up @@ -410,6 +406,7 @@ def expand_nuclei(gdf: gpd.GeoDataFrame, pixel_size: float, exp_um=5, plot=False
gdf_cell.geometry = gdf_cell.union(gdf.loc[~invalid_mask])

if plot:
import matplotlib.pyplot as plt
logger.info('Plotting...')
_, ax = plt.subplots(figsize=(50, 50))

Expand Down

0 comments on commit 345ceea

Please sign in to comment.