.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_auto_examples/first_steps_create_datacube.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr__auto_examples_first_steps_create_datacube.py: First steps to create a datacube =============================================================== To create a datacube using Earth Data Store from EarthDaily you have two possibilities. The first one is the more classic one, you request items, then you build your datacube, and then you can mask pixels using a cloudmask asset. The second one is the most turnkey one, the one we recommend, it allows to do all the process at once. .. GENERATED FROM PYTHON SOURCE LINES 13-15 Import librairies ------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 15-21 .. code-block:: Python from matplotlib import pyplot as plt import earthdaily from earthdaily import EarthDataStore, datasets .. GENERATED FROM PYTHON SOURCE LINES 22-23 Loading geometry .. GENERATED FROM PYTHON SOURCE LINES 23-26 .. code-block:: Python geometry = datasets.load_pivot() .. GENERATED FROM PYTHON SOURCE LINES 27-29 Init earthdatastore with environment variables or default credentials ---------------------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 29-32 .. code-block:: Python eds = EarthDataStore() .. GENERATED FROM PYTHON SOURCE LINES 33-35 Create datacube (in one step) -------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 35-51 .. code-block:: Python s2_datacube = eds.datacube( "sentinel-2-l2a", assets=["blue", "green", "red", "nir"], intersects=geometry, datetime=["2022-08-01", "2022-08-09"], mask_with="native", # equal to "scl" for sentinel-2 clear_cover=50, ) s2_datacube.clear_percent.plot.scatter(x="time") plt.title("Percentage of clear pixels on the study site") plt.show() s2_datacube.ed.plot_rgb(vmin=0, vmax=0.2, col="time", col_wrap=4) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /_auto_examples/images/sphx_glr_first_steps_create_datacube_001.png :alt: Percentage of clear pixels on the study site :srcset: /_auto_examples/images/sphx_glr_first_steps_create_datacube_001.png :class: sphx-glr-multi-img * .. image-sg:: /_auto_examples/images/sphx_glr_first_steps_create_datacube_002.png :alt: time = 2022-08-02, time = 2022-08-05, time = 2022-08-07 :srcset: /_auto_examples/images/sphx_glr_first_steps_create_datacube_002.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 52-54 Create datacube in three steps -------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 56-57 Request items .. GENERATED FROM PYTHON SOURCE LINES 57-64 .. code-block:: Python items = eds.search( "sentinel-2-l2a", intersects=geometry, datetime=["2022-08-01", "2022-08-09"], ) .. GENERATED FROM PYTHON SOURCE LINES 65-67 Creata datacube (independent from being log into earthdatastore) We request the "scl" assets which is the native cloudmask .. GENERATED FROM PYTHON SOURCE LINES 67-72 .. code-block:: Python s2_datacube = earthdaily.earthdatastore.datacube( items, assets=["blue", "green", "red", "nir", "scl"], intersects=geometry ) .. GENERATED FROM PYTHON SOURCE LINES 73-74 Mask datacube .. GENERATED FROM PYTHON SOURCE LINES 74-86 .. code-block:: Python # intersects or bbox are asked in order to compute accurate mask statistics s2_datacube = earthdaily.earthdatastore.mask.Mask(s2_datacube, intersects=geometry).scl( mask_statistics=True ) s2_datacube = earthdaily.earthdatastore.mask.filter_clear_cover( s2_datacube, 50 ) # at least 50% of clear pixels # s2_datacube.ed.plot_rgb(vmin=0, vmax=0.2, col="time", col_wrap=4) .. image-sg:: /_auto_examples/images/sphx_glr_first_steps_create_datacube_003.png :alt: time = 2022-08-02, time = 2022-08-05, time = 2022-08-07 :srcset: /_auto_examples/images/sphx_glr_first_steps_create_datacube_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 10.490 seconds) .. _sphx_glr_download__auto_examples_first_steps_create_datacube.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: first_steps_create_datacube.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: first_steps_create_datacube.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: first_steps_create_datacube.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_