geextract API

geextract

geextract.date_append(dl)[source]

Add time key to each element of a list of dictionaries

Parameters:dl (list) – List of dictionaries, each dictionary should at least contain the key ‘id’ in which a classic Landsat scene ID parsable by get_date is stored.
Returns:A list of dictionaries
Return type:list
geextract.dictify(x)[source]
Build a list of dictionaries from a list of lists as returned by running
getRegion on an Image collection
Parameters:x (list) – A list of list. First list element contain the keys while following list elements contain values.
Returns:A list of dictionaries
Return type:list

Examples

>>> l = [[u'id', u'B1', u'B2', u'B3', u'B7'],
...      [u'LC81970292013106', 649, 683, 910, 1365],
...      [u'LC81970292013122', 140, 191, 521, 965]]
>>> dictify(l)
geextract.dictlist2sqlite(dl, site, sensor, db_src, table)[source]

Write a list of dictionaries to a sqlite database

Parameters:
  • dl (list) – List of dictionaries
  • db_src (str) – Path an sqlite database (created in case it does not exist)
  • table (str) – Name of database table to write data
Returns:

This function is used for its side effect of writing data to a database;

it does not return anything

geextract.get_date(filename)[source]

Retriev date information from typical Landsat filenames

Parameters:filename (str) – Landsat file name
Returns:The corresponding date of the filename.
Return type:datetime.date

Examples

>>> import geextract
>>> geextract.get_date('LC81970292013106')
geextract.relabel(dl, sensor)[source]

Rename the keys of each element of a list of dictionaries

Parameters:
  • dl (list) – List of dictionaries
  • sensor (str) – Landsat sensor to which belong the data. Must be one of ‘LT4’, ‘LT5’, ‘LE7’ or ‘LC8’
Returns:

A list of dictionaries

Return type:

list

geextract.simplify(fc)[source]
Take a feature collection, as returned by mapping a reducer to a ImageCollection,
and reshape it into a simpler list of dictionaries
Parameters:fc (dict) – Dictionary representation of a feature collection, as returned by mapping a reducer to an ImageCollection
Returns:A list of dictionaries.
Return type:list

Examples

>>> fc = {u'columns': {},
...       u'features': [{u'geometry': None,
...                      u'id': u'LC81970292013106',
...                      u'properties': {u'B1': 651.8054424353023,
...                                      u'B2': 676.6018246419446},
...                      u'type': u'Feature'},
...                     {u'geometry': None,
...                      u'id': u'LC81970292013122',
...                      u'properties': {u'B1': 176.99323997958842,
...                                      u'B2': 235.83196553144882},
...                      u'type': u'Feature'}]}
>>> simplify(fc)
geextract.ts_extract(sensor, start, tiers=['T1', 'T2'], lon=None, lat=None, end=datetime.datetime(2018, 10, 30, 18, 9, 7, 245060), radius=None, feature=None, bands=None, stats='mean')[source]
Perform a spatio temporal query to extract Landsat surface reflectance data
from gee
Parameters:
  • lon (float) – Center longitude in decimal degree
  • lat (float) – Center latitude in decimal degree
  • sensor (str) – Landsat sensor to query data from. Must be one of ‘LT4’, ‘LT5’, ‘LE7’, ‘LC8’
  • tiers (list) – List of tiers to order. 'T1' corresponds to tiers 1. Default is ['T1', 'T2']
  • start (datetime.datetime) – Start date
  • end (datetime.datetime) – Optional end date; automatically set as today if unset
  • radius (float) – Optional radius around center point in meters. If unset, time-series of a single pixel are queried. Otherwise a reducer is used to spatially aggregate the pixels intersecting the circular feature built.
  • feature (dict) – Optional dictionary representation of a polygon feature in longlat CRS. If unset, time-series of a single pixel are queried. Otherwise a reducer is used to spatially aggregate the pixels intersecting the given feature.
  • bands (list) – List of Landsat band names. Optional, defaults to [‘B1’, ‘B2’, ‘B3’, ‘B4’, ‘B5’, ‘B7’] in the case of LC8 sensor and to [‘B1’, ‘B2’, ‘B3’, ‘B4’, ‘B5’, ‘B7’] otherwise.
  • stats (str) – Spatial aggregation function to use. Only relevant if a radius value is set.
Returns:

A dictionary representation of the json data returned by the gee platform.

Return type:

dict

Example

>>> import geextract
>>> from pprint import pprint
>>> from datetime import datetime
>>> lon = -89.8107197
>>> lat = 20.4159611
>>> out = geextract.ts_extract(lon=lon, lat=lat, sensor='LE7', start=datetime(1980, 1, 1, 0, 0),
>>>                            radius=500)
>>> pprint(out)