diff --git a/.github/workflows/omero_plugin.yml b/.github/workflows/omero_plugin.yml index 455b4b231..40b601e9e 100644 --- a/.github/workflows/omero_plugin.yml +++ b/.github/workflows/omero_plugin.yml @@ -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: diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index 81eccda37..f412a8e28 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -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 diff --git a/omero/analysis_scripts/Kymograph.py b/omero/analysis_scripts/Kymograph.py index 4e650a108..573317ea4 100644 --- a/omero/analysis_scripts/Kymograph.py +++ b/omero/analysis_scripts/Kymograph.py @@ -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) @@ -334,7 +334,7 @@ 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() @@ -342,7 +342,7 @@ def process_images(conn, script_params): 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} diff --git a/omero/analysis_scripts/Kymograph_Analysis.py b/omero/analysis_scripts/Kymograph_Analysis.py index 079231b6f..1af783232 100644 --- a/omero/analysis_scripts/Kymograph_Analysis.py +++ b/omero/analysis_scripts/Kymograph_Analysis.py @@ -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() @@ -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) diff --git a/omero/analysis_scripts/Plot_Profile.py b/omero/analysis_scripts/Plot_Profile.py index 815997b02..4d2cabaab 100644 --- a/omero/analysis_scripts/Plot_Profile.py +++ b/omero/analysis_scripts/Plot_Profile.py @@ -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( @@ -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) @@ -192,7 +193,7 @@ 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() @@ -200,7 +201,7 @@ def process_images(conn, script_params): 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, diff --git a/omero/annotation_scripts/KeyVal_to_csv.py b/omero/annotation_scripts/KeyVal_to_csv.py index fbab07b12..b29314081 100644 --- a/omero/annotation_scripts/KeyVal_to_csv.py +++ b/omero/annotation_scripts/KeyVal_to_csv.py @@ -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: @@ -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( diff --git a/omero/export_scripts/Batch_Image_Export.py b/omero/export_scripts/Batch_Image_Export.py index 6f1ec1d28..f4fdd4747 100644 --- a/omero/export_scripts/Batch_Image_Export.py +++ b/omero/export_scripts/Batch_Image_Export.py @@ -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( @@ -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", diff --git a/omero/export_scripts/Make_Movie.py b/omero/export_scripts/Make_Movie.py index 4c0e3e1a9..bd3c096eb 100644 --- a/omero/export_scripts/Make_Movie.py +++ b/omero/export_scripts/Make_Movie.py @@ -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 @@ -486,8 +486,8 @@ def write_movie(command_args, conn): c_windows = [] c_colours = [] for c in command_args["ChannelsExtended"]: - m = re.match('^(?P\d+)(\|(?P\d+)' + - '\:(?P\d+))?(\$(?P.+))?$', c) + m = re.match('^(?P\\d+)(\\|(?P\\d+)' + + '\\:(?P\\d+))?(\\$(?P.+))?$', 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'))]) @@ -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"] diff --git a/omero/figure_scripts/Movie_Figure.py b/omero/figure_scripts/Movie_Figure.py index 29dc4814f..8593e1979 100644 --- a/omero/figure_scripts/Movie_Figure.py +++ b/omero/figure_scripts/Movie_Figure.py @@ -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) @@ -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, @@ -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 @@ -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 diff --git a/omero/figure_scripts/Movie_ROI_Figure.py b/omero/figure_scripts/Movie_ROI_Figure.py index 4142035fe..dc2e97597 100644 --- a/omero/figure_scripts/Movie_ROI_Figure.py +++ b/omero/figure_scripts/Movie_ROI_Figure.py @@ -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 @@ -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): @@ -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)) @@ -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)) diff --git a/omero/figure_scripts/ROI_Split_Figure.py b/omero/figure_scripts/ROI_Split_Figure.py index 681b98a8e..5c534719a 100644 --- a/omero/figure_scripts/ROI_Split_Figure.py +++ b/omero/figure_scripts/ROI_Split_Figure.py @@ -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! @@ -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" @@ -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: @@ -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: @@ -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)) @@ -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 @@ -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)) @@ -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)) diff --git a/omero/figure_scripts/Split_View_Figure.py b/omero/figure_scripts/Split_View_Figure.py index 720871dc8..293a6dcaa 100644 --- a/omero/figure_scripts/Split_View_Figure.py +++ b/omero/figure_scripts/Split_View_Figure.py @@ -386,7 +386,8 @@ def make_split_view_figure(conn, pixel_ids, z_start, z_end, split_indexes, font = image_utils.get_font(fontsize) mode = "RGB" white = (255, 255, 255) - text_height = font.getsize("Textq")[1] + box = font.getbbox("Textq") + text_height = box[3] - box[1] # if adding text to the left, write the text on horizontal canvas, then # rotate to vertical (below) @@ -404,9 +405,9 @@ def make_split_view_figure(conn, pixel_ids, z_start, z_end, split_indexes, image_labels.reverse() for row in image_labels: py = left_text_width - text_gap # start at bottom - for l, label in enumerate(row): + for count, label in enumerate(row): 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((height - w) // 2) textdraw.text((px+inset, py), label, font=font, fill=(0, 0, 0)) @@ -442,7 +443,8 @@ def make_split_view_figure(conn, pixel_ids, z_start, z_end, split_indexes, py = top_text_height + spacer - (text_height + text_gap) for index in split_indexes: # calculate the position of the text, centered above the image - w = font.getsize(channel_names[index])[0] + box = font.getbbox(channel_names[index]) + w = box[2] - box[0] inset = int((width - w) // 2) # text is coloured if channel is grey AND in the merged image rgba = (0, 0, 0, 255) @@ -465,12 +467,14 @@ def make_split_view_figure(conn, pixel_ids, z_start, z_end, split_indexes, if rgba == (255, 255, 255, 255): # if white (unreadable) rgba = (0, 0, 0, 255) # needs to be black! name = channel_names[index] - comb_text_width = font.getsize(name)[0] + box = font.getbbox(name) + comb_text_width = box[2] - box[0] inset = int((width - comb_text_width) // 2) draw.text((px + inset, py), name, font=font, fill=rgba) py = py - text_height else: - comb_text_width = font.getsize("Merged")[0] + box = font.getbbox("Merged") + comb_text_width = box[2] - box[0] inset = int((width - comb_text_width) // 2) px = px + inset draw.text((px, py), "Merged", font=font, fill=(0, 0, 0)) diff --git a/omero/figure_scripts/Thumbnail_Figure.py b/omero/figure_scripts/Thumbnail_Figure.py index d303dcdf3..0f905b1c5 100644 --- a/omero/figure_scripts/Thumbnail_Figure.py +++ b/omero/figure_scripts/Thumbnail_Figure.py @@ -144,10 +144,14 @@ def paint_thumbnail_grid(thumbnail_store, length, spacing, pixel_ids, fontsize = (length // 10) + 5 font = get_font(fontsize) if left_label: - text_width, text_height = font.getsize(left_label) + box = font.getbbox(left_label) + text_width = box[2] - box[0] + text_height = box[3] - box[1] left_space = spacing + text_height + spacing if top_label: - text_width, text_height = font.getsize(top_label) + box = font.getbbox(top_label) + text_width = box[2] - box[0] + text_height = box[3] - box[1] top_space = spacing + text_height + spacing min_width = left_space + text_width + spacing @@ -168,7 +172,8 @@ def paint_thumbnail_grid(thumbnail_store, length, spacing, pixel_ids, label_size = (label_canvas_width, label_canvas_height) text_canvas = Image.new(mode, label_size, bg) draw = ImageDraw.Draw(text_canvas) - text_width = font.getsize(left_label)[0] + box = font.getbbox(left_label) + text_width = box[2] - box[0] text_x = (label_canvas_width - text_width) // 2 draw.text((text_x, spacing), left_label, font=font, fill=text_color) vertical_canvas = text_canvas.rotate(90) @@ -297,7 +302,8 @@ def paint_dataset_canvas(conn, images, title, tag_ids=None, # set-up fonts fontsize = length/7 + 5 font = get_font(fontsize) - text_height = font.getsize("Textq")[1] + box = font.getbbox("Textq") + text_height = box[3] - box[1] top_spacer = spacing + text_height left_spacer = spacing + text_height @@ -372,11 +378,13 @@ def paint_dataset_canvas(conn, images, title, tag_ids=None, 'showSubsetLabels': show_subset_labels}) # Find the indent we need - max_tag_name_width = max([font.getsize(ts['tagText'])[0] - for ts in toptag_sets]) + max_tag_name_width = 0 + for ts in toptag_sets: + box = font.getbbox(ts['tagText']) + max_tag_name_width = max(max_tag_name_width, box[2] - box[0]) if show_untagged: - max_tag_name_width = max(max_tag_name_width, - font.getsize("Not Tagged")[0]) + box = font.getbbox("Not Tagged") + max_tag_name_width = max(max_tag_name_width, (box[2] - box[0])) tag_sub_panes = [] @@ -435,7 +443,8 @@ def make_tagset_canvas(tag_string, tagset_pix_ids, show_subset_labels): p_y += pane.size[1] if tag_text is not None: draw = ImageDraw.Draw(tag_canvas) - tt_w, tt_h = font.getsize(tag_text) + box = font.getbbox(tag_text) + tt_h = box[3] - box[1] h_offset = (total_height - tt_h)/2 draw.text((spacing, h_offset), tag_text, font=font, fill=(50, 50, 50)) @@ -476,8 +485,8 @@ def make_tagset_canvas(tag_string, tagset_pix_ids, show_subset_labels): # figureDate = "%s - %s" % (firstdate, lastdate) draw = ImageDraw.Draw(full_canvas) - # dateWidth = draw.textsize(figureDate, font=font)[0] - # titleWidth = draw.textsize(title, font=font)[0] + # dateWidth = draw.textlength(figureDate, font=font) + # titleWidth = draw.textlength(title, font=font) # dateX = fullCanvas.size[0] - spacing - dateWidth # title draw.text((left_spacer, spacing), title, font=font, fill=(0, 0, 0)) diff --git a/omero/util_scripts/Dataset_To_Plate.py b/omero/util_scripts/Dataset_To_Plate.py index 88183b078..f6c060fff 100644 --- a/omero/util_scripts/Dataset_To_Plate.py +++ b/omero/util_scripts/Dataset_To_Plate.py @@ -63,7 +63,7 @@ def add_images_to_plate(conn, images, plate_id, column, row, remove_from=None): for image in images: if remove_from is not None: links = list(image.getParentLinks(remove_from.id)) - link_ids = [l.id for l in links] + link_ids = [link.id for link in links] conn.deleteObjects('DatasetImageLink', link_ids) return True diff --git a/omero/util_scripts/Images_From_ROIs.py b/omero/util_scripts/Images_From_ROIs.py index 465252e9c..e5f1d0108 100644 --- a/omero/util_scripts/Images_From_ROIs.py +++ b/omero/util_scripts/Images_From_ROIs.py @@ -140,7 +140,7 @@ def get_rectangles(conn, image_id): # note x and y for every T, to track moving object xy_by_time = {} for shape in roi.copyShapes(): - if type(shape) == omero.model.RectangleI: + if isinstance(shape, omero.model.RectangleI): # check t range and z range for every rectangle # t and z (and c) for shape is optional # https://www.openmicroscopy.org/site/support/omero5.2/developers/Model/EveryObject.html#shape diff --git a/omero/util_scripts/Move_Annotations.py b/omero/util_scripts/Move_Annotations.py index 625aeb83a..a57583905 100644 --- a/omero/util_scripts/Move_Annotations.py +++ b/omero/util_scripts/Move_Annotations.py @@ -62,11 +62,11 @@ def move_well_annotations(conn, well, ann_type, remove_anns, ns): ns=ns, params=params)) # Filter by type - old_links = [l for l in old_links + old_links = [link for link in old_links if (ann_type is None - or (l.child.__class__.__name__ == ann_type))] + or (link.child.__class__.__name__ == ann_type))] - link_ids = [l.id for l in old_links] + link_ids = [link.id for link in old_links] def get_key(ann_link, with_owner=False): # We use ann's 'key' to avoid adding duplicate annotations @@ -76,28 +76,28 @@ def get_key(ann_link, with_owner=False): links_dict = {} # Remove duplicate annotations according to get_key(l) - for l in old_links: - links_dict[get_key(l, conn.isAdmin())] = l + for link in old_links: + links_dict[get_key(link, conn.isAdmin())] = link old_links = links_dict.values() # Find existing links on Well so we don't try to duplicate them existing_well_links = list(conn.getAnnotationLinks('Well', [well.id], ns=ns, params=params)) - existing_well_keys = [get_key(l) for l in existing_well_links] + existing_well_keys = [get_key(link) for link in existing_well_links] new_links = [] - for l in old_links: - if get_key(l) in existing_well_keys: + for old_link in old_links: + if get_key(old_link) in existing_well_keys: continue - log(" Annotation: %s %s" % (l.child.id.val, - l.child.__class__.__name__)) + log(" Annotation: %s %s" % (old_link.child.id.val, + old_link.child.__class__.__name__)) link = WellAnnotationLinkI() link.parent = WellI(well.id, False) - link.child = l.child + link.child = old_link.child # If Admin, the new link Owner is same as old link Owner if conn.isAdmin(): - owner_id = l.details.owner.id.val + owner_id = old_link.details.owner.id.val link.details.owner = ExperimenterI(owner_id, False) new_links.append(link) try: