Module Index

downloader.py

class landsat.downloader.Downloader(verbose=False, download_dir=None)[source]

Bases: landsat.mixins.VerbosityMixin

The downloader class

amazon_s3(scene, band, path)[source]

Amazon S3 downloader

Parameters:
  • scene (String) – The scene ID.
  • band (String, Integer) – The band number.
  • path (String) – The directory path to where the image should be stored
Returns:

Boolean

amazon_s3_url(sat, filename)[source]

Return an amazon s3 url the contains the scene and band provided.

Parameters:
  • sat (dict) – Expects an object created by scene_interpreter method
  • filename (String) – The filename that has to be downloaded from Amazon
Returns:

(String) The URL to a S3 file

download(scenes, bands=None)[source]

Download scenese from Google Storage or Amazon S3 if bands are provided

Parameters:
  • scenes (List) – A list of scene IDs
  • bands – A list of bands. Default value is None.
Returns:

(List) includes downloaded scenes as key and source as value (aws or google)

fetch(url, path, filename)[source]

Downloads the given url.

Parameters:
  • url (String) – The url to be downloaded.
  • path (String) – The directory path to where the image should be stored
  • filename (String) – The filename that has to be downloaded
Returns:

Boolean

get_remote_file_size(url)[source]

Gets the filesize of a remote file.

Parameters:url (String) – The url that has to be checked.
Returns:int
google_storage(scene, path)[source]

Google Storage Downloader.

Parameters:
  • scene (String) – The scene id
  • path (String) – The directory path to where the image should be stored
Returns:

Boolean

google_storage_url(sat)[source]

Returns a google storage url the contains the scene provided.

Parameters:sat (dict) – Expects an object created by scene_interpreter method
Returns:(String) The URL to a google storage file
remote_file_exists(url)[source]

Checks whether the remote file exists.

Parameters:url (String) – The url that has to be checked.
Returns:True if remote file exists and False if it doesn’t exist.
scene_interpreter(scene)[source]

Conver sceneID to rows, paths and dates.

Parameters:scene (String) – The scene ID.
Returns:dict
Example output:
>>> anatomy = {
        'path': None,
        'row': None,
        'sat': None,
        'scene': scene
    }
exception landsat.downloader.IncorrectSceneId[source]

Bases: exceptions.Exception

Exception to be used when scene id is incorrect

exception landsat.downloader.RemoteFileDoesntExist[source]

Bases: exceptions.Exception

Exception to be used when the remote file does not exist

uploader.py

image.py

landsat.py

mixins.py

class landsat.mixins.VerbosityMixin[source]

Bases: object

Verbosity Mixin that generates beautiful stdout outputs.

exit(message)[source]

outputs an exit message and exits

Parameters:message (String) – The message to be outputed
Returns:void
output(value, normal=False, color=None, error=False, arrow=False, indent=None)[source]

Handles verbosity of this calls. if priority is set to 1, the value is printed

if class instance verbose is True, the value is printed

Parameters:
  • value (String) – a string representing the message to be printed
  • normal (String) – if set to true the message is always printed, otherwise it is only shown if verbosity is set
  • color – The color of the message, choices: ‘red’, ‘green’, ‘blue’
  • error (Boolean) – if set to true the message appears in red
  • arrow (Boolean) – if set to true an arrow appears before the message
  • indent (Boolean) – indents the message based on the number provided
Returns:

void

subprocess(argv)[source]

Execute subprocess commands with proper ouput. This is no longer used in landsat-util

Parameters:argv (List) – A list of subprocess arguments
Returns:void
verbose = False

search.py

class landsat.search.Search[source]

Bases: object

The search class

cloud_cover_prct_range_builder(min=0, max=100)[source]

Builds cloud cover percentage range query.

Parameters:
  • min (float) – float specifying the minimum percentage. Default is 0
  • max (float) – float specifying the maximum percentage. Default is 100
Returns:

String

date_range_builder(start='2013-02-11', end=None)[source]

Builds date range query.

Parameters:
  • start (String) – Date string. format: YYYY-MM-DD
  • end (String) – date string. format: YYYY-MM-DD
Returns:

String

lat_lon_builder(lat=0, lon=0)[source]

Builds lat and lon query.

Parameters:
  • lat (float) – The latitude. Default is 0
  • lon (float) – The The longitude. Default is 0
Returns:

String

query_builder(paths_rows=None, lat=None, lon=None, start_date=None, end_date=None, cloud_min=None, cloud_max=None)[source]

Builds the proper search syntax (query) for Landsat API.

Parameters:
  • paths_rows (String) – A string in this format: “003,003,004,004”. Must be in pairs and separated by comma.
  • lat (String, float, integer) – The latitude
  • lon (String, float, integer) – The The longitude
  • start_date (String) – Date string. format: YYYY-MM-DD
  • end_date (String) – date string. format: YYYY-MM-DD
  • cloud_min (float) – float specifying the minimum percentage. e.g. 4.3
  • cloud_max (float) – float specifying the maximum percentage. e.g. 78.9
Returns:

String

row_path_builder(path='', row='')[source]

Builds row and path query.

Parameters:
  • path (String) – Landsat path. Must be three digits
  • row (String) – Landsat row. Must be three digits
Returns:

String

search(paths_rows=None, lat=None, lon=None, start_date=None, end_date=None, cloud_min=None, cloud_max=None, limit=1)[source]

The main method of Search class. It searches Development Seed’s Landsat API.

Parameters:
  • paths_rows (String) – A string in this format: “003,003,004,004”. Must be in pairs and separated by comma.
  • lat (String, float, integer) – The latitude
  • lon (String, float, integer) – The The longitude
  • start_date (String) – Date string. format: YYYY-MM-DD
  • end_date (String) – date string. format: YYYY-MM-DD
  • cloud_min (float) – float specifying the minimum percentage. e.g. 4.3
  • cloud_max (float) – float specifying the maximum percentage. e.g. 78.9
  • limit (integer) – integer specigying the maximum results return.
Returns:

dict

Example:
>>> search = Search()
>>> search('003,003', '2014-01-01', '2014-06-01')
>>> {
        'status': u'SUCCESS',
        'total_returned': 1,
        'total': 1,
        'limit': 1
        'results': [
            {
                'sat_type': u'L8',
                'sceneID': u'LC80030032014142LGN00',
                'date': u'2014-05-22',
                'path': u'003',
                'thumbnail': u'http://....../landsat_8/2014/003/003/LC80030032014142LGN00.jpg',
                'cloud': 33.36,
                'row': u'003
            }
        ]
    }

utils.py

class landsat.utils.Capturing[source]

Bases: list

Captures a subprocess stdout.

Usage:
>>> with Capturing():
...     subprocess(args)
landsat.utils.check_create_folder(folder_path)[source]

Check whether a folder exists, if not the folder is created.

Parameters:folder_path (String) – Path to the folder
Returns:(String) the path to the folder
landsat.utils.convert_to_integer_list(value)[source]

Converts a comma separate string to a list

Parameters:

value (String) – the format must be 003,003,004,004 (commas with no space)

Returns:

List

Example:
>>> convert_to_integer_list('003,003,004,004')
['003', '003', '004', '004']
landsat.utils.create_paired_list(value)[source]

Create a list of paired items from a string.

Parameters:

value (String) – the format must be 003,003,004,004 (commas with no space)

Returns:

List

Example:
>>> create_paired_list('003,003,004,004')
[['003','003'], ['004', '004']]
landsat.utils.exit(message, code=0)[source]

output a message to stdout and terminates the process.

Parameters:
  • message (String) – Message to be outputed.
  • code (int) – The termination code. Default is 0
Returns:

void

landsat.utils.georgian_day(date)[source]

Returns the number of days passed since the start of the year.

Parameters:

date (String) – The string date with this format %m/%d/%Y

Returns:

int

Example:
>>> georgian_day('05/1/2015')
121
landsat.utils.get_file(path)[source]

Separate the name of the file or folder from the path and return it.

Parameters:

path (String) – Path to the folder

Returns:

(String) the filename

Example:
>>> get_file('/path/to/file.jpg')
'file.jpg'
landsat.utils.get_filename(path)[source]

Return the filename without extension.

Parameters:

path (String) – Path to the folder

Returns:

(String) the filename without extension

Example:
>>> get_filename('/path/to/file.jpg')
'file'
landsat.utils.reformat_date(date, new_fmt='%Y-%m-%d')[source]

Returns reformated date.

Parameters:
  • date (String) – The string date with this format %m/%d/%Y
  • new_fmt – date format string. Default is ‘%Y-%m-%d’
Returns:

int

Example:
>>> reformat_date('05/1/2015', '%d/%m/%Y')
'1/05/2015'
landsat.utils.three_digit(number)[source]

Add 0s to inputs that their length is less than 3.

Parameters:

number (int) – The number to convert

Returns:

String

Example:
>>> three_digit(1)
'001'
class landsat.utils.timer[source]

Bases: object

A timer class.

Usage:
>>> with timer():
...     your code
landsat.utils.year(date)[source]

Returns the year.

Parameters:

date (String) – The string date with this format %m/%d/%Y

Returns:

int

Example:
>>> year('05/1/2015')
2015