bmi-topography


Namebmi-topography JSON
Version 0.8.5 PyPI version JSON
download
home_pageNone
SummaryFetch and cache land elevation data from OpenTopography
upload_time2024-08-18 23:38:41
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT License
keywords bmi srtm alos nasadem copernicus topography elevation dem data csdms
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4608652.svg)](https://doi.org/10.5281/zenodo.4608652)
[![Conda Version](https://img.shields.io/conda/vn/conda-forge/bmi-topography.svg)](https://anaconda.org/conda-forge/bmi-topography)
[![PyPI](https://img.shields.io/pypi/v/bmi-topography)](https://pypi.org/project/bmi-topography)
[![Build/Test CI](https://github.com/csdms/bmi-topography/actions/workflows/test.yml/badge.svg)](https://github.com/csdms/bmi-topography/actions/workflows/test.yml)
[![Coverage Status](https://coveralls.io/repos/github/csdms/bmi-topography/badge.svg?branch=main)](https://coveralls.io/github/csdms/bmi-topography?branch=main)
[![Documentation Status](https://readthedocs.org/projects/bmi-topography/badge/?version=latest)](https://bmi-topography.readthedocs.io/en/latest/?badge=latest)

# bmi-topography

*bmi-topography* is a Python library for fetching and caching
land elevation data
using the [OpenTopography][ot] [REST API][ot-rest].

The *bmi-topography* library provides access to the following global raster datasets:

* SRTMGL3 (SRTM GL3 90m)
* SRTMGL1 (SRTM GL1 30m)
* SRTMGL1_E (SRTM GL1 Ellipsoidal 30m)
* AW3D30 (ALOS World 3D 30m)
* AW3D30_E (ALOS World 3D Ellipsoidal, 30m)
* SRTM15Plus (Global Bathymetry SRTM15+ V2.1)
* NASADEM (NASADEM Global DEM)
* COP30 (Copernicus Global DSM 30m)
* COP90 (Copernicus Global DSM 90m)

The library includes an API and a CLI that accept
the dataset type,
a latitude-longitude bounding box, and
the output file format.
Data are downloaded from OpenTopography and cached locally.
The cache is checked before downloading new data.
Data from a cached file can optionally be loaded into an
[xarray][xarray] [DataArray][xarray-da]
through [rioxarray][rioxarray].

The *bmi-topography* API is wrapped with a
[Basic Model Interface][bmi] (BMI),
which provides a standard set of functions for coupling with data or models
that also expose a BMI.
More information on the BMI can found in its [documentation][bmi].

## Installation

Install the latest stable release of *bmi-topography* with `pip`:
```
pip install bmi-topography
```
or with `conda`:
```
conda install -c conda-forge bmi-topography
```

The *bmi-topography* library can also be built and installed from source.
The library uses several other open source libraries,
so a convenient way of building and installing it is within a
[conda environment][conda-env].
After cloning or downloading the *bmi-topography*
[repository][bmi-topo-repo],
change into the repository directory
and set up a conda environment with the included environment file:
```
conda env create --file=environment.yml
```
Then build and install *bmi-topography* from source with
```
pip install -e .
```

## API key

To better understand usage,
OpenTopography [requires an API key][ot-api-key] to access datasets they host.
Getting an API key is easy, and it's free:
just follow the instructions in the link above.

Once you have an API key,
there are three ways to use it with *bmi-topography*:

1. *parameter*: Pass the API key as a string through the `api_key` parameter.
2. *environment variable*: In the shell, set the `OPENTOPOGRAPHY_API_KEY` environment variable to the API key value.
3. *dot file*: Put the API key in the file `.opentopography.txt` in the current directory or in your home directory.

If you attempt to use *bmi-topography* to access an OpenTopography dataset without an API key,
you'll get a error like this:
```
requests.exceptions.HTTPError: 401 Client Error: This dataset requires an API Key for access.
```

## Examples

A brief example of using the *bmi-topography* API is given in the following steps.

Start a Python session and import the `Topography` class:
```python
>>> from bmi_topography import Topography
```

For convenience,
a set of default parameter values for `Topography` are included in the class definition.
Copy these and modify them with custom values:
```python
>>> params = Topography.DEFAULT.copy()
>>> params["south"] = 39.93
>>> params["north"] = 40.00
>>> params["west"] = -105.33
>>> params["east"] = -105.26
>>> params
{'dem_type': 'SRTMGL3',
 'south': 39.93,
 'north': 40.0,
 'west': -105.33,
 'east': -105.26,
 'output_format': 'GTiff',
 'cache_dir': '~/.bmi_topography'}
```
These coordinate values represent an area around Boulder, Colorado.

Make a instance of `Topography` with these parameters:
```python
>>> boulder = Topography(**params)
```
then fetch the data from OpenTopography:
```python
>>> boulder.fetch()
PosixPath('/Users/mpiper/.bmi_topography/SRTMGL3_39.93_-105.33_40.0_-105.26.tif')
```
This step might take a few moments,
and it will increase for requests of larger areas.
Note that the file has been saved to a local cache directory.

Load the data into an xarray `DataArray` for further work:
```python
>>> boulder.load()
<xarray.DataArray 'SRTMGL3' (band: 1, y: 84, x: 84)>
array([[[2052, 2035, ..., 1645, 1643],
        [2084, 2059, ..., 1643, 1642],
        ...,
        [2181, 2170, ..., 1764, 1763],
        [2184, 2179, ..., 1773, 1769]]], dtype=int16)
Coordinates:
  * band         (band) int64 1
  * x            (x) float64 -105.3 -105.3 -105.3 ... -105.3 -105.3 -105.3
  * y            (y) float64 40.0 40.0 40.0 40.0 ... 39.93 39.93 39.93 39.93
    spatial_ref  int64 0
Attributes:
    _FillValue:    0.0
    scale_factor:  1.0
    add_offset:    0.0
    units:         meters
    location:      node
```

Note that coordinate reference system information is stored in the `spatial_ref` non-dimension coordinate:
```python
>>> boulder.da.spatial_ref
<xarray.DataArray 'spatial_ref' ()>
array(0)
Coordinates:
    spatial_ref  int64 0
Attributes:
    crs_wkt:                      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["...
    semi_major_axis:              6378137.0
    semi_minor_axis:              6356752.314245179
    inverse_flattening:           298.257223563
    reference_ellipsoid_name:     WGS 84
    longitude_of_prime_meridian:  0.0
    prime_meridian_name:          Greenwich
    geographic_crs_name:          WGS 84
    grid_mapping_name:            latitude_longitude
    spatial_ref:                  GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["...
    GeoTransform:                 -105.33041666668363 0.000833333333333144 0....
```

Display the elevations with the default xarray `DataArray` [plot][xarray-plot] method.
```python
>>> import matplotlib.pyplot as plt
>>> boulder.da.plot()
>>> plt.show()
```

![Example elevation data displayed through *xarray*.](./examples/bmi-topography_ex.png)

For examples with more detail,
see the two Jupyter Notebooks,
Python script, and shell script
included in the [examples][bmi-topo-examples] directory
of the *bmi-topography* repository.

User and developer documentation for *bmi-topography*
is available at https://bmi-topography.readthedocs.io.

<!-- Links (by alpha) -->

[bmi]: https://bmi.readthedocs.io
[bmi-topo-examples]: https://github.com/csdms/bmi-topography/tree/main/examples
[bmi-topo-repo]: https://github.com/csdms/bmi-topography
[conda-env]: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
[ot]: https://opentopography.org/
[ot-api-key]: https://opentopography.org/blog/introducing-api-keys-access-opentopography-global-datasets
[ot-rest]: https://portal.opentopography.org/apidocs/
[rioxarray]: https://corteva.github.io/rioxarray/stable/getting_started/getting_started.html
[xarray]: http://xarray.pydata.org/en/stable/
[xarray-da]: http://xarray.pydata.org/en/stable/api.html#dataarray
[xarray-plot]: https://xarray.pydata.org/en/stable/generated/xarray.plot.plot.html

Credits
=======

Project lead
------------

* Mark Piper

Contributors
------------

* Eric Hutton
* Mark Piper

Acknowledgments
---------------

This work is supported by the National Science Foundation under Award No.
[2026951](https://www.nsf.gov/awardsearch/showAward?AWD_ID=2026951),
*EarthCube Capabilities: Cloud-Based Accessible and Reproducible Modeling for Water and Sediment Research*.

MIT License
===========

Copyright (c) 2021 Community Surface Dynamics Modeling System

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "bmi-topography",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "Mark Piper <mark.piper@colorado.edu>, Eric Hutton <eric.hutton@colorado.edu>",
    "keywords": "bmi, srtm, alos, nasadem, copernicus, topography, elevation, dem, data, csdms",
    "author": null,
    "author_email": "Mark Piper <mark.piper@colorado.edu>",
    "download_url": "https://files.pythonhosted.org/packages/b4/31/16f407bee7e9577e5c7400b0c517abbfd6904bb6801f7879ec3fa1f292b1/bmi_topography-0.8.5.tar.gz",
    "platform": null,
    "description": "[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4608652.svg)](https://doi.org/10.5281/zenodo.4608652)\n[![Conda Version](https://img.shields.io/conda/vn/conda-forge/bmi-topography.svg)](https://anaconda.org/conda-forge/bmi-topography)\n[![PyPI](https://img.shields.io/pypi/v/bmi-topography)](https://pypi.org/project/bmi-topography)\n[![Build/Test CI](https://github.com/csdms/bmi-topography/actions/workflows/test.yml/badge.svg)](https://github.com/csdms/bmi-topography/actions/workflows/test.yml)\n[![Coverage Status](https://coveralls.io/repos/github/csdms/bmi-topography/badge.svg?branch=main)](https://coveralls.io/github/csdms/bmi-topography?branch=main)\n[![Documentation Status](https://readthedocs.org/projects/bmi-topography/badge/?version=latest)](https://bmi-topography.readthedocs.io/en/latest/?badge=latest)\n\n# bmi-topography\n\n*bmi-topography* is a Python library for fetching and caching\nland elevation data\nusing the [OpenTopography][ot] [REST API][ot-rest].\n\nThe *bmi-topography* library provides access to the following global raster datasets:\n\n* SRTMGL3 (SRTM GL3 90m)\n* SRTMGL1 (SRTM GL1 30m)\n* SRTMGL1_E (SRTM GL1 Ellipsoidal 30m)\n* AW3D30 (ALOS World 3D 30m)\n* AW3D30_E (ALOS World 3D Ellipsoidal, 30m)\n* SRTM15Plus (Global Bathymetry SRTM15+ V2.1)\n* NASADEM (NASADEM Global DEM)\n* COP30 (Copernicus Global DSM 30m)\n* COP90 (Copernicus Global DSM 90m)\n\nThe library includes an API and a CLI that accept\nthe dataset type,\na latitude-longitude bounding box, and\nthe output file format.\nData are downloaded from OpenTopography and cached locally.\nThe cache is checked before downloading new data.\nData from a cached file can optionally be loaded into an\n[xarray][xarray] [DataArray][xarray-da]\nthrough [rioxarray][rioxarray].\n\nThe *bmi-topography* API is wrapped with a\n[Basic Model Interface][bmi] (BMI),\nwhich provides a standard set of functions for coupling with data or models\nthat also expose a BMI.\nMore information on the BMI can found in its [documentation][bmi].\n\n## Installation\n\nInstall the latest stable release of *bmi-topography* with `pip`:\n```\npip install bmi-topography\n```\nor with `conda`:\n```\nconda install -c conda-forge bmi-topography\n```\n\nThe *bmi-topography* library can also be built and installed from source.\nThe library uses several other open source libraries,\nso a convenient way of building and installing it is within a\n[conda environment][conda-env].\nAfter cloning or downloading the *bmi-topography*\n[repository][bmi-topo-repo],\nchange into the repository directory\nand set up a conda environment with the included environment file:\n```\nconda env create --file=environment.yml\n```\nThen build and install *bmi-topography* from source with\n```\npip install -e .\n```\n\n## API key\n\nTo better understand usage,\nOpenTopography [requires an API key][ot-api-key] to access datasets they host.\nGetting an API key is easy, and it's free:\njust follow the instructions in the link above.\n\nOnce you have an API key,\nthere are three ways to use it with *bmi-topography*:\n\n1. *parameter*: Pass the API key as a string through the `api_key` parameter.\n2. *environment variable*: In the shell, set the `OPENTOPOGRAPHY_API_KEY` environment variable to the API key value.\n3. *dot file*: Put the API key in the file `.opentopography.txt` in the current directory or in your home directory.\n\nIf you attempt to use *bmi-topography* to access an OpenTopography dataset without an API key,\nyou'll get a error like this:\n```\nrequests.exceptions.HTTPError: 401 Client Error: This dataset requires an API Key for access.\n```\n\n## Examples\n\nA brief example of using the *bmi-topography* API is given in the following steps.\n\nStart a Python session and import the `Topography` class:\n```python\n>>> from bmi_topography import Topography\n```\n\nFor convenience,\na set of default parameter values for `Topography` are included in the class definition.\nCopy these and modify them with custom values:\n```python\n>>> params = Topography.DEFAULT.copy()\n>>> params[\"south\"] = 39.93\n>>> params[\"north\"] = 40.00\n>>> params[\"west\"] = -105.33\n>>> params[\"east\"] = -105.26\n>>> params\n{'dem_type': 'SRTMGL3',\n 'south': 39.93,\n 'north': 40.0,\n 'west': -105.33,\n 'east': -105.26,\n 'output_format': 'GTiff',\n 'cache_dir': '~/.bmi_topography'}\n```\nThese coordinate values represent an area around Boulder, Colorado.\n\nMake a instance of `Topography` with these parameters:\n```python\n>>> boulder = Topography(**params)\n```\nthen fetch the data from OpenTopography:\n```python\n>>> boulder.fetch()\nPosixPath('/Users/mpiper/.bmi_topography/SRTMGL3_39.93_-105.33_40.0_-105.26.tif')\n```\nThis step might take a few moments,\nand it will increase for requests of larger areas.\nNote that the file has been saved to a local cache directory.\n\nLoad the data into an xarray `DataArray` for further work:\n```python\n>>> boulder.load()\n<xarray.DataArray 'SRTMGL3' (band: 1, y: 84, x: 84)>\narray([[[2052, 2035, ..., 1645, 1643],\n        [2084, 2059, ..., 1643, 1642],\n        ...,\n        [2181, 2170, ..., 1764, 1763],\n        [2184, 2179, ..., 1773, 1769]]], dtype=int16)\nCoordinates:\n  * band         (band) int64 1\n  * x            (x) float64 -105.3 -105.3 -105.3 ... -105.3 -105.3 -105.3\n  * y            (y) float64 40.0 40.0 40.0 40.0 ... 39.93 39.93 39.93 39.93\n    spatial_ref  int64 0\nAttributes:\n    _FillValue:    0.0\n    scale_factor:  1.0\n    add_offset:    0.0\n    units:         meters\n    location:      node\n```\n\nNote that coordinate reference system information is stored in the `spatial_ref` non-dimension coordinate:\n```python\n>>> boulder.da.spatial_ref\n<xarray.DataArray 'spatial_ref' ()>\narray(0)\nCoordinates:\n    spatial_ref  int64 0\nAttributes:\n    crs_wkt:                      GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"...\n    semi_major_axis:              6378137.0\n    semi_minor_axis:              6356752.314245179\n    inverse_flattening:           298.257223563\n    reference_ellipsoid_name:     WGS 84\n    longitude_of_prime_meridian:  0.0\n    prime_meridian_name:          Greenwich\n    geographic_crs_name:          WGS 84\n    grid_mapping_name:            latitude_longitude\n    spatial_ref:                  GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"...\n    GeoTransform:                 -105.33041666668363 0.000833333333333144 0....\n```\n\nDisplay the elevations with the default xarray `DataArray` [plot][xarray-plot] method.\n```python\n>>> import matplotlib.pyplot as plt\n>>> boulder.da.plot()\n>>> plt.show()\n```\n\n![Example elevation data displayed through *xarray*.](./examples/bmi-topography_ex.png)\n\nFor examples with more detail,\nsee the two Jupyter Notebooks,\nPython script, and shell script\nincluded in the [examples][bmi-topo-examples] directory\nof the *bmi-topography* repository.\n\nUser and developer documentation for *bmi-topography*\nis available at https://bmi-topography.readthedocs.io.\n\n<!-- Links (by alpha) -->\n\n[bmi]: https://bmi.readthedocs.io\n[bmi-topo-examples]: https://github.com/csdms/bmi-topography/tree/main/examples\n[bmi-topo-repo]: https://github.com/csdms/bmi-topography\n[conda-env]: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html\n[ot]: https://opentopography.org/\n[ot-api-key]: https://opentopography.org/blog/introducing-api-keys-access-opentopography-global-datasets\n[ot-rest]: https://portal.opentopography.org/apidocs/\n[rioxarray]: https://corteva.github.io/rioxarray/stable/getting_started/getting_started.html\n[xarray]: http://xarray.pydata.org/en/stable/\n[xarray-da]: http://xarray.pydata.org/en/stable/api.html#dataarray\n[xarray-plot]: https://xarray.pydata.org/en/stable/generated/xarray.plot.plot.html\n\nCredits\n=======\n\nProject lead\n------------\n\n* Mark Piper\n\nContributors\n------------\n\n* Eric Hutton\n* Mark Piper\n\nAcknowledgments\n---------------\n\nThis work is supported by the National Science Foundation under Award No.\n[2026951](https://www.nsf.gov/awardsearch/showAward?AWD_ID=2026951),\n*EarthCube Capabilities: Cloud-Based Accessible and Reproducible Modeling for Water and Sediment Research*.\n\nMIT License\n===========\n\nCopyright (c) 2021 Community Surface Dynamics Modeling System\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Fetch and cache land elevation data from OpenTopography",
    "version": "0.8.5",
    "project_urls": {
        "Changelog": "https://github.com/csdms/bmi-topography/blob/main/CHANGES.md",
        "Documentation": "https://bmi-topography.readthedocs.io/",
        "Homepage": "https://csdms.colorado.edu",
        "Repository": "https://github.com/csdms/bmi-topography"
    },
    "split_keywords": [
        "bmi",
        " srtm",
        " alos",
        " nasadem",
        " copernicus",
        " topography",
        " elevation",
        " dem",
        " data",
        " csdms"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bd30fc8c7dee00bfbb7a932f1f73c0a43fc1541977d76a8bcf28cf316217e214",
                "md5": "7c184537ebe63ae739de25f01224f5a2",
                "sha256": "bd3e8094b7b50efd93211666a46ccbdde0aa7141e0d16625d66fe18583552158"
            },
            "downloads": -1,
            "filename": "bmi_topography-0.8.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7c184537ebe63ae739de25f01224f5a2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 17319,
            "upload_time": "2024-08-18T23:38:38",
            "upload_time_iso_8601": "2024-08-18T23:38:38.049684Z",
            "url": "https://files.pythonhosted.org/packages/bd/30/fc8c7dee00bfbb7a932f1f73c0a43fc1541977d76a8bcf28cf316217e214/bmi_topography-0.8.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b43116f407bee7e9577e5c7400b0c517abbfd6904bb6801f7879ec3fa1f292b1",
                "md5": "26790b800dd4e3aeb8e07fc8023862c0",
                "sha256": "a7c6b592ebdd8649081d84d972eb2c3b4838147e128f6d5005943a149651d453"
            },
            "downloads": -1,
            "filename": "bmi_topography-0.8.5.tar.gz",
            "has_sig": false,
            "md5_digest": "26790b800dd4e3aeb8e07fc8023862c0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 5050610,
            "upload_time": "2024-08-18T23:38:41",
            "upload_time_iso_8601": "2024-08-18T23:38:41.097856Z",
            "url": "https://files.pythonhosted.org/packages/b4/31/16f407bee7e9577e5c7400b0c517abbfd6904bb6801f7879ec3fa1f292b1/bmi_topography-0.8.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-18 23:38:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "csdms",
    "github_project": "bmi-topography",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "bmi-topography"
}
        
Elapsed time: 0.73218s