Code Monkey home page Code Monkey logo

geebap's Introduction

Best Available Pixel (Bap) Composite using the Python API of Google Earth Engine (Gee)

This code is based on Pixel-Based Image Compositing for Large-Area Dense Time Series Applications and Science. (White et al., 2014) http://www.tandfonline.com/doi/full/10.1080/07038992.2014.945827

It uses a series of pixel based scores to generate a composite with the Best Available Pixel, assuming it is the one that has better score.

License and Copyright

2017 Rodrigo E. Principe - geebap - https://github.com/fitoprincipe/geebap

This work thanks to: "Dirección de Bosques - SAyDS" (Argentine Nation) and CIEFAP (Centro de Investigación y Extensión Forestal Andino Patagónico)

Contact

Rodrigo E. Principe: [email protected]

Installation

To use this package you must have installed and running Google Earth Engine Python API: https://developers.google.com/earth-engine/python_install

Once you have that, proceed

pip install geebap

this will install also geetools that you could use besides geebap

Installation in DataLab

After following Option 1 or 2 in https://developers.google.com/earth-engine/python_install, open a new notebook and write:

import sys
!{sys.executable} -m pip install geebap

Available Collections

Collections come from geetools.collection. For examples see: https://github.com/gee-community/gee_tools/tree/master/notebooks/collection

Available Scores

  • Satellite
  • Distance to clouds and shadows masks
  • Atmospheric Opacity
  • Day of the year (best_doy)
  • Masked pixels percentage
  • Outliers
  • Absolute value of a vegetation index

Available Indices

  • ndvi
  • evi
  • nbr

Some considerations

  • Sites size should not be too big. Works with 300 km2 tiles

Basic Usage

If you are using Jupyter, you can download a notebook from https://github.com/fitoprincipe/geebap/blob/master/Best_Available_Pixel_Composite.ipynb

else, if you are using another approach, like Spyder, create an empty script and paste the following code:

import ee
ee.Initialize()

import geebap
from geetools import tools

import pprint
pp = pprint.PrettyPrinter(indent=2)

# SEASON
a_season = geebap.Season('11-15', '03-15')

# MASKS
cld_mask = geebap.masks.Mask()

# Combine masks in a tuple
masks = (cld_mask,)

# FILTERS
filt_cld = geebap.filters.CloudCover()
# filt_mask = geebap.filters.MaskCover() # Doesn't work

# Combine filters in a tuple
filters = (filt_cld,)#, filt_mask)

# SCORES
best_doy = geebap.scores.Doy('01-15', a_season)
sat = geebap.scores.Satellite()
out = geebap.scores.Outliers(("ndvi",))
ind = geebap.scores.Index("ndvi")
maskpercent = geebap.scores.MaskPercentKernel()
dist = geebap.scores.CloudDist()

# Combine scores in a tuple
scores = (
    best_doy,
    sat,
    out,
    ind,
    maskpercent,
    dist
)

# BAP OBJECT
BAP = geebap.Bap(range=(0, 0),
                 season=a_season,
                 masks=masks,
                 scores=scores,
                 filters=filters)

# SITE
site = ee.Geometry.Polygon([[-71.5,-42.5],
                            [-71.5,-43],
                            [-72,-43],
                            [-72,-42.5]])

# COMPOSITE
composite = BAP.build_composite_best(2019, site=site, indices=("ndvi",))

# `composite` is a ee.Image object, so you can do anything
# from here..
one_value = tools.image.getValue(composite,
                                 site.centroid(),
                                 30, 'client')
pp.pprint(one_value)

Prints:

{ 'blue': 733,
  'col_id': 29,
  'date': 20190201,
  'green': 552,
  'ndvi': 0.7752976417541504,
  'nir': 2524,
  'red': 313,
  'score': 5.351020336151123,
  'swir': 661,
  'swir2': 244,
  'thermal': 2883}

geebap's People

Contributors

fitoprincipe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

geebap's Issues

A question

when i import all the library in the sample code, errors occur as following:

AttributeError Traceback (most recent call last)
in ()
----> 1 from geebap import bap, season, filters, masks, scores, satcol, functions
2 from geetools import tools
3
4 import pprint
5 pp = pprint.PrettyPrinter(indent=2)

