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

Stop generating at .npy when running Topostats #802

Closed
derollins opened this issue Feb 16, 2024 · 0 comments · Fixed by #804
Closed

Stop generating at .npy when running Topostats #802

derollins opened this issue Feb 16, 2024 · 0 comments · Fixed by #804
Labels
enhancement New feature or request IO Input and Output Low Priority

Comments

@derollins
Copy link
Collaborator

derollins commented Feb 16, 2024

Is your feature request related to a problem?

A .npy file is generated for each processed image along side an image and an HDF5 .topostats file. This is no longer necessary since the image data is all head in the .topostats file and the .npy file just takes up extra space.

Describe the solution you would like.

Stop the generation of the .npy file.

Describe the alternatives you have considered.

Could also be made optional in the config file.

Additional context

No response

@derollins derollins added the enhancement New feature or request label Feb 16, 2024
@ns-rse ns-rse added Low Priority IO Input and Output labels Feb 16, 2024
ns-rse added a commit that referenced this issue Feb 20, 2024
Closes #802

Arrays and data are now saved in HDF5 files (#790) and so `.npy` arrays are somewhat redundant. This PR leaves the
`io.save_array()` function in place should interactive use require saving of arrays but removes its use from
`topostats.processing.run_filters()` so that the `.npy` files are no longer saved to disk.

Users wishing to access processed data should load it from the HDF5 formatted `.topostats` files that are saved during
processing.
ns-rse added a commit that referenced this issue Mar 4, 2024
Closes #806

Whislt #806 was meant to address why no Matplotlib image was generated and tested/compared to a target image when
plotting without axes or colorbar I discovered this was because the image is saved with `Images.save_array_figure()`.

This in turn uses
[`matplotlib.pyplot.imsave()`](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imsave.html) to save the
image and the test was using
[`skimage.io.imread()`](https://scikit-image.org/docs/stable/api/skimage.io.html#skimage.io.imread) to read the image
back as an array and test the `np.sum()` and `img.shape`.

We no longer need to save arrays nor images as readable arrays (see #804 / #802) and so the need to save the image in
this manner seemed redudant. The `Images.save_figure()` already has logic which excludes the axes and scale bars (see
lines 321 of current changeset).

Further the logic for deciding what to save within `Image.plot_and_save()` seemed overly complicated and if
`Images.save_array_figure()` were being called `Images.plot_and_save()` did not return a `fig` (Matplotlib Image) that
could be saved and tested using `pytest-mpl` extension.

To this end I have...

1. Removed `Images.save_array_figure()`.
2. Tweaked the plotting options under `Images.savefig()` starting at line 321 to use a [tight
   layout](https://matplotlib.org/2.0.2/users/tight_layout_guide.html) which ensures there is no border (see note
   below).
3. Simplified the logic in `Images.plot_and_save()` controlling whether images are saved so that `ValueError` are raised
   if `Images.savefig == False` or `if Images.image_set in ["all", "core"] or self.core_set:` evaluates to
   `False`. Ensures images are explicitly closed to reduce memory usage.
4. Added tests for the raising of `ValueError` exceptions in `Images.plot_and_save()`
5. Tidied up some test names to be consistent (resulted in image name change).
6. Tidied up passing of `plotting_config` into these tests.
7. Added a `pytest-mpl` test for `test_plot_and_save_no_axes_no_colorbar()`, adding the target image as required by #806

Note on Borders

The image generated by `pytest-mpl` against which comparisons are made _does_ have a border because it is saving the
returned `fig` object itself. The actual generated image doesn't have a border (manual checks have been made).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request IO Input and Output Low Priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants