chart module

This module relies on pygal library, so the returned charts are instances of pygal.chart. See options at pygal site

I made a JavaScript 'equivalent': https://code.earthengine.google.com/b2922b860b85c1120250794fb82dfda8


In [1]:
import ee

In [2]:
from geetools import ui

In [3]:
test_site = ee.Geometry.Point([-71, -42])

In [4]:
test_feat = ee.Feature(test_site, {'name': 'test feature'})

In [5]:
test_featcol = ee.FeatureCollection([
    test_feat, 
    test_feat.buffer(100).set('name', 'buffer 100'),
    test_feat.buffer(1000).set('name', 'buffer 1000')
])

Time Series


In [6]:
years = ee.List([2015, 2016, 2017, 2018])

In [7]:
col = ee.ImageCollection('COPERNICUS/S2').filterBounds(test_site)

In [8]:
def make_time_series(year):
    ''' make a time series from year's list '''
    eefilter = ee.Filter.calendarRange(year, field='year')
    filtered = col.filter(eefilter)
    return filtered.mean().set('system:time_start', ee.Date.fromYMD(year, 1, 1).millis())

In [9]:
time_series = ee.ImageCollection(years.map(make_time_series))

Chart series


In [10]:
chart_ts = ui.chart.Image.series(**{
    'imageCollection': time_series, 
    'region': test_site,
    'scale': 10,
    'bands': ['B1', 'B2', 'B3'],
    # 'xProperty': 'B4', # You can use a band too!
    'labels': ['band B1', 'B2 band', 'this is B3']
})

In [11]:
chart_ts.render_widget(width='50%')


Chart seriesByRegion


In [12]:
chart_ts_region = ui.chart.Image.seriesByRegion(**{
    'imageCollection': time_series,
    'reducer': ee.Reducer.median(),
    'regions': test_featcol,
    'scale': 10,
    'band': 'B11',
    'seriesProperty': 'name'
})

In [13]:
chart_ts_region.render_widget(height=500)



In [ ]: