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

Add rgb_range percentile support #322

Merged
merged 16 commits into from
Jan 7, 2024

Conversation

atanas-balevsky
Copy link
Contributor

Add support for using percentiles instead of absolute values for the /rgb's endpoint *_range parameters.

gives us the possibility to request the /rgb?r_range=p2,p97... instead of calling /metadata first to fetch the pct's absolute values in order to construct an /rgb url

Copy link
Collaborator

@dionhaefner dionhaefner left a comment

Choose a reason for hiding this comment

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

Thanks for the PR.

There are some issues with it that look fixable. More importantly, I want at least one additional contributor to weigh in whether this is a good idea or not.

The interface is getting pretty overloaded, as evidenced by the type annotations:

ListOfRanges = Sequence[Optional[Tuple[Optional[NumberOrString], Optional[NumberOrString]]]]

Does anyone else have mixed feelings about this?

@@ -29,25 +29,34 @@ class Meta:
g = fields.String(required=True, description="Key value for green band")
b = fields.String(required=True, description="Key value for blue band")
r_range = fields.List(
fields.Number(allow_none=True),
fields.String(allow_none=True, validate=validate.Regexp("^p?(\d*\.)?\d+$")),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not the correct format.

Previously, this accepted any number, which includes scientific notation like 1.3E-2. Also, percentiles must be ints between 0 and 100 and cannot be float numbers.

To prevent regressions I would advocate for still using fields.Number under the hood, with some additional logic to detect the percentile case. A custom field class should do, similar to what is described here.

"stretch_range", [[0, 20000], [10000, 20000], [-50000, 50000], [100, 100]]
"stretch_range", [
[0, 20000], [10000, 20000], [-50000, 50000], [100, 100],
["0", "20000"], ["10000", "20000"], ["-50000", "50000"], ["100", "100"],
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does this do?

@atanas-balevsky
Copy link
Contributor Author

Dear @dionhaefner ,
Thanks for the feedback! i've addressed some aspects of it.

now it's much clear that there can be a string or number. The regex is gone and there's more natural way of inferring the range type. i also added a test for the scientific notation when doing absolute values (didn't know you're supporting these)
i'm not sure why the tests action is not running now, but i believe it should be green

@mrpgraae
Copy link
Collaborator

Thanks for the PR.

There are some issues with it that look fixable. More importantly, I want at least one additional contributor to weigh in whether this is a good idea or not.

The interface is getting pretty overloaded, as evidenced by the type annotations:

ListOfRanges = Sequence[Optional[Tuple[Optional[NumberOrString], Optional[NumberOrString]]]]

Does anyone else have mixed feelings about this?

I may be biased since @atanas-balevsky is a colleague of mine, and we need this feature for something we are building over at SkyFi. Still, I think this is a good example of leveraging the fact that we have pre-computed information about an image to provide "magic" features like this, so I'd like to convince you that I think it's a good idea, even without my bias 🙂

Regarding the type, I think it was already quite complicated before. The only difference in this PR is that Number changed to NumberOrString. But if you think it would be better to do the percentiles as a separate query parameter, to not overload this parameter so much, then I don't see anything wrong with that. It would also help make the type validation simpler.

Copy link

codecov bot commented Dec 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (3cbc26c) 98.11% compared to head (63baa41) 98.15%.
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #322      +/-   ##
==========================================
+ Coverage   98.11%   98.15%   +0.03%     
==========================================
  Files          52       53       +1     
  Lines        2338     2379      +41     
  Branches      476      486      +10     
==========================================
+ Hits         2294     2335      +41     
  Misses         29       29              
  Partials       15       15              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@dionhaefner dionhaefner left a comment

Choose a reason for hiding this comment

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

Alright, I'm willing to merge this if we can address the issues above, plus:

  1. Add full type annotations to all functions + arguments.
  2. Ensure pre-commit hooks pass.
  3. Add the same argument to /singleband.
  4. Push coverage to the target.

Thanks @atanas-balevsky.

terracotta/handlers/rgb.py Outdated Show resolved Hide resolved
terracotta/server/rgb.py Outdated Show resolved Hide resolved
tests/handlers/test_rgb.py Outdated Show resolved Hide resolved
terracotta/server/rgb.py Outdated Show resolved Hide resolved
terracotta/server/rgb.py Outdated Show resolved Hide resolved
terracotta/handlers/rgb.py Outdated Show resolved Hide resolved
terracotta/handlers/rgb.py Outdated Show resolved Hide resolved
@atanas-balevsky atanas-balevsky force-pushed the rgb-range-percentiles branch 2 times, most recently from 58bfd58 to 7c4c20e Compare December 22, 2023 09:51
@atanas-balevsky
Copy link
Contributor Author

Alright, I'm willing to merge this if we can address the issues above, plus:

  1. Add full type annotations to all functions + arguments.
  2. Ensure pre-commit hooks pass.
  3. Add the same argument to /singleband.
  4. Push coverage to the target.

Thanks @atanas-balevsky.

Dear @dionhaefner,
thanks for the feedback, i believe i addressed all the points. can we rerun the tests & reports?

Happy holidays!
Nas

Copy link
Collaborator

@dionhaefner dionhaefner left a comment

Choose a reason for hiding this comment

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

Thanks, this looks really good! Some final nits.

terracotta/handlers/rgb.py Outdated Show resolved Hide resolved
tests/server/test_fields.py Show resolved Hide resolved
terracotta/handlers/singleband.py Outdated Show resolved Hide resolved
terracotta/image.py Outdated Show resolved Hide resolved
terracotta/server/fields.py Show resolved Hide resolved
terracotta/server/singleband.py Outdated Show resolved Hide resolved
terracotta/server/fields.py Outdated Show resolved Hide resolved
terracotta/server/rgb.py Outdated Show resolved Hide resolved
tests/server/test_flask_api.py Show resolved Hide resolved
tests/server/test_flask_api.py Outdated Show resolved Hide resolved
atanas-balevsky and others added 6 commits January 5, 2024 16:51
Co-authored-by: Dion Häfner <mail@dionhaefner.de>
Co-authored-by: Dion Häfner <mail@dionhaefner.de>
Co-authored-by: Dion Häfner <mail@dionhaefner.de>
Co-authored-by: Dion Häfner <mail@dionhaefner.de>
@atanas-balevsky
Copy link
Contributor Author

Dear @dionhaefner!
Thanks for the feedback. i believe i addressed most of the comments. can we rerun the test actions?

Copy link
Collaborator

@dionhaefner dionhaefner left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@dionhaefner dionhaefner merged commit 83bd1d7 into DHI:main Jan 7, 2024
9 checks passed
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.

None yet

3 participants