Skip to content

Commit f47b961

Browse files
authored
Merge pull request #168 from developmentseed/maintenance
Maintenance
2 parents f6fa7da + 9ac3e56 commit f47b961

File tree

11 files changed

+165
-65
lines changed

11 files changed

+165
-65
lines changed

.circleci/config.yml

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,65 @@
11
version: 2
2+
common: &common
3+
working_directory: ~/label-maker
4+
steps:
5+
- checkout
6+
- run:
7+
name: install dependencies
8+
command: pip install tox codecov --user
9+
- run:
10+
name: install tippecanoe
11+
command: .circleci/install_tippecanoe.sh
12+
- run:
13+
name: run tox
14+
command: ~/.local/bin/tox
215
jobs:
3-
build:
16+
"python-3.6":
17+
<<: *common
418
docker:
5-
- image: circleci/python:3.6-stretch
19+
- image: circleci/python:3.6.5
20+
environment:
21+
- TOXENV=py36
622

23+
"python-3.7":
24+
<<: *common
25+
docker:
26+
- image: circleci/python:3.7.2
27+
environment:
28+
- TOXENV=py37
29+
30+
deploy:
31+
docker:
32+
- image: circleci/python:3.7.2
33+
environment:
34+
- TOXENV=release
735
working_directory: ~/label-maker
836
steps:
937
- checkout
1038
- run:
11-
name: Installing Dependencies
39+
name: verify git tag vs. version
1240
command: |
13-
sudo apt-get update
14-
sudo apt-get install libgdal-dev
15-
sudo pip install numpy==1.13.3
16-
sudo pip install -r requirements.txt
17-
sudo pip install -r requirements-dev.txt
18-
git clone git@github.com:mapbox/tippecanoe.git
19-
cd tippecanoe
20-
sudo make -j
21-
sudo make install
22-
41+
VERSION=$(python setup.py --version)
42+
if [ "$VERSION" = "$CIRCLE_TAG" ]; then exit 0; else exit 3; fi
2343
- run:
24-
name: Pylint
25-
command: pylint ~/label-maker/label_maker --rcfile=~/label-maker/.config/pylintrc
44+
name: init .pypirc
45+
command: |
46+
echo -e "[pypi]" >> ~/.pypirc
47+
echo -e "username = $PYPI_USER" >> ~/.pypirc
48+
echo -e "password = $PYPI_PASSWORD" >> ~/.pypirc
2649
- run:
27-
name: Unit Tests
28-
command: python -m unittest discover -v -s test/unit
50+
name: install dependencies
51+
command: pip install tox --user
2952
- run:
30-
name: Integration Tests
31-
command: |
32-
sudo pip install .
33-
python -m unittest discover -v -s test/integration
34-
53+
name: run tox
54+
command: ~/.local/bin/tox
3555
- add_ssh_keys:
3656
fingerprints:
3757
- "79:16:39:74:e9:b3:39:52:87:2c:90:aa:ee:3c:09:13"
38-
3958
- run:
4059
name: Deploy documentation
4160
command: |
4261
if [ "${CIRCLE_BRANCH}" == "${PRODUCTION_BRANCH}" ]; then
62+
pip install -r requirements-dev.txt
4363
cd docs
4464
make html
4565
cd _build/html
@@ -56,3 +76,20 @@ jobs:
5676
else
5777
echo "Not the branch you're looking for, skipping documentation deploy"
5878
fi
79+
workflows:
80+
version: 2
81+
build_and_deploy:
82+
jobs:
83+
- "python-3.6"
84+
- "python-3.7":
85+
filters: # required since `deploy` has tag filters AND requires `build`
86+
tags:
87+
only: /.*/
88+
- deploy:
89+
requires:
90+
- "python-3.7"
91+
filters:
92+
tags:
93+
only: /^[0-9]+.*/
94+
branches:
95+
ignore: /.*/

.circleci/install_tippecanoe.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sudo apt-get update -y && sudo apt-get install libgdal-dev
2+
git clone git@github.com:mapbox/tippecanoe.git
3+
cd tippecanoe
4+
sudo make -j
5+
sudo make install

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ stdout*
1414
/integration*
1515
.idea/
1616
docs/_build/
17+
18+
.tox

