Skip to content

Commit

Permalink
Merge pull request #2 from developmentseed/master
Browse files Browse the repository at this point in the history
sync with original master
  • Loading branch information
wouellette authored May 17, 2019
2 parents c559fcf + 4b0f2ef commit 0d87e0d
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Label Maker
## Data Preparation for Satellite Machine Learning

The tool downloads [OpenStreetMap QA Tile]((https://osmlab.github.io/osm-qa-tiles/)) information and satellite imagery tiles and saves them as an [`.npz` file](https://docs.scipy.org/doc/numpy/reference/generated/numpy.savez.html) for use in machine learning training.
Label Maker downloads [OpenStreetMap QA Tile]((https://osmlab.github.io/osm-qa-tiles/)) information and satellite imagery tiles and saves them as an [`.npz` file](https://docs.scipy.org/doc/numpy/reference/generated/numpy.savez.html) for use in machine learning training.

![example classification image overlaid over satellite imagery](examples/images/classification.png)
_satellite imagery from [Mapbox](https://www.mapbox.com/) and [Digital Globe](https://www.digitalglobe.com/)_
Expand Down
17 changes: 12 additions & 5 deletions label_maker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,17 @@ def get_tile_wms(tile, imagery, folder, imagery_offset):
"""
Read a WMS endpoint with query parameters corresponding to a TMS tile
Converts the tile boundaries to the spatial reference system (SRS) specified
by the WMS query parameter.
Converts the tile boundaries to the spatial/coordinate reference system
(SRS or CRS) specified by the WMS query parameter.
"""
# retrieve the necessary parameters from the query string
query_dict = parse_qs(imagery.lower())
image_format = query_dict['format'][0].split('/')[1]
wms_srs = query_dict['srs'][0]
image_format = query_dict.get('format')[0].split('/')[1]
wms_version = query_dict.get('version')[0]
if wms_version == '1.3.0':
wms_srs = query_dict.get('crs')[0]
else:
wms_srs = query_dict.get('srs')[0]

# find our tile bounding box
bound = bounds(*[int(t) for t in tile.split('-')])
Expand All @@ -107,7 +111,10 @@ def get_tile_wms(tile, imagery, folder, imagery_offset):
# project the tile bounding box from lat/lng to WMS SRS
tile_ll_proj = transform(p1, p2, bound.west, bound.south)
tile_ur_proj = transform(p1, p2, bound.east, bound.north)
bbox = tile_ll_proj + tile_ur_proj
if wms_version == '1.3.0':
bbox = tile_ll_proj[::-1] + tile_ur_proj[::-1]
else:
bbox = tile_ll_proj + tile_ur_proj

# request the image with the transformed bounding box and save
wms_url = imagery.replace('{bbox}', ','.join([str(b) for b in bbox]))
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protobuf==3.5.0.post1
pyclipper==1.0.6
pycurl==7.43.0.1
pyproj==1.9.5.1
rasterio==1.0a12
rasterio[s3]==1.0a12
requests>=2.20.0
Shapely>=1.6.3
six==1.10.0
Expand Down
Binary file added test/fixtures/146-195-9.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed test/fixtures/4686-6267-14.jpeg
Binary file not shown.
Binary file removed test/tiles/1087767-1046604-21.jpg
Binary file not shown.
6 changes: 3 additions & 3 deletions test/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,16 @@ def test_get_tile_vrt(self):

def test_get_tile_wms(self):
"""Test reading of tile from a WMS endpoint"""
tile = '4686-6267-14'
tile = '146-195-9'
# create tiles directory
dest_folder = 'test'
tiles_dir = op.join(dest_folder, 'tiles')
if not op.isdir(tiles_dir):
makedirs(tiles_dir)

usgs_url = 'https://basemap.nationalmap.gov/arcgis/services/USGSImageryOnly/MapServer/WMSServer?SERVICE=WMS&REQUEST=GetMap&VERSION=1.1.1&LAYERS=0&STYLES=&FORMAT=image%2Fjpeg&TRANSPARENT=false&HEIGHT=256&WIDTH=256&SRS=EPSG%3A3857&BBOX={bbox}'
nasa_url = 'https://gibs.earthdata.nasa.gov/wms/epsg4326/best/wms.cgi?SERVICE=WMS&REQUEST=GetMap&layers=MODIS_Aqua_CorrectedReflectance_TrueColor&version=1.3.0&crs=EPSG:4326&transparent=false&width=256&height=256&bbox={bbox}&format=image/jpeg&time=2019-03-05'

get_tile_wms(tile, usgs_url, tiles_dir, None)
get_tile_wms(tile, nasa_url, tiles_dir, None)
test_tile = Image.open('test/tiles/{}.jpeg'.format(tile))
fixture_tile = Image.open('test/fixtures/{}.jpeg'.format(tile))
self.assertEqual(test_tile, fixture_tile)
Expand Down

0 comments on commit 0d87e0d

Please sign in to comment.