Skip to content

Conversation

@jhlegarreta
Copy link
Contributor

Annotate DWI optional data class parameters as such: add None to the type annotation of bzero and eddy_xfms attributes.

Ignore the bzero indexing static checking error when serializing the data to NIfTI: the indexing operation is protected by a conditional no_bzero statement, so at that point the class instance is bound to have a non-None bzero attribute value.

Assert that bzero is not None in tests to avoid static type checking errors.

Annotate DWI optional data class parameters as such: add `None` to the
type annotation of `bzero` and `eddy_xfms` attributes.

Ignore the `bzero` indexing static checking error when serializing the
data to NIfTI: the indexing operation is protected by a conditional
`no_bzero` statement, so at that point the class instance is bound to
have a non-`None` `bzero` attribute value.

Assert that `bzero` is not `None` in tests to avoid static type checking
errors.
@jhlegarreta jhlegarreta force-pushed the sty/annotate-opt-data-params branch from c205a9f to c3d8d19 Compare November 1, 2025 09:51
@jhlegarreta
Copy link
Contributor Author

No else exists in

if b0_file:
b0img = load_api(b0_file, SpatialImage)
b0vol = np.asanyarray(b0img.dataobj)
# We'll assume your DWI class has a bzero: np.ndarray | None attribute
dwi_obj.bzero = b0vol
# Otherwise, if any volumes remain outside gradmsk, compute a median B0:
elif np.any(~gradmsk):
# The b=0 volumes are those that did NOT pass b0_thres
b0_volumes = fulldata[..., ~gradmsk]
# A simple approach is to take the median across that last dimension
# Note that axis=3 is valid only if your data is 4D (x, y, z, volumes).
dwi_obj.bzero = np.median(b0_volumes, axis=3)

So bzero is allowed to be None.

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.

1 participant