Skip to content

Commit

Permalink
Merge pull request #214 from jburel/update
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
jburel authored Feb 5, 2024
2 parents d3fb626 + 92d3bd1 commit 4e04dc4
Show file tree
Hide file tree
Showing 16 changed files with 107 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/omero_plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
env:
STAGE: scripts
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Checkout omero-test-infra
uses: actions/checkout@master
with:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ jobs:
name: Build and publish Python distribution to PyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Build a binary wheel and a source tarball
run: |
python -mpip install wheel
Expand Down
10 changes: 5 additions & 5 deletions omero/analysis_scripts/Kymograph.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ def plane_gen():
line_data = []
points = shape['points']
the_z = shape['theZ']
for l in range(len(points)-1):
x1, y1 = points[l]
x2, y2 = points[l+1]
for point in range(len(points)-1):
x1, y1 = points[point]
x2, y2 = points[point+1]
ld = get_line_data(image, x1, y1, x2, y2,
line_width, the_z, the_c, the_t)
line_data.append(ld)
Expand Down Expand Up @@ -334,15 +334,15 @@ def process_images(conn, script_params):
z = the_z
# TODO: Add some filter of shapes. E.g. text? / 'lines' only
# etc.
if type(s) == omero.model.LineI:
if isinstance(s, omero.model.LineI):
x1 = s.getX1().getValue()
x2 = s.getX2().getValue()
y1 = s.getY1().getValue()
y2 = s.getY2().getValue()
lines[t] = {'theZ': z, 'x1': x1, 'y1': y1, 'x2': x2,
'y2': y2}

elif type(s) == omero.model.PolylineI:
elif isinstance(s, omero.model.PolylineI):
v = s.getPoints().getValue()
points = roi_utils.points_string_to_xy_list(v)
polylines[t] = {'theZ': z, 'points': points}
Expand Down
4 changes: 2 additions & 2 deletions omero/analysis_scripts/Kymograph_Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def process_images(conn, script_params):
for s in roi.copyShapes():
if s is None:
continue # seems possible in some situations
if type(s) == omero.model.LineI:
if isinstance(s, omero.model.LineI):
table_data += "\nLine ID: %s" % s.getId().getValue()
x1 = s.getX1().getValue()
x2 = s.getX2().getValue()
Expand All @@ -103,7 +103,7 @@ def process_images(conn, script_params):
[str(x) for x in (y1, x1, y2, x2, dy, dx, dx_per_y,
speed)])

