Skip to content
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

Feature/write complex valued data #106

Merged
merged 28 commits into from
Jul 4, 2023

Conversation

twitzelbos
Copy link
Contributor

@twitzelbos twitzelbos commented Jun 20, 2023

Okay, here it goes:

  • reads and writes RGB, RGBA, Complex64 and Complex128 now

  • the new (additional) tests write RGB and RGBA using write_nifti

  • I left the old write_rgb_nifti in place, but it can be removed

  • I made a bit of a mess replacing LinearTransform with NiftiDataRescaler (I did not like the name LinearTransform), resulting in more code, but could clean this up more.

  • For reading there is a function into_nifti_typed_data() now, which provides a vec of the native type, for when an ndarray is not needed/wanted

  • resolves issue Support reading and writing of complex-valued data #105

@twitzelbos
Copy link
Contributor Author

This is ready for review, @nilgoyette @Enet4

Copy link
Collaborator

@nilgoyette nilgoyette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to open this PR in a real IDE and study what's going on. This might take several days, depending on what comes up at my job.

Still, I left you some comments.

src/util.rs Outdated Show resolved Hide resolved
src/writer.rs Outdated Show resolved Hide resolved
tests/writer.rs Show resolved Hide resolved
src/typedef.rs Outdated Show resolved Hide resolved
src/volume/element.rs Outdated Show resolved Hide resolved
src/volume/element.rs Outdated Show resolved Hide resolved
@twitzelbos
Copy link
Contributor Author

Would you like me to change/add test cases, or is this enough for now? In principle, we could make tests where we write matrices of random content, read them back, and compare, but I feel the bitwise comparison to independently generated files is a better test. @nilgoyette @Enet4

Copy link
Owner

@Enet4 Enet4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I did a very quick code review for now. It seems mostly fine by me, and if there are no further objections other than the comments I made inline, I would guess that it's ready.

I also appreciate the effort and example of migrating the code to bytemuck from safe_transmute. Historically it made sense for me to use the crate I helped conceive myself, but nowadays it is considered safer to rely on what is considered the state-of-the-art crate for safe reinterpretation of bytes. This also means we have one more public dependency considered stable, which will help to stabilize this crate as well!

In principle, we could make tests where we write matrices of random content, read them back, and compare, but I feel the bitwise comparison to independently generated files is a better test.

Indeed, for these things I prefer to keep as many tests as fully deterministic as possible, so keeping a set of static curated test resources is a sufficiently good approach.

src/typedef.rs Outdated Show resolved Hide resolved
src/volume/element.rs Show resolved Hide resolved

/// A vessel to host the NiftiDataRescaler trait
#[derive(Debug)]
pub struct DataRescaler;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are lots of changes in this module. It makes me wonder if we could just keep all (or most) of it all private or pub(crate). But I guess this can be evaluated later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This did also occur to me, but presently this also leaks out to the public, so it cannot even be pub(crate). Presently many of the difficulties arise in the RandomAccess functionality, which I have never used, and haven't had the time to investigate yet. We are using this crate solely for the reading and writing of nifti files in rust (quite successfully I must say).

src/volume/element.rs Outdated Show resolved Hide resolved
src/volume/element.rs Show resolved Hide resolved
src/volume/streamed.rs Outdated Show resolved Hide resolved
@nilgoyette
Copy link
Collaborator

LGTM. Thank you for your work!

Copy link
Owner

@Enet4 Enet4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I think we are ready to move forward here? Thanks!

@Enet4 Enet4 merged commit 341f830 into Enet4:master Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants