-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3a97b1
commit ab83f30
Showing
19 changed files
with
836 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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, windows-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 gdal | ||
|
||
- name: Install xarray-leaflet | ||
run: | | ||
pip install .[test] | ||
- name: Check style | ||
run: | | ||
black --check xarray_leaflet tests | ||
flake8 xarray_leaflet tests | ||
# mypy xarray_leaflet | ||
- name: Run tests | ||
run: | | ||
# TODO | ||
# pytest xarray_leaflet/tests -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,48 @@ | ||
[bumpversion] | ||
current_version = 0.1.15 | ||
commit = True | ||
tag = True | ||
|
||
[bumpversion:file:setup.py] | ||
search = version='{current_version}' | ||
replace = version='{new_version}' | ||
|
||
[bumpversion:file:xarray_leaflet/__init__.py] | ||
search = __version__ = '{current_version}' | ||
replace = __version__ = '{new_version}' | ||
[metadata] | ||
name = xarray_leaflet | ||
version = attr: xarray_leaflet.__version__ | ||
description = An xarray extension for map plotting | ||
long_description = file: README.md | ||
long_description_content_type = text/markdown | ||
license = MIT | ||
author = David Brochart | ||
author_email = [email protected] | ||
url = https://github.com/xarray-contrib/xarray_leaflet | ||
platforms = Windows, Linux, Mac OS X | ||
keywords = xarray leaflet | ||
|
||
[bdist_wheel] | ||
universal = 1 | ||
|
||
[flake8] | ||
exclude = docs | ||
[options] | ||
include_package_data = True | ||
packages = find: | ||
python_requires = >=3.7 | ||
|
||
[aliases] | ||
# Define setup.py command aliases here | ||
install_requires = | ||
jupyter_server >=0.2.0 | ||
rioxarray >=0.0.30 | ||
ipyleaflet >=0.13.1 | ||
pillow >=7 | ||
matplotlib >=3 | ||
affine >=2 | ||
mercantile >=1 | ||
ipyspin >=0.1.1 | ||
ipyurl >=0.1.2 | ||
geocube | ||
pygeos >=0.12,<1.0.0 | ||
zarr >=2.0.0,<3.0.0 | ||
|
||
[options.extras_require] | ||
test = | ||
mypy | ||
flake8 | ||
black | ||
pytest | ||
|
||
[options.data_files] | ||
etc/jupyter/jupyter_server_config.d = etc/jupyter/jupyter_server_config.d/xarray_leaflet.json | ||
etc/jupyter/jupyter_notebook_config.d = etc/jupyter/jupyter_notebook_config.d/xarray_leaflet.json | ||
|
||
[flake8] | ||
max-line-length = 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,3 @@ | ||
#!/usr/bin/env python | ||
import setuptools | ||
|
||
"""The setup script.""" | ||
|
||
from setuptools import setup, find_packages | ||
|
||
def get_data_files(): | ||
"""Get the data files for the package. | ||
""" | ||
data_files = [ | ||
('etc/jupyter/jupyter_server_config.d', ['etc/jupyter/jupyter_server_config.d/xarray_leaflet.json']), | ||
('etc/jupyter/jupyter_notebook_config.d', ['etc/jupyter/jupyter_notebook_config.d/xarray_leaflet.json']) | ||
] | ||
return data_files | ||
|
||
requirements = [ | ||
'jupyter_server>=0.2.0', | ||
'rioxarray>=0.0.30', | ||
'ipyleaflet>=0.13.1', | ||
'pillow>=7', | ||
'matplotlib>=3', | ||
'affine>=2', | ||
'mercantile>=1', | ||
'ipyspin>=0.1.1', | ||
'ipyurl>=0.1.2', | ||
] | ||
|
||
setup_requirements = [ ] | ||
|
||
test_requirements = [ ] | ||
|
||
setup( | ||
author="David Brochart", | ||
author_email='[email protected]', | ||
python_requires='>=3.5', | ||
classifiers=[ | ||
'Development Status :: 2 - Pre-Alpha', | ||
'Intended Audience :: Developers', | ||
'License :: OSI Approved :: MIT License', | ||
'Natural Language :: English', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.5', | ||
'Programming Language :: Python :: 3.6', | ||
'Programming Language :: Python :: 3.7', | ||
'Programming Language :: Python :: 3.8', | ||
], | ||
description="An xarray extension for map plotting", | ||
install_requires=requirements, | ||
license="MIT license", | ||
long_description="An xarray extension for map plotting", | ||
include_package_data=True, | ||
keywords='xarray_leaflet', | ||
name='xarray_leaflet', | ||
packages=find_packages(include=['xarray_leaflet', 'xarray_leaflet.*']), | ||
setup_requires=setup_requirements, | ||
test_suite='tests', | ||
tests_require=test_requirements, | ||
url='https://github.com/davidbrochart/xarray_leaflet', | ||
version='0.1.15', | ||
zip_safe=False, | ||
data_files=get_data_files() | ||
) | ||
setuptools.setup() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import filecmp | ||
from tempfile import TemporaryDirectory | ||
|
||
import geopandas as gpd | ||
import mercantile | ||
from shapely.geometry import box | ||
from xarray_leaflet.vector import Zvect | ||
|
||
from .utils import save_fig | ||
|
||
|
||
HEIGHT = WIDTH = 256 | ||
|
||
|
||
def test_da_tile_full(): | ||
x, y, z = 3, 4, 5 | ||
bounds = mercantile.bounds(x, y, z) | ||
b = box(bounds.west, bounds.south, bounds.east, bounds.north) | ||
df = gpd.GeoDataFrame(geometry=gpd.GeoSeries([b])) | ||
df.set_crs(epsg=4326, inplace=True) | ||
measurement = "mask" | ||
df[measurement] = 1 | ||
tile = mercantile.bounding_tile(*df.to_crs(epsg=4326).geometry.total_bounds) | ||
assert tile.x == x | ||
assert tile.y == y | ||
assert tile.z == z | ||
zvect = Zvect(df, measurement, WIDTH, HEIGHT) | ||
da_tile = zvect.get_da_tile(tile) | ||
assert len(da_tile.x) == WIDTH | ||
assert len(da_tile.y) == HEIGHT | ||
expected, result = save_fig(da_tile, "test_da_tile_full.png") | ||
assert filecmp.cmp(expected, result) | ||
|
||
|
||
def test_da_tile_nybb(): | ||
path_to_data = gpd.datasets.get_path("nybb") | ||
df = gpd.read_file(path_to_data) | ||
measurement = "mask" | ||
df[measurement] = 1 | ||
tile = mercantile.bounding_tile(*df.to_crs(epsg=4326).geometry.total_bounds) | ||
zvect = Zvect(df, measurement, WIDTH, HEIGHT) | ||
da_tile = zvect.get_da_tile(tile) | ||
assert len(da_tile.x) == WIDTH | ||
assert len(da_tile.y) == HEIGHT | ||
expected, result = save_fig(da_tile, "test_da_tile_nybb.png") | ||
assert filecmp.cmp(expected, result) | ||
|
||
|
||
def test_get_da_llbbox(): | ||
path_to_data = gpd.datasets.get_path("nybb") | ||
df = gpd.read_file(path_to_data) | ||
measurement = "mask" | ||
df[measurement] = 1 | ||
bounds = df.to_crs(epsg=4326).geometry.total_bounds | ||
tile = mercantile.bounding_tile(*bounds) | ||
llbbox = mercantile.LngLatBbox(*bounds) | ||
with TemporaryDirectory() as tmpdirname: | ||
zvect = Zvect(df, measurement, WIDTH, HEIGHT, tmpdirname) | ||
da = zvect.get_da_llbbox(llbbox, tile.z + 1) | ||
expected, result = save_fig(da, "test_get_da_llbbox.png") | ||
assert filecmp.cmp(expected, result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from pathlib import Path | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
|
||
RESULTS = Path(__file__).parent / "results" | ||
RESULTS.mkdir(exist_ok=True) | ||
EXPECTED = Path(__file__).parent / "expected" | ||
EXPECTED.mkdir(exist_ok=True) | ||
|
||
|
||
def save_fig(da, name): | ||
result_path = RESULTS / name | ||
expected_path = EXPECTED / name | ||
da.plot() | ||
plt.savefig(result_path) | ||
plt.close() | ||
return result_path, expected_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import geopandas\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"from ipyleaflet import Map\n", | ||
"from xarray_leaflet import LeafletMap" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"path_to_data = geopandas.datasets.get_path(\"nybb\")\n", | ||
"df = geopandas.read_file(path_to_data)\n", | ||
"df[\"mask\"] = 1" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"m = Map(center=(40.68262616765372, -74.020909735734757), zoom=9, interpolation=\"nearest\")\n", | ||
"m" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"l = LeafletMap(df=df).plot(m, fit_bounds=False, colormap=plt.cm.inferno, measurement=\"mask\")" | ||
] | ||
} | ||
], | ||
"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": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.