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

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

Open
12rambau opened this issue Apr 20, 2022 · 0 comments · May be fixed by #63
Open

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

12rambau opened this issue Apr 20, 2022 · 0 comments · May be fixed by #63

Comments

@12rambau
Copy link
Contributor

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

@12rambau 12rambau linked a pull request Apr 21, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant