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

Improve open ijtiff #677

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Improve open ijtiff #677

wants to merge 2 commits into from

Conversation

bugraoezdemir
Copy link
Collaborator

This fixes the issue #671:

  1. Now boolean arrays are converted into uint8 type with values 0 and 255 before being saved.
  2. Axis metadata arguments are now optional.

Copy link
Collaborator

@k-dominik k-dominik left a comment

Choose a reason for hiding this comment

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

looks good, had some minor comments for improving user experience with this.

Comment on lines +177 to +179
ax_names: Optional[Sequence[str]] = None,
ax_scales: Optional[Sequence[float]] = None,
ax_units: Optional[Sequence[str]] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

The docstring could mention what happens if these are not supplied. The code suggests that this function assumes a particular axis order. E.g. when a user adds a 3-channel image, they should add a singleton for Z if they are not giving all metadata.

Comment on lines +209 to +211
assert len(ax_names) == image_array.ndim, f"The length of 'ax_names' must match the number of dimensions, which is {image_array.ndim}"
assert len(ax_units) == image_array.ndim, f"The length of 'ax_units' must match the number of dimensions, which is {image_array.ndim}"
assert len(ax_scales) == image_array.ndim, f"The length of 'ax_scales' must match the number of dimensions, which is {image_array.ndim}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

asserts can be removed at runtime if python is started with optimization flags.

try it
python -c "assert False; print('hehe')"
# will result in AssertionError

python -O -c "assert False; print('hehe')"
# will print

It is safer to do check in an if clause and raise ValueError (or something even more fitting) in case condition is met. After all this error should communicate to the user what went wrong. Assertions are still fine in code in general - I would personally not use them for something that is user input.


if ax_names is None:
ax_names = _full_axes[-image_array.ndim:]
if ax_units is None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

an improvement here would be to go by axis names already.

axis_units = {k: v for k, v in zip(_full_axes, _full_units)}
ax_units = [axis_units[ax] for ax in ax_names]

this would allow users to specify the axis tags only and still get sensible units

Comment on lines +217 to +218
if image_array.dtype == np.dtype(bool):
image_array = image_array.astype(np.uint8) * 255
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also this behavior should be documented in the function docstring.

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.

2 participants