label_maker/download.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,27 @@
33
from os import path
44
import tempfile
55
import gzip
6-
from homura import download
6+
import requests
7+
from tqdm import tqdm
78

9+
def download(url, path):
10+
"""Download url to target path"""
11+
file_size = int(requests.head(url).headers["Content-Length"])
12+
header = {"Range": "bytes=%s-%s" % (0, file_size)}
13+
pbar = tqdm(
14+
total=file_size,
15+
unit='B',
16+
unit_scale=True,
17+
desc=url.split('/')[-1]
18+
)
19+
req = requests.get(url, headers=header, stream=True)
20+
with(open(path, 'ab')) as f:
21+
for chunk in req.iter_content(chunk_size=1024):
22+
if chunk:
23+
f.write(chunk)
24+
pbar.update(1024)
25+
pbar.close()
26+
return file_size
827

928
def download_mbtiles(dest_folder, country, **kwargs):
1029
"""Download QA Tiles for the selected country.

label_maker/label.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import numpy as np
1111
import mapbox_vector_tile
12-
import pyproj
1312
from shapely.geometry import shape, mapping, Polygon
1413
from shapely.errors import TopologicalError
1514
from rasterio.features import rasterize
@@ -325,9 +324,3 @@ def _create_empty_label(ml_type, classes):
325324
elif ml_type == 'segmentation':
326325
return np.zeros((256, 256), dtype=np.int)
327326
return None
328-
329-
# Use with 'transform' to project to EPSG:4326
330-
project = partial(
331-
pyproj.transform,
332-
pyproj.Proj(init='epsg:3857'),
333-
pyproj.Proj(init='epsg:4326'))

label_maker/utils.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
from urllib.parse import urlparse, parse_qs
55

66
from mercantile import bounds
7-
from pyproj import Proj, transform
87
from PIL import Image
98
import numpy as np
109
import requests
1110
import rasterio
11+
from rasterio.crs import CRS
12+
from rasterio.warp import transform, transform_bounds
13+
14+
WGS84_CRS = CRS.from_epsg(4326)
1215

1316
def url(tile, imagery):
1417
"""Return a tile url provided an imagery template and a tile"""
@@ -49,8 +52,6 @@ def get_tile_tif(tile, imagery, folder, kwargs):
4952
imagery_offset = kwargs.get('imagery_offset') or [0, 0]
5053
with rasterio.open(imagery) as src:
5154
x_res, y_res = src.transform[0], src.transform[4]
52-
p1 = Proj({'init': 'epsg:4326'})
53-
p2 = Proj(**src.crs)
5455

5556
# offset our imagery in the "destination pixel" space
5657
offset_bound = dict()
@@ -63,8 +64,12 @@ def get_tile_tif(tile, imagery, folder, kwargs):
6364
offset_bound['south'] = bound.south + imagery_offset[1] * deg_per_pix_y
6465

6566
# project tile boundaries from lat/lng to source CRS
66-
tile_ul_proj = transform(p1, p2, offset_bound['west'], offset_bound['north'])
67-
tile_lr_proj = transform(p1, p2, offset_bound['east'], offset_bound['south'])
67+
x, y = transform(WGS84_CRS, src.crs, [offset_bound['west']], [offset_bound['north']])
68+
tile_ul_proj = x[0], y[0]
69+
70+
x, y = transform(WGS84_CRS, src.crs, [offset_bound['east']], [offset_bound['south']])
71+
tile_lr_proj = x[0], y[0]
72+
6873
# get origin point from the TIF
6974
tif_ul_proj = (src.bounds.left, src.bounds.top)
7075

@@ -106,16 +111,12 @@ def get_tile_wms(tile, imagery, folder, kwargs):
106111

107112
# find our tile bounding box
108113
bound = bounds(*[int(t) for t in tile.split('-')])
109-
p1 = Proj({'init': 'epsg:4326'})
110-
p2 = Proj({'init': wms_srs})
114+
xmin, ymin, xmax, ymax = transform_bounds(WGS84_CRS, CRS.from_string(wms_srs), *bound, densify_pts=21)
111115

112116
# project the tile bounding box from lat/lng to WMS SRS
113-
tile_ll_proj = transform(p1, p2, bound.west, bound.south)
114-
tile_ur_proj = transform(p1, p2, bound.east, bound.north)
115-
if wms_version == '1.3.0':
116-
bbox = tile_ll_proj[::-1] + tile_ur_proj[::-1]
117-
else:
118-
bbox = tile_ll_proj + tile_ur_proj
117+
bbox = (
118+
[ymin, xmin, ymax, xmax] if wms_version == "1.3.0" else [xmin, ymin, xmax, ymax]
119+
)
119120

120121
# request the image with the transformed bounding box and save
121122
wms_url = imagery.replace('{bbox}', ','.join([str(b) for b in bbox]))
@@ -136,7 +137,7 @@ def is_tif(imagery):
136137
valid_tif = False
137138
else:
138139
valid_tif = True
139-
except rasterio._err.CPLE_HttpResponseError: #pylint: disable=protected-access
140+
except rasterio.errors.RasterioIOError:
140141
# rasterio cannot open the path. this is the case for a
141142
# tile service
142143
valid_tif = False

requirements.txt

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
Cerberus==1.1
22
click==6.7
33
geojson==2.3.0
4-
homura==0.1.5
5-
humanize==0.5.1
64
mapbox-vector-tile==1.2.0
7-
mbutil==0.3.0
8-
mercantile==1.0.0
9-
numpy==1.13.3
10-
olefile==0.44
11-
Pillow==4.3.0
12-
protobuf==3.5.0.post1
13-
pyclipper==1.0.6
14-
pycurl==7.43.0.1
15-
pyproj==1.9.5.1
16-
rasterio[s3]==1.0a12
5+
mercantile>=1.0.3
6+
numpy>=1.18.4
7+
Pillow==7.1.2
8+
rasterio[s3]>=1.1
179
requests>=2.20.0
1810
Shapely>=1.6.3
19-
six==1.10.0
2011
tilepie==0.2.1
12+
tqdm>=4.46.0

setup.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

99
here = op.abspath(op.dirname(__file__))
1010

11+
extra_reqs = {
12+
"test": ["pytest", "pytest-cov"],
13+
"dev": ["pytest", "pytest-cov", "pre-commit"],
14+
}
15+
1116
# get the dependencies and installs
1217
with io.open(op.join(here, 'requirements.txt'), encoding='utf-8') as f:
13-
all_reqs = f.read().split('\n')
14-
15-
install_requires = [x.strip() for x in all_reqs if 'git+' not in x]
16-
dependency_links = [x.strip().replace('git+', '') for x in all_reqs if 'git+' not in x]
18+
install_requires = f.read().split('\n')
1719

1820
# readme
1921
with open('README.md') as f:
@@ -39,7 +41,7 @@
3941
packages=find_packages(exclude=['docs', 'tests*']),
4042
include_package_data=True,
4143
install_requires=install_requires,
42-
dependency_links=dependency_links,
44+
extras_require=extra_reqs,
4345
long_description=readme,
4446
long_description_content_type="text/markdown"
4547
)

test/integration/test_segmentation_labels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_cli(self):
3333
'62093-50164-17': 2400,
3434
'62094-50162-17': 21234,
3535
'62094-50164-17': 19146,
36-
'62094-50163-17': 21613,
36+
'62094-50163-17': 21611,
3737
'62093-50163-17': 31568
3838
}
3939

test/integration/test_segmentation_labels_sparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_cli(self):
3232
'62093-50164-17': 2400,
3333
'62094-50162-17': 21234,
3434
'62094-50164-17': 19146,
35-
'62094-50163-17': 21613,
35+
'62094-50163-17': 21611,
3636
'62093-50163-17': 31568
3737
}
3838

0 commit comments

Comments
 (0)