-
Notifications
You must be signed in to change notification settings - Fork 439
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
WIP: Add mapmri flow #1350
WIP: Add mapmri flow #1350
Conversation
Hi @Aarya, okay, you are moving towards the correct direction but not there yet. Will start commenting asap. Thanks! |
@Garyfallidis anything I can change? |
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.
Hi @aarya22, it is a good start! I made some comment on your PR. Firstfall, you should do a git rebase on your code to update your code with the mainstream. Second, build test failed because of your matplotlib
dependency (you can see it here. I suppose you do not really need this dependency. You can read the comment below to see why.
Let me know if you have any question or if you need help.
Thanks for this contribution!
dipy/workflows/reconst.py
Outdated
from dipy.reconst import mapmri | ||
import matplotlib | ||
matplotlib.use('agg') | ||
import matplotlib.pyplot as plt |
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, you do not need matplotlib
here
dipy/workflows/reconst.py
Outdated
def get_short_name(cls): | ||
return 'mapmri' | ||
|
||
def run(self, data_file, data_bvecs, data_bvals, small_delta, big_delta): |
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 should define output files init the run
function. Look at the example on the following link : https://github.com/nipy/dipy/blob/master/dipy/workflows/reconst.py#L34
It will be good if you can add default value too. Indeed, it will be useful for beginners who do not know what to put.
dipy/workflows/reconst.py
Outdated
return 'mapmri' | ||
|
||
def run(self, data_file, data_bvecs, data_bvals, small_delta, big_delta): | ||
img = nib.load(data_file) |
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.
try to use io_iterator
like the example here. It permits you to read many input files.
dipy/workflows/reconst.py
Outdated
|
||
def run(self, data_file, data_bvecs, data_bvals, small_delta, big_delta): | ||
img = nib.load(data_file) | ||
bvals,bvecs = read_bvals_bvecs(data_bval,data_bvec) |
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.
same as above
dipy/workflows/reconst.py
Outdated
cax = divider.append_axes("right", size="5%", pad=0.05) | ||
plt.colorbar(ind, cax=cax) | ||
|
||
plt.savefig('MAPMRI_maps_regularization.png') |
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 suppose we do not want to save this data in this way but we prefer to return many output files that can be input files for another process (or workflow). Currently, we can not do that with your code. So you should remove the matplolib
part and replace it. you can see an example in the link above
dipy/workflows/reconst.py
Outdated
return 'mapmri' | ||
|
||
def run(self, data_file, data_bvecs, data_bvals, small_delta, big_delta): | ||
img = nib.load(data_file) |
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.
Documentation is really important here. You can look at the example here how to make a good documentation
Codecov Report
@@ Coverage Diff @@
## master #1350 +/- ##
==========================================
- Coverage 87.07% 87.06% -0.01%
==========================================
Files 227 228 +1
Lines 29060 29170 +110
Branches 3123 3136 +13
==========================================
+ Hits 25303 25398 +95
- Misses 3047 3051 +4
- Partials 710 721 +11
Continue to review full report at Codecov.
|
Sorry for the long delay in replying to your comments @skoudoro I have been busy with school and midterms. Take a look at the updated workflow. Unfortunately, I cannot change the output of the workflow. Brain-Life is planning on using this workflow to power one of its applications (app-dipy-mapmri) and needs the png file as its output in order to work. I am also not sure what else to change it to so it can be compatible with other dipy workflows. Let me know if there are any problems here and hopefully I can change it promptly. |
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 problem and thanks for that @aarya22! I made some few comments below.
Can you add a test for your workflow? you will find an example in dipy/workflows/tests/test_reconst_dti
I am surprised that this workflow output is a plot screenshot and I wonder How you can use it as an input of other brain-life apps? Can you explain me more?
Path to the input volume. | ||
data_bvecs : string | ||
Path to the bvec files. | ||
data_bvals : |
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.
add the datatype -> data_bvals : string
Path to the bvec files. | ||
data_bvals : | ||
Path to the bval files. | ||
small_delta : |
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.
add the datatype -> small_delta : float
small_delta : | ||
Small delta value used in generation of gradient table of provided | ||
bval and bvec. (default: 0.0129) | ||
big_delta : |
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.
add the datatype -> big_delta : float
dipy/workflows/reconst.py
Outdated
big_delta : | ||
Big delta value used in generation of gradient table of provided | ||
bval and bvec. (default: 0.0218) | ||
save_metrics : |
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.
add the datatype -> save_metric : string
dipy/workflows/reconst.py
Outdated
big_delta=big_delta, b0_threshold=50) | ||
|
||
|
||
data_small = data[60:85, 80:81, 60:85] |
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.
Why do you crop the data? if it is really necessary, you have to warn the user that only a small part of its data will be processed. Otherwise, use the whole data.
I would not make the output of this a png. If brain-life requires a png, I
would do this in the definition of the app there.
…On Tue, Oct 31, 2017 at 11:00 AM, Serge Koudoro ***@***.***> wrote:
***@***.**** requested changes on this pull request.
no problem and thanks for that @aarya22 <https://github.com/aarya22>! I
made some few comments below.
Can you add a test for your workflow? you will find an example in
dipy/workflows/tests/test_reconst_dti
<https://github.com/nipy/dipy/blob/master/dipy/workflows/tests/test_reconst_dti.py>
I am surprised that this workflow output is a plot screenshot and I wonder
How you can use it as an input of other brain-life apps? Can you explain me
more?
------------------------------
In dipy/workflows/reconst.py
<#1350 (comment)>:
> + return 'mapmri'
+
+ def run(self, data_file, data_bvecs, data_bvals, small_delta=0.0129, big_delta=0.0218
+ save_metrics = [], out_dir='', out_mapmri='MAPMRI_maps_regularization.png'):
+ """ Workflow for the app-dipy-mapmri on Brain-Life (www.brain-life.org).
+ Generates RTOP graphs saved in a .png format in input files provided by
+ `data_file` and saves the png file to an output directory specified by
+ `out_dir`.
+
+ Parameters
+ ----------
+ data_file : string
+ Path to the input volume.
+ data_bvecs : string
+ Path to the bvec files.
+ data_bvals :
add the datatype -> data_bvals : string
------------------------------
In dipy/workflows/reconst.py
<#1350 (comment)>:
> + def run(self, data_file, data_bvecs, data_bvals, small_delta=0.0129, big_delta=0.0218
+ save_metrics = [], out_dir='', out_mapmri='MAPMRI_maps_regularization.png'):
+ """ Workflow for the app-dipy-mapmri on Brain-Life (www.brain-life.org).
+ Generates RTOP graphs saved in a .png format in input files provided by
+ `data_file` and saves the png file to an output directory specified by
+ `out_dir`.
+
+ Parameters
+ ----------
+ data_file : string
+ Path to the input volume.
+ data_bvecs : string
+ Path to the bvec files.
+ data_bvals :
+ Path to the bval files.
+ small_delta :
add the datatype -> small_delta : float
------------------------------
In dipy/workflows/reconst.py
<#1350 (comment)>:
> + Generates RTOP graphs saved in a .png format in input files provided by
+ `data_file` and saves the png file to an output directory specified by
+ `out_dir`.
+
+ Parameters
+ ----------
+ data_file : string
+ Path to the input volume.
+ data_bvecs : string
+ Path to the bvec files.
+ data_bvals :
+ Path to the bval files.
+ small_delta :
+ Small delta value used in generation of gradient table of provided
+ bval and bvec. (default: 0.0129)
+ big_delta :
add the datatype -> big_delta : float
------------------------------
In dipy/workflows/reconst.py
<#1350 (comment)>:
> +
+ Parameters
+ ----------
+ data_file : string
+ Path to the input volume.
+ data_bvecs : string
+ Path to the bvec files.
+ data_bvals :
+ Path to the bval files.
+ small_delta :
+ Small delta value used in generation of gradient table of provided
+ bval and bvec. (default: 0.0129)
+ big_delta :
+ Big delta value used in generation of gradient table of provided
+ bval and bvec. (default: 0.0218)
+ save_metrics :
add the datatype -> save_metric : string
------------------------------
In dipy/workflows/reconst.py
<#1350 (comment)>:
> + """
+ io_it = self.get_io_iterator()
+ for dwi, bval, bvec, mapname in io_it:
+
+ logging.info('Computing DTI metrics for {0}'.format(dwi))
+ img = nib.load(dwi)
+ data = img.get_data()
+ bvals,bvecs = read_bvals_bvecs(bval, bvec)
+
+
+ gtab = gradient_table(bvals=bvals, bvecs=bvecs,
+ small_delta=small_delta,
+ big_delta=big_delta, b0_threshold=50)
+
+
+ data_small = data[60:85, 80:81, 60:85]
Why do you crop the data? if it is really necessary, you have to warn the
user that only a small part of its data will be processed. Otherwise, use
the whole data.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1350 (review)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAHPNj667zJduuOuFuCWklQV1klVj5o6ks5sx2BFgaJpZM4PxdHu>
.
|
The reason I cropped the data and had the output be a png file is because I wanted this to be a simple preliminary test for making a brain-life application from a dipy workflow. I was thinking that eventually brain-life applications can simply become wrappers for the dipy workflow. I agree that png files should not be an output of the workflow, but I am not sure what else I should return from Mapmir. I do not know enough about the model, if you have any suggestions I will gladly take them. |
We can talk about that when we meet tomorrow. Ideally, this would produce
something similar to what the tensor workflow produces (
https://github.com/nipy/dipy/blob/master/dipy/workflows/reconst.py#L25) --
nifti files that store model parameters and derived maps.
…On Thu, Nov 2, 2017 at 10:09 AM, Aman Arya ***@***.***> wrote:
The reason I cropped the data and had the output be a png file is because
I wanted this to be a simple preliminary test for making a brain-life
application from a dipy workflow. I was thinking that eventually brain-life
applications can simply become wrappers for the dipy workflow.
I agree that png files should not be an output of the workflow, but I am
not sure what else I should return from Mapmir. I do not know enough about
the model, if you have any suggestions I will gladly take them.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1350 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAHPNoQvuYpdr8Ol_rEwgJnZ0v53v35nks5syfddgaJpZM4PxdHu>
.
|
Mmriflow
Fix unit tests
@skoudoro @arokem I've managed to get the Travis build test work for most of the environments, but there are a few environments that do not provide the CVXPY package which is necessary for the workflow to finish. I'm not sure how to access the config so I can include the CVXPY package in all the environments. |
Instead of installing cvxpy on all the machines, skip the tests that
require cvxpy, if that's not installed:
Like here:
https://github.com/nipy/dipy/blob/master/dipy/reconst/tests/test_mapmri.py#L624
…On Thu, Dec 7, 2017 at 6:11 PM, Aman Arya ***@***.***> wrote:
@skoudoro <https://github.com/skoudoro> @arokem
<https://github.com/arokem> I've managed to get the Travis build test
work for most of the environments, but there are a few environments that do
not provide the CVXPY package which is necessary for the workflow to
finish. I'm not sure how to access the config so I can include the CVXPY
package in all the environments.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1350 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAHPNpS-vdvWaSfnkB6-cr4rm1_lBWoGks5s-Jq1gaJpZM4PxdHu>
.
|
Add decorators to remove cvxpy from testing
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.
A few smaller comments, and questions about the overall design. @Garyfallidis : could you please take a look at this. Are we really supposed to have a separate object for every option of the model? That is a separate object for Laplacian regularization, for the positivity constraint, and for both?
return 'mapmri' | ||
|
||
def run(self, data_file, data_bvecs, data_bvals, model_type='', out_rtop='rtop.nii.gz', | ||
out_lapnorm='lapnorm.nii.gz',out_msd='msd.nii.gz', out_qiv='qiv.nii.gz', out_rtap='rtap.nii.gz', |
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.
PEP8: this line is >80 characters
out_lapnorm='lapnorm.nii.gz',out_msd='msd.nii.gz', out_qiv='qiv.nii.gz', out_rtap='rtap.nii.gz', | ||
out_rtpp='rtpp.nii.gz', small_delta=0.0129, big_delta=0.0218, save_metrics=[], out_dir=''): | ||
""" Workflow for the app-dipy-mapmri on Brain-Life (www.brain-life.org). | ||
Generates rtop, lapnorm, msd, qiv, rtap, rtpp saved in a nifti format in input files provided by |
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.
PEP8: line is >80 characters
io_it = self.get_io_iterator() | ||
for dwi, bval, bvec, out_rtop, out_lapnorm, out_msd, out_qiv, out_rtap, out_rtpp in io_it: | ||
|
||
logging.info('Computing DTI metrics for {0}'.format(dwi)) |
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 should be "Computing MAPMRI metrics..."
def get_short_name(cls): | ||
return 'mapmri' | ||
|
||
def run(self, data_file, data_bvecs, data_bvals, model_type='', out_rtop='rtop.nii.gz', |
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 model_type, I would suggest having a keyword argument for "laplacian" and for "positivity" (both set to True
per default)
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.
And a keyword argument for the laplacian weighting as well.
positivity_constraint=True) | ||
mapfit_aniso = map_model_aniso.fit(data) | ||
|
||
# Not sure where to get affine or 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.
Is this still an issue? Getting the affine? You can get it from the data_file
.
As an aside: if you have questions, it's better to ask them in the PR interface than put them as comments in your code!
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.
Ah thanks for pointing that out. I added those notes in the code to ask you at our weekly sessions and forgot to delete them.
format(os.path.dirname(out_rtpp))) | ||
|
||
|
||
class ReconstMAPMRILaplacian(ReconstMAPMRIFlow): |
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.
@Garyfallidis : is this the right way to do things? You create an interface for every setting of options to the model? I thought this was supposed to create a CLI that allows you to input key-word arguments?
Closed in favor of #1395 |
Not sure how to create a workflow or if this is correct
@Garyfallidis could you check this out and see if this is what you meant?