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

Simplify linear axis assignment logic #265

Merged
merged 8 commits into from
Jul 12, 2023
Merged

Simplify linear axis assignment logic #265

merged 8 commits into from
Jul 12, 2023

Conversation

elevans
Copy link
Member

@elevans elevans commented Jun 15, 2023

I split this PR from my metadata PR (#247). This PR aims to simply how we assign calibrated linear axes to datasets. Currently we check if net.imagej.axis.EnumeratedAxis is available and use that as our first choice. If net.imagej.axis.EnumeratedAxis is not available, then we fall back to net.imagej.axis.DefaultLinearAxis. This is fine for most things, but unfortunately this logic has some unintended consequences. @gselzer informed me that the BoneJ plugin actually checks for net.imagej.axis.DefaultLinearAxis and is unable to use the net.imagej.axis.EnumeratedAxis. The changes this PR brings are the following:

  • Drop net.imagej.axis.EnumeratedAxis from the axes assignment logic. While I would like to keep the option to use both, I don't realistically see how a user would indicate they want EnumeratedAxis or not. Also if they actually care about that, then it seems likely that they may have enough knowledge to change the CalibratedAxis type. Are there instances where ImageJ2 will produce a net.imagej.Dataset with net.imagej.axis.EnumeratedAxis? If not, then I think that is another point for dropping this behavior.
  • Resolve singleton dimension scale bug. I thought I got this into main already but I realize it has been passed around from one stale PR to another. Here it is! This change resolves a bug where getting the scale of a singleton dimension fails. This is because we calculate the slope from the dimensions coordinate array. The first two values are used for this math, which of course fails for singleton dimensions because their coordinate array is size 1. Thus all singleton dimensions should have their scale set to 1.

update 1

Thanks @gselzer for adding in a good way to have both EnumeratedAxis and DefaultLinearAxis as options based on coordinate array linearity.

Things for me to do:

TODO:

  • Write tests for new scale logic.

update 2

I've added the following changes:

  • Remove the Finally block and slightly reworked the logic. Finally was always triggered and replaced the EnumeratedAxis with DefaultLinearAxis.
  • Added tests for:
    • linear coords -> DefaultLinearAxis
    • non-linear coords -> EnumeratedAxis
    • non-numeric coords -> DefaultLinearAxis

@elevans elevans requested review from ctrueden and gselzer June 15, 2023 15:56
This commit changes how the linear and enumerated axes
are assigned. We now look for the "imagej" key in the
xarray's global attributes. If the key is present we look for
dim + "_axis_scale" to assign linear or enumerated axes.
Although the only calibrated axes used by nearly everyone are
DefaultLinearAxis and EnumeratedAxis, I added metadata support
for all CalibratedAxis types (e.g. PolynomialAxis etc...) just to
be thorough. This metadata will be used for matching the Calibrated
Axis type when going back to ImageJ/Java land.
@codecov-commenter
Copy link

codecov-commenter commented Jun 15, 2023

Codecov Report

Patch coverage: 90.62% and project coverage change: +0.42 🎉

Comparison is base (179f482) 76.93% compared to head (de50af9) 77.36%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #265      +/-   ##
==========================================
+ Coverage   76.93%   77.36%   +0.42%     
==========================================
  Files          16       16              
  Lines        1869     1869              
==========================================
+ Hits         1438     1446       +8     
+ Misses        431      423       -8     
Impacted Files Coverage Δ
src/imagej/dims.py 65.73% <86.95%> (+2.62%) ⬆️
src/imagej/_java.py 88.76% <100.00%> (+1.26%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@elevans and I talked about this in person. I don't see much reason to
remove EnumeratedAxis support, since it isn't hurting anything. Maybe we
can just exert more pressure towards using DefaultLinearAxis, and we can
use NumPy to check dimension linearity!
Mwahahahahahaha
The Finally block was always triggering,
overwriting the EnumeratedAxis with DefaultLinearAxis.
Non-numeric scales were never handled correctly. If the
coords are non-numeric, then trying to convert them to
a numpy array without checking if they're numbers will fail.
We now check if the coords are numeric or not and then
replace them with a linear scale if they are.
@elevans elevans requested a review from hinerm July 11, 2023 14:41
@hinerm hinerm merged commit 9f2feb7 into main Jul 12, 2023
@hinerm hinerm deleted the linear-axis-logic branch July 12, 2023 20:11
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.

4 participants