Skip to content

Conversation

@mlnagy
Copy link

@mlnagy mlnagy commented May 1, 2024

No description provided.

from mibidata import mibi_image as mi
from mibidata import tiff
import json
from mibitracker.request_helpers import MibiRequests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reordered the imports. Python style is to import 1) standard modules 2) modules installed with conda/pip 3) custom modules, such as those in the repo being worked on

if out_img is None:
out_img = np.zeros((h*shape_2d[0]+(h-1)*margin["y"], w*shape_2d[1]+(w-1)*margin["x"], ch_count),
dtype=fov_img.dtype)
out_img = np.zeros(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, and a bunch of other places, kept line lengths to <=80 characters

"fov" + "-" + str(
f["runOrder"]).zfill(2) + "-" + fov_name) + ".tiff")

print(f'Stitching {run} - {roi}: {len(roi_fov_paths)} FOVs')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the print statement a bit more informative/readable

f_split[0] = roi
out_mibi_tiff.set_fov_id(f_split[0], '/'.join(f_split))

if not out_folder:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made out_folder an optional parameter, if omitted then it defaults to saving in the run_folder

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment

if coord["y"] < um_min_y:
um_min_y = coord["y"]
roi_fov_paths.append(os.path.join(run_folder,"fov"+"-"+str(f["runOrder"]).zfill(2)+"-"+fov_name)+".tiff")
for r in run_json["rois"]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pulled out all the rest of the code from the with block

for t in range(MAX_TRIES):
try:
run_id = mr.get('/runs/', params={'name': run}).json()['results'][0]['id']
_ = mr.post('/images/', json=new_im_metadata)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the ignored return value

print(
f"Stitched MIBItiff, {out_path}, uploaded to MIBItracker.")

def parse_args(args):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of specifying variables in the script itself, let the users pass them as arguments when running it

''' Argument parsing helper function.
'''
parser = argparse.ArgumentParser(
description='Script for creating a stitched ROI MIBItiff from a folder '
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moves the script description and argument help text to argparse so that it can be viewed with python stitching.py --help

@jaytarolli
Copy link
Contributor

jaytarolli commented Jul 3, 2024

@mlnagy I made some changes and have added comments to my changes to give you context for why I did. I also tested it to some degree. Testing performed:

  • python .\stitching.py --run_folder "C:/Users/Jay Tarolli/data/M14/2024-05-30T21-45-35-7pass_largeROI": Success
  • python .\stitching.py --run_folder "C:/Users/Jay Tarolli/data/M14/2024-05-30T21-45-35-7pass_largeROI" --out_folder 'C:/Users/Jay Tarolli/data/M14/2024-05-30T21-45-35-7pass_largeROI_subset/subfolder': Success
  • python .\stitching.py --run_folder "C:/Users/Jay Tarolli/data/M14/2024-05-30T21-45-35-7pass_largeROI" --enforce_square: Sets enforce_square to True; canceled before TIFF generation
  • python .\stitching.py --run_folder "C:/Users/Jay Tarolli/data/M14/2024-05-30T21-45-35-7pass_largeROI" --upload_to_mibitracker: Sets upload_to_mibitracker to True, fails because URL, email, and password not specified
  • python .\stitching.py --run_folder "C:/Users/Jay Tarolli/data/M14/2024-05-30T21-45-35-7pass_largeROI" --upload_to_mibitracker --mibitracker_email [redacted] --mibitracker_password [redacted] --mibitracker_url [redacted]: MibiRequests instance created, verifying log in; canceled before upload
  • python .\stitching.py --run_folder "C:/Users/Jay Tarolli/data/M14/2024-05-30T21-45-35-7pass_largeROI": verified margin = {'x': 0, 'y': 0}
  • python .\stitching.py --run_folder "C:/Users/Jay Tarolli/data/M14/2024-05-30T21-45-35-7pass_largeROI" --fov_margin_size_x 10: verified margin = {'x': 10, 'y': 0}
  • python .\stitching.py --run_folder "C:/Users/Jay Tarolli/data/M14/2024-05-30T21-45-35-7pass_largeROI" --fov_margin_size_x 10 --fov_margin_size_y 2: verified margin = {'x': 10, 'y': 20}


MAX_TRIES = 5

def combine_entity_by_name(roi_fov_paths, cols, rows, enforce_square, margin):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that we probably won't be needing enforce_square anymore now that mibitracker allows for non-square images. Do we want to at least change this so that it has the default value of False?

int(max(w*shape_2d[1], h*shape_2d[0])), ref_metadata


def stitch_fovs(run_folder, out_folder, session_dict, upload_to_mibitracker,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to make it clear that out_folder can be None, can we have it have the default value of None?

f_split[0] = roi
out_mibi_tiff.set_fov_id(f_split[0], '/'.join(f_split))

if not out_folder:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment

from mibidata import tiff
from mibitracker.request_helpers import MibiRequests

MAX_TRIES = 5

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this and have a comment on what this is used for? Something like MAX_MIBITRACKER_REST_TRIES or something

@@ -0,0 +1,325 @@
""" Script for creating a stitched ROI MIBItiff from a folder of FOVs.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All methods in this file need a docstring explaining what the function does and what each argument is: https://peps.python.org/pep-0257/#multi-line-docstrings


import numpy as np

sys.path.append('../..')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is needed if a user is just using the mibilib conda env

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants