-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Hi, i normally use this pipeline (IMC Data Viewer) to produce images like attached.

I have many samples (50) e different ROIs and I want to automatize this part, here the code that i developed:
import numpy as np
import xarray as xr
import holoviews as hv
from holoviews import opts
import cv2
import pandas as pd
import os
hv.extension('bokeh', width=80)
from importlib import reload
from imc_viewer import IMCViewer
dir_path = 'imc_converted/Shauna_IMC/Panel_I_Francia'
res = []
for path in os.listdir(dir_path):
# check if current path is a file
IMC_name = path
for ROI_number in [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22]:
use_panel_file = False
panel_file = 'panel.xlsx'
panel_skip_rows = 3
try:
imcviewer = IMCViewer(IMC_name,ROI_number,use_panel_file=use_panel_file,panel_file=panel_file,panel_skip_rows=panel_skip_rows,path=dir_path)
imcviewer.print_channels()
except Exception:
pass
scalebar_size=1000
ch_to_display = [
['DNA1',0,'p99','blue',1,'DNA1'],
['DNA2',0,'p99','red',1,'DNA2'],
['Vimentin',0,'p99','green',1,'Vimentin'],
]
rescale_factor = 4
show_legend = True
legend_position = 'bottom_left'
imcviewer.view(ch_to_display,scalebar_size,rescale_factor,show_legend,legend_position)
imcviewer.select_zoomed_ROI()
imcviewer.crop_dataset()
filename = 'out_images/12042023_14H001163/ROI_06/Vimentin_green'
scalebar=True
scalebar_size = 200
scalebar_thickness = 20
scalebar_text_size = 1.5
scalebar_text_thickness = 3
distance_text_from_scalebar = 30
downsample = 1
median = 3
imcviewer.save_image(filename,scalebar=True,scalebar_size=scalebar_size, scalebar_thickness=scalebar_thickness, scalebar_text_thickness=scalebar_text_thickness, scalebar_text_size=scalebar_text_size,
text_dist = distance_text_from_scalebar, median=median, downsample=downsample)
The problem is that I receive this error (instead without the loop is ok).
TypeError Traceback (most recent call last)
Input In [31], in
24 legend_position = 'bottom_left'
25 imcviewer.view(ch_to_display,scalebar_size,rescale_factor,show_legend,legend_position)
---> 26 imcviewer.select_zoomed_ROI()
27 imcviewer.crop_dataset()
28 filename = 'out_images/12042023_14H001163/ROI_06/Vimentin_green'
File ~/Desktop/IMC_pipeline/IMAXT_IMC_pipeline/imc_viewer.py:458, in IMCViewer.select_zoomed_ROI(self)
454 def select_zoomed_ROI(self):
455 self.ROI_final = self.final_image.select(
456 x=self.rangexy.x_range, y=self.rangexy.y_range
457 )
--> 458 self.ROI_image = self.rendered_image.select(
459 x=self.rangexy.x_range, y=self.rangexy.y_range
460 )
461 self.x_range = self.rangexy.x_range
462 self.y_range = self.rangexy.y_range
File /opt/anaconda3/envs/imc_pipeline/lib/python3.9/site-packages/holoviews/core/data/init.py:207, in PipelineMeta.pipelined..pipelined_fn(*args, **kwargs)
204 inst._in_method = True
206 try:
--> 207 result = method_fn(*args, **kwargs)
208 if PipelineMeta.disable:
209 return result
File /opt/anaconda3/envs/imc_pipeline/lib/python3.9/site-packages/holoviews/element/raster.py:469, in Image.select(self, selection_specs, **selection)
467 sliced = True
468 else:
--> 469 y, x = self.sheet2matrixidx(coords[0], coords[1])
470 y = shape[0]-y-1
471 selection = (y, x)
File /opt/anaconda3/envs/imc_pipeline/lib/python3.9/site-packages/holoviews/core/sheetcoords.py:258, in SheetCoordinateSystem.sheet2matrixidx(self, x, y)
245 def sheet2matrixidx(self,x,y):
246 """
247 Convert a point (x,y) in sheet coordinates to the integer row
248 and column index of the matrix cell in which that point falls,
(...)
256 Valid for scalar or array x and y.
257 """
--> 258 r,c = self.sheet2matrix(x,y)
259 r = np.floor(r)
260 c = np.floor(c)
File /opt/anaconda3/envs/imc_pipeline/lib/python3.9/site-packages/holoviews/core/sheetcoords.py:232, in SheetCoordinateSystem.sheet2matrix(self, x, y)
230 float_col = (x-self.lbrt[0]) / xdensity
231 else:
--> 232 float_col = (x-self.lbrt[0]) * xdensity
234 ydensity = self.__ydensity
235 if ((isinstance(y, np.ndarray) and y.dtype.kind == 'M') or
236 isinstance(y, datetime_types)):
TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'