# Advice on creating a photometric RGB COG from an xarray source

**URL:** <https://discourse.pangeo.io/t/advice-on-creating-a-photometric-rgb-cog-from-an-xarray-source/5434>\
**Category:** Data\
**Created:** [October 30, 2025, 5:24pm UTC](https://discourse.pangeo.io/t/advice-on-creating-a-photometric-rgb-cog-from-an-xarray-source/5434 "2025-10-30T17:24:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jalder](https://avatars.discourse-cdn.com/v4/letter/j/f05b48/32.png) [@jalder](https://discourse.pangeo.io/u/jalder)\
**Post date:** [October 30, 2025, 5:24pm UTC](https://discourse.pangeo.io/t/advice-on-creating-a-photometric-rgb-cog-from-an-xarray-source/5434/1 "2025-10-30T17:24:23Z")

</div>

Hello all, I am considering using COGs as a data visualization tool in a web application and could use some advice. We’re currently using the ESRI JavaScript mapping API, which allows for COG layers, but only photometric RGB COGs. It doesn’t have the ability to render floating point data on the fly in the web browser. I know there is the amazing CarbonPlan CMIP demo web application that renders xarray data in real-time, but this requires a server side backend. I’m hoping for a solution that doesn’t require a backend, so photometric RGB COGs in a simple map viewer seems to fit the bill, but all the rendering options will be locked in.

So, the question is: what is the most efficient workflow to go from an xarray data source to an RGB COG? There is the rio.to\_raster() method, but I need to apply a colormap and vmin/vmax range to render floating point values to RBG bands. Well, perhaps RGBA to account for missing values since the data are land only and the oceans should be transparent. I could potentially use xarray.apply\_ufunc to do the color interpolation myself, but I was hoping there was already a library for this workflow.

Thanks

---

<div class="post-metadata">

**Author:** ![kirill.kzb](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pangeo.io/kirill.kzb/32/1276_2.png) [@kirill.kzb](https://discourse.pangeo.io/u/kirill.kzb)\
**Post date:** [October 31, 2025, 6:53am UTC](https://discourse.pangeo.io/t/advice-on-creating-a-photometric-rgb-cog-from-an-xarray-source/5434/2 "2025-10-31T06:53:17Z")

</div>

I would use something like this:

```auto
import odc.geo.xr # enables .odc accessor

# assuming `xx` is data array
# xx: xarray.DataArray

xx.odc.colorize(cmap='viridis', robust=True).odc.write_cog("tt.tif")

```

> **[odc.geo.xr.colorize — odc-geo 0.5.0rc1 documentation](https://odc-geo.readthedocs.io/en/latest/_api/odc.geo.xr.colorize.html)**

> **[odc.geo.xr.write\_cog — odc-geo 0.5.0rc1 documentation](https://odc-geo.readthedocs.io/en/latest/_api/odc.geo.xr.write_cog.html)**

`robust=True` mimics `xarray` plotting behavior by computing `vmin`/`vmax` using percentiles , but you can also supply fixed `vmin=, vmax=` also.
