Skip to content

ENH: Return level as type int if it is very close to an integer#128

Merged
Leengit merged 1 commit intoDigitalSlideArchive:masterfrom
Leengit:level_as_int
Apr 23, 2023
Merged

ENH: Return level as type int if it is very close to an integer#128
Leengit merged 1 commit intoDigitalSlideArchive:masterfrom
Leengit:level_as_int

Conversation

@Leengit
Copy link
Collaborator

@Leengit Leengit commented Apr 21, 2023

When large_image is asked to return tiles with an "exact" magnification it may end up using a level (in the sense that large_image defines it) that is a non-integer. (Also, a non-integer value of level might occur if the stored "native" magnifications are different by something other than powers of two.) However, if that level is within 1e-6 of an integer we will return it as type int rather than type float.

@cooperlab if it would be better to round to the integer value but leave it as type float, please let me know.

Closes #95.

@Leengit Leengit added the bug Something isn't working label Apr 21, 2023
@Leengit Leengit requested a review from cooperlab April 21, 2023 17:50
@Leengit Leengit self-assigned this Apr 21, 2023

slide["level"] = level
int_level = int(level + 0.5)
slide["level"] = int_level if abs(level - int_level) < 1e-6 else level
Copy link
Contributor

Choose a reason for hiding this comment

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

For what it is worth, I think we use 1e-4 as the threshold in geojs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just force-pushed with 1e-4 as the threshold. I also put a math.floor call in there because it appears that Python's int cast rounds towards zero rather than rounding towards negative infinity.

Copy link
Contributor

Choose a reason for hiding this comment

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

I probably would have used int(round(value)), but that also moves values that have exactly .5 as the fraction toward zero.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We reject int_level if it is farther than 1e-4 from the returned level, so what happens with 0.5 won't affect us here. I've gone with int(round(level)) with this latest force push.

@Leengit Leengit merged commit f9546fa into DigitalSlideArchive:master Apr 23, 2023
@Leengit Leengit deleted the level_as_int branch April 23, 2023 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: 'level' as float

2 participants