-
Notifications
You must be signed in to change notification settings - Fork 260
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
Minor style updates and QOL changes #830
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,3 +84,7 @@ Thumbs.db | |
doc/source/reference | ||
venv/ | ||
.buildbot.patch | ||
|
||
# IDE Settings # | ||
############ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ | |
img = nipy.load_image(img_fname) | ||
# Set affine as for FOV, not AC | ||
RZS = img.affine[:3, :3] | ||
vox_fov_center = -(np.array(img.shape) - 1) / 2. | ||
vox_fov_center = -(np.array(img.shape) - 1) / 2.0 | ||
T = RZS.dot(vox_fov_center) | ||
img.affine[:3, 3] = T | ||
# Take stuff off the top of the full image, to emphasize FOV | ||
|
@@ -63,18 +63,24 @@ | |
epi_br = np.array((92, 70)) * 2 | ||
epi_tl = np.array((7, 63)) * 2 | ||
# Find lengths of sides | ||
epi_y_len = np.sqrt((np.subtract(epi_bl, epi_tl)**2).sum()) | ||
epi_x_len = np.sqrt((np.subtract(epi_bl, epi_br)**2).sum()) | ||
epi_y_len = np.sqrt((np.subtract(epi_bl, epi_tl) ** 2).sum()) | ||
epi_x_len = np.sqrt((np.subtract(epi_bl, epi_br) ** 2).sum()) | ||
x, y = 0, 1 | ||
# Make a rectangular box with these sides | ||
|
||
|
||
def make_ortho_box(bl, x_len, y_len): | ||
""" Make a box with sides parallel to the axes | ||
""" | ||
return np.array((bl, | ||
[bl[x] + x_len, bl[y]], | ||
[bl[x], bl[y] + y_len], | ||
[bl[x] + x_len, bl[y] + y_len])) | ||
return np.array( | ||
( | ||
bl, | ||
[bl[x] + x_len, bl[y]], | ||
[bl[x], bl[y] + y_len], | ||
[bl[x] + x_len, bl[y] + y_len], | ||
) | ||
) | ||
|
||
|
||
orth_epi_box = make_ortho_box(epi_bl, epi_x_len, epi_y_len) | ||
|
||
|
@@ -86,8 +92,7 @@ def make_ortho_box(bl, x_len, y_len): | |
|
||
|
||
def plot_line(pt1, pt2, fmt='r-', label=None): | ||
plt.plot([pt1[0], pt2[0]], [pt1[1], pt2[1]], fmt, | ||
label=label) | ||
plt.plot([pt1[0], pt2[0]], [pt1[1], pt2[1]], fmt, label=label) | ||
|
||
|
||
def plot_box(box_def, fmt='r-', label=None): | ||
|
@@ -103,18 +108,14 @@ def rotate_box(box_def, angle, origin): | |
box_def_zeroed = box_def - origin | ||
cost = math.cos(angle) | ||
sint = math.sin(angle) | ||
rot_array = np.array([[cost, -sint], | ||
[sint, cost]]) | ||
rot_array = np.array([[cost, -sint], [sint, cost]]) | ||
box_def_zeroed = np.dot(rot_array, box_def_zeroed.T).T | ||
return box_def_zeroed + origin | ||
|
||
|
||
def labeled_point(pt, marker, text, markersize=10, color='k'): | ||
plt.plot(pt[0], pt[1], marker, markersize=markersize) | ||
plt.text(pt[0] + markersize / 2, | ||
pt[1] - markersize / 2, | ||
text, | ||
color=color) | ||
plt.text(pt[0] + markersize / 2, pt[1] - markersize / 2, text, color=color) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
|
||
|
||
def plot_localizer(): | ||
|
@@ -126,8 +127,10 @@ def plot_localizer(): | |
def save_plot(): | ||
# Plot using global variables | ||
plot_localizer() | ||
|
||
def vx2mm(pts): | ||
return pts - iso_center | ||
|
||
plot_box(vx2mm(rot_box), label='EPI bounding box') | ||
plot_box(vx2mm(anat_box), 'b-', label='Structural bounding box') | ||
labeled_point(vx2mm(epi_center), 'ro', 'EPI FOV center') | ||
|
@@ -145,7 +148,7 @@ def vx2mm(pts): | |
anat_center = np.mean(anat_box, axis=0) | ||
# y axis on the plot is first axis of image | ||
sag_y, sag_x = sagittal.shape | ||
iso_center = (np.array([sag_x, sag_y]) - 1) / 2. | ||
iso_center = (np.array([sag_x, sag_y]) - 1) / 2.0 | ||
sag_extents = [-iso_center[0], iso_center[0], -iso_center[1], iso_center[1]] | ||
|
||
# Back to image coordinates | ||
|
@@ -155,7 +158,7 @@ def vx2mm(pts): | |
rot = np.eye(4) | ||
rot[:3, :3] = euler.euler2mat(0, 0, -angle) | ||
# downsample to make smaller output image | ||
downsamp = 1/3 | ||
downsamp = 1 / 3 | ||
epi_scale = np.diag([downsamp, downsamp, downsamp, 1]) | ||
# template voxels to epi box image voxels | ||
vox2epi_vox = epi_scale.dot(rot.dot(epi_trans)) | ||
|
@@ -165,8 +168,7 @@ def vx2mm(pts): | |
epi_vox_shape = np.array([data.shape[0], epi_x_len, epi_y_len]) * downsamp | ||
# Make sure dimensions are odd by rounding up or down | ||
# This makes the voxel center an integer index, which is convenient | ||
epi_vox_shape = [np.floor(d) if np.floor(d) % 2 else np.ceil(d) | ||
for d in epi_vox_shape] | ||
epi_vox_shape = [np.floor(d) if np.floor(d) % 2 else np.ceil(d) for d in epi_vox_shape] | ||
# resample, preserving affine | ||
epi_cmap = nca.vox2mni(epi_vox2mm) | ||
epi = rsm.resample(t2_img, epi_cmap, np.eye(4), epi_vox_shape) | ||
|
@@ -178,8 +180,9 @@ def vx2mm(pts): | |
anat_trans[:3, 3] = -np.array([0, anat_box[0, 0], anat_box[0, 1]]) | ||
vox2anat_vox = anat_scale.dot(anat_trans) | ||
anat_vox2mm = t1_img.affine.dot(npl.inv(vox2anat_vox)) | ||
anat_vox_shape = np.round(np.divide( | ||
[data.shape[0], anat_x_len, anat_y_len], anat_vox_sizes)) | ||
anat_vox_shape = np.round( | ||
np.divide([data.shape[0], anat_x_len, anat_y_len], anat_vox_sizes) | ||
) | ||
anat_cmap = nca.vox2mni(anat_vox2mm) | ||
anat = rsm.resample(t1_img, anat_cmap, np.eye(4), anat_vox_shape) | ||
anat_data = anat.get_fdata() | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This was more readable before.