Skip to content

Commit

Permalink
Merge pull request #134 from developmentseed/hotfix
Browse files Browse the repository at this point in the history
fixes #127
  • Loading branch information
Scisco committed Dec 1, 2015
2 parents e36e99d + 1333af2 commit 49498a5
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 23 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ deploy:
secure: WtawFW/999XYszmZfj1Qk82l00OSyP2JBVOOGCERrW1gVO7MYtYsgP31HKRSzNTCTHJNVDpdK4WZWY6zPQqC3l2UfWYYsvRn0hCoI8AJxE5VCUEg6Ccpe6fMJuhp1pq6Zy7yrfBSZcOB9aqSHLBJsunD2o3mNlTC8WV8vNK74ck=
on:
repo: developmentseed/landsat-util
branch: master
branch:
- master
- develop

after_deploy:
if [ "$TRAVIS_BRANCH" == "master" ]; then
Expand Down
2 changes: 1 addition & 1 deletion landsat/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.9.1'
__version__ = '0.10b1'
25 changes: 16 additions & 9 deletions landsat/landsat.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
Commands:
Search:
landsat.py search [-p --pathrow] [--lat] [--lon] [--address] [-l LIMIT] [-s START] [-e END] [-c CLOUD] [-h]
landsat.py search [-p --pathrow] [--lat] [--lon] [--address] [-l LIMIT] [-s START] [-e END] [-c CLOUD]
[-h]
optional arguments:
-p, --pathrow Paths and Rows in order separated by comma. Use quotes "001,003".
Expand Down Expand Up @@ -86,9 +87,12 @@
--ndvi Calculates NDVI and produce a RGB GTiff with seperate colorbar.
--ndvigrey Calculates NDVI and produce a greyscale GTiff.
--clip Clip the image with the bounding box provided. Values must be in WGS84 datum,
and with longitude and latitude units of decimal degrees separated by comma.
Example: --clip -346.06658935546875,49.93531194616915,-345.4595947265625,50.2682767372753
Example: --clip -346.06658935546875,49.93531194616915,-345.4595947265625,
50.2682767372753
-u --upload Upload to S3 after the image processing completed
Expand Down Expand Up @@ -124,7 +128,8 @@
--clip Clip the image with the bounding box provided. Values must be in WGS84 datum,
and with longitude and latitude units of decimal degrees separated by comma.
Example: --clip -346.06658935546875,49.93531194616915,-345.4595947265625,50.2682767372753
Example: --clip -346.06658935546875,49.93531194616915,-345.4595947265625,
50.2682767372753
-v, --verbose Show verbose output
Expand Down Expand Up @@ -205,6 +210,7 @@ def args_options():
'image. Pansharpening requires larger memory')
parser_download.add_argument('--ndvi', action='store_true',
help='Whether to run the NDVI process. If used, bands parameter is disregarded')
parser_download.add_argument('--ndvigrey', action='store_true', help='Create an NDVI map in grayscale (grey)')
parser_download.add_argument('--clip', help='Clip the image with the bounding box provided. Values must be in ' +
'WGS84 datum, and with longitude and latitude units of decimal degrees ' +
'separated by comma.' +
Expand Down Expand Up @@ -297,7 +303,7 @@ def main(args):
if args.latest > 0:
args.limit = 25
end = datetime.now()
start = end-relativedelta(days=+365)
start = end - relativedelta(days=+365)
args.end = end.strftime("%Y-%m-%d")
args.start = start.strftime("%Y-%m-%d")
except (TypeError, ValueError):
Expand Down Expand Up @@ -359,7 +365,7 @@ def main(args):
if args.pansharpen:
bands.append(8)

if args.ndvi:
if args.ndvi or args.ndvigrey:
bands = [4, 5]

downloaded = d.download(args.scenes, bands)
Expand All @@ -377,7 +383,7 @@ def main(args):
path = path + '.tar.bz'

stored = process_image(path, args.bands, False, args.pansharpen, args.ndvi, force_unzip,
bounds=bounds)
args.ndvigrey, bounds=bounds)

if args.upload:
try:
Expand Down Expand Up @@ -446,9 +452,10 @@ def __main__():
global parser
parser = args_options()
args = parser.parse_args()
if args.json:
print main(args)
sys.exit(0)
if args.subs == 'search':
if args.json:
print main(args)
sys.exit(0)
else:
with timer():
exit(*main(args))
Expand Down
4 changes: 1 addition & 3 deletions landsat/ndvi.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ def write_band(self, output_band, output_file, image_data):

output.write_band(1, output_band)

cmap = {k: v[:3] for k, v in self.cmap.iteritems()}
output.write_colormap(1, cmap)
self.output("Writing to file", normal=True, color='green', indent=1)
return output_file

Expand Down Expand Up @@ -123,7 +121,7 @@ def write_band(self, output_band, output_file, image_data):
crs=self.dst_crs) as output:

for i in range(3):
output.write_band(i+1, rgb_bands[i])
output.write_band(i + 1, rgb_bands[i])

self.output("Writing to file", normal=True, color='green', indent=1)
return output_file
23 changes: 16 additions & 7 deletions tests/test_landsat.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_download_process_continuous(self, mock_downloader, mock_process):
output = landsat.main(self.parser.parse_args(args))
mock_downloader.assert_called_with(['LC80010092015051LGN00', 'LC80010092014051LGN00'], [4, 3, 2])
mock_process.assert_called_with('path/to/folder/LC80010092014051LGN00', '432',
False, False, False, False, bounds=None)
False, False, False, False, False, bounds=None)
self.assertEquals(output, ["The output is stored at image.TIF", 0])

