-
Notifications
You must be signed in to change notification settings - Fork 97
DOC: Contributing instructions, BytesIO, switch from rasterio, GDAL config, & external courses #910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
168e141
Add page with rasterio and rioxarray equivalences and add doc about w…
remi-braun 95f2314
Add and initialize external courses toctree
remi-braun 79defcb
Modify course entry
remi-braun 82078c8
Add links
remi-braun 466a9b3
Add Geospatial Python courses by Earth Lab at University of Colorado,…
remi-braun c41ea89
Add a build documentation section in contributing
remi-braun 403899c
Reformat rasterio section
remi-braun dd538f2
Other updates
remi-braun ded9b24
Add GDAL env page
remi-braun 7fca982
Add other rasterio dataset parameters
remi-braun 5b7cadb
Update pages
remi-braun d554aea
Update contributing
remi-braun 38cb5dc
Updates related to PR comments
remi-braun 48477d7
Link functions
remi-braun df412ef
Updates
remi-braun 501f24c
Fix parenthesis
remi-braun 7cb25ff
Apply suggestions from code review
remi-braun f6cfe7d
Apply suggestions from code review
remi-braun 74e1faf
Lint
remi-braun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| .. _gdal_env: | ||
|
|
||
| Configure GDAL environment | ||
| ========================== | ||
|
|
||
| ``rioxarray`` relies on ``rasterio`` so setting up GDAL environment stays the same. See ``rasterio``'s `documentation <https://rasterio.readthedocs.io/en/latest/topics/configuration.html#rasterio>`__ for more insights. | ||
|
|
||
| Setting up GDAL environment is very useful when working with cloud-stored data. | ||
| You can find Development Seed's TiTiler environment proposition `here <https://developmentseed.org/titiler/advanced/performance_tuning/#recommended-configuration-for-dynamic-tiling>`__. | ||
|
|
||
| With Dask clusters | ||
| ~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| When setting up a Dask cluster, be sure to pass the GDAL environment (and AWS session) to every workers. | ||
| First create a function setting up the env and then submit it to every worker. | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| import os | ||
| from dask.distributed import Client | ||
|
|
||
|
|
||
| def set_env(): | ||
| # Set that to dask workers to make process=True work on cloud | ||
| os.environ["AWS_S3_ENDPOINT"] = os.getenv("AWS_S3_ENDPOINT") | ||
| os.environ["AWS_S3_AWS_ACCESS_KEY_ID"] = os.getenv("AWS_S3_AWS_ACCESS_KEY_ID") | ||
| os.environ["AWS_S3_AWS_SECRET_ACCESS_KEY"] = os.getenv( | ||
| "AWS_S3_AWS_SECRET_ACCESS_KEY" | ||
| ) | ||
| os.environ["CPL_VSIL_CURL_ALLOWED_EXTENSIONS"] = ".vrt" | ||
|
|
||
|
|
||
| # Run the client | ||
| with Client(processes=True) as client: | ||
|
|
||
| # Propagate the env variables | ||
| client.run(set_env) | ||
| ... | ||
|
|
||
|
|
||
| .. note:: | ||
|
|
||
| There are gotchas with the environment and dask workers, see this `discussion <https://github.com/corteva/rioxarray/discussions/630>`__ for more insights. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| .. _switching_from_rasterio: | ||
|
|
||
| Switching from ``rasterio`` | ||
| =========================== | ||
|
|
||
| Reasons to switch from ``rasterio`` to ``rioxarray`` | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Usually, switching from ``rasterio`` to ``rioxarray`` means you are working with rasters and you have to adapt your code to ``xarray``. | ||
|
|
||
| ``xarray`` is a powerful abstraction of both the raster dataset and the raster array. There is a lot of advantages to unite these two notions under the same object, as it simplifies the use of the functions, using attributes stored in the object rather than passing arguments to the functions. | ||
|
|
||
| ``xarray`` comes also with a lot of very interesting built-in functions and can leverage several backends to replace ``numpy`` in cases where it is limiting (out-of-memory computation, running the code on clusters, on GPU...). Dask is one of the most well-knwown. ``rioxarray`` handles some basic ``dask`` features in I/O (see `Dask I/O example <https://corteva.github.io/rioxarray/html/examples/dask_read_write.html>`__) but is not designed to support ``dask`` in more evolved functions such as reproject. | ||
|
|
||
| Beware, ``xarray`` comes also with gotchas! You can see some of them in `the dedicated section <https://corteva.github.io/rioxarray/html/getting_started/manage_information_loss.html>`__. | ||
|
|
||
|
|
||
| .. note:: | ||
|
|
||
| ``rasterio`` Dataset and xarray Dataset are two completely different things! Please be careful with these overlapping names. | ||
|
|
||
| Equivalences between ``rasterio`` and ``rioxarray`` | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| To ease the switch from ``rasterio`` and ``rioxarray``, here is a table of the usual parameters or functions used. | ||
|
|
||
| ``ds`` stands for ``rasterio`` Dataset | ||
|
|
||
| Profile | ||
| ------- | ||
|
|
||
| Here is the parameters that you can derive from ``rasterio``'s Dataset profile: | ||
|
|
||
| +----------------------------------+-----------------------------------------------------------------------------------------------------------------------+ | ||
| | ``rasterio`` from ``ds.profile`` | ``rioxarray`` from DataArray | | ||
| +==================================+=======================================================================================================================+ | ||
| | :attr:`blockxsize` | :attr:`.encoding["preferred_chunks"]["x"]` | | ||
| +----------------------------------+-----------------------------------------------------------------------------------------------------------------------+ | ||
| | :attr:`blockysize` | :attr:`.encoding["preferred_chunks"]["y"]` | | ||
| +----------------------------------+-----------------------------------------------------------------------------------------------------------------------+ | ||
| | :attr:`compress` | *Unused in rioxarray* | | ||
| +----------------------------------+-----------------------------------------------------------------------------------------------------------------------+ | ||
| | :attr:`~rasterio.io.DatasetReader.count` | :attr:`rio.count <rioxarray.rioxarray.XRasterBase.count>` | | ||
| +----------------------------------+-----------------------------------------------------------------------------------------------------------------------+ | ||
| | :attr:`~rasterio.io.DatasetReader.crs` | :attr:`rio.crs <rioxarray.rioxarray.XRasterBase.crs>` | | ||
| +----------------------------------+-----------------------------------------------------------------------------------------------------------------------+ | ||
| | :attr:`~rasterio.io.DatasetReader.driver` | Unused in rioxarray | | ||
| +----------------------------------+-----------------------------------------------------------------------------------------------------------------------+ | ||
| | :attr:`~rasterio.io.DatasetReader.dtype` | :attr:`.encoding["rasterio_dtype"]` | | ||
| +----------------------------------+-----------------------------------------------------------------------------------------------------------------------+ | ||
| | :attr:`~rasterio.io.DatasetReader.height` | :attr:`rio.height <rioxarray.rioxarray.XRasterBase.height>` | | ||
| +----------------------------------+-----------------------------------------------------------------------------------------------------------------------+ | ||
| | :attr:`interleave` | Unused in rioxarray | | ||
| +----------------------------------+-----------------------------------------------------------------------------------------------------------------------+ | ||
| | :attr:`~rasterio.io.DatasetReader.nodata` | :attr:`rio.nodata <rioxarray.raster_array.RasterArray.nodata>` (or `encoded_nodata <nodata_management.html>`_ ) | | ||
| +----------------------------------+-----------------------------------------------------------------------------------------------------------------------+ | ||
| | :attr:`tiled` | Unused in rioxarray | | ||
| +----------------------------------+-----------------------------------------------------------------------------------------------------------------------+ | ||
| | :attr:~rasterio.io.DatasetReader.transform` | :func:`rio.transform() <rioxarray.rioxarray.XRasterBase.transform>` | | ||
| +----------------------------------+-----------------------------------------------------------------------------------------------------------------------+ | ||
| | :attr:`~rasterio.io.DatasetReader.width` | :attr:`rio.width <rioxarray.rioxarray.XRasterBase.width>` | | ||
| +----------------------------------+-----------------------------------------------------------------------------------------------------------------------+ | ||
|
|
||
| The values not used in ``rioxarray`` comes from the abstraction of the dataset in ``xarray``: a dataset no longer belongs to a file on disk even if read from it. The driver and other file-related notions are meaningless in this context. | ||
|
|
||
| Other dataset parameters | ||
| ------------------------ | ||
|
|
||
| +----------------------------------+-------------------------------------------------------------------+ | ||
| | ``rasterio`` from ``ds`` | ``rioxarray`` from DataArray | | ||
| +==================================+===================================================================+ | ||
| | :attr:`~rasterio.io.DatasetReader.gcps` or :func:`~rasterio.io.DatasetReader.get_gcps` | :func:`rio.get_gcps() <rioxarray.rioxarray.XRasterBase.get_gcps>` | | ||
| +----------------------------------+-------------------------------------------------------------------+ | ||
| | :attr:`~rasterio.io.DatasetReader.rpcs` | :func:`rio.get_rpcs() <rioxarray.rioxarray.XRasterBase.get_rpcs>` | | ||
| +----------------------------------+-------------------------------------------------------------------+ | ||
| | :attr:`~rasterio.io.DatasetReader.bounds` | :func:`rio.bounds() <rioxarray.rioxarray.XRasterBase.bounds>` | | ||
| +----------------------------------+-------------------------------------------------------------------+ | ||
|
|
||
| Functions | ||
| --------- | ||
|
|
||
| +------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | ||
| | ``rasterio`` | ``rioxarray`` | | ||
| +====================================+===================================================================================================================================+ | ||
| | :func:`rasterio.open` | :func:`rioxarray.open_rasterio` or :attr:`xarray.open_dataset(..., engine="rasterio", decode_coords="all") <xarray.open_dataset>` | | ||
| +------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | ||
| | :func:`~rasterio.io.DatasetReader.read` | :func:`compute() <xarray.DataArray.compute>` (load data into memory) | | ||
| +------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | ||
| | :func:`ds.read(... window=) <rasterio.io.DatasetReader.read>` | :func:`rio.isel_window() <rioxarray.rioxarray.XRasterBase.isel_window>` | | ||
| +------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | ||
| | :func:`~rasterio.io.DatasetWriter.write` | :func:`rio.to_raster() <rioxarray.raster_array.RasterArray.to_raster>` | | ||
| +------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | ||
| | :func:`mask(..., crop=False) <rasterio.mask.mask>` | :func:`rio.clip(..., drop=False) <rioxarray.raster_array.RasterArray.clip>` | | ||
| +------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | ||
| | :func:`mask(..., crop=True) <rasterio.mask.mask>` | :func:`rio clip(..., drop=True) <rioxarray.raster_array.RasterArray.clip>` | | ||
| +------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | ||
| | :func:`~rasterio.warp.reproject` | :func:`rio.reproject() <rioxarray.raster_array.RasterArray.reproject>` | | ||
| +------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | ||
| | :func:`~rasterio.merge.merge` | :func:`rioxarray.merge.merge_arrays` | | ||
| +------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | ||
| | :func:`~rasterio.fill.fillnodata` | :func:`rio.interpolate_na() <rioxarray.raster_array.RasterArray.interpolate_na>` | | ||
| +------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | ||
|
|
||
|
|
||
|
|
||
| By default, ``xarray`` is lazy and therefore not loaded into memory, hence the ``compute`` equivalent to ``read``. | ||
|
|
||
|
|
||
| Going back to ``rasterio`` | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| ``rioxarray`` 0.21+ enables recreating a ``rasterio`` Dataset from ``rioxarray``. | ||
| This is useful when translating your code from ``rasterio`` to ``rioxarray``, even if it is sub-optimal, because the array will be loaded and written in memory behind the hood. | ||
| It is always better to look for ``rioxarray``'s native functions. | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| with dataarray.rio.to_rasterio_dataset() as rio_ds: | ||
| ... |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.