-
Notifications
You must be signed in to change notification settings - Fork 79
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
Conversation
There was a problem hiding this 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?
terracotta/server/rgb.py
Outdated
@@ -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+$")), |
There was a problem hiding this comment.
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.
tests/handlers/test_rgb.py
Outdated
"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"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this do?
Dear @dionhaefner , 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 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 |
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
There was a problem hiding this 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:
- Add full type annotations to all functions + arguments.
- Ensure pre-commit hooks pass.
- Add the same argument to
/singleband
. - Push coverage to the target.
Thanks @atanas-balevsky.
58bfd58
to
7c4c20e
Compare
7c4c20e
to
aaf852b
Compare
Dear @dionhaefner, Happy holidays! |
There was a problem hiding this 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.
Co-authored-by: Dion Häfner <[email protected]>
Co-authored-by: Dion Häfner <[email protected]>
Co-authored-by: Dion Häfner <[email protected]>
Co-authored-by: Dion Häfner <[email protected]>
Dear @dionhaefner! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
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