Field evolution and zonal stats

Using Agriculture cloud mask from EarthDaily, and data from L2A, zonal stats for evolution

Import librairies

from matplotlib import pyplot as plt

import earthdaily as ed

Load plot

# load geojson
pivot = ed.datasets.load_pivot()

Init earthdatastore with environment variables or default credentials

eds = ed.EarthDataStore()
Traceback (most recent call last):
  File "/private/var/folders/_t/czv_cfrd613_6_gd_p8qpqd80000gp/T/tmpmap_d3kq/7261d0bf6bc6b22a0278281791f6623d19ddf89a/examples/field_evolution.py", line 26, in <module>
    eds = ed.EarthDataStore()
          ^^^^^^^^^^^^^^^^^^^
  File "/private/var/folders/_t/czv_cfrd613_6_gd_p8qpqd80000gp/T/tmpmap_d3kq/7261d0bf6bc6b22a0278281791f6623d19ddf89a/earthdaily/__init__.py", line 51, in EarthDataStore
    return earthdatastore.Auth.from_credentials(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/folders/_t/czv_cfrd613_6_gd_p8qpqd80000gp/T/tmpmap_d3kq/7261d0bf6bc6b22a0278281791f6623d19ddf89a/earthdaily/earthdatastore/__init__.py", line 464, in from_credentials
    config = cls.read_credentials(
             ^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/folders/_t/czv_cfrd613_6_gd_p8qpqd80000gp/T/tmpmap_d3kq/7261d0bf6bc6b22a0278281791f6623d19ddf89a/earthdaily/earthdatastore/__init__.py", line 529, in read_credentials
    raise NotImplementedError("Credentials weren't found.")
NotImplementedError: Credentials weren't found.

Search for collection items for June 2022. where at least 50% of the field is clear according to the native cloudmask.

datacube = eds.datacube(
    "sentinel-2-l2a",
    intersects=pivot,
    datetime=["2022-06", "2022-07"],
    assets=["red", "green", "blue", "nir"],
    mask_with="native",
    clear_cover=50,
)
datacube.clear_percent.plot.scatter(x="time")

Add spectral indices using spyndex from earthdaily accessor

datacube = datacube.ed.add_indices(["NDVI"])

Plots cube with SCL with at least 50% of clear data

datacube = datacube.load()
datacube.ed.plot_rgb(col_wrap=4, vmin=0, vmax=0.3)
plt.title("Pivot evolution masked with native cloudmasks")
plt.show()

Compute zonal stats for the pivot

zonal_stats = datacube.ed.zonal_stats(pivot, ["mean", "max", "min"])
zonal_stats.isel(feature=0).to_array(dim="band").plot.line(
    x="time", col="band", hue="zonal_statistics", col_wrap=3
)
plt.show()

Total running time of the script: (0 minutes 0.005 seconds)

Gallery generated by Sphinx-Gallery