Skip to content

Conversation

@jhlegarreta
Copy link
Contributor

Validate PET data objects' attributes at instantiation: ensures that the attributes are present and match the expected dimensionalities.

@jhlegarreta
Copy link
Contributor Author

Depends on PR #335.

@jhlegarreta
Copy link
Contributor Author

@mnoergaard While working on this I've realized that as things stand now on main, there is a risk that two instances of a PET object contain different data if instantiated directly (i.e. PET()) or from a NIfTI file (i.e. from_nii). So, I would like to have your confirm on the following:

  • To build a valid PET instance, the only required piece of information are the data sequence and frame_time, as uptake can be computed from the former, and midframe and total_duration can all be computed from the latter.

I think that answer will allow me to refactor this properly and avoid inconsistencies. Thanks.

@mnoergaard
Copy link
Contributor

@mnoergaard While working on this I've realized that as things stand now on main, there is a risk that two instances of a PET object contain different data if instantiated directly (i.e. PET()) or from a NIfTI file (i.e. from_nii). So, I would like to have your confirm on the following:

  • To build a valid PET instance, the only required piece of information are the data sequence and frame_time, as uptake can be computed from the former, and midframe and total_duration can all be computed from the latter.

I think that answer will allow me to refactor this properly and avoid inconsistencies. Thanks.

@jhlegarreta - that is correct! Thanks.

@jhlegarreta jhlegarreta force-pushed the enh/validate-pet-data-attrs branch 2 times, most recently from 745e408 to bc7617e Compare November 22, 2025 20:41
@jhlegarreta
Copy link
Contributor Author

@mnoergaard Please, see if the refactoring for the PET data class instantiation and from_nii make sense. Thanks.

@jhlegarreta jhlegarreta force-pushed the enh/validate-pet-data-attrs branch from bc7617e to 7dc1033 Compare November 22, 2025 20:42
Validate PET data objects' attributes at instantiation: ensures that the
attributes are present and match the expected dimensionalities.

Refactor the PET attributes so that only the required (`frame_time` and
`uptake`) and optional (`frame_duration`) parameters are accepted by the
constructor. The `midframe` and the `total_duration` attributes can be
computed from the required parameters, so exclude it from `__init__`.

Although `uptake` can also be computed from the PET frame data, the
rationale behind requiring it is similar to the one for the DWI class
`bzero`: users will be able compute the `uptake` using their preferred
strategy and provide it to the constructor. For the `from_nii` function,
if a callable is provided, it will be used to compute the value;
otherwise a default strategy is used to compute it.

Refactor the `from_nii` function so that the required parameters are
present when instantiating the PET instance. Increase consistency with
the `dmri` data module `from_nii` counterpart function.

Refactor the PET data creation fixture in `conftest.py` to accept the
required/optional arguments and to return the necessary data.

Refactor the tests accordingly and increase consistency with the `dmri`
data module testing helper functions. Reduces cognitive load and
maintenance burden.

Add additional object instantiation equality checks: check that objects
intantiated through reading NIfTI files equal objects instantiated
directly.
@jhlegarreta jhlegarreta force-pushed the enh/validate-pet-data-attrs branch from 7dc1033 to 803b020 Compare November 22, 2025 20:50
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.

Ensure the dataset mandatory attributes are present in data instantiation

2 participants