Skip to content

Commit

Permalink
Merge pull request #135 from developmentseed/default_download
Browse files Browse the repository at this point in the history
download zip if bands are not specified
  • Loading branch information
Scisco committed Dec 1, 2015
2 parents 49498a5 + 4cb9143 commit b44bfcf
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 20 deletions.
2 changes: 2 additions & 0 deletions docs/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ Commands

--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
Expand Down
2 changes: 1 addition & 1 deletion docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Download images by their custom sceneID, which you get from landsat search::

$: landsat download LC80090452014008LGN00

Download only band 4, 3 and 2 for a particular sceneID::
By default landsat-util downloads the full zip file from Google Storage unless you specify the bands or run an image processing right after download. For example to download only band 4, 3 and 2 for a particular sceneID run::

$: landsat download LC80090452014008LGN00 --bands 432

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.10b1'
__version__ = '0.10b2'
17 changes: 12 additions & 5 deletions landsat/landsat.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def args_options():
help="Provide Full sceneID, e.g. LC81660392014196LGN00")

parser_download.add_argument('-b', '--bands', help='If you specify bands, landsat-util will try to download '
'the band from S3. If the band does not exist, an error is returned', default='432')
'the band from S3. If the band does not exist, an error is returned', default='')
parser_download.add_argument('-d', '--dest', help='Destination path')
parser_download.add_argument('-p', '--process', help='Process the image after download', action='store_true')
parser_download.add_argument('--pansharpen', action='store_true',
Expand Down Expand Up @@ -362,15 +362,22 @@ def main(args):
d = Downloader(download_dir=args.dest)
try:
bands = convert_to_integer_list(args.bands)
if args.pansharpen:
bands.append(8)

if args.ndvi or args.ndvigrey:
bands = [4, 5]
if args.process:
if args.pansharpen:
bands.append(8)

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

if not args.bands:
bands = [4, 3, 2]

downloaded = d.download(args.scenes, bands)

if args.process:
if not args.bands:
args.bands = '432'
force_unzip = True if args.force_unzip else False
for scene, src in downloaded.iteritems():
if args.dest:
Expand Down
27 changes: 14 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def readme():
return f.read()

test_requirements = [
'nose>=1.3.7',
'mock>=1.3.0'
'nose>=1.3.7',
'mock>=1.3.0'
]

setup(
Expand All @@ -35,17 +35,18 @@ def readme():
license='CCO',
platforms='Posix; MacOS X; Windows',
install_requires=[
'requests==2.7.0',
'python-dateutil>=2.4.2',
'numpy>=1.9.3',
'termcolor>=1.1.0',
'rasterio>=0.26.0',
'six==1.9.0',
'scipy>=0.16.0',
'scikit-image>=0.11.3',
'homura>=0.1.2',
'boto>=2.38.0',
'polyline==1.1'
'requests==2.7.0',
'python-dateutil>=2.4.2',
'numpy>=1.9.3',
'termcolor>=1.1.0',
'rasterio>=0.26.0',
'six==1.9.0',
'scipy>=0.16.0',
'scikit-image>=0.11.3',
'homura>=0.1.2',
'boto>=2.38.0',
'polyline==1.1',
'geocoder>=1.5.1'
],
test_suite='nose.collector',
tests_require=test_requirements
Expand Down
23 changes: 23 additions & 0 deletions tests/test_landsat.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,29 @@ def test_download_correct(self, mock_downloader):
mock_downloader.return_value.download.assert_called_with(['LC80010092015051LGN00'], [11])
self.assertEquals(output, ['Download Completed', 0])

@mock.patch('landsat.landsat.Downloader')
def test_download_correct_zip(self, mock_downloader):
"""Download command should download zip if no bands are given"""
mock_downloader.download.return_value = True

args = ['download', 'LC80010092015051LGN00', '-d', self.mock_path]
output = landsat.main(self.parser.parse_args(args))
mock_downloader.assert_called_with(download_dir=self.mock_path)
mock_downloader.return_value.download.assert_called_with(['LC80010092015051LGN00'], [])
self.assertEquals(output, ['Download Completed', 0])

@mock.patch('landsat.landsat.process_image')
@mock.patch('landsat.landsat.Downloader.download')
def test_download_no_bands_with_process(self, mock_downloader, mock_process):
"""Download command should not download zip if no bands are given but process flag is used"""
mock_downloader.return_value = {'LC80010092015051LGN00': 'aws'}
mock_process.return_value = 'image.TIF'

args = ['download', 'LC80010092015051LGN00', '-p', '-d', self.mock_path]
output = landsat.main(self.parser.parse_args(args))
mock_downloader.assert_called_with(['LC80010092015051LGN00'], [4, 3, 2])
self.assertEquals(output, ["The output is stored at image.TIF", 0])

def test_download_incorrect(self):
"""Test download command with incorrect input"""
args = ['download', 'LT813600']
Expand Down

0 comments on commit b44bfcf

Please sign in to comment.