Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

381 changes: 183 additions & 198 deletions tutorials/coregistration.ipynb → tutorials/02_Coregistration.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
"source": [
"## Cloudless Mosaic\n",
"\n",
"This tutorial constructs a *cloudless mosaic* (also known as a composite) from a time series of satellite images. We'll see the following:\n",
"In this tutorial, you'll learn how to constructs a *cloudless mosaic* (also known as a composite) from a time series of satellite images. The tutorial covers the following steps:\n",
"\n",
"* Find a time series of images at a particular point on Earth\n",
"* Stack those images together into a single array\n",
"* Compute the cloudless mosaic by taking a median\n",
"* Visualize the results\n",
"* [Find a time series of images at a particular point on Earth](#Discover-data)\n",
"* [Stack those images together into a single array](#Stack-images)\n",
"* [Compute the cloudless mosaic by taking a median](#Median-composite)\n",
"* [Create mosaics after grouping the data](#Monthly-composite)\n",
"\n",
"This example uses [Sentinel-2 Level-2A](https://planetarycomputer.microsoft.com/dataset/sentinel-2-l2a) data. The techniques used here apply equally well to other remote-sensing datasets."
"This example uses [Sentinel-2 Level-2A](https://planetarycomputer.microsoft.com/dataset/sentinel-2-l2a) data. The techniques used here work equally well with other remote-sensing datasets.\n",
"\n",
"---"
]
},
{
Expand Down Expand Up @@ -41,7 +43,7 @@
"source": [
"### Create a Dask cluster\n",
"\n",
"We're going to process a large amount of data. To cut down on the execution time, we'll use a Dask cluster to do the computation in parallel, adaptively scaling to add and remove workers as needed. See [Scale With Dask](../quickstarts/scale-with-dask.ipynb) for more on using Dask."
"This example requires processing a large amms match our seaunt of data. To cut down on the execution time, use a Dask cluster to do the computation in parallel, adaptively scaling to add and remove workers as needed. See [Scale With Dask](../quickstarts/scale-with-dask.ipynb) for more on using Dask."
]
},
{
Expand All @@ -58,7 +60,7 @@
}
],
"source": [
"cluster = GatewayCluster() # Creates the Dask Scheduler. Might take a minute.\n",
"cluster = GatewayCluster() # creates the Dask Scheduler - might take a minute.\n",
"\n",
"client = cluster.get_client()\n",
"\n",
Expand All @@ -72,7 +74,7 @@
"source": [
"### Discover data\n",
"\n",
"In this example, we define our area of interest as a GeoJSON object. It's near Redmond, Washington."
"In this example, the area of interest is located near Redmond, Washington. It is defined as a GeoJSON object."
]
},
{
Expand Down Expand Up @@ -100,7 +102,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Using `pystac_client` we can search the Planetary Computer's STAC endpoint for items matching our query parameters."
"Use `pystac_client` to search the Planetary Computer's STAC endpoint for items matching your query parameters:"
]
},
{
Expand Down Expand Up @@ -135,7 +137,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"So 138 items match our search requirements, over space, time, and cloudiness. Those items will still have *some* clouds over portions of the scenes, though. To create our cloudless mosaic, we'll load the data into an [xarray](https://xarray.pydata.org/en/stable/) DataArray using [stackstac](https://stackstac.readthedocs.io/) and then reduce the time-series of images down to a single image."
"As you can see, there are 138 items that match your search requirements in terms of location, time, and cloudiness. Those items will still have *some* clouds over portions of the scenes, though. \n",
"\n",
"### Stack images\n",
"\n",
"To create a cloudless mosaic, first, load the data into an [xarray](https://xarray.pydata.org/en/stable/) DataArray using [stackstac](https://stackstac.readthedocs.io/):"
]
},
{
Expand All @@ -160,6 +166,13 @@
" signed_items.append(planetary_computer.sign(item).to_dict())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next, reduce the time series of images down to a single image:"
]
},
{
"cell_type": "code",
"execution_count": 6,
Expand Down Expand Up @@ -1471,7 +1484,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Since the data matching our query isn't too large we can persist it in distributed memory. Once in memory, subsequent operations will be much faster."
"Since the data matching your query isn't too large, you can persist it in distributed memory. Once it is stored in memory, subsequent operations will be much faster."
]
},
{
Expand All @@ -1489,7 +1502,7 @@
"source": [
"### Median composite\n",
"\n",
"Using normal xarray operations, we can [compute the median](http://xarray.pydata.org/en/stable/generated/xarray.DataArray.median.html) over the time dimension. Under the assumption that clouds are transient, the composite shouldn't contain (many) clouds, since they shouldn't be the median pixel value at that point over many images.\n",
"Using regular xarray operations, you can [compute the median](http://xarray.pydata.org/en/stable/generated/xarray.DataArray.median.html) over the time dimension. Under the assumption that clouds are transient, the composite shouldn't contain (many) clouds, since clouds shouldn't be the median pixel value at that point over many images.\n",
"\n",
"This will be computed in parallel on the cluster (make sure to open the Dask Dashboard using the link printed out above)."
]
Expand All @@ -1507,7 +1520,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"To visualize the data, we'll use xarray-spatial's `true_color` method to convert to red/green/blue values."
"Use Xarray-Spatial's `true_color` method to visualize your data by converting it to red/green/blue values."
]
},
{
Expand Down Expand Up @@ -1552,7 +1565,7 @@
"source": [
"### Monthly composite\n",
"\n",
"Now suppose we don't want to combine images from different parts of the year (for example, we might not want to combine images from January that often include snow with images from July). Again using standard xarray syntax, we can create set of per-month composites by grouping by month and then taking the median."
"Now suppose you don't want to combine images from different parts of the year (for example, you might not want to combine images from January that often include snow with images from July). Again using standard xarray syntax, you can create sets of per-month composites by grouping by month and then computing the median:"
]
},
{
Expand All @@ -1568,7 +1581,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's convert each of those arrays to a true-color image and plot the results as a grid."
"Convert each of those arrays to a true-color image and plot the results as a grid:"
]
},
{
Expand Down Expand Up @@ -1604,15 +1617,17 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Learn more\n",
"### Next steps\n",
"\n",
"To learn more about using the Planetary Computer's STAC API, see [Reading data from the STAC API](../quickstarts/reading-stac.ipynb). To learn more about Dask, see [Scaling with Dask](../quickstarts/scale-with-dask.ipynb).\n",
"\n",
"To learn more about using the the Planetary Computer's STAC API, see [Reading data from the STAC API](../quickstarts/reading-stac.ipynb). To learn more about Dask, see [Scaling with Dask](../quickstarts/scale-with-dask.ipynb)."
"Click on this link to go to the next notebook: [04 Geospatial Classification](04_Geospatial_Classification.ipynb)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -1626,7 +1641,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.9.1"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
Expand Down

Large diffs are not rendered by default.

81 changes: 38 additions & 43 deletions tutorials/local-tools.ipynb → tutorials/05_Local_Tools.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,23 @@
"id": "e9045413",
"metadata": {},
"source": [
"## Exploring Xarray-spatial Local Tools Functions"
"## Exploring local tools in Xarray-Spatial"
]
},
{
"cell_type": "markdown",
"id": "32b5e1bf",
"metadata": {},
"source": [
"Local tools operate at the cell level, where values with the same position from a set of input rasters are used to calculate the values of the cells at the output raster.\n",
"Some examples of the application of local tools are:\n",
"In this tutorial, you'll learn how to use various local tools in [Xarray-Spatial](http://xarray-spatial.org/). Local tools operate at the cell level, where values with the same position from a set of input rasters are used to calculate the values of the cells at the output raster. Some examples of the application of local tools are:\n",
"\n",
"- Change over time: You can use local tools to identify places where a value like land use or temperature changed over time.\n",
"- Aggregate over time: You can use local tools to aggregate values over time, for example calculating the average rainfall or hours of sunshine for each cell.\n",
"- Threshold over time: You can use local tools to identify places where a value is above or below a specified threshold, for example where the temperature was below a 0 °C.\n",
"- Data aggregation: You can use local tools to calculate the [cost surface](http://wiki.gis.com/wiki/index.php/Cost_surface) of an area, summing up different types of cost over the same cell in different layers."
]
},
{
"cell_type": "markdown",
"id": "ea55ffed",
"metadata": {},
"source": [
"In this notebook, we'll demonstrate how to use the [Xarray-spatial](http://xarray-spatial.org/) local tools functions supported by [Numpy](https://numpy.org/). The spatial functions available are:\n",
"- Aggregate over time: You can use local tools to aggregate values over time, for example to calculate the average rainfall or hours of sunshine for each cell.\n",
"- Threshold over time: You can use local tools to identify places where a value is above or below a specified threshold, for example where the temperature was below 0 °C.\n",
"- Data aggregation: You can use local tools to calculate the [cost surface](http://wiki.gis.com/wiki/index.php/Cost_surface) of an area, summing up different types of cost over the same cell in different layers.\n",
"\n",
"This notebook demonstrates the Xarray-Spatial local tools functions supported by [Numpy](https://numpy.org/). The available spatial functions are:\n",
"\n",
"- [Cell Statistics](#Cell-Statistics)\n",
"- [Combine](#Combine)\n",
"- [Lesser Frequency](#Lesser-Frequency)\n",
Expand All @@ -35,23 +30,13 @@
"- [Lowest Position](#Lowest-Position)\n",
"- [Highest Position](#Highest-Position)\n",
"- [Popularity](#Popularity)\n",
"- [Rank](#Rank)"
]
},
{
"cell_type": "markdown",
"id": "b9c4ed8c",
"metadata": {},
"source": [
"### Creating the sample data"
]
},
{
"cell_type": "markdown",
"id": "af3c5207",
"metadata": {},
"source": [
"In order to present the functions in a very simple and easy to understand way, we'll use 4x4 data arrays and create an `xarray.Dataset`."
"- [Rank](#Rank)\n",
"\n",
"---\n",
"\n",
"### Creating the sample data\n",
"\n",
"To have some data to test the functions on, create four 4 x 4 [xarray DataArrays](http://xarray.pydata.org/en/stable/generated/xarray.DataArray.html) and merge them into a [xarray Dataset](http://xarray.pydata.org/en/stable/generated/xarray.Dataset.html):"
]
},
{
Expand Down Expand Up @@ -94,7 +79,7 @@
"id": "17d54999",
"metadata": {},
"source": [
"This function will be used to plot the arrays for all the examples in this notebook."
"The following function will be used to plot the arrays for all the examples in this notebook:"
]
},
{
Expand Down Expand Up @@ -143,7 +128,7 @@
"id": "01ab159c",
"metadata": {},
"source": [
"[`xrspatial.local.cell_stats`](https://xarray-spatial.org/reference/_autosummary/xrspatial.local.cell_stats.html) calculates statistics from a raster dataset on a cell-by-cell basis."
"[xrspatial.local.cell_stats](https://xarray-spatial.org/reference/_autosummary/xrspatial.local.cell_stats.html) calculates statistics from a raster dataset on a cell-by-cell basis."
]
},
{
Expand Down Expand Up @@ -207,7 +192,7 @@
"id": "87c34a83",
"metadata": {},
"source": [
"[`xrspatial.local.combine`](https://xarray-spatial.org/reference/_autosummary/xrspatial.local.combine.html) combines multiple arrays from a raster dataset, assigning a unique output value to each unique combination of raster values."
"[xrspatial.local.combine](https://xarray-spatial.org/reference/_autosummary/xrspatial.local.combine.html) combines multiple arrays from a raster dataset, assigning a unique output value to each unique combination of raster values."
]
},
{
Expand Down Expand Up @@ -255,7 +240,7 @@
"id": "4f6da50e",
"metadata": {},
"source": [
"[`xrspatial.local.lesser_frequency`](https://xarray-spatial.org/reference/_autosummary/xrspatial.local.lesser_frequency.html) calculates, given a raster dataset, the number of times the data variables values are lower than the values of a given reference data variable on a cell-by-cell basis."
"[xrspatial.local.lesser_frequency](https://xarray-spatial.org/reference/_autosummary/xrspatial.local.lesser_frequency.html) calculates, given a raster dataset, the number of times the data variables values are lower than the values of a given reference data variable on a cell-by-cell basis."
]
},
{
Expand Down Expand Up @@ -305,7 +290,7 @@
"id": "intelligent-philadelphia",
"metadata": {},
"source": [
"[`xrspatial.local.equal_frequency`](https://xarray-spatial.org/reference/_autosummary/xrspatial.local.equal_frequency.html) calculates, given a raster dataset, the number of times the data variables values are equal than the values of a given reference data variable on a cell-by-cell basis."
"[xrspatial.local.equal_frequency](https://xarray-spatial.org/reference/_autosummary/xrspatial.local.equal_frequency.html) calculates, given a raster dataset, the number of times the data variables values are equal to the values of a given reference data variable on a cell-by-cell basis."
]
},
{
Expand Down Expand Up @@ -355,7 +340,7 @@
"id": "vocational-inside",
"metadata": {},
"source": [
"[`xrspatial.local.greater_frequency`](https://xarray-spatial.org/reference/_autosummary/xrspatial.local.greater_frequency.html) calculates, given a raster dataset, the number of times the data variables values are greater than the values of a given reference data variable on a cell-by-cell basis."
"[xrspatial.local.greater_frequency](https://xarray-spatial.org/reference/_autosummary/xrspatial.local.greater_frequency.html) calculates, given a raster dataset, the number of times the data variables values are greater than the values of a given reference data variable on a cell-by-cell basis."
]
},
{
Expand Down Expand Up @@ -405,7 +390,7 @@
"id": "8d7235ec",
"metadata": {},
"source": [
"[`xrspatial.local.lowest_position`](https://xarray-spatial.org/reference/_autosummary/xrspatial.local.lowest_position.html) calculates the data variable index of the lowest value on a cell-by-cell basis."
"[xrspatial.local.lowest_position](https://xarray-spatial.org/reference/_autosummary/xrspatial.local.lowest_position.html) calculates the data variable index of the lowest value on a cell-by-cell basis."
]
},
{
Expand Down Expand Up @@ -454,7 +439,7 @@
"id": "a17c6e93",
"metadata": {},
"source": [
"[`xrspatial.local.highest_position`](https://xarray-spatial.org/reference/_autosummary/xrspatial.local.highest_position.html) calculates the data variable index of the highest value on a cell-by-cell basis."
"[xrspatial.local.highest_position](https://xarray-spatial.org/reference/_autosummary/xrspatial.local.highest_position.html) calculates the data variable index of the highest value on a cell-by-cell basis."
]
},
{
Expand Down Expand Up @@ -503,7 +488,7 @@
"id": "e5408cea",
"metadata": {},
"source": [
"[`xrspatial.local.popularity`](https://xarray-spatial.org/reference/_autosummary/xrspatial.local.popularity.html) calculates the number of occurrences of each value of a raster dataset, on a cell-by-cell basis. The output value is assigned based on the reference data variable nth most popular."
"[xrspatial.local.popularity](https://xarray-spatial.org/reference/_autosummary/xrspatial.local.popularity.html) calculates the number of occurrences of each value of a raster dataset, on a cell-by-cell basis. The output value is assigned based on the reference data variable nth most popular."
]
},
{
Expand Down Expand Up @@ -554,7 +539,7 @@
"id": "385dac65",
"metadata": {},
"source": [
"[`xrspatial.local.rank`](https://xarray-spatial.org/reference/_autosummary/xrspatial.local.rank.html) calculates the rank of each value of a raster dataset, on a cell-by-cell basis. The output value is assigned based on the rank of the reference data variable rank."
"[xrspatial.local.rank](https://xarray-spatial.org/reference/_autosummary/xrspatial.local.rank.html) calculates the rank of each value of a raster dataset, on a cell-by-cell basis. The output value is assigned based on the rank of the reference data variable rank."
]
},
{
Expand Down Expand Up @@ -590,11 +575,21 @@
" [\"arr_ref\", \"arr1\", \"arr2\", \"arr3\", \"result\"],\n",
")"
]
},
{
"cell_type": "markdown",
"id": "7849e658-30a7-43a9-babc-360b9a18d8c4",
"metadata": {},
"source": [
"## Next steps\n",
"\n",
"Click on this link to go to the next notebook: [06 Focal Statistics](06_Focal_Statistics.ipynb)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -608,7 +603,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.9.1"
}
},
"nbformat": 4,
Expand Down
Loading