MCPcopy Index your code
hub / github.com/pydata/xarray / _rescale_imshow_rgb

Function _rescale_imshow_rgb

xarray/plot/utils.py:753–783  ·  view source on GitHub ↗
(darray, vmin, vmax, robust)

Source from the content-addressed store, hash-verified

751
752
753def _rescale_imshow_rgb(darray, vmin, vmax, robust):
754 assert robust or vmin is not None or vmax is not None
755
756 # Calculate vmin and vmax automatically for `robust=True`
757 if robust:
758 if vmax is None:
759 vmax = np.nanpercentile(darray, 100 - ROBUST_PERCENTILE)
760 if vmin is None:
761 vmin = np.nanpercentile(darray, ROBUST_PERCENTILE)
762 # If not robust and one bound is None, calculate the default other bound
763 # and check that an interval between them exists.
764 elif vmax is None:
765 vmax = 255 if np.issubdtype(darray.dtype, np.integer) else 1
766 if vmax < vmin:
767 raise ValueError(
768 f"vmin={vmin!r} is less than the default vmax ({vmax!r}) - you must supply "
769 "a vmax > vmin in this case."
770 )
771 elif vmin is None:
772 vmin = 0
773 if vmin > vmax:
774 raise ValueError(
775 f"vmax={vmax!r} is less than the default vmin (0) - you must supply "
776 "a vmin < vmax in this case."
777 )
778 # Scale interval [vmin .. vmax] to [0 .. 1], with darray as 64-bit float
779 # to avoid precision loss, integer over/underflow, etc with extreme inputs.
780 # After scaling, downcast to 32-bit float. This substantially reduces
781 # memory usage after we hand `darray` off to matplotlib.
782 darray = ((darray.astype("f8") - vmin) / (vmax - vmin)).astype("f4")
783 return np.minimum(np.maximum(darray, 0), 1)
784
785
786def _update_axes(

Callers 1

newplotfuncFunction · 0.90

Calls 1

astypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…