Giter VIP home page Giter VIP logo

xarray_leaflet's Introduction

xarray-contrib

xarray-contrib is a GitHub organization for gathering high-quality open source projects that build on Xarray.

Vision

As more and more projects build on Xarray, we wanted to provide a central place to collect community projects. We hope that including projects under the xarray-contrib organization improves project visibility and increases the likelihood of sustainable open source maintenance and development.

Guidelines

Projects in xarray-contrib should contain sufficient functionality and documentation to be useful and welcoming to new users. They should also follow software development best practices:

  • Open-source license
  • Supports a recent version of Xarray
  • Available on PyPI and/or conda-forge
  • Documentation sufficient for new users to get started, which typically includes:
    • A user guide or tutorial
    • Usage examples
    • API reference
  • Unit tests + continuous integration
  • PEP8 compliant code style

If you have a project that meets these requirements, open a new issue in this repository to discuss transfering it to the xarray-contrib organization.

Disclaimer

This organization is merely a container for projects that use Xarray. Projects included in xarray-contrib organization are not supported by the Xarray Core Developer Team.

xarray_leaflet's People

Contributors

12rambau avatar davidbrochart avatar dependabot[bot] avatar dustinmichels avatar liamtoney avatar tylere avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xarray_leaflet's Issues

Display colorbar

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.

Extra install for vector support

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].

open_rasterio masked=True

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.

DataArrays that aren't in lat-lon co-ordinates: are they supported?

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.

module 'xarray.core' has no attribute 'rolling'

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

How to render xarray_leaflet with voila? E.g. $ voila xarray_interact.ipynb

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
Figure: A) rendering voila through the Jupyter interface or B) with voila.

Notebook example to reproduce the issue xarray_interact.ipynb.zip

Thanks

Installing xarray-leaflet causes jupyter server to be really slow to start

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

Renamed default branch to main

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

Default CRS and nodata

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

can't see data on map

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:

  • Docker version 19.03.14
  • Ubuntu 18.04.4 LTS (Bionic Beaver)

Please let me know if you need more info.

Cheers
Rosa

Possible use case: point-location information in xarray

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.

Plot multi-band raster dataset

Is it possible to plot multi-band raster datasets (e.g., Landsat imagery)? For now, I can only display one band at a time. It would be great if it can display three RGB bands.

No data display

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.

Problem displaying GeoTIFF

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.

'LeafletMap' object has no attribute 'base_url' in JupyterLab

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?

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

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

LocalTileLayer does not appear on map

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 :

  • IPython : 8.12.0
  • ipykernel : 6.22.0
  • ipywidgets : 8.0.6
  • jupyter_client : 8.2.0
  • jupyter_core : 5.3.0
  • jupyter_server : 1.24.0
  • jupyterlab : 3.6.3
  • nbclient : 0.7.3
  • nbconvert : 7.3.1
  • nbformat : 5.8.0
  • notebook : 6.5.4
  • qtconsole : not installed
  • traitlets : 5.9.0

Many thanks for any help !

Change tile server

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.

Local raster are not displayed when using a sub 'notebooks' folder

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.

Tile doesn't display if the notebook folder is called 'notebooks' or 'voila'

As referenced in (sepal_ui #35)[https://github.com/12rambau/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.

Attribute error on open_rasterio function

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

No data display

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)

xarray.Dataset.leaflet.plot() ?

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).

Automatic cleanup of tile files

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.

raster doesn't display in voila

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

Setting layer name shown under the layer control

Is it possible to set the layer name shown under the layer control? Currently, it seems the default layer name is empty. I tried using l.name = 'layer name', but it has no effect. It would be great if the da.leaflet.plot() has a name argument that can be set directly. Thanks.

Spinner

Tiles can take some time to be generated/sent to the browser. We should have a spinner on the map for that.

Vertical lines

Some vertical lines can be seen at tile boundaries, I think this has to do with coarsen().

Time dimension support

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).

Interact with extra dimensions

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

Tile URL management

With #44 the base URL is now automatically retrieved from JupyterLab, so in order to handle any other platform a function returning the base URL must be passed in get_base_url.
Closing #42, #40, #39, #37.

Zarr support

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.

Black tiles with non-square images

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:

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.