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

New commands: peaksconvert, peakscheck #2918

Draft
wants to merge 1 commit into
base: dwi_metadata
Choose a base branch
from

Conversation

Lestropie
Copy link
Member

Draft PR.

Depends on #2917 (uses that as base branch).

This is work that I deemed necessary for BIDS BEP016 DWI models (bids-standard/bids-bep016#24).

To have any kind of confidence around robust encoding of the outcomes of diffusion model fits on the filesystem, in my mind there are two requirements:

  • Prove that the purported coordinate system is correct.
    This necessitates a broader set of data. Showing that for one data instance, the purported coordinate system seems reasonable, is not evidence that in some other use case the interpretation will be incorrect.
  • Have the capability to convert data between different encodings or reference frames.

Here I've created two new commands, that are requisite for later parts of this validation tool.

  • peaksconvert converts both between different reference frames, and between 3-vector versus spherical coordinate encodings. This for instance should allow loading the outcomes of diffusion model fits from FSL and MRtrix in the converse software.

  • peakscheck does something similar to dwigradcheck, just using peaks images and tckgen -algorithm fact. Similar to dwigradcheck: Enhancements #2902 (which happened during the course of generating this changeset) the set of possible errors in encoding that are evaluated can be more complex than just axis permutations and flips.


Outstanding TODOs, many of which are plucked from code comments:

  • Deep in the spherical coordinates handling, the prospect of a triplet of spherical coefficients appears, where the third element is inferred to be a radius. This is however contrary to ISO convention, where the first element should be the radius. Would need to audit what code uses it, but I would like to consider changing that behaviour. Potentially to avoid unexpected errors, revert those functions to only consider unit spherical coordinates, and have newly named functions that deal with the prospect of triplets?

  • For spherical coordinates, should support for both physics and mathematics conventions be implemented?
    peakscheck tests for the prospect of swapping the order of the two angles; but permitting explicit specification of which of the two is in use may be preferable (relates to Spherical coordinates convention bids-standard/bids-bep016#96).

  • Give peaksconvert ability to change fill value of absent fixels

  • Give peaksconvert ability to reduce maximal number of fixels
    Hypothetically, this could be done either by culling volumes, or by first sorting by the value per fixel (as 3-vector norm or spherical radius) and then removing

  • Multi-thread peaksconvert

  • Check whether peaksconvert works across bootstrap realisations, if those realisations appear along the fifth image axis
    (In BEP016 I want to define explicitly if an image axis is used to encode orientation information vs. if an image axis is used to encode bootstrap realisations; see Bootstrapping bids-standard/bids-bep016#38. But that may not necessarily propagate to MRtrix)

  • peakscheck: Try to catch case where upstream there has been an erroneous transformation; eg. someone has orientations in IJK, they erroneously applied an XYZ2IJK transformation, and so now they need to apply the IJK2XYZ transformation twice to get their orientations in MRtrix's expected XYZ

  • peakscheck: Reduce doubling-up between ijk and bvec reference frames.
    Ideally evaluate each unique transformation only once; there may however be multiple interpretations to a unique transformation.

  • peakscheck: Add -in_reference option; the variant that includes the corresponding transformation to XYZ should then be considered the "expected" interpretation of the input data, used to determine whether the return code should be non-zero.

  • Add ability to disable internal transform realignment on image load via environment variable; make use of this in peakscheck

@Lestropie Lestropie self-assigned this Jun 6, 2024
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 25 out of 44. Check the log or trigger a new build to see more.

// TODO Do we need to support both mathematics and physics conventions for spherical coordinates?
// And if so, where do we do it?

const char *const formats[] = {"unitspherical", "spherical", "unit3vector", "3vector", nullptr};
Copy link

Choose a reason for hiding this comment

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

warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]

const char *const formats[] = {"unitspherical", "spherical", "unit3vector", "3vector", nullptr};
      ^


const char *const formats[] = {"unitspherical", "spherical", "unit3vector", "3vector", nullptr};
enum class format_t { UNITSPHERICAL, SPHERICAL, UNITTHREEVECTOR, THREEVECTOR };
const char *const references[] = {"xyz", "ijk", "bvec", nullptr};
Copy link

Choose a reason for hiding this comment

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

warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]

const char *const references[] = {"xyz", "ijk", "bvec", nullptr};
      ^

OPTIONS
+ OptionGroup ("Options providing information about the input image")
+ Option ("in_format", "specify the format in which the input directions are specified")
+ Argument("choice").type_choice(formats)
Copy link

Choose a reason for hiding this comment

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

warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]

    + Argument("choice").type_choice(formats)
                                     ^

+ Argument("choice").type_choice(formats)
+ Option ("in_reference", "specify the reference axes against which the input directions are specified"
" (assumed to be real / scanner space if omitted)")
+ Argument("choice").type_choice(references)
Copy link

Choose a reason for hiding this comment

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

warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]

    + Argument("choice").type_choice(references)
                                     ^

+ OptionGroup ("Options providing information about the output image")
+ Option ("out_format", "specify the format in which the output directions will be specified"
" (will default to 3-vectors if omitted)")
+ Argument("choice").type_choice(formats)
Copy link

Choose a reason for hiding this comment

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

warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]

    + Argument("choice").type_choice(formats)
                                     ^

}
};

class ThreeVector : public FormatBase<3> {
Copy link

Choose a reason for hiding this comment

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

warning: destructor of 'ThreeVector' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]

class ThreeVector : public FormatBase<3> {
      ^
Additional context

cmd/peaksconvert.cpp:160: make it public and virtual

class ThreeVector : public FormatBase<3> {
      ^


class ThreeVector : public FormatBase<3> {
public:
ThreeVector(Eigen::Matrix<default_type, 3, 1> in) : FormatBase(in), threevector(in) {}
Copy link

Choose a reason for hiding this comment

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

warning: the parameter 'in' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]

Suggested change
ThreeVector(Eigen::Matrix<default_type, 3, 1> in) : FormatBase(in), threevector(in) {}
ThreeVector(const Eigen::Matrix<default_type, 3, 1>& in) : FormatBase(in), threevector(in) {}

Eigen::Matrix<default_type, 3, 1> operator()() const override { return threevector; }
Eigen::Matrix<default_type, 3, 1> normalized() const { return threevector.normalized(); }
default_type radius() const { return threevector.norm(); }
Eigen::Vector3d threevector;
Copy link

Choose a reason for hiding this comment

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

warning: member variable 'threevector' has public visibility [misc-non-private-member-variables-in-classes]

  Eigen::Vector3d threevector;
                  ^

Eigen::Vector3d unit_threevector_xyz;
default_type radius;

static transform_linear_type in_ijk2xyz;
Copy link

Choose a reason for hiding this comment

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

warning: variable 'in_ijk2xyz' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]

  static transform_linear_type in_ijk2xyz;
                               ^

default_type radius;

static transform_linear_type in_ijk2xyz;
static bool in_bvec_flipi;
Copy link

Choose a reason for hiding this comment

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

warning: variable 'in_bvec_flipi' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]

  static bool in_bvec_flipi;
              ^

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.

None yet

1 participant