Skip to content

is it possible to filter out some values when using the plot function ?  #62

@12rambau

Description

@12rambau

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

Capture d’écran 2022-04-20 à 22 42 49

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions