Landsat, a joint program of the USGS and NASA, has been observing the Earth continuously from 1972 through the present day. Today the Landsat satellites image the entire Earth's surface at a 30-meter resolution about once every two weeks, including multispectral and thermal data.
Landsat data is available in Earth Engine in its raw form, as Surface Reflectance, TOA-corrected reflectance, and in various ready-to-use computed products such as NDVI and EVI vegetation indices.
> **📝 Note:**
>In this course we will only work with *Landsat Collection 2* that marks the second major reprocessing effort on the Landsat archive by the USGS that results in several data product improvements over Collection 1 that harness recent advancements in data processing and algorithm development.
// Select Landsat 8 images in area of interest and time period
varl8_filter=landsat_8
.filterDate(startDate,endDate)
.filterBounds(roi)
varl9_filter=landsat_9
.filterDate(startDate,endDate)
.filterBounds(roi)
```
## Apply scaling factors
A scale factor must be applied to both Collection 1 and Collection 2 Landsat Level-2 surface reflectance and surface temperature products before using the data.
**Landsat Collection 2** have the following scale factors, fill values, data type, and valid range.
> **Examples for scaling Landsat Collection 2 Level-2 science products**
> <font size="2">Landsat Collection 2 surface reflectance has a scale factor of 0.0000275 and an additional offset of -0.2 per pixel. <br/> For example, a pixel value of 18,639 is multiplied by 0.0000275 for the scale factor and then -0.2 is added for the additional offset to get a reflectance value of 0.313 after the scale factor is applied. </font>
Most optical satellite imagery products come with one or more QA-bands that allows the user to assess quality of each pixel and extract pixels that meet their requirements. The most common application for QA-bands is to extract information about cloudy pixels and mask them. But the QA bands contain a wealth of other information that can help you remove low quality data from your analysis. Typically the information contained in QA bands is stored as Bitwise Flags. [More info about bitmasks](https://spatialthoughts.com/2021/08/19/qa-bands-bitmasks-gee/)
In Landsat imagery, pixel quality assessment (QA_PIXEL) bands are generated by the CFMask algorithm. Different bit definitions are used because the cirrus band is only available on Landsat 8 and 9. This band is relevant to both Surface Reflectance and Surface Temperature products.
The Sentinel-2 L2 data are downloaded from the Copernicus DataSpace. They were computed by running Sen2Cor.
All information concerning *Harmonized Sentinel-2 MSI: MultiSpectral Instrument, Level-2A* are available [here](https://developers.google.com/earth-engine/datasets/catalog/COPERNICUS_S2_SR_HARMONIZED#description)
>The Sentinel Level-1C and Level-2A data products have a harmonized time series. The "harmonized" designation means that the band-dependent offset added to reflectance bands in the 04.00 processing baseline has been removed. The offset affects data after January 24th 2022; removing the offset puts these data in spectral alignment with pre-04.00 baseline data. If you are using COPERNICUS/S2 or COPERNICUS/S2_SR, it is recommended that you switch to COPERNICUS/S2_HARMONIZED and COPERNICUS/S2_SR_HARMONIZED.
Reducers are the way to aggregate data over time, space, bands, arrays and other data structures in Earth Engine. The `ee.Reducer` class specifies how data is aggregated. The reducers in this class can specify a simple statistic to use for the aggregation (e.g. minimum, maximum, mean, median, standard deviation, etc.), or a more complex summary of the input data (e.g. histogram, linear regression, list).
Reductions may occur over :
-**time (`imageCollection.reduce()`),**
- space (`image.reduceRegion()`, `image.reduceNeighborhood()`),
- bands (`image.reduce()`),
- attribute space of a `FeatureCollection`** (`featureCollection.reduceColumns()` or `FeatureCollection` methods that start with `aggregate_`).
Consider the example of needing to take the median over a time series of images represented by an `ImageCollection`. To reduce an `ImageCollection`, use `imageCollection.reduce()`. This reduces the collection of images to an individual image. Specifically, the output is computed pixel-wise, such that each pixel in the output is composed of the median value of all the images in the collection at that location. To get other statistics, such as mean, sum, variance, an arbitrary percentile, etc., the appropriate reducer should be selected and applied.
```{note}
For basic statistics like min, max, mean, etc., `ImageCollection` has shortcut methods like `min()`, `max()`, `mean()`, etc. They function in exactly the same way as calling `reduce()`, except the resultant band names will not have the name of the reducer appended.
```
**To composite images in an `ImageCollection`, use `imageCollection.reduce()`. This will composite all the images in the collection to a single image representing, for example, the min, max, mean or standard deviation of the images.**

```js
vars2_composite_cloudsQA=s2_mask_cloudsQA
.median()
.clip(roi)
```
## Visualization
```js
varvisParams={
bands:['B4','B3','B2'],
min:0.0,
max:0.3,
};
```
```js
Map.centerObject(roi,8)
Map.addLayer(s2_composite_cloudsQA,visParams,'S2 SR masked QA60')
// Export the image, specifying the CRS, transform, and region.
Export.image.toDrive({
image:s2_composite_cloudsQA,
description:'S2_2025_median_composite',
folder:'LBRAT2104',
crs:projection.crs,// The base coordinate reference system of this projection (e.g. 'EPSG:4326')
crsTransform:projection.transform,// The transform between projected coordinates and the base coordinate system
region:roi
});
```
> Composite images created by reducing an image collection are able to produce pixels in any requested projection and therefore have no fixed output projection. Instead, composites have the default projection of WGS-84 with 1-degree resolution pixels. Composites with the default projection will be computed in whatever output projection is requested. A request occurs by displaying the composite in the Code Editor or by explicitly specifying a projection/scale as in an aggregation such as `ReduceRegion` or `Export`.