# Call with force unzip flag
Expand All @@ -116,7 +116,7 @@ def test_download_process_continuous(self, mock_downloader, mock_process):
output = landsat.main(self.parser.parse_args(args))
mock_downloader.assert_called_with(['LC80010092015051LGN00', 'LC80010092014051LGN00'], [4, 3, 2])
mock_process.assert_called_with('path/to/folder/LC80010092014051LGN00', '432', False, False, False,
True, bounds=None)
True, False, bounds=None)
self.assertEquals(output, ["The output is stored at image.TIF", 0])

# Call with pansharpen
Expand All @@ -125,7 +125,7 @@ def test_download_process_continuous(self, mock_downloader, mock_process):
output = landsat.main(self.parser.parse_args(args))
mock_downloader.assert_called_with(['LC80010092015051LGN00', 'LC80010092014051LGN00'], [4, 3, 2, 8])
mock_process.assert_called_with('path/to/folder/LC80010092014051LGN00', '432', False, True, False,
False, bounds=None)
False, False, bounds=None)
self.assertEquals(output, ["The output is stored at image.TIF", 0])

# Call with pansharpen and clipping
Expand All @@ -134,7 +134,7 @@ def test_download_process_continuous(self, mock_downloader, mock_process):
output = landsat.main(self.parser.parse_args(args))
mock_downloader.assert_called_with(['LC80010092015051LGN00', 'LC80010092014051LGN00'], [4, 3, 2, 8])
mock_process.assert_called_with('path/to/folder/LC80010092014051LGN00', '432', False, True, False,
False, bounds=[-180.0, -180.0, 0.0, 0.0])
False, False, bounds=[-180.0, -180.0, 0.0, 0.0])
self.assertEquals(output, ["The output is stored at image.TIF", 0])

# Call with ndvi
Expand All @@ -143,7 +143,16 @@ def test_download_process_continuous(self, mock_downloader, mock_process):
output = landsat.main(self.parser.parse_args(args))
mock_downloader.assert_called_with(['LC80010092015051LGN00', 'LC80010092014051LGN00'], [4, 5])
mock_process.assert_called_with('path/to/folder/LC80010092014051LGN00', '432', False, False, True,
False, bounds=None)
False, False, bounds=None)
self.assertEquals(output, ["The output is stored at image.TIF", 0])

# Call with ndvigrey
args = ['download', 'LC80010092015051LGN00', 'LC80010092014051LGN00', '-b', '432', '-d',
self.mock_path, '-p', '--ndvigrey']
output = landsat.main(self.parser.parse_args(args))
mock_downloader.assert_called_with(['LC80010092015051LGN00', 'LC80010092014051LGN00'], [4, 5])
mock_process.assert_called_with('path/to/folder/LC80010092014051LGN00', '432', False, False, False,
False, True, bounds=None)
self.assertEquals(output, ["The output is stored at image.TIF", 0])

@mock.patch('landsat.landsat.Uploader')
Expand All @@ -160,7 +169,7 @@ def test_download_process_continuous_with_upload(self, mock_downloader, mock_pro
output = landsat.main(self.parser.parse_args(args))
mock_downloader.assert_called_with(['LC80010092015051LGN00'], [4, 3, 2])
mock_process.assert_called_with('path/to/folder/LC80010092015051LGN00', '432', False, False, False,
False, bounds=None)
False, False, bounds=None)
mock_upload.assert_called_with('somekey', 'somesecret', 'this')
mock_upload.return_value.run.assert_called_with('mybucket', 'image.TIF', 'image.TIF')
self.assertEquals(output, ['The output is stored at image.TIF', 0])
Expand All @@ -177,7 +186,7 @@ def test_download_process_continuous_with_wrong_args(self, mock_downloader, mock
output = landsat.main(self.parser.parse_args(args))
mock_downloader.assert_called_with(['LC80010092015051LGN00'], [4, 3, 2])
mock_process.assert_called_with('path/to/folder/LC80010092015051LGN00', '432', False, False, False,
False, bounds=None)
False, False, bounds=None)
self.assertEquals(output, ['Could not authenticate with AWS', 1])

@mock.patch('landsat.landsat.process_image')
Expand Down
8 changes: 6 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,13 @@ def test_convert_to_integer_list(self):
self.assertEqual([1, 11, 10, 'QA'], r)

def test_geocode(self):
self.assertEqual({'lat': 38.89767579999999, 'lon': -77.0364823}, utils.geocode('1600 Pennsylvania Ave NW, Washington, DC 20500'))
loc = utils.geocode('1600 Pennsylvania Ave NW, Washington, DC 20500')

self.assertEqual(round(loc['lat'], 3), 38.898)
self.assertEqual(round(loc['lon'], 3), -77.037)
self.assertRaises(ValueError, utils.geocode, 'Pennsylvania Ave NW, Washington, DC')
self.assertEqual({'lat': 38.8987352, 'lon': -77.0350902}, utils.geocode('Pennsylvania Ave NW, Washington, DC', 10.))
self.assertEqual({'lat': 38.8987352, 'lon': -77.0350902},
utils.geocode('Pennsylvania Ave NW, Washington, DC', 10.))

def test_convert_to_float_list(self):
# correct input
Expand Down

0 comments on commit 49498a5

Please sign in to comment.