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

Implement clim_percentile for RGB #6137

Closed
wants to merge 2 commits into from
Closed

Conversation

ahuang11
Copy link
Collaborator

@ahuang11 ahuang11 commented Feb 28, 2024

Addresses part of holoviz/hvplot#1251

image
from pystac_client import Client
from odc.stac import load
import numpy as np

client = Client.open("https://earth-search.aws.element84.com/v1")
collection = "sentinel-2-l2a"
tas_bbox = [146.5, -43.6, 146.7, -43.4]
search = client.search(collections=[collection], bbox=tas_bbox, datetime="2023-12")

ds = load(search.items(), bbox=tas_bbox, groupby="solar_day", chunks={})
da = ds[["red", "green", "blue"]].isel(time=2).load().to_array()
low, high = np.nanpercentile(da, (2, 98))
img = np.clip(da, low, high)
img /= img.max(["x", "y"])

import matplotlib.pyplot as plt
fig, axes = plt.subplots(2, figsize=(10, 10))
da.plot.imshow(ax=axes[0], robust=True)
axes[0].set_title("ORIGINAL; GOLD STANDARD")
img.plot.imshow(ax=axes[1])
axes[1].set_title("MIMICKED XARRAY")

import hvplot.xarray
da.hvplot.rgb(x="x", y="y", bands="variable").opts(clim_percentile=True, title="INTERNAL CHANGES") + \
img.hvplot.rgb(x="x", y="y", bands="variable").opts(title="MIMICKED XARRAY")

Now, I'm have trouble figuring out how to apply this logic into HoloViews internally.

I took a stab at it anyway, but it looks a little different than the original imshow with robust=True because imshow uses vmin/vmax of the colorbar, but colorbars aren't a concept in HoloView's RGB (I think), so I'm forced to clip?

@ahuang11 ahuang11 requested a review from hoxbro February 28, 2024 17:42
@jlstevens
Copy link
Contributor

... colorbars aren't a concept in HoloView's RGB

That is correct. Generally, colorbars only make sense when colormapping and RGBs are already mapped directly to colors.

@codecov-commenter
Copy link

codecov-commenter commented Feb 28, 2024

Codecov Report

Attention: Patch coverage is 28.57143% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 88.67%. Comparing base (9e5f904) to head (326d8ab).

Files Patch % Lines
holoviews/plotting/bokeh/raster.py 28.57% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6137      +/-   ##
==========================================
- Coverage   88.69%   88.67%   -0.03%     
==========================================
  Files         316      316              
  Lines       66017    66024       +7     
==========================================
- Hits        58554    58546       -8     
- Misses       7463     7478      +15     
Flag Coverage Δ
ui-tests 23.79% <14.28%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

holoviews/plotting/bokeh/raster.py Show resolved Hide resolved
holoviews/plotting/bokeh/raster.py Outdated Show resolved Hide resolved
@jlstevens
Copy link
Contributor

What is frustrating here is that the concept of clim_percentile is so close to the right thing here - and yet a name involving clim is really quite confusing in the context of RGB(A) images.

I suppose this can be documented nicely but I am still not convinced this shouldn't be something handled at the hvplot level only. Alternatively, if we need this at the HoloViews level, maybe it should be implemented as an operation instead?

Again, it is really annoying how close this looks to be the right thing even though I do think the semantics are being muddied here!

else: # True
low, high = np.percentile(img, (self.clim_percentile, 100 - self.clim_percentile))
img = np.clip(img, low, high)
img = img / high * 255
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
img = img / high * 255
img = (img - low) / (high - low) * 255

Another thought as I don't think we are using the full range of the RGB.

@ahuang11
Copy link
Collaborator Author

ahuang11 commented Mar 4, 2024

Superseded in holoviz/hvplot#1291

@ahuang11 ahuang11 closed this Mar 4, 2024
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants