Skip to content

Commit

Permalink
reorg docs navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenpawley committed May 20, 2024
1 parent 1f3a4a0 commit 0bf73e3
Show file tree
Hide file tree
Showing 21 changed files with 141 additions and 52 deletions.
4 changes: 2 additions & 2 deletions _freeze/docs/geoprocessing/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"hash": "8123d3a3f702c15b1bb93adfcbf4c95d",
"hash": "5f253fe0d4b07a283614d077bb8a5e51",
"result": {
"engine": "jupyter",
"markdown": "---\ntitle: Raster Geoprocessing\nformat:\n html:\n code-fold: false\n---\n\nPyspatialml includes common geoprocessing methods that collectively operate on\nstacks of raster datasets, such as cropping, reprojecting, masking etc. Most\nof these methods are simple wrappers around underlying rasterio functions, but\napplied to stacks of raster datasets.\n\n## Handling of Temporary Files\n\nAll of the geoprocessing methods have a `file_path` parameter to specify a file\npath to save the results of th geoprocessing operation. However, pyspatialml is\ndesigned for quick an interactive analyses on raster datasets, and if a file\npath is not specified then the results are saved to a temporary file location\nand a new Raster object is returned with the geoprocessing results.\n\nFor datasets that will easily fit into memory, all geoprocessing methods also\nhave an `in_memory` parameter. If `in_memory=True` is set, then the results\nwill be created using Rasterio's in-memory files and stored in RAM. This has\nperformance advantages, at the expense of memory expenditure.\n\n## Cropping\n\nAll layers within a Raster can be cropped to a new extent using the\n`Raster.crop` method.\n\n::: {#348dfba4 .cell execution_count=1}\n``` {.python .cell-code}\nimport geopandas as gpd\nimport matplotlib.pyplot as plt\nfrom pyspatialml import Raster\nfrom pyspatialml.datasets import nc\n\npredictors = [nc.band1, nc.band2, nc.band3, nc.band4, nc.band5, nc.band7]\ntraining_py = gpd.read_file(nc.polygons)\n\nstack = Raster(predictors)\n\nstack.plot()\nplt.show()\n```\n\n::: {.cell-output .cell-output-display}\n![](geoprocessing_files/figure-html/cell-2-output-1.png){width=604 height=372}\n:::\n:::\n\n\n::: {#83a2f02e .cell execution_count=2}\n``` {.python .cell-code}\n# crop to new extent (xmin, ymin, xmax, ymax)\ncrop_bounds = training_py.loc[0, \"geometry\"].bounds\nstack_cropped = stack.crop(crop_bounds)\n\nstack_cropped.plot()\nplt.show()\n```\n\n::: {.cell-output .cell-output-display}\n![](geoprocessing_files/figure-html/cell-3-output-1.png){width=604 height=370}\n:::\n:::\n\n\n## Masking\n\nIn comparison to cropping, masking can be used to set pixels that occur outside\nof masking geometries to NaN, and optionally can also crop a Raster.\n\n::: {#1e020e6a .cell execution_count=3}\n``` {.python .cell-code}\nimport geopandas as gpd\nimport pyspatialml.datasets.nc as nc\nfrom pyspatialml import Raster\n\ntraining_py = gpd.read_file(nc.polygons)\nmask_py = training_py.iloc[0:1, :]\n\npredictors = [nc.band1, nc.band2, nc.band3, nc.band4, nc.band5, nc.band7]\nstack = Raster(predictors)\n\n# mask a Raster\nmasked_object = stack.mask(mask_py)\n```\n:::\n\n\n## Intersecting Layers\n\nThe `Raster.intersect` method computes the geometric intersection of the\nRasterLayers with the Raster object. This will cause nodata values in any of\nthe rasters to be propagated through all of the output rasters.\n\n::: {#3ca232a1 .cell execution_count=4}\n``` {.python .cell-code}\nimport pyspatialml.datasets.nc as nc\nfrom pyspatialml import Raster\n\npredictors = [nc.band1, nc.band2, nc.band3, nc.band4, nc.band5, nc.band7]\nstack = Raster(predictors)\n\nresult = stack.intersect()\n```\n:::\n\n\nThe intersect method is memory-safe, i.e. the intersection occurs during\nwindowed reading and writing of the Raster. The size and dimensions of the\nwindows can be changed using the `Raster.block_shapes` property.\n\n## Reprojecting\n\nReprojecting a raster using the `Raster.to_crs` method.\n\n::: {#603ee1d3 .cell execution_count=5}\n``` {.python .cell-code}\nstack_prj = stack.to_crs(crs={\"init\": \"EPSG:4326\"})\n```\n:::\n\n\nOther parameters that can be passed and their defaults are\nresampling=\"nearest\", file_path=None, driver=\"GTiff\", nodata=None, n_jobs=1,\nwarp_mem_lim=0, progress=False, and other kwargs that are passed to the raster\nformat drivers.\n\n## Resampling\n\nThe `Raster.aggregate` method is used to resample a raster to a different\nresolution using the decimated reading approach in the rasterio library.\n\n::: {#0221ad98 .cell execution_count=6}\n``` {.python .cell-code}\nstack.aggregate(out_shape=(50, 50), resampling=\"nearest\", driver=\"GTiff\")\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nRaster Object Containing 6 Layers\n attribute values\n0 names [lsat7_2000_10, lsat7_2000_20, lsat7_2000_30, ...\n1 files [/var/folders/_m/kbp8r1612yj1xl6ndb2y8vpm0000g...\n2 rows 50\n3 cols 50\n4 res (278.73, 252.51)\n5 nodatavals [-3.4028234663852886e+38, -3.4028234663852886e...\n```\n:::\n\n::: {.cell-output .cell-output-display execution_count=6}\n```\n\n```\n:::\n:::\n\n\n## Computation\n\nApply user-supplied function to a Raster object.\n\n::: {#69ee5a1c .cell execution_count=7}\n``` {.python .cell-code}\ndef myfun(x):\n return x + 1\n\nstack.apply(myfun)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nRaster Object Containing 6 Layers\n attribute values\n0 names [tmpzi3ud0tl_1, tmpzi3ud0tl_2, tmpzi3ud0tl_3, ...\n1 files [/var/folders/_m/kbp8r1612yj1xl6ndb2y8vpm0000g...\n2 rows 443\n3 cols 489\n4 res (28.5, 28.5)\n5 nodatavals [-3.4028234663852886e+38, -3.4028234663852886e...\n```\n:::\n\n::: {.cell-output .cell-output-display execution_count=7}\n```\n\n```\n:::\n:::\n\n\nWhere `function` is a user-defined python that takes an numpy array as a\nsingle argument, and can return either a 2d array that represents a single\nraster dataset, such as NDVI, or can operate on a number of layers and can\nreturn a raster with multiple layers in a 3d array in (layer, row, col)\norder.\n\nThe apply function is memory-safe, i.e. it applies the function to windows\nof the raster data that are read sequentially or in parallel\n(with n_jobs != 1). The size and dimensions of the windows can be changed\nusing the `Raster.block_shapes` property.\n\n## Raster Algebra\n\nRasterLayer objects also support basic raster math operations using python's\nmagic methods, which supports all of the usual math operators. Calculations\non RasterLayers occur in memory using Rasterio's in-memory files, thus they\nare not memory safe. For applying computations and algebra to large raster\ndatasets in windows, use `Raster.apply()`.\n\n::: {#9f76d5a9 .cell execution_count=8}\n``` {.python .cell-code}\na = stack.iloc[0] + stack.iloc[1]\nb = stack.iloc[0] - stack.iloc[1]\n\nndvi = (stack.iloc[3] - stack.iloc[2]) / (stack.iloc[3] + stack.iloc[2])\n```\n:::\n\n\nArithmetic operations on RasterLayer's will return another RasterLayer. The\nresult can be coerced into a Raster object using:\n\n::: {#d6126218 .cell execution_count=9}\n``` {.python .cell-code}\nndvi = Raster((stack.iloc[3] - stack.iloc[2]) / (stack.iloc[3] + stack.iloc[2]))\n```\n:::\n\n\nCurrently, arithmetic operations are only supported on RasterLayer objects and\nnot in a parent Raster object directly.\n\n",
"markdown": "---\ntitle: Raster Geoprocessing\nformat:\n html:\n code-fold: false\n toc: true\n---\n\nPyspatialml includes common geoprocessing methods that collectively operate on\nstacks of raster datasets, such as cropping, reprojecting, masking etc. Most\nof these methods are simple wrappers around underlying rasterio functions, but\napplied to stacks of raster datasets.\n\n## Handling of Temporary Files\n\nAll of the geoprocessing methods have a `file_path` parameter to specify a file\npath to save the results of th geoprocessing operation. However, pyspatialml is\ndesigned for quick an interactive analyses on raster datasets, and if a file\npath is not specified then the results are saved to a temporary file location\nand a new Raster object is returned with the geoprocessing results.\n\nFor datasets that will easily fit into memory, all geoprocessing methods also\nhave an `in_memory` parameter. If `in_memory=True` is set, then the results\nwill be created using Rasterio's in-memory files and stored in RAM. This has\nperformance advantages, at the expense of memory expenditure.\n\n## Cropping\n\nAll layers within a Raster can be cropped to a new extent using the\n`Raster.crop` method.\n\n::: {#ea62e8fb .cell execution_count=1}\n``` {.python .cell-code}\nimport geopandas as gpd\nimport matplotlib.pyplot as plt\nfrom pyspatialml import Raster\nfrom pyspatialml.datasets import nc\n\npredictors = [nc.band1, nc.band2, nc.band3, nc.band4, nc.band5, nc.band7]\ntraining_py = gpd.read_file(nc.polygons)\n\nstack = Raster(predictors)\n\nstack.plot()\nplt.show()\n```\n\n::: {.cell-output .cell-output-display}\n![](geoprocessing_files/figure-html/cell-2-output-1.png){width=604 height=372}\n:::\n:::\n\n\n::: {#27da6008 .cell execution_count=2}\n``` {.python .cell-code}\n# crop to new extent (xmin, ymin, xmax, ymax)\ncrop_bounds = training_py.loc[0, \"geometry\"].bounds\nstack_cropped = stack.crop(crop_bounds)\n\nstack_cropped.plot()\nplt.show()\n```\n\n::: {.cell-output .cell-output-display}\n![](geoprocessing_files/figure-html/cell-3-output-1.png){width=604 height=370}\n:::\n:::\n\n\n## Masking\n\nIn comparison to cropping, masking can be used to set pixels that occur outside\nof masking geometries to NaN, and optionally can also crop a Raster.\n\n::: {#62aa311f .cell execution_count=3}\n``` {.python .cell-code}\nimport geopandas as gpd\nimport pyspatialml.datasets.nc as nc\nfrom pyspatialml import Raster\n\ntraining_py = gpd.read_file(nc.polygons)\nmask_py = training_py.iloc[0:1, :]\n\npredictors = [nc.band1, nc.band2, nc.band3, nc.band4, nc.band5, nc.band7]\nstack = Raster(predictors)\n\n# mask a Raster\nmasked_object = stack.mask(mask_py)\n```\n:::\n\n\n## Intersecting Layers\n\nThe `Raster.intersect` method computes the geometric intersection of the\nRasterLayers with the Raster object. This will cause nodata values in any of\nthe rasters to be propagated through all of the output rasters.\n\n::: {#95547375 .cell execution_count=4}\n``` {.python .cell-code}\nimport pyspatialml.datasets.nc as nc\nfrom pyspatialml import Raster\n\npredictors = [nc.band1, nc.band2, nc.band3, nc.band4, nc.band5, nc.band7]\nstack = Raster(predictors)\n\nresult = stack.intersect()\n```\n:::\n\n\nThe intersect method is memory-safe, i.e. the intersection occurs during\nwindowed reading and writing of the Raster. The size and dimensions of the\nwindows can be changed using the `Raster.block_shapes` property.\n\n## Reprojecting\n\nReprojecting a raster using the `Raster.to_crs` method.\n\n::: {#7f381ff1 .cell execution_count=5}\n``` {.python .cell-code}\nstack_prj = stack.to_crs(crs={\"init\": \"EPSG:4326\"})\n```\n:::\n\n\nOther parameters that can be passed and their defaults are\nresampling=\"nearest\", file_path=None, driver=\"GTiff\", nodata=None, n_jobs=1,\nwarp_mem_lim=0, progress=False, and other kwargs that are passed to the raster\nformat drivers.\n\n## Resampling\n\nThe `Raster.aggregate` method is used to resample a raster to a different\nresolution using the decimated reading approach in the rasterio library.\n\n::: {#ea8062fa .cell execution_count=6}\n``` {.python .cell-code}\nstack.aggregate(out_shape=(50, 50), resampling=\"nearest\", driver=\"GTiff\")\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nRaster Object Containing 6 Layers\n attribute values\n0 names [lsat7_2000_10, lsat7_2000_20, lsat7_2000_30, ...\n1 files [/var/folders/_m/kbp8r1612yj1xl6ndb2y8vpm0000g...\n2 rows 50\n3 cols 50\n4 res (278.73, 252.51)\n5 nodatavals [-3.4028234663852886e+38, -3.4028234663852886e...\n```\n:::\n\n::: {.cell-output .cell-output-display execution_count=6}\n```\n\n```\n:::\n:::\n\n\n## Computation\n\nApply user-supplied function to a Raster object.\n\n::: {#7bb1d342 .cell execution_count=7}\n``` {.python .cell-code}\ndef myfun(x):\n return x + 1\n\nstack.apply(myfun)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nRaster Object Containing 6 Layers\n attribute values\n0 names [tmpsdyk3x5h_1, tmpsdyk3x5h_2, tmpsdyk3x5h_3, ...\n1 files [/var/folders/_m/kbp8r1612yj1xl6ndb2y8vpm0000g...\n2 rows 443\n3 cols 489\n4 res (28.5, 28.5)\n5 nodatavals [-3.4028234663852886e+38, -3.4028234663852886e...\n```\n:::\n\n::: {.cell-output .cell-output-display execution_count=7}\n```\n\n```\n:::\n:::\n\n\nWhere `function` is a user-defined python that takes an numpy array as a\nsingle argument, and can return either a 2d array that represents a single\nraster dataset, such as NDVI, or can operate on a number of layers and can\nreturn a raster with multiple layers in a 3d array in (layer, row, col)\norder.\n\nThe apply function is memory-safe, i.e. it applies the function to windows\nof the raster data that are read sequentially or in parallel\n(with n_jobs != 1). The size and dimensions of the windows can be changed\nusing the `Raster.block_shapes` property.\n\n## Raster Algebra\n\nRasterLayer objects also support basic raster math operations using python's\nmagic methods, which supports all of the usual math operators. Calculations\non RasterLayers occur in memory using Rasterio's in-memory files, thus they\nare not memory safe. For applying computations and algebra to large raster\ndatasets in windows, use `Raster.apply()`.\n\n::: {#ecdd3638 .cell execution_count=8}\n``` {.python .cell-code}\na = stack.iloc[0] + stack.iloc[1]\nb = stack.iloc[0] - stack.iloc[1]\n\nndvi = (stack.iloc[3] - stack.iloc[2]) / (stack.iloc[3] + stack.iloc[2])\n```\n:::\n\n\nArithmetic operations on RasterLayer's will return another RasterLayer. The\nresult can be coerced into a Raster object using:\n\n::: {#801a16a6 .cell execution_count=9}\n``` {.python .cell-code}\nndvi = Raster((stack.iloc[3] - stack.iloc[2]) / (stack.iloc[3] + stack.iloc[2]))\n```\n:::\n\n\nArithmetic operations are only supported on RasterLayer objects and\nnot in a parent Raster object directly.\n\n",
"supporting": [
"geoprocessing_files"
],
Expand Down
12 changes: 12 additions & 0 deletions _freeze/docs/index/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"hash": "ad8c6f130700c0c117e7364cfea56be7",
"result": {
"engine": "jupyter",
"markdown": "---\ntitle: Overview\nformat:\n html:\n code-fold: false\n---\n\nPyspatialml is a Python package for applying scikit-learn machine learning\nmodels to raster-based datasets. It is inspired by the famous \n[raster](https://cran.r-project.org/web/packages/raster/index.html)\npackage in the R statistical programming language which has been extensively\nused for applying statistical and machine learning models to geospatial raster\ndatasets.\n\nPyspatialml includes functions and classes for working with multiple raster\ndatasets and applying typical machine learning workflows including raster data\nmanipulation, feature engineering on raster datasets, extraction of training\ndata, and application of the ``predict`` or ``predict_proba`` methods of\nscikit-learn estimator objects to a stack of raster datasets.\n\nPyspatialml is built upon the \n[rasterio](https://rasterio.readthedocs.io/en/latest/) Python package which\nperforms all of the heavy lifting and is designed to work with the\n[geopandas](https://geopandas.org) package for related raster-vector data\ngeoprocessing operations.\n\n## Purpose\n\nA supervised machine-learning workflow as applied to spatial raster data\ntypically involves several steps:\n\n1. Using vector features or labelled pixels to extract training data from a\n stack of raster-based predictors (e.g. spectral bands, terrain derivatives,\n or climate grids). The training data represent locations when some\n property/state/concentration is already established, and might comprise\n point locations of arsenic concentrations, or labelled pixels with\n integer-encoded values that correspond to known landcover types.\n\n2. Developing a machine learning classification or regression model on the\n training data. Pyspatialml is designed to use scikit-learn compatible api's\n for this purpose.\n3. Applying the fitted machine learning model to make predictions on all of\n the pixels in the stack of raster data.\n\nPyspatialml is designed to make it easy to develop spatial prediction models on\nstacks of 2D raster datasets that are held on disk. Unlike using python's\n``numpy`` module directly where raster datasets need to be held in memory, the\nmajority of functions within pyspatialml work with raster datasets that are\nstored on disk and allow processing operations to be performed on datasets that\nare too large to be loaded into memory.\n\nPyspatialml is designed to make it easy to work with typical raster data stacks\nconsisting of multiple 2D grids such as different spectal bands, maps etc.\nHowever, it's purpose is not to work with multidimensional datasets, i.e. those\nthat have more than 3 dimensions such as spacetime cubes of multiband data. The\n[xarray](http://xarray.pydata.org/en/stable/index.html) package can provide a\nstructure for this type of data.\n\n",
"supporting": [
"index_files"
],
"filters": [],
"includes": {}
}
}
12 changes: 12 additions & 0 deletions _freeze/docs/installation/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"hash": "65228f7d1a193c5cace2c9a9607b0799",
"result": {
"engine": "jupyter",
"markdown": "---\ntitle: Installation\nformat:\n html:\n code-fold: false\n---\n\nPyspatialml is available on PyPI and can be installed in the usual manner with:\n\n::: {#c5a4b2b4 .cell execution_count=1}\n``` {.python .cell-code}\npip install Pyspatialml\n```\n:::\n\n\nThe development version, which is more up-to-date with changes to the package\nespecially during these earlier stages of development, can be installed\ndirectly via:\n\n::: {#3b8af2ce .cell execution_count=2}\n``` {.python .cell-code}\npip install git+https://github.com/stevenpawley/Pyspatialml\n```\n:::\n\n\n",
"supporting": [
"installation_files"
],
"filters": [],
"includes": {}
}
}
16 changes: 16 additions & 0 deletions _freeze/docs/landcover/execute-results/html.json

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0bf73e3

Please sign in to comment.