Skip to content

Commit

Permalink
Merge 2e78c13 into 3b6c483
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 committed Jan 27, 2020
2 parents 3b6c483 + 2e78c13 commit f285fab
Show file tree
Hide file tree
Showing 14 changed files with 180 additions and 232 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -76,7 +76,7 @@ docs: ## generate Sphinx HTML documentation, including API docs
$(MAKE) -C docs clean
$(MAKE) -C docs html

docs-browser: ## generate Sphinx HTML documentation, including API docs
docs-browser: docs ## generate Sphinx HTML documentation, including API docs
$(BROWSER) docs/_build/html/index.html

release: dist ## package and upload a release
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Expand Up @@ -78,7 +78,7 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "examples/.ipynb_checkpoints"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "sphinx"
Expand Down
6 changes: 4 additions & 2 deletions docs/examples/COG.ipynb
Expand Up @@ -4,7 +4,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Example - Cloud Optimized GeoTiff (COG)"
"# Example - Cloud Optimized GeoTiff (COG)\n",
"\n",
"See docs for [rioxarray.open_rasterio](../rioxarray.rst#rioxarray-open-rasterio)"
]
},
{
Expand Down Expand Up @@ -127,7 +129,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.6.7"
}
},
"nbformat": 4,
Expand Down
64 changes: 45 additions & 19 deletions docs/examples/clip_box.ipynb

Large diffs are not rendered by default.

