Note
Go to the end to download the full example code.
EarthDaily Simulated Dataset
Following a pivot field
Import librairies
import datetime
import earthdaily
from dask.diagnostics import ProgressBar
from matplotlib import pyplot as plt
from earthdaily import datasets, EarthDataStore
ProgressBar().register() # to have chunks progress bar
Loading pivot
pivot = datasets.load_pivot_corumba()
Init earthdatastore with environment variables or default credentials
eds = EarthDataStore()
Define timerange
delta_days = 10
datetime_list = ["2018-10-01", "2019-04-15"]
Request items for vnir dataset
items = eds.search(
"earthdaily-simulated-cloudless-l2a-cog-edagro",
intersects=pivot,
datetime=datetime_list,
query={"instruments": {"contains": "vnir"}},
prefer_alternate="download",
)[::delta_days] # an keep on item every n delta_days
Generate datacube for RGB and NIR
datacube = earthdaily.earthdatastore.datacube(
items, intersects=pivot, assets=["blue", "green", "red", "nir"]
).load()
[ ] | 0% Completed | 142.83 us
[ ] | 0% Completed | 100.36 ms
[ ] | 0% Completed | 200.57 ms
[ ] | 0% Completed | 300.75 ms
[ ] | 0% Completed | 400.91 ms
[ ] | 0% Completed | 501.10 ms
[ ] | 1% Completed | 601.28 ms
[ ] | 1% Completed | 701.45 ms
[# ] | 3% Completed | 801.62 ms
[## ] | 5% Completed | 901.80 ms
[## ] | 5% Completed | 1.00 s
[## ] | 5% Completed | 1.10 s
[## ] | 5% Completed | 1.20 s
[## ] | 6% Completed | 1.30 s
[### ] | 8% Completed | 1.40 s
[#### ] | 10% Completed | 1.50 s
[#### ] | 10% Completed | 1.60 s
[#### ] | 10% Completed | 1.70 s
[#### ] | 10% Completed | 1.80 s
[#### ] | 10% Completed | 1.90 s
[#### ] | 11% Completed | 2.00 s
[##### ] | 13% Completed | 2.10 s
[###### ] | 15% Completed | 2.20 s
[###### ] | 15% Completed | 2.30 s
[###### ] | 15% Completed | 2.41 s
[###### ] | 15% Completed | 2.51 s
[###### ] | 16% Completed | 2.61 s
[####### ] | 18% Completed | 2.71 s
[######## ] | 20% Completed | 2.81 s
[######## ] | 20% Completed | 2.91 s
[######## ] | 20% Completed | 3.01 s
[######## ] | 20% Completed | 3.11 s
[######## ] | 20% Completed | 3.21 s
[######### ] | 23% Completed | 3.31 s
[########## ] | 25% Completed | 3.41 s
[########## ] | 25% Completed | 3.51 s
[########## ] | 25% Completed | 3.61 s
[########## ] | 25% Completed | 3.71 s
[########## ] | 25% Completed | 3.81 s
[########### ] | 27% Completed | 3.91 s
[############ ] | 30% Completed | 4.01 s
[############ ] | 30% Completed | 4.11 s
[############ ] | 30% Completed | 4.21 s
[############ ] | 30% Completed | 4.31 s
[############ ] | 30% Completed | 4.41 s
[############ ] | 31% Completed | 4.51 s
[############# ] | 33% Completed | 4.61 s
[############## ] | 35% Completed | 4.71 s
[############## ] | 35% Completed | 4.81 s
[############## ] | 35% Completed | 4.91 s
[############## ] | 36% Completed | 5.01 s
[############## ] | 36% Completed | 5.11 s
[############### ] | 37% Completed | 5.21 s
[############### ] | 38% Completed | 5.31 s
[############### ] | 38% Completed | 5.41 s
[################ ] | 40% Completed | 5.51 s
[################ ] | 40% Completed | 5.61 s
[################ ] | 41% Completed | 5.71 s
[################# ] | 42% Completed | 5.81 s
[################# ] | 43% Completed | 5.91 s
[################# ] | 43% Completed | 6.01 s
[################## ] | 45% Completed | 6.11 s
[################## ] | 45% Completed | 6.21 s
[################## ] | 46% Completed | 6.31 s
[################### ] | 47% Completed | 6.41 s
[################### ] | 48% Completed | 6.51 s
[################### ] | 48% Completed | 6.61 s
[################### ] | 49% Completed | 6.71 s
[#################### ] | 50% Completed | 6.81 s
[#################### ] | 51% Completed | 6.91 s
[#################### ] | 51% Completed | 7.01 s
[##################### ] | 53% Completed | 7.11 s
[##################### ] | 53% Completed | 7.21 s
[##################### ] | 53% Completed | 7.31 s
[##################### ] | 53% Completed | 7.41 s
[###################### ] | 55% Completed | 7.51 s
[###################### ] | 56% Completed | 7.61 s
[####################### ] | 57% Completed | 7.71 s
[####################### ] | 58% Completed | 7.82 s
[####################### ] | 58% Completed | 7.92 s
[####################### ] | 58% Completed | 8.02 s
[######################## ] | 61% Completed | 8.12 s
[######################### ] | 62% Completed | 8.22 s
[######################### ] | 62% Completed | 8.32 s
[######################### ] | 62% Completed | 8.42 s
[######################### ] | 63% Completed | 8.52 s
[######################### ] | 63% Completed | 8.62 s
[########################## ] | 66% Completed | 8.72 s
[########################## ] | 66% Completed | 8.82 s
[########################## ] | 66% Completed | 8.92 s
[########################## ] | 66% Completed | 9.02 s
[########################### ] | 67% Completed | 9.12 s
[########################### ] | 67% Completed | 9.22 s
[########################### ] | 67% Completed | 9.32 s
[############################ ] | 71% Completed | 9.42 s
[############################ ] | 71% Completed | 9.52 s
[############################ ] | 71% Completed | 9.62 s
[############################# ] | 72% Completed | 9.72 s
[############################# ] | 72% Completed | 9.82 s
[############################# ] | 73% Completed | 9.92 s
[############################## ] | 75% Completed | 10.02 s
[############################## ] | 76% Completed | 10.12 s
[############################## ] | 76% Completed | 10.22 s
[############################## ] | 76% Completed | 10.32 s
[############################### ] | 77% Completed | 10.42 s
[############################### ] | 77% Completed | 10.52 s
[################################ ] | 80% Completed | 10.62 s
[################################ ] | 81% Completed | 10.72 s
[################################ ] | 81% Completed | 10.82 s
[################################ ] | 81% Completed | 10.92 s
[################################# ] | 82% Completed | 11.02 s
[################################# ] | 82% Completed | 11.12 s
[################################# ] | 82% Completed | 11.22 s
[################################## ] | 85% Completed | 11.32 s
[################################## ] | 86% Completed | 11.42 s
[################################### ] | 87% Completed | 11.52 s
[################################### ] | 87% Completed | 11.62 s
[################################### ] | 87% Completed | 11.72 s
[################################### ] | 88% Completed | 11.82 s
[#################################### ] | 90% Completed | 11.92 s
[#################################### ] | 90% Completed | 12.02 s
[#################################### ] | 90% Completed | 12.12 s
[##################################### ] | 92% Completed | 12.22 s
[##################################### ] | 92% Completed | 12.32 s
[##################################### ] | 93% Completed | 12.42 s
[###################################### ] | 95% Completed | 12.52 s
[###################################### ] | 95% Completed | 12.62 s
[###################################### ] | 96% Completed | 12.72 s
[###################################### ] | 96% Completed | 12.82 s
[####################################### ] | 97% Completed | 12.92 s
[####################################### ] | 98% Completed | 13.03 s
[####################################### ] | 98% Completed | 13.13 s
[########################################] | 100% Completed | 13.23 s
Plot RGB image time series
datacube[["red", "green", "blue"]].ed.plot_rgb(
col="time", col_wrap=4, vmax=0.2
)
<xarray.plot.facetgrid.FacetGrid object at 0x7fc53867b2d0>
Plot mean RGB time series
datacube[["blue", "green", "red", "nir"]].groupby("time").mean(...).to_array(
dim="band"
).plot(col="band")
<xarray.plot.facetgrid.FacetGrid object at 0x7fc530b2b190>
Plot NDVI evolution
datacube["ndvi"] = (datacube["nir"] - datacube["red"]) / (
datacube["nir"] + datacube["red"]
)
fig, ax = plt.subplots()
mean_ndvi = datacube[["ndvi"]].groupby("time").mean(...).to_array(dim="band")
std_ndvi = datacube[["ndvi"]].groupby("time").std(...).to_array(dim="band")
ax.fill_between(
mean_ndvi.time,
(mean_ndvi.values + std_ndvi.values)[0, ...],
(mean_ndvi.values - std_ndvi.values)[0, ...],
alpha=0.3,
color="C1",
)
mean_ndvi.plot(ax=ax, c="C1")
plt.grid(alpha=0.4)
plt.title("NDVI evolution every 10 days")
Text(0.5, 1.0, 'NDVI evolution every 10 days')
Total running time of the script: (0 minutes 25.270 seconds)