xarray-contrib / xarray_leaflet Goto Github PK
View Code? Open in Web Editor NEWAn xarray extension for tiled map plotting.
Home Page: https://xarray-leaflet.readthedocs.io
License: MIT License
An xarray extension for tiled map plotting.
Home Page: https://xarray-leaflet.readthedocs.io
License: MIT License
A time dimension should be supported, through e.g. a slider, probably by changing the URL.
A time range could also be supported, which would allow to compute aggregation operations (e.g. the mean), or to create animations (through a GIF or a video).
Hi David
Congratulations on the package, I'm really looking forward to use it, but I simply can't see any data on the map.
See notebook test_xarray_leaflet_simple.ipynb
This is probably not an issue with your package but with my jupyter setting, but maybe you could shed some light. I don't know where else to ask.
I'm using Jupyter Lab from the jupyter/scipy-notebook:703d8b2dcb88
docker image and have all the python packages and widgets seemly working properly: xarray, ipywidgets, ipyleaflet, ipyspin.
And also:
jupyter --version
jupyter core : 4.7.0
jupyter-notebook : 6.1.6
qtconsole : not installed
ipython : 7.19.0
ipykernel : 5.4.2
jupyter client : 6.1.7
jupyter lab : 2.2.9
nbconvert : 6.0.7
ipywidgets : 7.6.2
nbformat : 5.0.8
traitlets : 5.0.5
jupyter labextension list
JupyterLab v2.2.9
Known labextensions:
app dir: /opt/conda/share/jupyter/lab
@bokeh/jupyter_bokeh v2.0.4 enabled OK
@jupyter-widgets/jupyterlab-manager v2.0.0 enabled OK
ipyspin v0.1.2 enabled OK
jupyter-leaflet v0.13.5 enabled OK
jupyter-matplotlib v0.7.4 enabled OK
running with:
Please let me know if you need more info.
Cheers
Rosa
On a fresh install (no .pyc files), just importing xarray_leaflet takes about 9s:
(notebook) jovyan@jupyter-yuvipanda:~$ time python -c 'import xarray_leaflet'
real 0m9.275s
user 0m8.100s
sys 0m1.134s
As this is imported each time jupyter server is started, the user can not see their notebook until this initialization is complete. When coupled with other slow loading extensions (such as panel holoviz/panel#4271), this can cause server starts to time out in JupyterHubs. There is no way to disable this (jupyter server will still import your package even if it is disabled), so the only way to get a faster startup is to uninstall xarray-leaflet completely.
I think a majority of the import time comes from rioxarray
(notebook) jovyan@jupyter-yuvipanda:~$ time python -c 'import rioxarray'
real 0m7.707s
user 0m5.787s
sys 0m0.912s
Hello !
First of all thanks for the work, this library sounds amazing and I can't wait to try it.
However, I still have difficulties to run the introduction notebooks from my machine (Ubuntu 22).
When lauching introduction.ipynb as a jupyter notebook, I have this JavaScript error at block 7 when layer is added on the map :
Failed to create view for 'UrlView' from module 'ipyurl' with model 'UrlModel' from module 'ipyurl'
ReferenceError: process is not defined
at e.makeSettings (http://localhost:8888/nbextensions/ipyurl/index.js?v=20230426160827:2:69011)
at e.makeSettings (http://localhost:8888/nbextensions/ipyurl/index.js?v=20230426160827:2:67987)
at o.get_url (http://localhost:8888/nbextensions/ipyurl/index.js?v=20230426160827:2:404124)
at o.render (http://localhost:8888/nbextensions/ipyurl/index.js?v=20230426160827:2:403836)
at http://localhost:8888/nbextensions/jupyter-js-widgets/extension.js?v=20230426160827:2:747630
My environment was created from scratch using /binder/environment.yml with python 3.10, notably my ipyurl version is 0.1.2 and my xarray-leaflet version is 0.1.16
Here are my jupyter versions :
Many thanks for any help !
My Travis build started to crash on a xarray_leaflet test 4 days ago.
I use the latest release (0.1.13) and I share with you the full traceback :
Traceback (most recent call last):
599 File "/home/travis/build/12rambau/sepal_ui/tests/test_SepalMap.py", line 82, in test_remove_local_raster
600 m.add_raster(dem, colormap='terrain', layer_name='DEM')
601 File "/home/travis/build/12rambau/sepal_ui/sepal_ui/mapping/mapping.py", line 348, in add_raster
602 da = rioxarray.open_rasterio(image, masked=True)
603 File "/home/travis/virtualenv/python3.8.7/lib/python3.8/site-packages/rioxarray/_io.py", line 868, in open_rasterio
604 result._file_obj = manager
605 File "/home/travis/virtualenv/python3.8.7/lib/python3.8/site-packages/xarray/core/common.py", line 276, in __setattr__
606 raise AttributeError(
607AttributeError: cannot set attribute '_file_obj' on a 'DataArray' object. Use __setitem__ styleassignment (e.g., `ds['name'] = ...`) instead of assigning variables.
If you need any additional information please let me know
I'm trying to display a raster image in an ipyleaflet map but there is a black tile in the background, I suspect that it might be related to the shape of the image but I can't display it in a good way, this is the code I'm using.
import rioxarray
import numpy as np
import ipyleaflet
import xarray_leaflet
map_ = ipyleaflet.Map()
da = rioxarray.open_rasterio(image, masked=True)
da = da.rio.write_nodata(np.nan)
da = da.sel(band=1)
da.leaflet.plot(map_)
l,b,r,t=da.rio.bounds()
lat = (t-b)/2 + b
lon = (r-l)/2 + l
map_.center=(lat,lon)
map_
This is my env:
rioxarray version '0.1.0'
ipyleaflet version '0.13.3'
xarray_leaflet version '0.1.10'
An this is what I'm getting:
This could be done by using https://github.com/corteva/geocube to rasterize geopandas vector data.
Hello,
Looks very interesting. But I can't manage to make it working with a zarr store actually. It seems rioxarray is not compliant with zarr format.
Thanks for any tip.
I am exploring a streamflow information data set in netCDF that has point lat/lon coordinates and am scouting for reusable xarray-related leaflet viewers. xaray_leaflet appears geared towards raster information, but issues #22 and #26 appear to suggest
For background my dataset is following some netCDF conventions for water forecasting.
I did a while back a sample lithology data viewer on top of ipyleaflet and am considering packaging this material to facilitate visualising other point-based information through ipyleaflet, including xarray based.
I am not clear about the details of use case(s), but want to flag this if there is an intersect; happy to submit a PR for some of these features.
Tiles can take some time to be generated/sent to the browser. We should have a spinner on the map for that.
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
The color bar does not display if the option dynamic=False
. The problem is that turning dynamic=True
gives unstable behaviour.
Anyone who has the repository already cloned will likely need to update it. These are the commands GitHub suggests:
git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a
Today the tile files are not cleaned up. This can be a problem especially for dynamic maps, as new tile files are created for each interaction with the map. We need to have a mechanism to automatically remove these files.
The tile server is currently the Jupyter server, and because this is a different process than the kernel, the web handlers have to poll for the existence of the files, which is not great.
In https://github.com/davidbrochart/xtrude we have a different approach, the tile server is inside the kernel, and it works pretty well.
The rasters are not displayed on the map when the notebook is run with voila.
This bug has been reported in #143 of the geemap repository but I prefer to report it here as it seems to be linked to xarray_leaflet.
I'll be glad to help
When a DataArray is passed without any CRS, we could assume that it is WGS 84 and write it automatically. Same for nodata
, we could assume it's np.nan
(if the type of the data is floating-point):
da = da.rio.write_crs(4326) # WGS 84
da = da.rio.write_nodata(np.nan)
See #34
Hi,
Recently, I've been looking into xarray-leaflet. It's an exciting project, thanks for all the great work!
Would you know how to render the map directly through voila?
It works when navigating to voila through Jupyter (i.e. voila/render/notebook.ipynb) (Figure A). However, $ voila xarray_interact.ipynb does not render the data on the map for me (Figure B).
Figure: A) rendering voila through the Jupyter interface or B) with voila.
Notebook example to reproduce the issue xarray_interact.ipynb.zip
Thanks
I know that this is the exact same title as #39 But as the OP now have a solution that cannot be used in my case I preferred to open a new one.
I'm working on a company environment so I have no opportunity to start from a "fresh" conda env and I'm force to better understand the libs we use. We were using the lib to display raster as in the geemap librairy and it was working very effectivelly.
As referred here, we recently lost the abbility to load anything on the map...
I checked my configuration over the one in setup.py
setup.py | our environment |
---|---|
jupyter_server>=0.2.0 | jupyter-server==1.4.1 |
rioxarray>=0.0.30 | rioxarray==0.3.1 |
ipyleaflet>=0.13.1 | ipyleaflet==0.13.3 |
pillow>=7 | Pillow==8.1.1 |
ipyspin>=0.1.1 | ipyspin==0.1.5 |
mercantile>=1 | mercantile==1.1.6 |
affine>=2 | affine==2.3.0 |
matplotlib>=3 | matplotlib==3.3.4 |
It should work but instead the spinning wheel turns forever and nothing appears on the map.
I also check the javascript console and appart from warnings about the cartoDB basemap, nothing.
Would you think about anything that could prevent the loading of the generated tiles ? (I'm in particular thinking about authorization to read or write in specific folder but I don't knwo which one to verify)
Just wanted to point out the masked=True and the mask_and_scale=True options. Based on your getting started example, I figured this would be helpful.
I am working in a cloud environment that stores production notebooks in a /shared/notebooks/
path... digging into xarray_leaflet
code I saw that when the module states the base_url
, is using the word 'notebooks'. So in my case, it will cause a wrong URL referencing and will point to nowhere.
I doubt posting the issue here but as many people could store its notebooks in that folder, would be better if this is fixed in the module.
I was thinking instead of finding the last occurrence, just get the first.
When showing a DataArray, every dimension other than x
and y
should be assigned to a slider, e.g. to be able to move through a time dimension.
xref. #26
xarray-leaflet could be a general purpose visualization tool, not specific to geographical data. For that we could use CRS.Simple
(see https://leafletjs.com/examples/crs-simple/crs-simple.html).
We need a way to display a colorbar. The colormap currently uses matplotlib, so the easiest way is to show the colorbar with matplotlib and show it outside the map. It should also be possible to show it inside the map.
Another way would be to use a custom legend control in Leaflet, but we need a way to match matplotlib's colormap. Or use Leaflet's colormap instead of matplotlib's.
I get the following error when importing the library:
AttributeError: module 'xarray.core' has no attribute 'rolling'1
The versions are:
xarray 2022.6.0
xarray_leaflet 0.1.15
Is there any idea what could be the reason?
Thanks
I was trying to display a small DEM (epsg:4326) on the map. However, I noticed the DEM was being displayed at three locations with varying sizes. Only the smallest one at the upper left is the correct one.
Here is the notebook to reproduce the issue.
In the latest master commits, there is a color map option for the plot method, are you considering releasing a v0.1.14 that would include this functionality ?
Some vertical lines can be seen at tile boundaries, I think this has to do with coarsen()
.
This can especially be seen at zoom levels 1 or 2, for instance in https://github.com/davidbrochart/xarray_leaflet/blob/master/examples/introduction.ipynb.
I don't know if the issue comes from xarray-leaflet or rasterio.
As referenced in (sepal_ui #35)[https://github.com/openforis/sepal_ui/issues/35], Local raster images are not being displayed in voilá dashboards nor Jupyter SEPAL dashboards, the problem comes up when the xarray_leaflet module is stating the base_url, using the 'notebooks' word.
The sepal module dashboards are being stored in /shared/notebooks/, so the condition is trying to find the last 'notebook' word, but as there are two occurrences in the URL, it will take the second, causing confusion and pointing to nowhere.
This would basically work like xarray.DataArray.leaflet.plot()
, with an additional LayersControl
(or a dropdown widget) to show/hide data variables in the Dataset (provided that all data variables are compatible).
Since v0.13.0, ipyleaflet supports custom projections. xarray-leaflet can take advantage of it, since it can reproject.
It seems xarray-leaflet is not working properly on Windows. The map tiles could not load. When checking the map tiles under the Temp folders, most tiles are empty. A relevant issue was reported by another geemap user.
OS: Windows 10
Python: v3.8
xarray-leaflet: v0.1.13
Notebook: xarray_leaflet/examples/introduction.ipynb
It would be great if somehow we could draw a rectangle on the map (using ipyleaflet's controls) and get the selected region as a new xarray.DataArray
object.
Hi David,
Enjoying the ease of use with this package, however I'm suffering the same issue as issue#36, so I'm sorry to repeat that I can't visualise any data on the map. I've tried all of your notebooks, and even Rosa's notebook with your issue#36 solution. I'm thinking maybe there is an issue with my environment set up, I've attached what I'm working with. Any help is appreciated, would love to get this package working!
´´´
!jupyter --version
jupyter core : 4.7.0
jupyter-notebook : 6.2.0
qtconsole : not installed
ipython : 7.16.1
ipykernel : 5.3.0
jupyter client : 6.1.7
jupyter lab : not installed
nbconvert : 6.0.7
ipywidgets : 7.6.3
nbformat : 5.1.2
traitlets : 4.3.3
!jupyter labextension list
Config option kernel_spec_manager_class
not recognized by ListLabExtensionsApp
.
JupyterLab v2.1.3
Known labextensions:
app dir: /opt/conda/share/jupyter/lab
@bokeh/jupyter_bokeh v2.0.2 enabled OK
@jupyter-widgets/jupyterlab-manager v2.0.0 enabled OK
jupyter-leaflet v0.13.5 enabled OK
jupyter-matplotlib v0.7.2 enabled OK
keplergl-jupyter v0.2.2 enabled OK
´´´
If I've missed something please let me know.
I'm trying to use xarray_leaflet to display an image that I've loaded via rioxarray. The image isn't in WGS84 projection (it's in a UK-based projection). It doesn't appear on the map, so I've been looking into the code.
In _get_tiles()
the DataArray seems to be indexed by the lat/lon co-ordinates of a mercantile tile.
Does this mean that xarray_leaflet does not currently support working with DataArrays that are not indexed in lat/lon co-ordinates? I notice that the examples use large-scale global datasets that seem to be in WGS84.
In #69 we are introducing new dependencies that can make it harder to install.
Maybe the vector support should be separate and require an explicit e.g. import xarray_leaflet.vector
, as well as a pip install xarray_leaflet[vector]
.
The Zzarr
class introduced in #69 can be used to build a group of hierarchical arrays at various zoom levels. @rabernat mentioned it could implement the multiscale convention. He also mentioned https://github.com/christophenoel/geozarr-spec.
It seems that inferring the base URL is failing for me in JupyterLab 3.0.12.
The .window_url
of my map is 'http://localhost:8888/lab/workspaces/auto-s/tree/nb/leaflet.ipynb'
, which doesn't match the .endswith("lab")
logic trying to identify JupyterLab. Maybe the URL scheme has changed recently?
I'm imagine missing something here, but is the goal of the "find the base URL" logic to figure out the URL of the Jupyter server? In that case, would something like
url = urllib.parse.urlparse(m.window_url)
self.base_url = f"{url.scheme}://{url.netloc}"
work for all the cases in general?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.