25 changes: 21 additions & 4 deletions docs/examples/clip_geom.ipynb
Expand Up @@ -24,7 +24,10 @@
"source": [
"## Load in xarray dataset\n",
"\n",
"See docs for [rioxarray.open_rasterio](../rioxarray.rst#rioxarray-open-rasterio)\n",
" \n",
"Notes:\n",
"\n",
" - `chunks=True` only works if you have a dask installed. Otherwise, you can skip this.\n",
" - `masked=True` will convert from integer to `float64` and fill with `NaN`. If this behavior is not desired, you can skip this."
]
Expand All @@ -35,7 +38,11 @@
"metadata": {},
"outputs": [],
"source": [
"xds = rioxarray.open_rasterio(\"../../test/test_data/compare/small_dem_3m_merged.tif\", masked=True, chunks=True)"
"xds = rioxarray.open_rasterio(\n",
" \"../../test/test_data/compare/small_dem_3m_merged.tif\",\n",
" masked=True,\n",
" chunks=True,\n",
")"
]
},
{
Expand Down Expand Up @@ -105,7 +112,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Clip using a geometry"
"## Clip using a geometry\n",
"\n",
"API Reference for `rio.clip`:\n",
"\n",
" - [DataArray.clip](../rioxarray.rst#rioxarray.rioxarray.RasterArray.clip)\n",
" - [Dataset.clip](../rioxarray.rst#rioxarray.rioxarray.RasterDataset.clip)"
]
},
{
Expand Down Expand Up @@ -213,7 +225,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Clip using a GeoDataFrame"
"## Clip using a GeoDataFrame\n",
"\n",
"API Reference for `rio.clip`:\n",
"\n",
" - [DataArray.clip](../rioxarray.rst#rioxarray.rioxarray.RasterArray.clip)\n",
" - [Dataset.clip](../rioxarray.rst#rioxarray.rioxarray.RasterDataset.clip)"
]
},
{
Expand Down Expand Up @@ -311,5 +328,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
162 changes: 39 additions & 123 deletions docs/examples/convert_to_raster.ipynb
Expand Up @@ -7,10 +7,10 @@
"# Example - Convert dataset to raster (GeoTiff)\n",
"\n",
"Often, it is desirable to take a variable (band) out of your dataset and export it to a raster.\n",
"This is possible with the `rio.to_raster()` method. It does most of the work for you so you don't\n",
"This is possible with the [rio.to_raster()](../rioxarray.rst#rioxarray.rioxarray.RasterArray.to_raster) method. It does most of the work for you so you don't\n",
"have to.\n",
"\n",
"Note: The `rio.to_raster()` method only works on a 2-dimensional or 3-dimensional `xarray.DataArray`"
"Note: The [rio.to_raster()](../rioxarray.rst#rioxarray.rioxarray.RasterArray.to_raster) method only works on a 2-dimensional or 3-dimensional `xarray.DataArray`"
]
},
{
Expand All @@ -20,10 +20,18 @@
"outputs": [],
"source": [
"import rioxarray\n",
"import rasterio\n",
"import xarray\n",
"import re"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"See docs for [rioxarray.open_rasterio](../rioxarray.rst#rioxarray-open-rasterio)"
]
},
{
"cell_type": "code",
"execution_count": 2,
Expand Down Expand Up @@ -71,127 +79,36 @@
"rds"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\u001b[0;31mSignature:\u001b[0m\n",
"\u001b[0mrds\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgreen\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrio\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto_raster\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mraster_path\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mdriver\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'GTiff'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mtags\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mwindowed\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mrecalc_transform\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mprofile_kwargs\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mDocstring:\u001b[0m\n",
"Export the DataArray to a raster file.\n",
"\n",
"Parameters\n",
"----------\n",
"raster_path: str\n",
" The path to output the raster to.\n",
"driver: str, optional\n",
" The name of the GDAL/rasterio driver to use to export the raster.\n",
" Default is \"GTiff\".\n",
"dtype: str, optional\n",
" The data type to write the raster to. Default is the datasets dtype.\n",
"tags: dict, optional\n",
" A dictionary of tags to write to the raster.\n",
"windowed: bool, optional\n",
" If True, it will write using the windows of the output raster.\n",
" This only works if the output raster is tiled. As such, if you\n",
" set this to True, the output raster will be tiled.\n",
" Default is False.\n",
"**profile_kwargs\n",
" Additional keyword arguments to pass into writing the raster. The\n",
" nodata, transform, crs, count, width, and height attributes\n",
" are ignored.\n",
"\u001b[0;31mFile:\u001b[0m ~/scripts/rioxarray/rioxarray/rioxarray.py\n",
"\u001b[0;31mType:\u001b[0m method\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"rds.green.rio.to_raster?"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"rds.green.rio.to_raster(\"green_band.tif\", tiled=True, compress=\"LZMA\", windowed=True)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"((2, 10, 10), CRS.from_dict(init='epsg:32722'), nan, (-1.5, 7.5, 10.5, 1.5))"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rds.green.shape, rds.green.rio.crs, rds.green.rio.nodata, rds.green.rio.bounds()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\"bounds\": [-0.5, 9.5, 9.5, -0.5], \"colorinterp\": [\"gray\", \"undefined\"], \"compress\": \"lzma\", \"count\": 2, \"crs\": \"EPSG:32722\", \"descriptions\": [null, null], \"driver\": \"GTiff\", \"dtype\": \"float64\", \"height\": 10, \"indexes\": [1, 2], \"interleave\": \"pixel\", \"lnglat\": [-141.2324487629403, -85.5261559938556], \"mask_flags\": [[\"nodata\"], [\"nodata\"]], \"nodata\": NaN, \"res\": [1.0, -1.0], \"shape\": [10, 10], \"tiled\": false, \"transform\": [1.0, 0.0, -0.5, 0.0, 1.0, -0.5, 0.0, 0.0, 1.0], \"units\": [null, null], \"width\": 10}\n"
]
}
],
"source": [
"!rio info green_band.tif"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Managing Information Loss with xarray operations\n",
"\n",
"Sometimes, you can lose important information from your dataset when performing operations.\n",
"You will likely want to keep track of your `nodata` and your `CRS`."
"You will likely want to keep track of your `nodata` and your `CRS`.\n",
"\n",
"API Reference:\n",
"\n",
"- [rio.to_raster()](../rioxarray.rst#rioxarray.rioxarray.RasterArray.to_raster)\n",
"- [rio.write_crs()](../rioxarray.rst#rioxarray.rioxarray.RasterArray.write_crs)\n",
"- [rio.update_attrs()](../rioxarray.rst#rioxarray.rioxarray.RasterArray.update_attrs)\n",
"- [rio.crs](../rioxarray.rst#rioxarray.rioxarray.RasterArray.crs)\n",
"- [rio.nodata](../rioxarray.rst#rioxarray.rioxarray.RasterArray.nodata)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(OrderedDict(), CRS.from_dict(init='epsg:32722'), None)"
"({}, CRS.from_epsg(32722), None)"
]
},
"execution_count": 7,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -203,7 +120,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -212,14 +129,14 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\"bounds\": [-0.5, 9.5, 9.5, -0.5], \"colorinterp\": [\"gray\", \"undefined\"], \"count\": 2, \"crs\": \"EPSG:32722\", \"descriptions\": [null, null], \"driver\": \"GTiff\", \"dtype\": \"float64\", \"height\": 10, \"indexes\": [1, 2], \"interleave\": \"pixel\", \"lnglat\": [-141.2324487629403, -85.5261559938556], \"mask_flags\": [[\"all_valid\"], [\"all_valid\"]], \"nodata\": null, \"res\": [1.0, -1.0], \"shape\": [10, 10], \"tiled\": false, \"transform\": [1.0, 0.0, -0.5, 0.0, 1.0, -0.5, 0.0, 0.0, 1.0], \"units\": [null, null], \"width\": 10}\n"
"{\"bounds\": [466266.0, 8084670.0, 466296.0, 8084700.0], \"colorinterp\": [\"gray\", \"undefined\"], \"count\": 2, \"crs\": \"EPSG:32722\", \"descriptions\": [\"green\", \"green\"], \"driver\": \"GTiff\", \"dtype\": \"float64\", \"height\": 10, \"indexes\": [1, 2], \"interleave\": \"pixel\", \"lnglat\": [-51.31732641226951, -17.322997474192466], \"mask_flags\": [[\"all_valid\"], [\"all_valid\"]], \"nodata\": null, \"res\": [3.0, 3.0], \"shape\": [10, 10], \"tiled\": false, \"transform\": [3.0, 0.0, 466266.0, 0.0, -3.0, 8084700.0, 0.0, 0.0, 1.0], \"units\": [null, null], \"width\": 10}\n"
]
}
],
Expand All @@ -229,25 +146,24 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(OrderedDict([('grid_mapping', 'spatial_ref'),\n",
" ('NETCDF_DIM_time', 0),\n",
" ('nodata', 0),\n",
" ('units', ('DN', 'DN')),\n",
" ('_FillValue', nan),\n",
" ('transform', (3.0, 0.0, 466266.0, 0.0, -3.0, 8084700.0)),\n",
" ('scales', (1.0, 1.0)),\n",
" ('offsets', (0.0, 0.0))]),\n",
" CRS.from_dict(init='epsg:32722'),\n",
"({'grid_mapping': 'spatial_ref',\n",
" 'nodata': 0,\n",
" 'units': ('DN', 'DN'),\n",
" '_FillValue': nan,\n",
" 'transform': (3.0, 0.0, 466266.0, 0.0, -3.0, 8084700.0),\n",
" 'scale_factor': 1.0,\n",
" 'add_offset': 0.0},\n",
" CRS.from_epsg(32722),\n",
" nan)"
]
},
"execution_count": 10,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -261,7 +177,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -270,14 +186,14 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\"bounds\": [-0.5, 9.5, 9.5, -0.5], \"colorinterp\": [\"gray\", \"undefined\"], \"count\": 2, \"crs\": \"EPSG:32722\", \"descriptions\": [null, null], \"driver\": \"GTiff\", \"dtype\": \"float64\", \"height\": 10, \"indexes\": [1, 2], \"interleave\": \"pixel\", \"lnglat\": [-141.2324487629403, -85.5261559938556], \"mask_flags\": [[\"nodata\"], [\"nodata\"]], \"nodata\": NaN, \"res\": [1.0, -1.0], \"shape\": [10, 10], \"tiled\": false, \"transform\": [1.0, 0.0, -0.5, 0.0, 1.0, -0.5, 0.0, 0.0, 1.0], \"units\": [null, null], \"width\": 10}\n"
"{\"bounds\": [466266.0, 8084670.0, 466296.0, 8084700.0], \"colorinterp\": [\"gray\", \"undefined\"], \"count\": 2, \"crs\": \"EPSG:32722\", \"descriptions\": [\"green\", \"green\"], \"driver\": \"GTiff\", \"dtype\": \"float64\", \"height\": 10, \"indexes\": [1, 2], \"interleave\": \"pixel\", \"lnglat\": [-51.31732641226951, -17.322997474192466], \"mask_flags\": [[\"nodata\"], [\"nodata\"]], \"nodata\": NaN, \"res\": [3.0, 3.0], \"shape\": [10, 10], \"tiled\": false, \"transform\": [3.0, 0.0, 466266.0, 0.0, -3.0, 8084700.0, 0.0, 0.0, 1.0], \"units\": [null, null], \"width\": 10}\n"
]
}
],
Expand All @@ -302,7 +218,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.6.7"
}
},
"nbformat": 4,
Expand Down
18 changes: 16 additions & 2 deletions docs/examples/crs_management.ipynb
Expand Up @@ -30,7 +30,21 @@
"\n",
"#### Search order for the CRS for Dataset:\n",
"If the CRS is not found using the search methods above, it also searches the `data_vars` and uses the\n",
"first valid CRS found."
"first valid CRS found.\n",
"\n",
"#### API Documentation\n",
"\n",
"Links to DataArray methods/attributes used:\n",
"\n",
"- [rio.set_crs()](../rioxarray.rst#rioxarray.rioxarray.RasterArray.set_crs)\n",
"- [rio.write_crs()](../rioxarray.rst#rioxarray.rioxarray.RasterArray.write_crs)\n",
"- [rio.crs](../rioxarray.rst#rioxarray.rioxarray.RasterArray.crs)\n",
"\n",
"Links to Dataset methods/attributes used:\n",
"\n",
"- [rio.set_crs()](../rioxarray.rst#rioxarray.rioxarray.RasterDataset.set_crs)\n",
"- [rio.write_crs()](../rioxarray.rst#rioxarray.rioxarray.RasterDataset.write_crs)\n",
"- [rio.crs](../rioxarray.rst#rioxarray.rioxarray.RasterDataset.crs)"
]
},
{
Expand Down Expand Up @@ -322,7 +336,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.6.7"
}
},
"nbformat": 4,
Expand Down

0 comments on commit f285fab

Please sign in to comment.