elif type(s) == omero.model.PolylineI:
elif isinstance(s, omero.model.PolylineI):
table_data += "\nPolyline ID: %s" % s.getId().getValue()
v = s.getPoints().getValue()
points = roi_utils.points_string_to_xy_list(v)
Expand Down
27 changes: 14 additions & 13 deletions omero/analysis_scripts/Plot_Profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def process_polylines(conn, script_params, image, polylines, line_width, fout):
points = pl['points']
for the_c in the_cs:
ldata = []
for l in range(len(points)-1):
x1, y1 = points[l]
x2, y2 = points[l+1]
for point in range(len(points)-1):
x1, y1 = points[point]
x2, y2 = points[point+1]
if round(x1 - x2) == 0 and round(y1 - y2) == 0:
continue
ld = roi_utils.get_line_data(
Expand Down Expand Up @@ -103,17 +103,18 @@ def process_lines(conn, script_params, image, lines, line_width, fout):
pixels = image.getPrimaryPixels()
the_cs = script_params['Channels']

for l in lines:
the_t = l['theT']
the_z = l['theZ']
roi_id = l['id']
if round(l['x1'] - l['x2']) == 0 and round(l['y1'] - l['y2']) == 0:
for line in lines:
the_t = line['theT']
the_z = line['theZ']
roi_id = line['id']
if round(line['x1'] - line['x2']) == 0 and round(line['y1'] - line['y2']) == 0: # noqa
continue
for the_c in the_cs:
line_data = []
line_data = roi_utils.get_line_data(pixels, l['x1'], l['y1'],
l['x2'], l['y2'], line_width,
the_z, the_c, the_t)
line_data = roi_utils.get_line_data(pixels, line['x1'], line['y1'],
line['x2'], line['y2'],
line_width, the_z, the_c,
the_t)

if script_params['Sum_or_Average'] == 'Sum':
output_data = line_data.sum(axis=0)
Expand Down Expand Up @@ -192,15 +193,15 @@ def process_images(conn, script_params):
z = the_z
# TODO: Add some filter of shapes e.g. text? / 'lines' only
# etc.
if type(s) == omero.model.LineI:
if isinstance(s, omero.model.LineI):
x1 = s.getX1().getValue()
x2 = s.getX2().getValue()
y1 = s.getY1().getValue()
y2 = s.getY2().getValue()
lines.append({'id': roi_id, 'theT': t, 'theZ': z,
'x1': x1, 'y1': y1, 'x2': x2, 'y2': y2})

elif type(s) == omero.model.PolylineI:
elif isinstance(s, omero.model.PolylineI):
v = s.getPoints().getValue()
points = roi_utils.points_string_to_xy_list(v)
polylines.append({'id': roi_id, 'theT': t, 'theZ': z,
Expand Down
6 changes: 3 additions & 3 deletions omero/annotation_scripts/KeyVal_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
def get_existing_map_annotions(obj):
ord_dict = OrderedDict()
for ann in obj.listAnnotations():
if(isinstance(ann, omero.gateway.MapAnnotationWrapper)):
if isinstance(ann, omero.gateway.MapAnnotationWrapper):
kvs = ann.getValue()
for k, v in kvs:
if k not in ord_dict:
Expand Down Expand Up @@ -152,8 +152,8 @@ def run_script():

# remove the csv if it exists
for ann in ds.listAnnotations():
if(isinstance(ann, omero.gateway.FileAnnotationWrapper)):
if(ann.getFileName() == csv_name):
if isinstance(ann, omero.gateway.FileAnnotationWrapper):
if ann.getFileName() == csv_name:
# if the name matches delete it
try:
delete = Delete2(
Expand Down
4 changes: 2 additions & 2 deletions omero/export_scripts/Batch_Image_Export.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def save_plane(image, format, c_name, z_range, project_z, t=0, channel=None,
w, h = plane.size
fraction = (float(zoom_percent) / 100)
plane = plane.resize((int(w * fraction), int(h * fraction)),
Image.ANTIALIAS)
Image.LANCZOS)

if format == "PNG":
img_name = make_image_name(
Expand Down Expand Up @@ -572,7 +572,7 @@ def run_script():
scripts.String(
"Zoom", grouping="7", values=zoom_percents,
description="Zoom (jpeg, png or tiff) before saving with"
" ANTIALIAS interpolation", default="100%"),
" LANCZOS interpolation", default="100%"),

scripts.String(
"Format", grouping="8",
Expand Down
8 changes: 4 additions & 4 deletions omero/export_scripts/Make_Movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def reshape_to_fit(image, size_x, size_y, bg=(0, 0, 0)):
# scale
ratio = min(float(size_x) / image_w, float(size_y) / image_h)
image = image.resize(map(lambda x: int(x*ratio), image.size),
Image.ANTIALIAS)
Image.LANCZOS)
# paste
bg = Image.new("RGBA", (size_x, size_y), (0, 0, 0)) # black bg
ovlpos = (size_x-image.size[0]) / 2, (size_y-image.size[1]) / 2
Expand Down Expand Up @@ -486,8 +486,8 @@ def write_movie(command_args, conn):
c_windows = []
c_colours = []
for c in command_args["ChannelsExtended"]:
m = re.match('^(?P<i>\d+)(\|(?P<ws>\d+)' +
'\:(?P<we>\d+))?(\$(?P<c>.+))?$', c)
m = re.match('^(?P<i>\\d+)(\\|(?P<ws>\\d+)' +
'\\:(?P<we>\\d+))?(\\$(?P<c>.+))?$', c)
if m is not None:
c_range.append(int(m.group('i'))-1)
c_windows.append([float(m.group('ws')), float(m.group('we'))])
Expand Down Expand Up @@ -594,7 +594,7 @@ def write_movie(command_args, conn):
movie_name = "%s.%s" % (movie_name, ext)

# spaces etc in file name cause problems
movie_name = re.sub("[$&\;|\(\)<>' ]", "", movie_name)
movie_name = re.sub("[$&\\;|\\(\\)<>' ]", "", movie_name)
frames_per_sec = 2
if "FPS" in command_args:
frames_per_sec = command_args["FPS"]
Expand Down
13 changes: 8 additions & 5 deletions omero/figure_scripts/Movie_Figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ def createmovie_figure(conn, pixel_ids, t_indexes, z_start, z_end, width,
col_count = min(max_col_count, len(rendered_images))
row_count = int(math.ceil(len(rendered_images) / col_count))
font = image_utils.get_font(width // 12)
font_height = font.getsize("Textq")[1]
box = font.getbbox("Textq")
font_height = box[3] - box[1]
canvas_width = ((width + spacer) * col_count) + spacer
canvas_height = row_count * (spacer // 2 + font_height +
spacer + height)
Expand All @@ -211,7 +212,8 @@ def createmovie_figure(conn, pixel_ids, t_indexes, z_start, z_end, width,
if t_index >= size_t:
continue
time = time_labels[t]
text_w = font.getsize(time)[0]
box = font.getbbox(time)
text_w = box[2] - box[0]
inset = (width - text_w) // 2
textdraw = ImageDraw.Draw(canvas)
textdraw.text((text_x+inset, text_y), time, font=font,
Expand Down Expand Up @@ -295,7 +297,8 @@ def add_left_labels(panel_canvas, image_labels, row_index, width, spacer):
mode = "RGB"
white = (255, 255, 255)
font = image_utils.get_font(width/12)
text_height = font.getsize("Sampleq")[1]
box = font.getbbox("Sampleq")
text_height = box[3] - box[1]
text_gap = spacer / 2

# find max number of labels
Expand All @@ -311,9 +314,9 @@ def add_left_labels(panel_canvas, image_labels, row_index, width, spacer):

labels = image_labels[row_index]
py = left_text_height - text_gap # start at bottom
for l, label in enumerate(labels):
for count, label in enumerate(labels):
py = py - text_height # find the top of this row
w = textdraw.textsize(label, font=font)[0]
w = textdraw.textlength(label, font=font)
inset = int((left_text_width - w) / 2)
textdraw.text((inset, py), label, font=font, fill=(0, 0, 0))
py = py - text_gap # add space between rows
Expand Down
11 changes: 7 additions & 4 deletions omero/figure_scripts/Movie_ROI_Figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ def get_roi_movie_view(re, query_service, pixels, time_shape_map,
row_count += 1
col_count = max_columns
font = image_utils.get_font(font_size)
text_height = font.getsize("Textq")[1]
box = font.getbbox("Textq")
text_height = box[3] - box[1]
# no spaces around panels
canvas_width = ((panel_width + spacer) * col_count) - spacer
row_height = rendered_images[0].size[1] + spacer + text_height
Expand All @@ -221,7 +222,8 @@ def get_roi_movie_view(re, query_service, pixels, time_shape_map,
col = 0
for i, img in enumerate(rendered_images):
label = time_labels[i]
indent = (panel_width - (font.getsize(label)[0])) // 2
box = font.getbbox(label)
indent = (panel_width - (box[2] - box[0])) // 2
draw.text((px+indent, text_y), label, font=font, fill=(0, 0, 0))
image_utils.paste_image(img, canvas, px, panel_y)
if col == (col_count - 1):
Expand Down Expand Up @@ -381,7 +383,8 @@ def get_split_view(conn, image_ids, pixel_ids, merged_indexes, merged_colours,
elif width > 200:
font_size = 16
font = image_utils.get_font(font_size)
text_height = font.getsize("Textq")[1]
box = font.getbbox("Textq")
text_height = box[3] - box[1]
max_count = 0
for row in image_labels:
max_count = max(max_count, len(row))
Expand Down Expand Up @@ -589,7 +592,7 @@ def get_tags(name, tags_list, pd_list):
try:
height = int(h)
except ValueError:
log("Invalid height: %s Using default value" % (str(h), size_y))
log("Invalid height: %s Using default value %s" % (str(h), size_y))

log("Image dimensions for all panels (pixels): width: %d height: %d"
% (width, height))
Expand Down
23 changes: 14 additions & 9 deletions omero/figure_scripts/ROI_Split_Figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def get_roi_split_view(re, pixels, z_start, z_end, split_indexes,
# hoping that when we zoom, don't zoom fullImage
if roi_zoom != 1:
new_size = (int(roi_width*roi_zoom), int(roi_height*roi_zoom))
roi_image = roi_image.resize(new_size, Image.ANTIALIAS)
roi_image = roi_image.resize(new_size, Image.LANCZOS)
rendered_images.append(roi_image)
panel_width = roi_image.size[0]
re.setActive(index, False) # turn the channel off again!
Expand Down Expand Up @@ -213,7 +213,7 @@ def get_roi_split_view(re, pixels, z_start, z_end, split_indexes,

if roi_zoom != 1:
new_size = (int(roi_width*roi_zoom), int(roi_height*roi_zoom))
roi_merged_image = roi_merged_image.resize(new_size, Image.ANTIALIAS)
roi_merged_image = roi_merged_image.resize(new_size, Image.LANCZOS)

if channel_mismatch:
log(" WARNING channel mismatch: The current image has fewer channels"
Expand All @@ -224,7 +224,8 @@ def get_roi_split_view(re, pixels, z_start, z_end, split_indexes,

# now assemble the roi split-view canvas
font = image_utils.get_font(fontsize)
text_height = font.getsize("Textq")[1]
box = font.getbbox("Textq")
text_height = box[3] - box[1]
top_spacer = 0
if show_top_labels:
if merged_names:
Expand All @@ -247,7 +248,8 @@ def get_roi_split_view(re, pixels, z_start, z_end, split_indexes,
draw = ImageDraw.Draw(canvas)
for i, index in enumerate(split_indexes):
label = channel_names.get(index, index)
indent = (panel_width - (font.getsize(label)[0])) // 2
box = font.getbbox(label)
indent = (panel_width - (box[2] - box[0])) // 2
# text is coloured if channel is not coloured AND in the merged image
rgb = (0, 0, 0)
if index in merged_colours:
Expand Down Expand Up @@ -275,12 +277,14 @@ def get_roi_split_view(re, pixels, z_start, z_end, split_indexes,
name = channel_names[index]
else:
name = str(index)
comb_text_width = font.getsize(name)[0]
box = font.getbbox(name)
comb_text_width = box[2] - box[0]
inset = int((panel_width - comb_text_width) / 2)
draw.text((px + inset, text_y), name, font=font, fill=rgb)
text_y = text_y - text_height
else:
comb_text_width = font.getsize("Merged")[0]
box = font.getbbox("Merged")
comb_text_width = box[2] - box[0]
inset = int((panel_width - comb_text_width) / 2)
draw.text((px + inset, text_y), "Merged", font=font,
fill=(0, 0, 0))
Expand Down Expand Up @@ -320,7 +324,7 @@ def get_rectangle(roi_service, image_id, roi_label):
roi_count += 1
# go through all the shapes of the ROI
for shape in roi.copyShapes():
if type(shape) == omero.model.RectangleI:
if isinstance(shape, omero.model.RectangleI):
the_t = unwrap(shape.getTheT())
the_z = unwrap(shape.getTheZ())
t = 0
Expand Down Expand Up @@ -431,7 +435,8 @@ def get_split_view(conn, image_ids, pixel_ids, split_indexes, channel_names,
elif width > 200:
fontsize = 16
font = image_utils.get_font(fontsize)
text_height = font.getsize("Textq")[1]
box = font.getbbox("Textq")
text_height = box[3] - box[1]
max_count = 0
for row in image_labels:
max_count = max(max_count, len(row))
Expand Down Expand Up @@ -660,7 +665,7 @@ def get_tags(name, tags_list, pd_list):
try:
height = int(h)
except ValueError:
log("Invalid height: %s Using default value" % (str(h), size_y))
log("Invalid height: %s Using default value: %d" % (str(h), size_y)) # noqa

log("Image dimensions for all panels (pixels): width: %d height: %d"
% (width, height))
Expand Down
Loading

0 comments on commit 4e04dc4

Please sign in to comment.