-
Notifications
You must be signed in to change notification settings - Fork 9
Mib 21: Add stitching script #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
… file name; added margins
| from mibidata import mibi_image as mi | ||
| from mibidata import tiff | ||
| import json | ||
| from mibitracker.request_helpers import MibiRequests |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"]: |
There was a problem hiding this comment.
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
scripts/stitching/stitching.py
Outdated
| 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) |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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 ' |
There was a problem hiding this comment.
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
|
@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:
|
|
|
||
| MAX_TRIES = 5 | ||
|
|
||
| def combine_entity_by_name(roi_fov_paths, cols, rows, enforce_square, margin): |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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. | |||
There was a problem hiding this comment.
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('../..') |
There was a problem hiding this comment.
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
No description provided.