Skip to content

Conversation

@jhlegarreta
Copy link
Contributor

@jhlegarreta jhlegarreta commented Nov 1, 2025

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

Fixes #302.

@jhlegarreta jhlegarreta force-pushed the enh/validate-necessary-attrs branch 2 times, most recently from a9b3338 to 0e26d53 Compare November 1, 2025 12:04
@jhlegarreta
Copy link
Contributor Author

Notes:

  • Attribute checks are done sequentially.
  • This disallows instantiating data objects with partial attributes e.g.
    dwi_obj = DWI(
    dataobj=fulldata[..., gradmsk],
    affine=img.affine,
    # We'll assign the filtered gradients below.
    )

So a refactoring will be required if we go for this. Even if this requires more code than the checks removed in the PRs referenced in issue #302, these are no longer spread across the code base, and we do not run the risk of forgetting checks, or producing e.g. numpy error messages downstream that are harder to debug.

@jhlegarreta jhlegarreta force-pushed the enh/validate-necessary-attrs branch 4 times, most recently from 3c360d6 to 0cd7187 Compare November 1, 2025 14:23
@jhlegarreta jhlegarreta force-pushed the enh/validate-necessary-attrs branch from 0cd7187 to c67bd96 Compare November 14, 2025 07:57
@jhlegarreta jhlegarreta force-pushed the enh/validate-necessary-attrs branch from c67bd96 to 1fc5f1e Compare November 18, 2025 00:55
except (TypeError, ValueError):
data_vols = None

if data_vols is not None:
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 is now duplicating par of what _normalize_gradients does: leaving here until PR #327 gets merged.



@pytest.mark.random_uniform_spatial_data((2, 2, 2, 4), 0.0, 1.0)
def test_brainmask_volume_mismatch_error(request, setup_random_uniform_spatial_data):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jhlegarreta jhlegarreta force-pushed the enh/validate-necessary-attrs branch from 1fc5f1e to 702e7f2 Compare November 18, 2025 01:09
if value is None:
raise ValueError(GRADIENT_ABSENCE_ERROR_MSG)
if not isinstance(value, np.ndarray) or value.shape[1] != 4:
raise ValueError(GRADIENT_SHAPE_ERROR_MSG)
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 is failing for the HDF5 file because it is a 4x102 matrix, and the functions runs before __attrs_post_init__ which would transpose it.

@jhlegarreta jhlegarreta force-pushed the enh/validate-necessary-attrs branch from 702e7f2 to fbee186 Compare November 19, 2025 02:27
@jhlegarreta jhlegarreta marked this pull request as draft November 19, 2025 02:27
@jhlegarreta jhlegarreta force-pushed the enh/validate-necessary-attrs branch 5 times, most recently from 22528df to 87893bd Compare November 20, 2025 01:51
@jhlegarreta jhlegarreta force-pushed the enh/validate-necessary-attrs branch from 87893bd to 275fd21 Compare November 21, 2025 13:06
Validate DWI data objects' attributes at instantiation: ensures that the
attributes are present and match the expected dimensionalities.
@jhlegarreta jhlegarreta force-pushed the enh/validate-necessary-attrs branch from 275fd21 to 3ba23e8 Compare November 22, 2025 01:09
@oesteban oesteban closed this Nov 22, 2025
@jhlegarreta jhlegarreta deleted the enh/validate-necessary-attrs branch November 22, 2025 17:08
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