-
Notifications
You must be signed in to change notification settings - Fork 15
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
BB template & vertex outliers #333
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c46cb5e
vertex cleaning, especially for DG
3f73bf3
effectively resotres parameters to previous defaults
8f1367c
lint
426058a
note
c819072
restoreing one more parameter
f863be6
addresses configurable DG surface
cbf3b0a
lint
9211322
surface configuration now more editable
e03417a
bigbrain filled; not on OSF
8f08698
renaming & lower resolution
003dbf3
grouped outlier opts
482ad53
lint
86fe801
Merge branch 'dev-v2.0.0' into BBtemplate
jordandekraker b57eaee
lint
09c3e49
removed redudant hemi conditional; replaced with hippVSdentate
2d945d9
bugfixes
3a92196
Merge branch 'dev-v2.0.0' into BBtemplate
jordandekraker 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
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import nibabel as nib | ||
import numpy as np | ||
from scipy.stats import zscore | ||
import copy | ||
|
||
SDthreshold = snakemake.params.threshold | ||
iters = snakemake.params.dist | ||
|
||
gii = nib.load(snakemake.input.gii) | ||
varr = gii.get_arrays_from_intent("NIFTI_INTENT_POINTSET")[0] | ||
V = varr.data | ||
farr = gii.get_arrays_from_intent("NIFTI_INTENT_TRIANGLE")[0] | ||
F = farr.data | ||
|
||
|
||
# find local outliers by smoothing and then substracting from original | ||
# https://github.com/MICA-MNI/hippomaps/blob/master/hippomaps/utils.py | ||
def avg_neighbours(F, cdat, n): | ||
frows = np.where(F == n)[0] | ||
v = np.unique(F[frows, :]) | ||
cdat = np.reshape(cdat, (len(cdat), -1)) | ||
out = np.nanmean(cdat[v, :], 0) | ||
return out | ||
|
||
|
||
def surfdat_smooth(F, cdata, iters=1): | ||
sz = cdata.shape | ||
cdata = cdata.reshape(cdata.shape[0], -1) | ||
cdata_smooth = copy.deepcopy(cdata) | ||
for i in range(iters): | ||
for n in range(len(cdata)): | ||
cdata_smooth[n, :] = avg_neighbours(F, cdata, n) | ||
cdata = copy.deepcopy(cdata_smooth) | ||
return cdata_smooth.reshape(sz) | ||
|
||
|
||
Vsmooth = surfdat_smooth(F, V, iters=iters) | ||
Vdiffs = V - Vsmooth | ||
Vdists = np.sqrt((Vdiffs[:, 0]) ** 2 + (Vdiffs[:, 1]) ** 2 + (Vdiffs[:, 2]) ** 2) | ||
Vzscored = zscore(Vdists) | ||
outliers = (Vzscored > SDthreshold) | (Vzscored < -SDthreshold) | ||
V[outliers, :] = np.nan | ||
|
||
|
||
# most nans should be just isolated points, but in case there is an island of nans this will erode it, replacing with decent (but not perfect) guesses of where vertices should be | ||
while np.isnan(np.sum(V)): | ||
# index of vertices containing nan | ||
i = np.where(np.isnan(V)) | ||
ii = np.unique(i[0]) | ||
# replace with the nanmean of neighbouring vertices | ||
newV = V | ||
for n in ii: | ||
f = np.where(F == n) | ||
v = F[f[0]] | ||
vv = np.unique(v) | ||
newV[n, :] = np.nanmean(V[vv, :], 0) | ||
V = newV | ||
|
||
nib.save(gii, snakemake.output.gii) |
Oops, something went wrong.
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.
I know this PR is merged already, but easier to comment here than anew -- these changes break the rule because epsilon is not a parameter in the rule. Also, unfold_gx/unfold_gy/unfold_gz get create here, but don't actually get used .. so it seems we can just revert the create_warps changes to fix the problem, unless you were trying to do something else here?
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.
oh yeah, good point. Looks like we were never actually using the epsilon that we'd previously defined? I'll make a small PR to patch this & 1 other small bug i found
Also yeah
points
andunfold_gx
somehow became redundant. We can cut the latter.