<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 <a id="top"></a>
Composites
<hr>
Background
Composites are 2-dimensional representations of 3-dimensional data.
There are many cases in which this is desired. Sometimes composites are used in visualization - such as showing an RGB image of an area. Other times they are used for convenience, such as reducing the run time of an analysis by reducing the amount of data to be processed in a task by working with composites instead of full datasets. Other times they are required by an algorithm.
There are several kinds of composites that can be made. This notebook provides an overview of several of them and shows how to create them in the context of Open Data Cube.
<hr>
Index
Import Dependencies and Connect to the Data Cube
Load Data from the Data Cube
Most Common Composites
Mean composites
Median composites
Geometric median (geomedian) composites
Geometric medoid (geomedoid) composites
Other Composites
Most-recent composites
Least-recent composites
<span id="Composites_import">Import Dependencies and Connect to the Data Cube &#9652;</span>
Step1:  <span id="Composites_retrieve_data">Load Data from the Data Cube &#9652;</span>
Step2:  <span id="Composites_most_common">Most Common Composites &#9652;</span>
Mean composites
A mean composite is obtained by finding the mean (average) value of each band for each pixel. To create mean composites, we use the built-in mean() method of xarray objects.
Step3:  Median composites
A median composite is obtained by finding the median value of each band for each pixel. Median composites are quick to obtain and are usually fairly representative of their data, so they are acceptable for visualization as images. To create median composites, we use the built-in median() method of xarray objects.
Step4:  Geometric median (geomedian) composites
Geometric median (or "geomedian") composites are the best composites to use for most applications for which a representative, synthetic (calculated, not selected from the data) time slice is desired. They are essentiall median composites, but instead of finding the median on a per-band basis, they find the median for all bands together. If a composite will be used for analysis - not just visualization - it should be a geomedian composite. The only downside of this composite type is that it takes much longer to obtain than other composite types. For more information, see the Geomedians_and_Geomedoids notebook.
Step5:  Geometric medoid (geomedoid) composites
Geometric medoid (or "geomedoid") composites are the best composites to use for most applications for which a representative, non-syntheic (selected from the data, not calculated) time slice is desired. For more information, see the Geomedians_and_Geomedoids notebook.
Step6:  <span id="Composites_other_composites">Other Composites &#9652;</span>
Most-recent composites
Most-recent composites use the most recent cloud-free pixels in an image. To create, a most-recent composite, we use the create_mosaic utility function.
Step7:  Least-recent composites
Least-recent composites are simply the opposite of most-recent composites. To create, a least-recent composite, we use the create_mosaic utility function, specifying reverse_time=True.
<ASSISTANT_TASK:>
Python Code:
import sys
import os
sys.path.append(os.environ.get('NOTEBOOK_ROOT'))
from utils.data_cube_utilities.clean_mask import landsat_clean_mask_full
# landsat_qa_clean_mask, landsat_clean_mask_invalid
from utils.data_cube_utilities.dc_mosaic import create_hdmedians_multiple_band_mosaic
from utils.data_cube_utilities.dc_mosaic import create_mosaic
from datacube.utils.aws import configure_s3_access
configure_s3_access(requester_pays=True)
import datacube
dc = datacube.Datacube()
Explanation: <a id="top"></a>
Composites
<hr>
Background
Composites are 2-dimensional representations of 3-dimensional data.
There are many cases in which this is desired. Sometimes composites are used in visualization - such as showing an RGB image of an area. Other times they are used for convenience, such as reducing the run time of an analysis by reducing the amount of data to be processed in a task by working with composites instead of full datasets. Other times they are required by an algorithm.
There are several kinds of composites that can be made. This notebook provides an overview of several of them and shows how to create them in the context of Open Data Cube.
<hr>
Index
Import Dependencies and Connect to the Data Cube
Load Data from the Data Cube
Most Common Composites
Mean composites
Median composites
Geometric median (geomedian) composites
Geometric medoid (geomedoid) composites
Other Composites
Most-recent composites
Least-recent composites
<span id="Composites_import">Import Dependencies and Connect to the Data Cube &#9652;</span>
End of explanation
product = 'ls8_usgs_sr_scene'
platform = 'LANDSAT_8'
collection = 'c1'
level = 'l2'
landsat_ds = dc.load(platform=platform, product=product,
                     time=("2017-01-01", "2017-12-31"), 
                     lat=(-1.395447, -1.172343), 
                     lon=(36.621306, 37.033980),
                     group_by='solar_day',
                     dask_chunks={'latitude':500, 'longitude':500,
                                  'time':5})
# clean_mask = (landsat_qa_clean_mask(landsat_ds, platform) & 
#               (landsat_ds != -9999).to_array().all('variable') & 
#               landsat_clean_mask_invalid(landsat_ds))
clean_mask = landsat_clean_mask_full(dc, landsat_ds, product=product, platform=platform, 
                                     collection=collection, level=level)
landsat_ds = landsat_ds.where(clean_mask)
Explanation: <span id="Composites_retrieve_data">Load Data from the Data Cube &#9652;</span>
End of explanation
mean_composite = landsat_ds.mean('time', skipna=True)
Explanation: <span id="Composites_most_common">Most Common Composites &#9652;</span>
Mean composites
A mean composite is obtained by finding the mean (average) value of each band for each pixel. To create mean composites, we use the built-in mean() method of xarray objects.
End of explanation
median_composite = landsat_ds.median('time', skipna=True)
Explanation: Median composites
A median composite is obtained by finding the median value of each band for each pixel. Median composites are quick to obtain and are usually fairly representative of their data, so they are acceptable for visualization as images. To create median composites, we use the built-in median() method of xarray objects.
End of explanation
geomedian_composite = create_hdmedians_multiple_band_mosaic(landsat_ds)
Explanation: Geometric median (geomedian) composites
Geometric median (or "geomedian") composites are the best composites to use for most applications for which a representative, synthetic (calculated, not selected from the data) time slice is desired. They are essentiall median composites, but instead of finding the median on a per-band basis, they find the median for all bands together. If a composite will be used for analysis - not just visualization - it should be a geomedian composite. The only downside of this composite type is that it takes much longer to obtain than other composite types. For more information, see the Geomedians_and_Geomedoids notebook.
End of explanation
geomedoid_composite = create_hdmedians_multiple_band_mosaic(landsat_ds, operation='medoid')
Explanation: Geometric medoid (geomedoid) composites
Geometric medoid (or "geomedoid") composites are the best composites to use for most applications for which a representative, non-syntheic (selected from the data, not calculated) time slice is desired. For more information, see the Geomedians_and_Geomedoids notebook.
End of explanation
most_recent_composite = create_mosaic(landsat_ds)
Explanation: <span id="Composites_other_composites">Other Composites &#9652;</span>
Most-recent composites
Most-recent composites use the most recent cloud-free pixels in an image. To create, a most-recent composite, we use the create_mosaic utility function.
End of explanation
most_recent_composite = create_mosaic(landsat_ds, reverse_time=True)
Explanation: Least-recent composites
Least-recent composites are simply the opposite of most-recent composites. To create, a least-recent composite, we use the create_mosaic utility function, specifying reverse_time=True.
End of explanation
<END_TASK>