Skip to content

Add vector rendering #69

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

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Tests

on:
push:
branches:
- main
pull_request:
branches:
- main

defaults:
run:
shell: bash -l {0}

jobs:
tests:
name: Unit Tests
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [ '3.7' ]

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup conda
uses: conda-incubator/setup-miniconda@v2
with:
mamba-version: "*"
channels: conda-forge

- name: Mamba install dependencies
run: mamba install python=${{ matrix.python-version }} pip

- name: Install xarray-leaflet
run: |
pip install .[test]

- name: Check style
run: |
black --check xarray_leaflet tests
isort --check --profile=black xarray_leaflet tests
flake8 xarray_leaflet tests
# mypy xarray_leaflet

- name: Run tests
run: |
# TODO
# pytest xarray_leaflet/tests -v
11 changes: 9 additions & 2 deletions .github/workflows/ui-tests.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
name: UI Tests

on: [push, pull_request]
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
ui-tests:
name: Visual Regression
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python: [3.8]
fail-fast: false

Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/update_galata_references.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Update Galata References

on:
issue_comment:
types: [created, edited]

permissions:
contents: write
pull-requests: write

defaults:
run:
shell: bash -l {0}

jobs:
update-reference-screenshots:
name: Update Galata References
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, 'update galata references') }}
runs-on: [ubuntu-latest, macos-latest]

steps:
- name: Checkout
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Configure git to use https
run: git config --global hub.protocol https

- name: Checkout the branch from the PR that triggered the job
run: hub pr checkout ${{ github.event.issue.number }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Setup conda
uses: conda-incubator/setup-miniconda@v2
with:
mamba-version: "*"
channels: conda-forge

- name: Mamba install dependencies
run: mamba install python=${{ matrix.python-version }} pip

- name: Install xarray_leaflet
run: pip install .

- name: Install ui-tests
run: jlpm install --frozen-lockfile
working-directory: ui-tests

- uses: jupyterlab/maintainer-tools/.github/actions/update-snapshots@main
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
server_url: http-get://localhost:8888/
test_folder: ui-tests
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ Using pip:
pip install xarray_leaflet
```

For development:

```bash
pip install -e .
# manually copy these files in your environment, e.g.:
# cp etc/jupyter/jupyter_notebook_config.d/* ~/mambaforge/envs/xarray_leaflet/etc/jupyter/jupyter_notebook_config.d/
# cp etc/jupyter/jupyter_server_config.d/* ~/mambaforge/envs/xarray_leaflet/etc/jupyter/jupyter_server_config.d/
```

## Using xarray-leaflet with Voila

To work with xarray-leaflet, Voila has to be launched with the following command:
Expand Down
15 changes: 8 additions & 7 deletions binder/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ name: xarray-leaflet
channels:
- conda-forge
dependencies:
- requests
- tqdm
- scipy
- dask
- rasterio=1.2.6
- jupyterlab=3
- xarray_leaflet=0.1.15
- pip
- pip:
- requests
- tqdm
- scipy
- dask
- jupyterlab
- git+https://github.com/davidbrochart/xarray_leaflet.git@vector#egg=xarray_leaflet
2 changes: 1 addition & 1 deletion examples/introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
"version": "3.10.5"
}
},
"nbformat": 4,
Expand Down
134 changes: 134 additions & 0 deletions examples/markers_or_density.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "15eefe2f-7d1b-4814-9a5b-3b57df451fd7",
"metadata": {},
"outputs": [],
"source": [
"from ipyleaflet import GeoData, Map, basemaps, LayersControl, WidgetControl\n",
"from ipywidgets import FloatSlider\n",
"import xarray_leaflet\n",
"import geopandas as gpd\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "30114fbe-e6ef-4547-98ab-28686f8980b1",
"metadata": {},
"outputs": [],
"source": [
"!wget https://raw.githubusercontent.com/drei01/geojson-world-cities/master/cities.geojson"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ab8cd637-be46-4953-96a8-edd918aeccf8",
"metadata": {},
"outputs": [],
"source": [
"df = gpd.read_file(\"cities.geojson\")\n",
"df.geometry = df.geometry.centroid\n",
"measurement = \"mask\"\n",
"df[measurement] = 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "55a78adf",
"metadata": {},
"outputs": [],
"source": [
"m = Map(center=(34.36519854648025, -47.3743535773436), zoom=3, basemap=basemaps.CartoDB.DarkMatter, interpolation='nearest')\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6180d7f5-05e5-4f56-b179-78cc8f581f1a",
"metadata": {},
"outputs": [],
"source": [
"class LayerManager:\n",
"\n",
" def __init__(self, df, measurement):\n",
" self.df = df\n",
" self.measurement = measurement\n",
" self.marker_layer = None\n",
"\n",
" def visible_callback(self, m, da, bbox):\n",
" # show density if there are too many points\n",
" # otherwise show individual markers\n",
" density_visible = da.sum() > 500\n",
" if self.marker_layer:\n",
" # remove markers\n",
" m.remove(self.marker_layer)\n",
" self.marker_layer = None\n",
" if not density_visible:\n",
" # only show markers that are on the map view\n",
" self.marker_layer = GeoData(geo_dataframe=self.df.clip(bbox))\n",
" m.add(self.marker_layer)\n",
" return density_visible\n",
"\n",
"layer_manager = LayerManager(df, measurement)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2ab54311-d960-4b51-9623-e8d91b97ad75",
"metadata": {},
"outputs": [],
"source": [
"l = df.leaflet.plot(m, measurement=\"mask\", colormap=plt.cm.inferno, visible_callback=layer_manager.visible_callback)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fe1ea3ac-7c1b-4443-8f82-2bffe819b27c",
"metadata": {},
"outputs": [],
"source": [
"layers_control = LayersControl(position='topright')\n",
"m.add_control(layers_control)\n",
"\n",
"opacity_slider = FloatSlider(description='Opacity:', min=0, max=1, value=1)\n",
"\n",
"def set_opacity(change):\n",
" l.opacity = change['new']\n",
"\n",
"opacity_slider.observe(set_opacity, names='value')\n",
"slider_control = WidgetControl(widget=opacity_slider, position='bottomleft')\n",
"m.add_control(slider_control)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading