Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

NF Operator class#1014

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
htwangtw wants to merge8 commits intonipy:master
base:master
Choose a base branch
Loading
fromhtwangtw:tals_dream
Open

NF Operator class#1014

htwangtw wants to merge8 commits intonipy:masterfromhtwangtw:tals_dream

Conversation

@htwangtw
Copy link
Contributor

@htwangtwhtwangtw commentedMay 6, 2021
edited
Loading

Closes#939.

This is a draft for feedback. Any suggestion is welcome!
I am not very familiar with python class so please let me know if there's things in python I haven't taken advantage of already. I would like to know:

  1. Are there header/affine check functions that already exist innibabel that I can reuse?
  2. More efficient way to add more operators? I don't quite understand the example in the original issue:
    __and__ = partial(_op, op=operator.__and__)

To-do

  • check any other operator we want to cover
  • better/flexible evaluation of data shape - I would usefslmaths as a reference dealing with masking 4D array with 3D image
  • more test cases
  • better error handling
  • docstring
  • warning related to caching

This is a draft for community feedback.I would like to know1. Are there header/affine check functions that already exist in nibabelthat I can reuse?2. more efficient way to add more operators?I have to admit I am not super familiar with a lot of tools related toclass object that comes with python.
@pep8speaks
Copy link

pep8speaks commentedMay 6, 2021
edited
Loading

Hello@htwangtw, Thank you for updating!

Cheers! There are no style issues detected in this Pull Request. 🍻 To test for issues locally,pip install flake8 and then runflake8 nibabel.

Comment last updated at 2021-06-21 13:21:22 UTC

@codecov
Copy link

codecovbot commentedMay 6, 2021
edited
Loading

Codecov Report

Merging#1014 (fb3bcfc) intomaster (44a1052) willincrease coverage by0.03%.
The diff coverage is98.46%.

Impacted file tree graph

@@            Coverage Diff             @@##           master    #1014      +/-   ##==========================================+ Coverage   92.26%   92.29%   +0.03%==========================================  Files         100      101       +1       Lines       12201    12265      +64       Branches     2134     2144      +10     ==========================================+ Hits        11257    11320      +63  Misses        616      616- Partials      328      329       +1
Impacted FilesCoverage Δ
nibabel/arrayops.py98.41% <98.41%> (ø)
nibabel/nifti1.py92.12% <100.00%> (+0.01%)⬆️

Continue to review full report at Codecov.

Legend -Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered byCodecov. Last update44a1052...fb3bcfc. Read thecomment docs.

@effigies
Copy link
Member

Hi@htwangtw, I'm interpreting theDRAFT heading to mean you want to push on this more pre-review, but please just ping me whenever you want feedback, or if you have design questions you want to raise.

htwangtw reacted with thumbs up emoji

@htwangtwhtwangtw changed the titleDRAFT/NF Operator classNF Operator classMay 12, 2021
@htwangtwhtwangtw marked this pull request as ready for reviewMay 12, 2021 20:34
@htwangtw
Copy link
ContributorAuthor

I found the draft function not particular meaningful to me so I just make it a normal PR...
@effigies I have a few questions:

  1. Memory management: A normal image loaded bynibabel,dataobj is some reference to the data on disc. When we do an operation, thedataobj will be read and stored in the memory, and the same for the new nifti image generate. Am I missing anything?

  2. ZeroDivisionError: To my surprise numpy returnsinf, notZeroDivisionError when dividing a value by zero. Is this a thing better be flagged as error before the operation or just let it be?

  3. Behaviour when dealing with 3D vs 4D image: I don't have a good answer on this one. We can assume people are familiar withfslmaths and get similar image outputs. We can just disallow this kind of case, but I think it would be nice to havefslmaths like behaviour. Thoughts???

  4. Operators that only require one input: I can seeabs(img),-img,+img really useful. I just don't have an idea how they can fit into the current_op method. Thoughts?

@effigies
Copy link
Member

I found the draft function not particular meaningful to me so I just make it a normal PR...
@effigies I have a few questions:

  1. Memory management: A normal image loaded bynibabel,dataobj is some reference to the data on disc. When we do an operation, thedataobj will be read and stored in the memory, and the same for the new nifti image generate. Am I missing anything?

Nope. No avoiding it. The only other way to do it would be by allowingArrayProxys to build up a sequence of partial applications, but that is a much bigger task than is called for here.

  1. ZeroDivisionError: To my surprise numpy returnsinf, notZeroDivisionError when dividing a value by zero. Is this a thing better be flagged as error before the operation or just let it be?

It's a valid IEEE754 value. You pays your money, you takes your chances.

  1. Behaviour when dealing with 3D vs 4D image: I don't have a good answer on this one. We can assume people are familiar withfslmaths and get similar image outputs. We can just disallow this kind of case, but I think it would be nice to havefslmaths like behaviour. Thoughts???

I'm not sure what thefslmaths behavior is here, but I would expect if the volumetric dimensions match, to broadcast along the time dimension. I suspect this is the numpy default?

  1. Operators that only require one input: I can seeabs(img),-img,+img really useful. I just don't have an idea how they can fit into the current_op method. Thoughts?

You could do something like:

classOperableImage:def_binop(self,val,*,op):        ...def_unop(self,*,op):        ...
htwangtw reacted with thumbs up emojihtwangtw reacted with laugh emoji

@htwangtw
Copy link
ContributorAuthor

htwangtw commentedJun 21, 2021
edited
Loading

Hey@effigies -

I tried to add someNifti1Image.dataobj type test and realise theNifti1Image class itself has pretty comprehensive checks upon image creation. Can you think of a case that invalidNifti1Image.dataobj value can be loaded?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Implement arithmetic and logical operator support?

3 participants

@htwangtw@pep8speaks@effigies

[8]ページ先頭

©2009-2025 Movatter.jp