xarray_leaflet
xarray_leaflet copied to clipboard
is it possible to filter out some values when using the plot function ?
I try to display a raster. This raster has 1 band, values from 0 to 1, nan outside of Uganda and 0 where restoration cannot be performed. I would like to display it on my map and filter the nan and 0s out (or make them transparent).
I'm use t the imshow
function where I can play with "vmin" and then add a set_under
in my colormap. I even tried to used set_bad
but it seems xarray doesn't support the ma
modules from numpy
.
As you're the owner of the lib I thought that maybe there is a more elegant solution to my issue.
here is a reproductible example (using the default magma colormap):
from pathlib import Path
from urllib.request import urlretrieve
import rioxarray
import xarray_leaflet
from rasterio.crs import CRS
import numpy as np
from ipyleaflet import Map, basemaps
###################### trick for the SEPAL environmnent ########################
def get_base_url(_):
return "https://sepal.io/api/sandbox/jupyter"
################################################################################
url = "https://iisau-weplan.s3.eu-west-1.amazonaws.com/weplan_data/UGA_v002/available_v002.tif"
file = Path.home()/"available_v002.tif"
urlretrieve(url, file)
da = rioxarray.open_rasterio(file, masked=True)
da = da.rio.reproject("EPSG:4326")
da = da.sel(band=1)
da = da.chunk((1000, 1000))
m = Map(zoom=3, basemap=basemaps.CartoDB.Positron)
l = da.leaflet.plot(m=m, get_base_url=get_base_url)
l.opacity = 1
m
