Working With Time Series
In this example notebook, we’ll introduce the TimeSeries
class, which is the basis of most of the functionality in wxee
. Any ImageCollection
can be turned into a TimeSeries
, allowing you to access additional time series-specific methods and properties.
Setup
[ ]:
!pip install wxee
[1]:
import ee
import wxee
[2]:
ee.Authenticate()
wxee.Initialize()
Creating a Time Series
There are two ways to create a TimeSeries
.
From an ID
You can create a TimeSeries
the same way you create an ImageCollection
, by using an ID from the Earth Engine catalog. Let’s create a TimeSeries
from the Sentinel-2 dataset.
[3]:
ts = wxee.TimeSeries("COPERNICUS/S2_SR")
From an Existing Collection
You can also turn an existing ImageCollection
into a TimeSeries
, which may be helpful if you decide you want time series functionality after doing other processing. Just use the wx
accessor and the to_time_series
method.
[4]:
col = ee.ImageCollection("COPERNICUS/S2_SR")
ts = col.wx.to_time_series()
Earth Engine Methods
A TimeSeries
has all the methods of an Earth Engine ImageCollection
. For example, we can use filterMetadata
, filterBounds
, and size
to see how many cloudless (or at least mostly cloudless) images there are over a given location (Svalbard, Norway).
[5]:
svalbard = ee.Geometry.Point([15.5861, 78.1969])
[6]:
cloudless = ts.filterBounds(svalbard).filterMetadata("CLOUDY_PIXEL_PERCENTAGE", "less_than", 5)
cloudless.size().getInfo()
[6]:
80
wxee Methods
A time series also has additional methods added by wxee
to help describe and process time series data. Let’s start by looking at the describe
, dataframe
, and timeline
methods that provide info on how many images are in the time series and when they were acquired.
describe
First, describe
provides a brief summary of the time series including the number of images, the system:start_time
of the first and last chronological image, and the mean interval between images.
[7]:
cloudless.describe()
COPERNICUS/S2_SR
Images: 80
Start date: 2018-03-27 12:27:55 UTC
End date: 2021-09-03 11:59:18 UTC
Mean interval: 15.90 days
As you can see, there have been 80 mostly cloudless images captured over this area–on average, about one every 16 days.
dataframe
We can summarize the ID and start and end dates of those 80 images as a pandas.DataFrame
using dataframe
.
[8]:
df = cloudless.dataframe()
df.head()
[8]:
id | time_start | time_end | |
---|---|---|---|
0 | COPERNICUS/S2_SR/20180327T122729_20180327T1227... | 2018-03-27 12:27:55 | 2018-03-27 12:27:55 |
1 | COPERNICUS/S2_SR/20180405T120651_20180405T1206... | 2018-04-05 12:06:45 | 2018-04-05 12:06:45 |
2 | COPERNICUS/S2_SR/20180405T125659_20180405T1257... | 2018-04-05 12:57:02 | 2018-04-05 12:57:02 |
3 | COPERNICUS/S2_SR/20180406T122649_20180406T1226... | 2018-04-06 12:26:49 | 2018-04-06 12:26:49 |
4 | COPERNICUS/S2_SR/20180407T115639_20180407T1156... | 2018-04-07 11:56:39 | 2018-04-07 11:56:39 |
timeline
Finally, we can visualize when those cloudless images were collected with an interactive plot using timeline
.
[9]:
cloudless.timeline()
Now we can see that most of the cloudless days occur between spring and summer!
Other Methods
The TimeSeries
class contains many other methods for processing such as interpolate_time
, aggregate_time
, climatology_anomaly
, and others. Detailed example notebooks can be found here.
Note
This page was auto-generated from a Jupyter notebook. For full functionality, download the notebook from Github and run it in a local Python environment.