f:\Anaconda3\envs\GEE\lib\site-packages\geebap\bap.py in ()
10 if not ee.data._initialized: ee.Initialize()
11
---> 12 import satcol
13 import season as temp
14 import functions

f:\Anaconda3\envs\GEE\lib\site-packages\geebap\satcol.py in ()
901
902
--> 903 GROUPS = {'Landsat': [col.ID for col in ColGroup.Landsat().collections],
904 'MSS': [col.ID for col in ColGroup.MSS().collections],
905 'Landsat_Sentinel': [col.ID for col in ColGroup.Landsat_Sentinel().collections],

f:\Anaconda3\envs\GEE\lib\site-packages\geebap\satcol.py in Landsat(cls)
827 Collection.Landsat2(),
828 Collection.Landsat3(),
--> 829 Collection.Landsat4TOA(),
830 Collection.Landsat4USGS(),
831 Collection.Landsat5TOA(),

f:\Anaconda3\envs\GEE\lib\site-packages\geebap\satcol.py in Landsat4TOA(cls)
428
429 obj.clouds_band = "BQA"
--> 430 obj.fclouds = cld.landsatTOA()
431 # obj.ID = "LANDSAT/LT4_L1T_TOA_FMASK"
432 obj.ID = IDS[obj.short]

AttributeError: 'module' object has no attribute 'landsatTOA'

Install error

Hellow,

When I tried to run ,I have returned the following error:

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-EMcAa9/geetools/

Can you help me?

Example code does not work

The sample code does not work. This is the code:

`rom geebap import bap, season, filters, masks,
scores, satcol, functions
from geetools import tools

import ee
ee.Initialize()

COLLECTION

col_group = satcol.ColGroup.Landsat()

SEASON

a_season = season.Season.Growing_South()

MASKS

cld_mask = masks.Clouds()
equiv_mask = masks.Equivalent()

Combine masks in a tuple

masks = (cld_mask, equiv_mask)

FILTERS

filt_cld = filters.CloudsPercent()
filt_mask = filters.MaskPercent()

Combine filters in a tuple

filters = (filt_cld, filt_mask)

SCORES

doy = scores.Doy()
sat = scores.Satellite()
op = scores.AtmosOpacity()
out = scores.Outliers(("ndvi",))
ind = scores.Index("ndvi")
mascpor = scores.MaskPercent()
dist = scores.CloudDist()

Combine scores in a tuple

scores = (doy, sat, op, out, ind, mascpor, dist)

BAP OBJECT

bap = bap.Bap(year=2010, range=(0, 0),
season=a_season,
colgroup=col_group,
masks=masks,
scores=scores,
filters=filters)

SITE

site = ee.Geometry.Polygon([[-71,-42],
[-71,-43],
[-72,-43],
[-72,-42]])

COMPOSITE

composite = bap.bestpixel(site=site,
indices=("ndvi",))

The result (composite) is a namedtuple, so

image = composite.image

image is a ee.Image object, so you can do anything

from here..

one_value = tools.get_value(image,
site.centroid(),
30, 'client')

print(one_value)

See below for the debug output:

scores: ['score-doy', 'score-sat', 'score-atm-op', 'score-outlier', 'score-inde
', 'score-maskper', 'score-cld-dist']

Satellite: LEDAPS/LT5_L1T_SR
ini: 2009-11-15 ,end: 2010-03-15
size after filters: 15
** score-doy **
** score-sat **
** score-atm-op **
** score-outlier **
1.2.3.4.5.6.7.8.9.10.** score-index **
** score-maskper **
1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.3
.** score-cld-dist **
1.2.3.4.5.6.7.8.9.10.
Satellite: LANDSAT/LT5_SR
ini: 2009-11-15 ,end: 2010-03-15
size after filters: 0

Satellite: LANDSAT/LE7_SR
ini: 2009-11-15 ,end: 2010-03-15
size after filters: 0

Satellite: LEDAPS/LE7_L1T_SR
ini: 2009-11-15 ,end: 2010-03-15
size after filters: 29
** score-doy **
** score-sat **
** score-atm-op **
** score-outlier **
1.2.3.4.5.6.7.8.9.10.** score-index **
** score-maskper **
1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.3
.** score-cld-dist **
1.2.3.4.5.6.7.8.9.10.final collection size: 0
Traceback (most recent call last):
File "", line 3, in
File "C:\Users\geogz\AppData\Local\Continuum\Anaconda2\lib\site-packages\geeb
p\bap.py", line 474, in bestpixel
imgCol = colbap.col
AttributeError: 'NoneType' object has no attribute 'col'

The result (composite) is a namedtuple, so

... image = composite.image
Traceback (most recent call last):
File "", line 2, in
NameError: name 'composite' is not defined

image is a ee.Image object, so you can do anything

... # from here..
...

one_value = tools.get_value(image,
... site.centroid(),
... 30, 'client')
Traceback (most recent call last):
File "", line 1, in
NameError: name 'tools' is not defined

print(one_value)

It seems the final collection after filtering is 0 and the bap.py does not check if there is at least one image?

Updated version available?

Hi there,

I was just wondering if you had an updated version of the code anywhere?
Thanks a lot for the great work!

S

Problem upon import

Hi Rodrigo,

Thanks for the updates. I have updated to 0.2.2, Conda 3.6 and I get this error during import. Any idea why?

Thanks a lot

S

>>> from geebap import bap
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/sebastien/anaconda3/envs/ee/lib/python3.6/site-packages/geebap/__init__.py", line 24, in <module>
    from . import bap, date, expgen, expressions, filters, functions,\
  File "/Users/sebastien/anaconda3/envs/ee/lib/python3.6/site-packages/geebap/bap.py", line 5, in <module>
    from . import scores, priority, functions, utils, __version__
  File "/Users/sebastien/anaconda3/envs/ee/lib/python3.6/site-packages/geebap/scores.py", line 33, in <module>
    from . import priority
  File "/Users/sebastien/anaconda3/envs/ee/lib/python3.6/site-packages/geebap/priority.py", line 23, in <module>
    class SeasonPriority(object):
  File "/Users/sebastien/anaconda3/envs/ee/lib/python3.6/site-packages/geebap/priority.py", line 55, in SeasonPriority
    ee_relation = ee.Dictionary(relation)
  File "/Users/sebastien/anaconda3/envs/ee/lib/python3.6/site-packages/ee/computedobject.py", line 32, in __call__
    return type.__call__(cls, *args, **kwargs)
  File "/Users/sebastien/anaconda3/envs/ee/lib/python3.6/site-packages/ee/dictionary.py", line 27, in __init__
    self.initialize()
  File "/Users/sebastien/anaconda3/envs/ee/lib/python3.6/site-packages/ee/dictionary.py", line 48, in initialize
    apifunction.ApiFunction.importApi(cls, 'Dictionary', 'Dictionary')
  File "/Users/sebastien/anaconda3/envs/ee/lib/python3.6/site-packages/ee/apifunction.py", line 180, in importApi
    cls.initialize()
  File "/Users/sebastien/anaconda3/envs/ee/lib/python3.6/site-packages/ee/apifunction.py", line 151, in initialize
    signatures = data.getAlgorithms()
  File "/Users/sebastien/anaconda3/envs/ee/lib/python3.6/site-packages/ee/data.py", line 426, in getAlgorithms
    return send_('/algorithms', {}, 'GET')
  File "/Users/sebastien/anaconda3/envs/ee/lib/python3.6/site-packages/ee/data.py", line 838, in send_
    response.status)
ee.ee_exception.EEException: Server returned HTTP code: 404

overwriting module name in example notebook

@fitoprincipe - super cool tool. I've just started playing around with it. One thing you might want to consider changing is this line in your Best_Available_Pixel_Composite,ipynb script:

bap = bap.Bap(year=2000, range=(0, 0),
          season=a_season,
          masks=(cld_mask,),
          scores=(doy, sat, atm_op, dist, out, maskper, ind),
          filters=(filt_cld, filt_mask))

If a user steps through the code sequentially, but then comes back and changes reruns this block, the variable name bap has now clobbered the module name. Minor annoyance, but might trip up some people. Thanks for your work on this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.