From 12a5dba0ef1396f0055f260e618ea3b53787bae0 Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Wed, 10 Jan 2024 11:18:30 +0000 Subject: [PATCH] fix flake8 issue --- omero/analysis_scripts/Kymograph.py | 10 ++++----- omero/analysis_scripts/Kymograph_Analysis.py | 4 ++-- omero/analysis_scripts/Plot_Profile.py | 20 +++++++++--------- omero/annotation_scripts/KeyVal_to_csv.py | 6 +++--- omero/export_scripts/Make_Movie.py | 4 ++-- omero/figure_scripts/Movie_Figure.py | 2 +- omero/figure_scripts/Movie_ROI_Figure.py | 2 +- omero/figure_scripts/ROI_Split_Figure.py | 4 ++-- omero/figure_scripts/Split_View_Figure.py | 2 +- omero/util_scripts/Dataset_To_Plate.py | 2 +- omero/util_scripts/Images_From_ROIs.py | 2 +- omero/util_scripts/Move_Annotations.py | 22 ++++++++++---------- 12 files changed, 40 insertions(+), 40 deletions(-) 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..be04db1e6 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,11 +103,11 @@ 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: continue for the_c in the_cs: line_data = [] @@ -192,7 +192,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 +200,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/Make_Movie.py b/omero/export_scripts/Make_Movie.py index 4c0e3e1a9..f886135a3 100644 --- a/omero/export_scripts/Make_Movie.py +++ b/omero/export_scripts/Make_Movie.py @@ -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'))]) diff --git a/omero/figure_scripts/Movie_Figure.py b/omero/figure_scripts/Movie_Figure.py index 29dc4814f..815badda2 100644 --- a/omero/figure_scripts/Movie_Figure.py +++ b/omero/figure_scripts/Movie_Figure.py @@ -311,7 +311,7 @@ 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] inset = int((left_text_width - w) / 2) diff --git a/omero/figure_scripts/Movie_ROI_Figure.py b/omero/figure_scripts/Movie_ROI_Figure.py index 4142035fe..0c02dbee9 100644 --- a/omero/figure_scripts/Movie_ROI_Figure.py +++ b/omero/figure_scripts/Movie_ROI_Figure.py @@ -589,7 +589,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..0b0f61a37 100644 --- a/omero/figure_scripts/ROI_Split_Figure.py +++ b/omero/figure_scripts/ROI_Split_Figure.py @@ -320,7 +320,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 @@ -660,7 +660,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)) 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..971343765 100644 --- a/omero/figure_scripts/Split_View_Figure.py +++ b/omero/figure_scripts/Split_View_Figure.py @@ -404,7 +404,7 @@ 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] inset = int((height - w) // 2) 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..d3f76dce8 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))] - 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(l) for link in existing_well_links] new_links = [] - for l in old_links: - if get_key(l) in existing_well_keys: + for link in old_links: + if get_key(link) in existing_well_keys: continue - log(" Annotation: %s %s" % (l.child.id.val, - l.child.__class__.__name__)) + log(" Annotation: %s %s" % (link.child.id.val, + link.child.__class__.__name__)) link = WellAnnotationLinkI() link.parent = WellI(well.id, False) - link.child = l.child + link.child = 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 = link.details.owner.id.val link.details.owner = ExperimenterI(owner_id, False) new_links.append(link) try: