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

Check if specified raster size exists before trying to download it #47

Merged
merged 2 commits into from
Apr 20, 2023

Conversation

willgearty
Copy link
Collaborator

This is a small fix for edge cases where the specified raster size doesn't exist on phylopic. In these cases, we now return whatever is the first raster (which I believe is usually the largest one) and also display a warning.

Fixes #46.

@willgearty willgearty added the bug label Apr 1, 2023
@willgearty willgearty added this to the 1.1.0 milestone Apr 1, 2023
@willgearty willgearty self-assigned this Apr 1, 2023
@keesey
Copy link

keesey commented Apr 5, 2023

To be more robust you might sort them by size before picking the largest. (But the first one is the largest, yes, and I can't think of a reason that would change.)

Copy link
Collaborator

@LewisAJones LewisAJones left a comment

Choose a reason for hiding this comment

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

Nothing to add of any value here. All looks great to me! Great job @willgearty. I only have one tiny comment if I'm being picky but it doesn't really matter.

ind <- grepl(format, rasters$sizes)
if (!any(ind)) {
ind <- 1
warning(paste("No raster image with dimension", format, "available.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
warning(paste("No raster image with dimension", format, "available.",
warning(paste("No raster image with dimensions", format, "available.",

Here you use dimension but dimensions in L54. The same in L43 and L44.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, so those spellings are/were intentional because the first value in each message is just a single number (e.g., "512"), hence "dimension", whereas the second number in each message is two values (e.g., "512x300"), hence "dimensions"

Copy link
Collaborator

Choose a reason for hiding this comment

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

That makes absolute sense then. Do you think this could be potentially confusing for a user though? After receiving such a warning, they might want to update their script to use the specific dimension to prevent getting warnings? Should they always use the first value? If so, maybe we should just return this?

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 thought about doing that, but sometimes the phylopic is landscape, so the larger number (which I believe is always the format value) isn't always the first value in the dimensions (e.g., "300x512"). I suppose we could do some string manipulation to extract the larger of the two numbers? But that seemed like more work than it was worth at the time.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see! Yes, that's a bit trickier. If the format value is always the larger value then it should be relatively straightforward as you've suggested. I don't think it is a huge issue as it is though... I can just imagine a few puzzled faces every now and then. I'll let you decide!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So, I was about to implement this, but then noticed that if the only available size is smaller than the options we currently provide (in the case of c8f71c27-71db-4b34-ac2d-e97fea8762cf, the largest size raster is 210x143), then the user won't be able to supply that format to get_phylopic as the function is currently implemented.

We could expand the format options to any number (and then pick the closest size, maybe?), but I feel like that opens a whole new can of worms that I think is outside of the scope of this PR.

@willgearty willgearty merged commit c124755 into main Apr 20, 2023
8 checks passed
@willgearty willgearty deleted the dim-check branch April 20, 2023 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better error handling when specified raster size doesn't exist
3 participants