-
Notifications
You must be signed in to change notification settings - Fork 261
ENH: Add nib-roi command to crop (maybe flip) axes #947
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
Conversation
Hello @effigies, Thank you for updating! Cheers! There are no style issues detected in this Pull Request. 🍻 To test for issues locally, Comment last updated at 2020-10-09 12:41:12 UTC |
Codecov Report
@@ Coverage Diff @@
## master #947 +/- ##
==========================================
+ Coverage 91.87% 91.91% +0.04%
==========================================
Files 98 99 +1
Lines 12451 12514 +63
Branches 2193 2204 +11
==========================================
+ Hits 11439 11502 +63
Misses 678 678
Partials 334 334
Continue to review full report at Codecov.
|
80d6761
to
7e6bbf7
Compare
7e6bbf7
to
310a242
Compare
This could use a review. @chrispycheng any interest? |
@effigies Sure, let me get back to you! Plate's a bit stacked ATM |
No worries. |
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.
Ran the function and looks awesome! Skimmed the code and raised just one point of concern for your review. Also, figured I wouldn't rehash codecov, esp. since areas lacking coverage seem pretty insignificant.
Thanks for the review. I went ahead and added tests that should cover the remaining lines. |
The quest for coverage ended up finding an edge case. Full coverage and tests passing. @chrispycheng Do you have time for a final review? |
I’m smothered with work right now.. maybe in 2 weeks? is that OK?
…Sent from my iPhone
On Oct 9, 2020, at 21:17, Chris Markiewicz <[email protected]> wrote:
The quest for coverage ended up finding an edge case. Full coverage and tests passing.
@chrispycheng<https://github.com/chrispycheng> Do you have time for a final review?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#947 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AGU42AIZXEESWAMJ73AM4FDSJ4EM5ANCNFSM4QGSIMKQ>.
|
No worries. Thanks for the heads up. |
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.
Looks good - few comments
print("Could not slice image. Full traceback follows.") | ||
raise | ||
nb.save(sliced_img, opts.out_file) | ||
return 0 |
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.
is this needed?
return 0 |
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.
Not really, makes the output of calling main()
identical to the exit code, though. If I change this, I think I'll need to update a test, but I can.
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.
nbd 🤷♂️
parser.add_argument("-t", metavar="T1:T2", help="Start/stop along fourth axis (0-indexed)") | ||
parser.add_argument("in_file", help="Image file to crop") | ||
parser.add_argument("out_file", help="Output file name") | ||
|
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.
should this show the help if no arguments are provided?
if not args: | |
parser.print_help() | |
sys.exit(1) |
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.
You do at least get usage:
$ nib-roi
usage: nib-roi [-h] [--version] [-i I1:I2[:-1]] [-j J1:J2[:-1]]
[-k K1:K2[:-1]] [-t T1:T2]
in_file out_file
nib-roi: error: the following arguments are required: in_file, out_file
$ nib-roi --help
usage: nib-roi [-h] [--version] [-i I1:I2[:-1]] [-j J1:J2[:-1]]
[-k K1:K2[:-1]] [-t T1:T2]
in_file out_file
Crop images to a region of interest
positional arguments:
in_file Image file to crop
out_file Output file name
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
-i I1:I2[:-1] Start/stop [flip] along first axis (0-indexed)
-j J1:J2[:-1] Start/stop [flip] along second axis (0-indexed)
-k K1:K2[:-1] Start/stop [flip] along third axis (0-indexed)
-t T1:T2 Start/stop along fourth axis (0-indexed)
If a start or stop value is omitted, the start or end of the axis is assumed.
We don't have a terribly consistent style, to go by:
$ nib-ls; echo $?
0
$ nib-conform; echo $?
usage: nib-conform [-h] [--out-shape OUT_SHAPE OUT_SHAPE OUT_SHAPE]
[--voxel-size VOXEL_SIZE VOXEL_SIZE VOXEL_SIZE]
[--orientation ORIENTATION] [-f] [-V]
infile outfile
nib-conform: error: the following arguments are required: infile, outfile
2
$ nib-diff; echo $?
Traceback (most recent call last):
File "/home/cjmarkie/anaconda3/envs/nibabel_dev/bin/nib-diff", line 11, in <module>
load_entry_point('nibabel', 'console_scripts', 'nib-diff')()
File "/home/cjmarkie/Projects/nipy/nibabel/nibabel/cmdline/diff.py", line 362, in main
dtype=opts.dtype
File "/home/cjmarkie/Projects/nipy/nibabel/nibabel/cmdline/diff.py", line 315, in diff
assert len(files) >= 2, "Please enter at least two files"
AssertionError: Please enter at least two files
1
$ nib-tck2trk; echo $?
usage: nib-tck2trk [-h] [-f] anatomy tractogram [tractogram ...]
nib-tck2trk: error: the following arguments are required: anatomy, tractogram
2
But on the whole I think I'm okay with argparse defaults.
Since none of the comments seemed blocking, I'm going to go ahead and merge. Thanks for the reviews, @chrispycheng, @mgxd! |
Quick command to easily crop images using slice notation. Inspired by
fslroi
.Features:
-1
step (but downsampling with other steps is not...)Safety checks
that are not there:notchecked for, e.g.-i 1:1
or-j 5:6:-1
.will cause a BusError as the image being read will be truncated.will avoid mmaping and is tested for.With a basic usable tool, I'm not inclined to push further today, so I figured I'd give people a chance to comment.