Code Monkey home page Code Monkey logo

richdem's Introduction

RichDEM

ReadTheDocs Travis DOI

Author: Richard Barnes ([email protected])

RichDEM is a set of digital elevation model (DEM) hydrologic analysis tools. RichDEM uses parallel processing and state of the art algorithms to quickly process even very large DEMs.

RichDEM offers a variety of flow metrics, such as D8 and D∞. It can flood or breach depressions. It can calculate flow accumulation, slops, curvatures, &c.

RichDEM is available as a performant C++ library, a low-dependency Python package, and a set of command-line tools.

Please cite RichDEM (see below).

Using It

Citing It

As of 883ea734e957, David A. Wheeler's SLOCCount estimates the value of RichDEM at $240,481 and 1.78 person-years of development effort. This value is yours to use, but citations are encouraged as they provide justification of continued development.

General usage of the library can be cited as:

Barnes, Richard. 2016. RichDEM: Terrain Analysis Software. http://github.com/r-barnes/richdem

An example BibTeX entry is:

@manual{RichDEM,
  title        = {RichDEM: Terrain Analysis Software},
  author       = {Richard Barnes},
  year         = {2016},
  url          = {http://github.com/r-barnes/richdem},
}

This information will be updated as versioned releases become available.

Although I have written all of the code in this library, some of the algorithms were discovered or invented by others, and they deserve credit for their good work. Citations to particular algorithms will be printed whenever an app, program, or library function is run. Such citations are prefixed by the character C and look like:

C Barnes, R., Lehman, C., Mulla, D., 2014. Priority-flood: An optimal depression-filling and watershed-labeling algorithm for digital elevation models. Computers & Geosciences 62, 117–127. doi:10.1016/j.cageo.2013.04.024

A typical academic citation might read as follows:

We performed hydrological corrections on our DEM using the Zhou (2016) algorithm implemented in RichDEM (Barnes 2016).

Compilation

To compile, first acquire the source code:

git clone --recursive https://github.com/r-barnes/richdem

You will need a C++ compiler, cmake, and, optionally, libgdal. If you are using conda, you can install these requirements in a new environment with the following commands:

$ conda create -n richdem
$ conda activate richdem
$ conda install --file=requirements.txt -c conda-forge

Then compile using the standard cmake sequence:

$ mkdir build
$ cd build
$ cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
$ make -j 6    # Adjust to use more or fewer processors

If you do not want to build richdem with gdal, use the -DUSE_GDAL=OFF option. To install richdem:

$ cmake --install . --prefix /my/install/prefix

If you are using conda, /my/install/prefix should be $CONDA_PREFIX.

RichDEM includes some programs to process extremely large digital elevation models, as well as for handling many DEM formats. Special prerequisites, automatically detected by cmake, are needed for these to compile: GDAL, MPI, and Boost. To install these on a Debian machine use:

sudo apt install openmpi-bin libgdal-dev libopenmpi-dev libboost-iostreams-dev

As A Python Package

From source

After installing the richdem library (as described above), you can build richdem as a Python package. To do this, you will of course need Python (3.7+), which you can install with conda,

$ conda install python

You can now build the richdem Python package,

$ cd wrappers/pyrichdem
$ pip install pybind11
$ python3 setup.py install --user

From conda

To install a pre-built version of richdem using conda,

$ conda install richdem -c conda-forge

From Google Colabs

You can compile and run RichDEM from source in Google Colabs by placing these commands into a cell and running it.

!pip install pybind11
!git clone --recursive https://github.com/r-barnes/richdem.git ghrichdem
!cd ghrichdem/wrappers/pyrichdem && pip install .

From PyPI using pip

Get the package with:

$ pip install richdem

And use:

>>> import richdem

The command:

>>> help(richdem)

provides all the relevant documentation.

As A Command-line Tool

To get the command-line tools, install the Python package with:

pip3 install richdem

The command-line tools are all named rd_*, so typing rd_ on your command- line and hitting tab a few times should give you the full list of what's available.

As A Library

Upon compilation, point your library search path to the include directory. Include various files using, e.g.

#include "richdem/common/Array2D.hpp"

All files include extensive documentation. At this stage the location of certain functions may be subject to change. This will be noted in the NEWS file. (TODO)

As A Handy Collection of Tools

Running make in the apps directory will produce a large number of useful scripts which are essentially wrappers around standard uses of the RichDEM libraries. The apps/README.md file and the apps themselves contain documentation explaining what they all do.

For Processing Large Datasets

The programs directory contains several programs which have not been converted to libraries. This is usually because their functionality is specific and they are unlikely to be useful as a library. Each directory contains a makefile and a readme explaining the purpose of the program.

Documentation

Documentation is available at richdem.com. The documentation is auto-generated from the many README.md files throughout the codebase and the extensive comments in the source code.

Design Philosophy

The design of RichDEM is guided by these principles:

  • Algorithms will be well-tested. Every algorithm is verified by a rigorous testing procedure. See below.

  • Algorithms will be fast, without compromising safety and accuracy. The algorithms used in RichDEM are state of the art, permitting analyses that would take days on other systems to be performed in hours, or even minutes.

  • Algorithms will be available as libraries, whenever possible. RichDEM is designed as a set of header-only C++ libraries, making it easy to include in your projects and easy to incorporate into other programming languages. RichDEM also includes apps, which are simple wrappers around the algorithms, and a limited, but growing, set of algorithms which may have special requirements, like MPI, that make them unsuitable as libraries. These are available as programs.

  • Programs will have a command-line interface, not a GUI. Command-line interfaces are simple to use and offer extreme flexibility for both users and programmers. They are available on every type of operating system. RichDEM does not officially support any GUI. Per the above, encapsulating RichDEM in a high-level interface of your own is not difficult.

  • Algorithms and programs will be portable. Linux, Mac, and Windows should all be supported.

  • The code will be beautiful. RichDEM's code utilizes sensible variable names and reasonable abstractions to make it easy to understand, use, and design algorithms. The code contains extensive internal documentation which is DOxygen compatible.

  • Programs and algorithms will provide useful feedback. Progress bars will appear if desired and the output will be optimized for machine parsing.

  • Analyses will be reproducible. Every time you run a RichDEM command that command is logged and timestamped in the output data, along with the version of the program you created the output with. Additionally, a history of all previous manipulations to the data is kept. Use rd_view_processing_history to see this.**

Testing Methodology

Simple algorithms are shown to be correct through visual inspection and comparison against hand-crafted examples. Correctness for more complex algorithms is often "boot-strapped" by comparing the results of simple algorithms versus the complex algorithms on a large number of randomly-generated datasets.

This is a work in progress. TODO

Correctness

Correctness is established via a number of methodologies building from code inspection in the simplest cases to output comparison between simple and complex implementations.

Correctness is noted in source code comments under @correctness sections. These are, in turn, printed to the Doxygen documentation output.

A master list of how correctness was established for each algorithm is available at tests/README.md.

Parsable Output

Every line of output from RichDEM begins with one of the following characters, making it easy to parse with a machine.

  • A: Algorithm name

  • a: Analysis command: the command line used to run the program

  • c: Configuration information: program version, input files, and command line options, &c.

  • C: Citation for algorithm

  • d: Debugging info

  • E: Indicates an error condition

  • i: I/O: Amount of data loaded from disk

  • m: Miscallaneous counts

  • n: I/O: Amount of data transferred through a network

  • p: Progress information: inform the user to keep calm because we're carrying on.

  • r: Amount of RAM used

  • t: Timing information: How long stuff took

  • W: Indicates a warning

All output data shall have the form:

<INDICATOR CHARACTER> <MESSAGE/MEASUREMENT NAME> [= <VALUE> [UNIT]]

The amount of whitespace may very for aesthetic purposes.

Specific Algorithms

Many of the algorithms used in RichDEM are documented in journal or conference publications. In the case of older algorithms by other authors, it is often possible to find the paper in the literature. Some of the newer algorithms I developed have not yet had a chance to be widely utilized. These algorithms are listed below.

Additionally, each publication has its own GitHub repository featuring easily-compiled, minimum working examples of the algorithms, along with examples and test data sets.

These are available as follows:

  • Flat-resolution algorithm. Link
  • Depression-filling algorithm. Link
  • Large dataset depression-filling algorithm. Link
  • Large dataset flow accumulation algorithm. Link

Publications

The algorithms used in RichDEM have been published in the following articles. Every algorithm/program will provide its relevant citation information when run.

  • Barnes, R., 2017. Parallel non-divergent flow accumulation for trillion cell digital elevation models on desktops or clusters. Environmental Modelling & Software 92, 202–212. doi:10.1016/j.envsoft.2017.02.022

  • Barnes, R., 2016. Parallel priority-flood depression filling for trillion cell digital elevation models on desktops or clusters. Computers & Geosciences 96, 56–68. doi:10.1016/j.cageo.2016.07.001

  • Barnes, R., Lehman, C., Mulla, D., 2014a. An efficient assignment of drainage direction over flat surfaces in raster digital elevation models. Computers & Geosciences 62, 128–135. doi:10.1016/j.cageo.2013.01.009

  • Barnes, R., Lehman, C., Mulla, D., 2014b. Priority-flood: An optimal depression-filling and watershed-labeling algorithm for digital elevation models. Computers & Geosciences 62, 117–127. doi:10.1016/j.cageo.2013.04.024

  • Barnes, Lehman, Mulla. 2011. "Distributed Parallel D8 Up-Slope Area Calculation in Digital Elevation Models". Intn'l Conf. on Parallel & Distributed Processing Techniques & Applications. Link

  • Horn, B.K.P., 1981. Hill shading and the reflectance map. Proceedings of the IEEE 69, 14–47. doi:10.1109/PROC.1981.11918

  • Mulla et al. including Barnes. 2012. "Strategic Planning for Minnesota’s Natural and Artificial Watersheds". Report to the Minnesota LCCMR.

  • Tarboton, D.G. 1997. A new method for the determination of flow directions and upslope areas in grid digital elevation models. Water Resources Research. Vol. 33. pp 309-319.

  • Zevenbergen, L.W., Thorne, C.R., 1987. Quantitative analysis of land surface topography. Earth surface processes and landforms 12, 47–56.

  • Zhou, G., Sun, Z., Fu, S., 2016. An efficient variant of the Priority-Flood algorithm for filling depressions in raster digital elevation models. Computers & Geosciences 90, Part A, 87 – 96. doi:10.1016/j.cageo.2016.02.021

Credits

RichDEM has been developed and tested using computational resources provided by the Minnesota Supercomputing Institute (MSI) and the U.S. National Science Foundation's XSEDE.

Funding for the development of RichDEM has been provided by the Legislative-Citizen Commission on Minnesota Resources (LCCMR), the U.S. National Science Foundation Graduate Research Fellowship, and the U.S. Department of Energy Computational Science Graduate Fellowship.

Feedback

If you see something, say something.

Users are encouraged to report any issues experienced with the code via Github's issue tracker. Feedback is also accepted via email ([email protected]), though this is highly discouraged as it does not provide a resource for others.

richdem's People

Contributors

benbovy avatar crghilardi avatar jsta avatar kcallaghan avatar mcflugen avatar r-barnes avatar tbartholomaus avatar tgrandje avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

richdem's Issues

Trouble with pit filling and slope applying

import richdem as rd
import numpy as np
dem              = nd.array([[250,260,265,270],[240,200,200,210],[230,220,225,205]])
dem              = rd.rdarray(dem, no_data=-9999)
dem_filled       = rd.FillDepressions(dem, epsilon=False, in_place=False,topology='D4')
dem_flat_resolve = rd.ResolveFlats(dem_filled, in_place=False)

print(dem)
print(dem_filled)
print(dem_flat_resolve)
>>> print(dem)
[[250 260 265 270]
 [240 200 200 210]
 [230 220 225 205]]
>>> print(dem_filled)
[[250 260 265 270]
 [240 210 210 210]
 [230 220 225 205]]
>>> print(dem_flat_resolve)
[[250 260 265 270]
 [240 206 208 210]
 [230 220 225 205]]
>>> 

I realize that when I try to correct flat areas with the ResolveFlats function, my flat area turns back into depression. The slope gradient for the flat area is in the opposite direction to what might be expected.

Could you please enlighten me on that point?

Thanks in advance

Trouble installing on Mac

Hello! Thank you so much for providing this code!

I'm having trouble installing on Mac (Linux works fine)...

System info

  • Anaconda Python 3.6:
     $ python --version
    Python 3.6.4 :: Anaconda, Inc.
    
  • Pip 18.0:
     $ pip --version
    pip 18.0 from /Users/josh/anaconda3/lib/python3.6/site-packages/pip (python 3.6)
    
  • Mac OSX High Sierra, 10.13.6
  • Compiler info:
    $ gcc --version
    Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
    Apple LLVM version 9.1.0 (clang-902.0.39.1)
    Target: x86_64-apple-darwin17.7.0
    Thread model: posix
    InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
    

Pip logs

 $ pip install richdem
Collecting richdem
  Using cached https://files.pythonhosted.org/packages/20/8f/1fa0e1af7c4f0107305081513dae0234f327cbe5fc3a5db41d38915a2213/richdem-0.3.4.tar.gz
Requirement already satisfied: numpy<2,>=1.7 in /Users/josh/anaconda3/lib/python3.6/site-packages (from richdem) (1.14.3)
Building wheels for collected packages: richdem
  Running setup.py bdist_wheel for richdem ... error
  Complete output from command /Users/josh/anaconda3/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/kr/8t58jdkx02q9ft2zcvsvlzvm0000gn/T/pip-install-d542h8fx/richdem/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /private/var/folders/kr/8t58jdkx02q9ft2zcvsvlzvm0000gn/T/pip-wheel-5804lbo7 --python-tag cp36:
  Using RichDEM hash=Unknown, time=Unknown
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.7-x86_64-3.6
  creating build/lib.macosx-10.7-x86_64-3.6/richdem
  copying richdem/__init__.py -> build/lib.macosx-10.7-x86_64-3.6/richdem
  copying richdem/cli.py -> build/lib.macosx-10.7-x86_64-3.6/richdem
  running build_ext
  COMPILER unix
  COMPILER ARGUMENTS ['-std=c++11', '-g', '-fvisibility=hidden', '-O3', '-Wno-unknown-pragmas']
  building '_richdem' extension
  creating build/temp.macosx-10.7-x86_64-3.6
  creating build/temp.macosx-10.7-x86_64-3.6/src
  creating build/temp.macosx-10.7-x86_64-3.6/lib
  creating build/temp.macosx-10.7-x86_64-3.6/lib/richdem
  creating build/temp.macosx-10.7-x86_64-3.6/lib/richdem/common
  gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/josh/anaconda3/include -arch x86_64 -I/Users/josh/anaconda3/include -arch x86_64 -DDOCTEST_CONFIG_DISABLE -DRICHDEM_COMPILE_TIME="\"Unknown\"" -DRICHDEM_GIT_HASH="\"Unknown\"" -DRICHDEM_LOGGING -D_USE_MATH_DEFINES -Ilib/ -I/Users/josh/anaconda3/include/python3.6m -c src/pywrapper.cpp -o build/temp.macosx-10.7-x86_64-3.6/src/pywrapper.o -std=c++11 -g -fvisibility=hidden -O3 -Wno-unknown-pragmas
  In file included from src/pywrapper.cpp:1:
  In file included from lib/pybind11/pybind11.h:43:
  In file included from lib/pybind11/attr.h:13:
  In file included from lib/pybind11/cast.h:13:
  In file included from lib/pybind11/pytypes.h:12:
  lib/pybind11/detail/common.h:139:10: fatal error: 'forward_list' file not found
  #include <forward_list>
           ^~~~~~~~~~~~~~
  1 error generated.
  error: command 'gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for richdem
  Running setup.py clean for richdem
Failed to build richdem
Installing collected packages: richdem
  Running setup.py install for richdem ... error
    Complete output from command /Users/josh/anaconda3/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/kr/8t58jdkx02q9ft2zcvsvlzvm0000gn/T/pip-install-d542h8fx/richdem/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/kr/8t58jdkx02q9ft2zcvsvlzvm0000gn/T/pip-record-xdnnpvdt/install-record.txt --single-version-externally-managed --compile:
    Using RichDEM hash=Unknown, time=Unknown
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.7-x86_64-3.6
    creating build/lib.macosx-10.7-x86_64-3.6/richdem
    copying richdem/__init__.py -> build/lib.macosx-10.7-x86_64-3.6/richdem
    copying richdem/cli.py -> build/lib.macosx-10.7-x86_64-3.6/richdem
    running build_ext
    COMPILER unix
    COMPILER ARGUMENTS ['-std=c++11', '-g', '-fvisibility=hidden', '-O3', '-Wno-unknown-pragmas']
    building '_richdem' extension
    creating build/temp.macosx-10.7-x86_64-3.6
    creating build/temp.macosx-10.7-x86_64-3.6/src
    creating build/temp.macosx-10.7-x86_64-3.6/lib
    creating build/temp.macosx-10.7-x86_64-3.6/lib/richdem
    creating build/temp.macosx-10.7-x86_64-3.6/lib/richdem/common
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/josh/anaconda3/include -arch x86_64 -I/Users/josh/anaconda3/include -arch x86_64 -DDOCTEST_CONFIG_DISABLE -DRICHDEM_COMPILE_TIME="\"Unknown\"" -DRICHDEM_GIT_HASH="\"Unknown\"" -DRICHDEM_LOGGING -D_USE_MATH_DEFINES -Ilib/ -I/Users/josh/anaconda3/include/python3.6m -c src/pywrapper.cpp -o build/temp.macosx-10.7-x86_64-3.6/src/pywrapper.o -std=c++11 -g -fvisibility=hidden -O3 -Wno-unknown-pragmas
    In file included from src/pywrapper.cpp:1:
    In file included from lib/pybind11/pybind11.h:43:
    In file included from lib/pybind11/attr.h:13:
    In file included from lib/pybind11/cast.h:13:
    In file included from lib/pybind11/pytypes.h:12:
    lib/pybind11/detail/common.h:139:10: fatal error: 'forward_list' file not found
    #include <forward_list>
             ^~~~~~~~~~~~~~
    1 error generated.
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/Users/josh/anaconda3/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/kr/8t58jdkx02q9ft2zcvsvlzvm0000gn/T/pip-install-d542h8fx/richdem/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/kr/8t58jdkx02q9ft2zcvsvlzvm0000gn/T/pip-record-xdnnpvdt/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/kr/8t58jdkx02q9ft2zcvsvlzvm0000gn/T/pip-install-d542h8fx/richdem/

negative values for the slope in degrees?

Hi thanks for the lib.
I have a dgm file and calculated the values with slope_degrees. I wonder why I only have positive angles? I would have expected to get both positive and negative calculated.

How do I get the negative slopes as well?

I use the Python package richdem 1.21.3.

thanks
img

Issue with breaching and resolving flats

Hello there

For my bachelor thesis I am comparing preprocessing tools. I also want to include RichDEM but have an issue, especially with the FlatResolve algorithm, as some others previously had.

Because by resolving flats new depressions are produced and while I was able to use epsilon filling instead for the fill algorithm there is no alternative with the breaching algorithm. I also tried only breaching, but then discovered that all breached channels are the same height and therefore again a flat.

Is there any workaround within RichDEM to either resolve flats without producing new depressions or alternatively breach without producing new flats?

Thanks in advance and kind regards

Flow accumulation raster is not in sync with actual river network

Hi

A problem location in my study area on Open Street Map basemap as below
image

But, FAC derived through RichDEM with Dinf algorithm is not in sync with the basemap as below
image

And, FAC derived through TauDEM with Dinf algorithm is in sync with the basemap as below
image

Kindly help me know what could be the reason and/or reply for any more information/data to needed to get better understanding of the problem statement.

Thank you
Ramesh

Option to silent function TerrainAttribute

The function TerrainAttribute prints references to the screen when run. E.g. for the slope:

A Slope calculation (degrees)
C Horn, B.K.P., 1981. Hill shading and the reflectance map. Proceedings of the IEEE 69, 14–47. doi:10.1109/PROC.1981.11918

I understand the idea behind it, but it can become annoying when looping over many items, and trying to add a progress bar. I could not find any option to silent that print. Please let me know if there is a way, otherwise would it be possible to include this as an option?

Since the print is called from the C++ function, it does not seem possible to catch the stdout in Python directly. I tried for example this option and this option, without success. It works with a pure Python function though. So I don't think there is any way on my end to capture that output that comes from the C++ function.

Using RichDEM in a Jupyter notebook fails

On Jupyter 4.4.0, calling import richdem fails with The kernel appears to have died. It will restart automatically. and this console log output:

[I 13:03:32.650 NotebookApp] Kernel started: bbf60be4-9ad6-4069-9ee2-dc5e332b6f52
[I 13:03:33.323 NotebookApp] Adapting to protocol v5.1 for kernel bbf60be4-9ad6-4069-9ee2-dc5e332b6f52
python(86058,0x7fffafcac3c0) malloc: *** error for object 0x10d0862c0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
[I 13:03:38.650 NotebookApp] KernelRestarter: restarting kernel (1/5), keep random ports
WARNING:root:kernel bbf60be4-9ad6-4069-9ee2-dc5e332b6f52 restarted

With --debug,

[D 13:08:38.113 NotebookApp] Received kernel info: {'implementation': 'ipython', 'implementation_version': '6.5.0', 'status': 'ok', 'language_info': {'name': 'python', 'pygments_lexer': 'ipython3', 'codemirror_mode': {'version': 3, 'name': 'ipython'}, 'version': '3.5.5', 'nbconvert_exporter': 'python', 'file_extension': '.py', 'mimetype': 'text/x-python'}, 'protocol_version': '5.1', 'help_links': [{'text': 'Python Reference', 'url': 'https://docs.python.org/3.5'}, {'text': 'IPython Reference', 'url': 'https://ipython.org/documentation.html'}, {'text': 'NumPy Reference', 'url': 'https://docs.scipy.org/doc/numpy/reference/'}, {'text': 'SciPy Reference', 'url': 'https://docs.scipy.org/doc/scipy/reference/'}, {'text': 'Matplotlib Reference', 'url': 'https://matplotlib.org/contents.html'}, {'text': 'SymPy Reference', 'url': 'http://docs.sympy.org/latest/index.html'}, {'text': 'pandas Reference', 'url': 'https://pandas.pydata.org/pandas-docs/stable/'}], 'banner': "Python 3.5.5 |Anaconda, Inc.| (default, Mar 12 2018, 16:25:05) \nType 'copyright', 'credits' or 'license' for more information\nIPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.\n"}
[I 13:08:38.113 NotebookApp] Adapting to protocol v5.1 for kernel 39f4312c-87b4-4b6a-a8a9-d60afd08ca45
[D 13:08:38.114 NotebookApp] activity on 39f4312c-87b4-4b6a-a8a9-d60afd08ca45: status
[D 13:08:38.115 NotebookApp] 101 GET /api/kernels/39f4312c-87b4-4b6a-a8a9-d60afd08ca45/channels?session_id=62d1c99272144fa29699cf9536ac4d84 (::1) 607.39ms
[D 13:08:38.115 NotebookApp] Opening websocket /api/kernels/39f4312c-87b4-4b6a-a8a9-d60afd08ca45/channels
[D 13:08:38.115 NotebookApp] Getting buffer for 39f4312c-87b4-4b6a-a8a9-d60afd08ca45
[D 13:08:38.115 NotebookApp] Connecting to: tcp://127.0.0.1:53143
[D 13:08:38.116 NotebookApp] Connecting to: tcp://127.0.0.1:53144
[D 13:08:38.116 NotebookApp] Connecting to: tcp://127.0.0.1:53145
[D 13:08:38.126 NotebookApp] activity on 39f4312c-87b4-4b6a-a8a9-d60afd08ca45: status
[D 13:08:38.126 NotebookApp] activity on 39f4312c-87b4-4b6a-a8a9-d60afd08ca45: status
[D 13:08:38.130 NotebookApp] activity on 39f4312c-87b4-4b6a-a8a9-d60afd08ca45: status
[D 13:08:38.133 NotebookApp] activity on 39f4312c-87b4-4b6a-a8a9-d60afd08ca45: status
[D 13:08:46.167 NotebookApp] activity on 39f4312c-87b4-4b6a-a8a9-d60afd08ca45: status
[D 13:08:46.169 NotebookApp] activity on 39f4312c-87b4-4b6a-a8a9-d60afd08ca45: execute_input
python(86286,0x7fffafcac3c0) malloc: *** error for object 0x104cd22c0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
[I 13:08:46.487 NotebookApp] KernelRestarter: restarting kernel (1/5), keep random ports
WARNING:root:kernel 39f4312c-87b4-4b6a-a8a9-d60afd08ca45 restarted

On macOS High Sierra; compiled with homebrew GCC 8.2.0.

Note that RichDEM works perfectly within scripts, it's only in Jupyter where it fails.

Suppressing log messages

Is there a way to suppress the log messages?

I am using richdem to perform calculations on a lot of small locations in a loop. As a result I get very verbose logs from richdem with a progress bar and the citation string. This is a bit annoying when I collect the logs and check them after large jobs on a cluster. Is there an option to turn of log messages from the C libs when using the python api? a sort of --verbose 0.

This is what I am using:

    rda = rd.rdarray(dem_arr, no_data=-9999)
    with HiddenPrints():
        attrs = [rd.TerrainAttribute(rda, attrib=attr) for attr in attributes]
    return attrs

HiddenPrints suppresses those from python already.

Setting geotransform for rdarray

I'm trying to set the geotransform on an rdarray that I make from a numpy array. It doesn't seem to be working, as that attribute of the rdarray remains blank after I set it, and "Warning! No geotransform defined...." continues to appear after I run FillDepressions and FlowAccumulation. Can anyone help?

eta = np.ones((len(x),len(y)))*z_0 + 0.01*np.random.rand(len(x),len(y)) dem = rd.rdarray(eta, no_data=-9999, geotransform = (0.0,delta,0.0,0.0,0.0,delta)) rd.FillDepressions(dem, epsilon=False, in_place=True)

installing on wndows

I am trying to install in windows and having no luck. Below is the error I get:
C:\Users\npongo\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DDOCTEST_CONFIG_DISABLE "-DRICHDEM_COMPILE_TIME="2018-01-06 11:21:19 -0600"" -DRICHDEM_GIT_HASH="ef44525" -DRICHDEM_LOGGING -Ilib/ -Ic:\python27\include -Ic:\python27\PC /Tpsrc\pywrapper.cpp /Fobuild\temp.win-amd64-2.7\Release\src\pywrapper.obj -std=c++11 -g -fvisibility=hidden -O3 -Wno-unknown-pragmas
cl : Command line error D8021 : invalid numeric argument '/Wno-unknown-pragmas'
error: command 'C:\Users\npongo\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe' failed with exit status 2

I have played with the setup.py to remove this argument but still no luck, It then does not find the random.cpp file

any help or suggests welcome on how to build this on windows.

Update pybind11

The currently vendored pybind11 does not build against Python 3.10. It should be updated or removed.

Allow disabling verbosity

Hello,

The progress bar that gets emitted seems super useful for interactive analysis, but it is quite obtrusive when using richdem in non-interactive code, where the output gets jumbled all together. It'd be great if it could be disabled somehow, e.g. passing verbose=False.

segmentation fault in parallel_pf.exe

Hi Rich,

I'm trying to get parallel_pf to run on my local machine and also on a USGS cluster and I get a segmentation fault in both when it runs (error below). It compiled without issue. Am I calling it correctly? I just want to do some simple comparisons with other algorithms.

Thank you!

(richDEM) tbarnhart@parallel_priority_flood$ mpirun -n 2 ./parallel_pf.exe one @
evict ~/projects/DEM_processing/data/test_data.tiff %n_richDEM_fill.tiff
c Program name = RichDEM v0.0.0
c Script compiled at = 2018-01-02 20:34:19 UTC
c Git hash = f138566
c Copyright = Richard Barnes © 2016
a Analysis command = ./parallel_pf.exe one @evict /home/tbarnhart/projects/DEM
_processing/data/test_data.tiff %n_richDEM_fill.tiff
A A Barnes (2016) Parallel Priority-Flood
C C Barnes, R., 2016. "Parallel priority-flood depression filling for trillion c
ell digital elevation models on desktops or clusters". Computers & Geosciences.
doi:10.1016/j.cageo.2016.07.001
c Running with = 2 processes
c Many or one = one
c Input file = /home/tbarnhart/projects/DEM_processing/data/test_data.tiff
c Retention strategy = @evict
c Block width = -1
c Block height = -1
c Flip horizontal = 0
c Flip vertical = 0
c World Size = 2
m Total width = 2401
m Total height = 3601
m Block width = 2401
m Block height = 3601
m Total cells to be processed = 8646001
t Preparer time = 0.009007 s
[IGSKKBCWLT762:08182] *** Process received signal ***
[IGSKKBCWLT762:08182] Signal: Segmentation fault (11)

Access flow direction array directly

Hello Richards,

I have started to work with the richdem Python package. It is a great tool! I am using winpython37 and the tools works out of the box just by using the pip installer.

I have two question/request which would greatly help me in my current work:

(1) Is there a function to access the flow coordinate system (https://richdem.readthedocs.io/en/latest/flow_metrics.html), so the values which indicate the next cell by an integer value between 1 and 8? I implemented a Python version of D8 as well, but with a very limited functionality. So, your tool fits quite well for my current work. But I want to plot the flow directions as arrows colored by the altitude (see the attached figure). I have a function which can do that, but I need the flow coordinate system.

(2) Is there a way to include a predefined stream network for catchment processing? For example, the model SWAT holds the option to consider a stream network (poly line) when creating the sub-catchments.

Would be great if you could address my questions.

Best regards,
Sebastian

syntax of parallel_flats.exe

After I used the parallel_priority_flood (https://github.com/r-barnes/richdem/tree/master/programs/parallel_priority_flood) to filled the pits of DEM, I am trying to use the tiled_flat_resolution program ( https://github.com/r-barnes/richdem/tree/master/programs/tiled_flat_resolution) to solve the flat surface problem. The parallel_priority_flood is a very fast and easy-use parallel program. The results from parallel_priority_flood looks great! However, I have some troubles in the tiled_flat_resolution program.

I found that the syntax description of parallel_flats.exe is not very clear. When I run the problem, the program showed that the syntax is as below:

Syntax: ./parallel_flats.exe <noflip/fliph/flipv/fliphv>
or use 'table' for cache size

However, the description above is not as same as the syntax in the git-hub here (https://github.com/r-barnes/richdem/blob/master/programs/tiled_flat_resolution/help.txt ).

I am wondering what the and parameters look like; and where I should write the input file?

It is really help is you can answer my question.
Thank you for your help and time in advance @r-barnes

parallel_priority_flood: processes are occupied

Since my data volume is very large, I am trying to use the parallel_priority_flood tool (https://github.com/r-barnes/richdem/tree/master/programs/parallel_priority_flood) to fill the pits.

I have compiled the program. When I run the program, it reported error message as below:


Job starting at: Sun Jun 23 23:12:09 CDT 2019


c Program name = RichDEM v2.2.9
c Script compiled at = 2019-06-23 17:13:10 UTC
c Git hash = abc04d8
c Copyright = Richard Barnes © 2018
a Analysis command = ./parallel_pf.exe one @offloadall ./dem_srtm_18_04/srtm_18_04.tif outroot -w 500 -h 500
A Barnes (2016) Parallel Priority-Flood
C Barnes, R., 2016. Parallel priority-flood depression filling for trillion cell digital elevation models on desktops or clusters. Computers & Geosciences 96, 56-68. doi:10.1016/j.cageo.2016.07.001
parallel_pflood.exe [--flipV] [--flipH] [--bwidth #] [--bheight #] <many/one>
Use '--help' to show help.
E Retention must be @evict or @retain or a path.

Primary job terminated normally, but 1 process returned
a non-zero exit code. Per user-direction, the job has been aborted.


mpirun detected that one or more processes exited with non-zero status, thus causing
the job to be terminated. The first process to do so was:

Process name: [[30101,1],0]
Exit code: 255


Job completed at: Sun Jun 23 23:12:12 CDT 2019


Would you please help me troubleshoot it?
Thank you for your help and time in advance. @r-barnes

SSL certificate failure on pip install

Ran pip install richdem in a python 3.6 conda environment on Windows 10 and got this error showing a certificate problem

(py36) C:>pip install richdem
Collecting richdem
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)': /simple/richdem/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)': /simple/richdem/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)': /simple/richdem/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)': /simple/richdem/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)': /simple/richdem/
Could not fetch URL https://pypi.org/simple/richdem/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/richdem/ (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)) - skipping
ERROR: Could not find a version that satisfies the requirement richdem (from versions: none)
ERROR: No matching distribution found for richdem
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)) - skipping

conda forge package?

Thanks so much for providing this amazing tool the the python community!

Several users here at LDEO (e.g. @jkingslake, @jjspergel) are interested in trying richdem but are hitting problems with the pip install.

Most scientific python packages, especially those with compiled code, now provide a conda-forge package. The process for creating a conda-forge recipe is quite straightforward. If you could consider adding a conda package, I think you would get a lot more users.

Provide examples for C++ usage

I notice that RichDEM is rich with python script example ( such as this one), but I don't see C++ calling.

I'm planning to call RichDEM from my C++ code, and as such, C++ sample would be useful.

Thank you for your help!

More info: I'm running on Windows, Visual Studio 2015. So it would be great if you can provide the VS 2015 solution and csproject files on Github.

BreachDepressions missing in python RichDEM

Hi Rich,

I'm back to testing out some of these tools in python. RichDEM installed to a python 3 environment without a hitch on one of the USGS clusters! However, it seems that the BreachDepressions function is missing although it is documented at richdem.com. Here is the error I get:

In [12]: rd.BreachDepressions(dat,mode='Complete',in_place=True)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-12-ddda26957d72> in <module>()
----> 1 rd.BreachDepressions(dat,mode='Complete',in_place=True)

AttributeError: module 'richdem' has no attribute 'BreachDepressions'

I used pip install richdem to install the package.

Am I missing something about where the function went? I do not see in listed as a function when I use the help(richdem) command either.

Thank you for all your work with this!

slope_percentage units

Thank you for this very performant library! I am working with a DEM:

Driver: GTiff/GeoTIFF
Files: demdir/srtm30_sierra.tif
Size is 3867, 3782
Coordinate System is:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0],
    UNIT["degree",0.0174532925199433],
    AUTHORITY["EPSG","4326"]]
Origin = (-121.696527777777774,40.410694444444445)
Pixel Size = (0.000277777777778,-0.000277777777778)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  COMPRESSION=DEFLATE
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (-121.6965278,  40.4106944) (121d41'47.50"W, 40d24'38.50"N)
Lower Left  (-121.6965278,  39.3601389) (121d41'47.50"W, 39d21'36.50"N)
Upper Right (-120.6223611,  40.4106944) (120d37'20.50"W, 40d24'38.50"N)
Lower Right (-120.6223611,  39.3601389) (120d37'20.50"W, 39d21'36.50"N)
Center      (-121.1594444,  39.8854167) (121d 9'34.00"W, 39d53' 7.50"N)
Band 1 Block=256x256 Type=Int16, ColorInterp=Gray
  Minimum=19.000, Maximum=2610.000, Mean=1280.813, StdDev=528.253
  NoData Value=-32768
  Metadata:
    STATISTICS_MAXIMUM=2610
    STATISTICS_MEAN=1280.8126836157
    STATISTICS_MINIMUM=19
    STATISTICS_STDDEV=528.25340415591
    STATISTICS_VALID_PERCENT=100

and running the following:
rd.TerrainAttribute(rdem, attrib='slope_percentage')

i get the following:

gdalinfo -stats demdir/srtm30_sierra_slope_percentage.tif
Driver: GTiff/GeoTIFF
Files: demdir/srtm30_sierra_slope_percentage.tif
Size is 3867, 3782
Coordinate System is:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0],
    UNIT["degree",0.0174532925199433],
    AUTHORITY["EPSG","4326"]]
Origin = (-121.696527777777774,40.410694444444445)
Pixel Size = (0.000277777777778,-0.000277777777778)
Metadata:
  AREA_OR_POINT=Area
  PROCESSING_HISTORY=2019-12-18 23:33:01.228009 UTC | RichDEM (Python 0.3.4) (hash="Unknown", hashdate="Unknown") | LoadGDAL(filename=demdir/srtm30_sierra.tif, no_data=-32768.0)
2019-12-18 23:33:01.240228 UTC | RichDEM (Python 0.3.4) (hash="Unknown", hashdate="Unknown") | TerrainAttribute(dem, attrib=slope_percentage, zscale=1.0)
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (-121.6965278,  40.4106944) (121d41'47.50"W, 40d24'38.50"N)
Lower Left  (-121.6965278,  39.3601389) (121d41'47.50"W, 39d21'36.50"N)
Upper Right (-120.6223611,  40.4106944) (120d37'20.50"W, 40d24'38.50"N)
Lower Right (-120.6223611,  39.3601389) (120d37'20.50"W, 39d21'36.50"N)
Center      (-121.1594444,  39.8854167) (121d 9'34.00"W, 39d53' 7.50"N)
Band 1 Block=3867x1 Type=Float32, ColorInterp=Gray
  Minimum=0.000, Maximum=29749186.000, Mean=2705832.259, StdDev=2037984.629
  NoData Value=-9999
  Metadata:
    STATISTICS_MAXIMUM=29749186
    STATISTICS_MEAN=2705832.2586814
    STATISTICS_MINIMUM=0
    STATISTICS_STDDEV=2037984.6293424
    STATISTICS_VALID_PERCENT=100

Can someone help me to understand the units in the derived slope raster? I was expecting a floating point between 0 and 1. Thank you!

Retrieve D4 flow direction raster

Hello!

I would like to be able to recover the flow direction raster for D4 algorithm.

I tried to get it from Flow Proportions function :

beau=rd.LoadGDAL("dem.tif")
beau_filled=rd.FillDepressions(beau,epsilon=False,in_place=False,topology='D4')
bprops=rd.FlowProportions(dem=beau_filled,method='D4')

However, I get cells with no flow (-1 value ; 0th value of the nine values) although I made sure to fill all the pits before.

Do you have any idea how I might do that?

Here is the dem :
dem.zip

Thanks in advance for your help

rd.rdShow() raises value error: cannot convert float NaN to integer

Hello,

I downloaded DEM from Google earth engine as tiff files and loaded it in richdem, when I try to print rdarray with rd.rdShow(dem), it raises value error: cannot convert float NaN to integer. Even I type casted all values in my DEM to to int type, filled all nan values with -9999 and reset dem.no_data to -9999, but still it is raising same error. When I use matplotlib imshow to print it then it works very good. I do not know why rd.rdShow() is not working. Please see in picture below;
Richdem

Kindly help. Thanks

failed assertion in parallel_d8_accum

Hi Rich,

Thank you for helping me with the other problem. Now when I try to run parallel_d8_accum it produces the following error and I've gdalinfoed the file I'm using below as well. Thank you for all your help!


(richDEM) tbarnhart@parallel_d8_accum$ mpirun -n 2 ./parallel_d8_accum.exe one @evict ~/projects/DEM_processing/data/0_0_richDEM_fill.tiff ~/projects/DEM_processing/da
ta/%n_richDEM_accum.tiff
c Program name       = RichDEM v0.0.0
c Script compiled at = 2018-01-04 15:21:55 UTC
c Git hash           = 8d45cc88d1d65384
c Copyright          = Richard Barnes © 2016
a Analysis command   = ./parallel_d8_accum.exe one @evict /home/tbarnhart/projects/DEM_processing/data/0_0_richDEM_fill.tiff /home/tbarnhart/projects/DEM_processing/da
ta/%n_richDEM_accum.tiff
A Parallel Flow Accumulation
C Barnes, R. 2016. "Parallel D8 Flow Accumulation For Trillion Cell Digital Elevation Models On Desktops Or Clusters". In-progress.
c Processes = 2
c Many or one = one
c Input file = /home/tbarnhart/projects/DEM_processing/data/0_0_richDEM_fill.tiff
c Retention strategy = @evict
c Block width = -1
c Block height = -1
c Flip horizontal = 0
c Flip vertical = 0
c Cache compression = FALSE
m Total width =  2401
m Total height = 3601
m Block width =  2401
m Block height = 3601
m Total cells to be processed = 8646001
t Preparer time = 0.008008 s
c Input data type = Int16
m Jobs created = 1
p Jobs remaining = 0
parallel_d8_accum.exe: ../../include/richdem/common/Array2D.hpp:528: richdem::Array2D<T>::i_t richdem::Array2D<T>::getN(richdem::Array2D<T>::i_t, uint8_t) const [with
T = unsigned char; richdem::Array2D<T>::i_t = unsigned int; uint8_t = unsigned char]: Assertion `0<=n && n<=8' failed.
[IGSKKBCWLT762:08598] *** Process received signal ***
[IGSKKBCWLT762:08598] Signal: Aborted (6)
[IGSKKBCWLT762:08598] Signal code:  (-6)
[IGSKKBCWLT762:08598] [ 0] /lib/x86_64-linux-gnu/libpthread.so.0(+0x10330) [0x7fd19e7b0330]
[IGSKKBCWLT762:08598] [ 1] /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x37) [0x7fd19e406c37]
[IGSKKBCWLT762:08598] [ 2] /lib/x86_64-linux-gnu/libc.so.6(abort+0x148) [0x7fd19e40a028]
[IGSKKBCWLT762:08598] [ 3] /lib/x86_64-linux-gnu/libc.so.6(+0x2fbf6) [0x7fd19e3ffbf6]
[IGSKKBCWLT762:08598] [ 4] /lib/x86_64-linux-gnu/libc.so.6(+0x2fca2) [0x7fd19e3ffca2]
[IGSKKBCWLT762:08598] [ 5] ./parallel_d8_accum.exe() [0x40d878]
[IGSKKBCWLT762:08598] [ 6] ./parallel_d8_accum.exe() [0x430fff]
[IGSKKBCWLT762:08598] [ 7] ./parallel_d8_accum.exe() [0x436fdc]
[IGSKKBCWLT762:08598] [ 8] ./parallel_d8_accum.exe() [0x439b92]
[IGSKKBCWLT762:08598] [ 9] ./parallel_d8_accum.exe() [0x40c83a]
[IGSKKBCWLT762:08598] [10] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7fd19e3f1f45]
[IGSKKBCWLT762:08598] [11] ./parallel_d8_accum.exe() [0x40d68b]
[IGSKKBCWLT762:08598] *** End of error message ***
--------------------------------------------------------------------------
mpirun noticed that process rank 1 with PID 8598 on node XXXXX exited on signal 6 (Aborted).
--------------------------------------------------------------------------


Output from gdalinfo for the file I'm trying to run the accumulation process on is:

(richDEM) tbarnhart@parallel_d8_accum$ gdalinfo ~/projects/DEM_processing/data/0_0_richDEM_fill.tiff
Driver: GTiff/GeoTIFF
Files: /home/tbarnhart/projects/DEM_processing/data/0_0_richDEM_fill.tiff
Size is 2401, 3601
Coordinate System is:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0],
    UNIT["degree",0.0174532925199433],
    AUTHORITY["EPSG","4326"]]
Origin = (-113.000416666666666,47.000416666666666)
Pixel Size = (0.000833333333333,-0.000833333333333)
Metadata:
  AREA_OR_POINT=Area
  PROCESSING_HISTORY=2018-01-04 15:32:34 UTC | RichDEM v0.0.0 (hash=8d45cc88d1d65384, compiled=2018-01-04 15:22:25 UTC) | ./parallel_pf.exe one @evict /home/tbarnhart/
projects/DEM_processing/data/test_data.tiff /home/tbarnhart/projects/DEM_processing/data/%n_richDEM_fill.tiff
  TIFFTAG_DATETIME=2018-01-04 15:32:34 UTC
  TIFFTAG_SOFTWARE=RichDEM v0.0.0 (hash=8d45cc88d1d65384, compiled=2018-01-04 15:22:25 UTC)
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (-113.0004167,  47.0004167) (113d 0' 1.50"W, 47d 0' 1.50"N)
Lower Left  (-113.0004167,  43.9995833) (113d 0' 1.50"W, 43d59'58.50"N)
Upper Right (-110.9995833,  47.0004167) (110d59'58.50"W, 47d 0' 1.50"N)
Lower Right (-110.9995833,  43.9995833) (110d59'58.50"W, 43d59'58.50"N)
Center      (-112.0000000,  45.5000000) (112d 0' 0.00"W, 45d30' 0.00"N)
Band 1 Block=2401x1 Type=Int16, ColorInterp=Gray
  NoData Value=-32767

Problems with GDAL. Tried to install GDAL with pip but I couldn't

Hi,
Do you have any advice to solve the GDAL problem? (I'm using macOS Catalina).
Thanks!

shasta_dem = rd.LoadGDAL(dem_path)
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3296, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
shasta_dem = rd.LoadGDAL(dem_path)
File "/usr/local/lib/python3.7/site-packages/richdem/init.py", line 255, in LoadGDAL
raise Exception("richdem.LoadGDAL() requires GDAL.")
Exception: richdem.LoadGDAL() requires GDAL.

parallel_flats.exe passing a NULL argument

Hi, I'm having some issues in "parallel_flats". The problem basically states that a string is passing a NULL argument, it happens when the program tries to save results fds.saveGDAL(output_filename);. See error below.

I zipped the files I'm using in case you want to reproduce the error:
https://uob-my.sharepoint.com/:f:/g/personal/js16170_bristol_ac_uk/EnskrpF-f11GiNuOKDiZCHQBAGJRl5OS56CIgOtT51Z0AQ?e=NYjVlm

The invoking line is:
./parallel_flats.exe fil/layout_f.layout 100 tmp/ned_%f.tif dir/%f_d8.tif noflip

Error:

c Program name       = RichDEM v2.2.9
c Script compiled at = 2019-04-26 16:18:34 UTC
c Git hash           = abc04d81216d7cf5
c Copyright          = Richard Barnes © 2018
a Analysis command   = /scratch/hydro3/js16170/thirdparty/richdem/programs/tiled_flat_resolution/parallel_flats.exe fil/layout_f.layout 100 tmp/ned_%f.tif dir/%f_d8.tif noflip
A Tiled Flat Resolution (Greedy Resolution)
C Barnes, R. 2016. RichDEM: Terrain Analysis Software. http://github.com/r-barnes/richdem
p Processed: 0 of 9 tiles infs/infs (infhr/infhr)
p Processed: 1 of 9 tiles 48.5344s/54.6012s (0.0134818hr/0.015167hr)
p Processed: 2 of 9 tiles 40.624s/52.2308s (0.0112844hr/0.0145086hr)
p Processed: 3 of 9 tiles 34.14s/51.21s (0.00948334hr/0.014225hr)
p Processed: 4 of 9 tiles 29.3668s/52.8602s (0.00815743hr/0.0146834hr)
p Processed: 5 of 9 tiles 22.7592s/51.2081s (0.00632199hr/0.0142245hr)
p Processed: 6 of 9 tiles 18.1705s/54.5116s (0.00504737hr/0.0151421hr)
p Processed: 7 of 9 tiles 12.5511s/56.4799s (0.00348641hr/0.0156889hr)
p Processed: 8 of 9 tiles 6.21921s/55.9729s (0.00172756hr/0.015548hr)
p Saving results...
terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_S_construct null not valid
main.sh: line 2: 183702 Aborted                 (core dumped) /scratch/hydro3/js16170/thirdparty/richdem/programs/tiled_flat_resolution/parallel_flats.exe fil/layout_f.layout 100 tmp/ned_%f.tif dir/%f_d8.tif noflip

Any idea about this?

bad_alloc in parallel_pf

Hi,

I tried to run the parallel priority flood program on a rather large DEM.
The program halt on the second processing step with bad_alloc.

I ran the program on a 8-core Xeon machine with 16 Go RAM, running on Ubuntu 18.04.2

Any pointer to solve this issue ?
Can it be caused by insufficient memory resources ?

I include hereafter some output information on the error, with the hope it will help.

Thanks.

c Program name       = RichDEM v2.2.9
c Script compiled at = 2019-03-19 15:32:14 UTC
c Git hash           = abc04d81216d7cf5
c Copyright          = Richard Barnes © 2018
a Analysis command   = parallel_pf one CACHE/tmp_%n.tif RGEALTI.tif FLOW/tile_%n.tif -h 5000 -w 5000 
A Barnes (2016) Parallel Priority-Flood
C Barnes, R., 2016. Parallel priority-flood depression filling for trillion cell digital elevation models on desktops or clusters. Computers & Geosciences 96, 56-68. doi:10.1016/j.cageo.2016.07.001
c Running with = 8 processes
c Many or one = one
c Input file = RGEALTI.tif
c Retention strategy = CACHE/tmp_%n.tif
c Block width = 5000
c Block height = 5000
c Flip horizontal = 0
c Flip vertical = 0
c World Size = 8
m Total width =  98000
m Total height = 143000
m Block width =  5000
m Block height = 5000
m Total cells to be processed = 1129098112
t Preparer time = 0.0110046 s
c Input data type = Float32
m Jobs created = 580

(snip)

n First stage Tx = 109220 B
n First stage Rx = 93937200 B
Constructing mastergraph...
Merging graphs...
!Total labels required: 122444
Handling adjacent edges and corners...
!Mastergraph constructed in 0.646268s. 
Performing aggregated priority flood
!Aggregated priority flood time: 0.0865886s.
p Jobs left to receive = 579
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

(snip)

/usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x931ec)[0x7f5f6034c1ec]
[gpkfx:29646] [ 8] /usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_mutateEmmPKcm+0x6b)[0x7f5f603ddcfb]
[gpkfx:29646] [ 9] /usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE14_M_replace_auxEmmmc+0xc0)[0x7f5f603de6d0]
[gpkfx:29646] [10] parallel_pf(+0x2aee4)[0x56015b813ee4]
[gpkfx:29646] [11] parallel_pf(+0x65c98)[0x56015b84ec98]
[gpkfx:29646] [12] parallel_pf(+0x10a0b)[0x56015b7f9a0b]
[gpkfx:29646] [13] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7)[0x7f5f5fab2b97]
[gpkfx:29646] [14] parallel_pf(+0x112ea)[0x56015b7fa2ea]
[gpkfx:29646] *** End of error message ***

Maximum DEM size for slope calculation?

Is there a limit to the size of the grids that can be handled by the slope calculations in rd.TerrainAttribute?

I'm attempting to calculate a slope map from the ArcticDEM datasets. Using the 1 km resolution grid works fine, but the 100 m resolution grid is incorrectly truncated.

The 1 km dataset is here (87 MB compressed; 220 MB in memory) and the 100 m dataset is here (7.8 GB compressed; 22 GB in memory).

A notebook illustrating successful processing of the 1 km dataset is here. However, with the higher resolution data I get the following:

import richdem as rd

dem_path = r"./arcticDEM/arcticdem_mosaic_100m_v3.0.tif"
dem = rd.LoadGDAL(dem_path)
rd.rdShow(dem, axes=False, cmap="terrain", figsize=(8, 5.5));

image

slope = rd.TerrainAttribute(dem, attrib="slope_degrees")
print("Max. slope:", slope.max(), "degrees.")
rd.rdShow(slope, axes=False, cmap="magma", figsize=(8, 5.5));

image

Does anyone have any suggestions for settings I can tweak to avoid the lower portion of the slope map being truncated like this, please? Or ideas for possible causes?

I have access to a large machine (960 GB of RAM). My code all completes without error and peak memory consumption is never more than about 150 GB, so I'm not running out of memory.

Any suggestions gratefully received!

Thanks :-)

Error in FlowAccumulation

Hi Rich,

I get the following error in richdem.FlowAccumulation with both the 'D8' and 'Dinf' methods. Any thoughts on how to resolve it are appreciated.

Thank you!

In [7]: dem = rd.LoadGDAL('./cedar2m/hdr.adf')

In [8]: rd.FillDepressions(dem,in_place=True)

A Priority-Flood (Zhou2016 version)
C Zhou, G., Sun, Z., Fu, S., 2016. An efficient variant of the Priority-Flood algorithm for filling depressions in raster digital el
evation models. Computers & Geosciences 90, Part A, 87 – 96. doi:http://dx.doi.org/10.1016/j.cageo.2016.02.021

t Zhou2016 wall-time = 169.659 s

In [9]: accumD8 = rd.FlowAccumulation(dem,method='D8')

A Generic Flow Accumulation Algorithm

A O'Callaghan (1984)/Marks (1984) Flow Accumulation (aka D8)
C O'Callaghan, J.F., Mark, D.M., 1984. The Extraction of Drainage Networks from Digital Elevation Data. Computer vision, graphics, a
nd image processing 28, 323--344.

[                                                  ] (0% - infs - 1 threads)--------------------------------------------------------
-------------------
IndexError                                Traceback (most recent call last)
<ipython-input-9-402d8b713134> in <module>()
----> 1 accumD8 = rd.FlowAccumulation(dem,method='D8')

~/.conda/envs/py36/lib/python3.6/site-packages/richdem/__init__.py in FlowAccumulation(dem, method, exponent, weights, in_place)
    422
    423   if method in facc_methods:
--> 424     facc_methods[method](dem.wrap(),accumw)
    425   elif method in facc_methods_exponent:
    426     if exponent is None:

IndexError: vector::_M_range_check

Have to flip the calculated aspect vertically

Until now, I calculated the aspect of a digital elevation model with the following command:

gdaldem aspect -of NETCDF $DEM_TIF $OUTPUT_netCDF.nc

When I calculate the aspect with richdem within Python:

import richdem as rd
aspect = rd.TerrainAttribute(rd.LoadGDAL($DEM_TIF), attrib = 'aspect')

I have to flip the array vertically (with numpy.flipud(aspect)) to store the aspect as netCDF and have the same results as with gdaldem.
Could you help me to identify what might be the reason. I want to calculate the aspect with richdem, because for some DEMs I get NaNs for some pixels with gdaldem.

Internally draining basins should not be filled

import richdem as rd
import numpy as np

arr = np.array([[250,260,265,270],[240,-9999,100,210],[230,220,225,205]])
dem = rd.rdarray(dem, no_data=-9999)

dem_filled = rd.FillDepressions(dem)
dem_filled_e = rd.FillDepressions(dem, epsilon = True)

print(dem_filled)
[[250 260 265 270]
[240 205 205 210]
[230 220 225 205]]

print(dem_filled_e)
[[ 250 260 265 270]
[ 240 -9999 204 210]
[ 230 220 225 205]]

Not clear on why Epsilon fill treats NoData cells differently. But neither behaves the way I would expect. My hope is that there would be no filling of this array, as there is an "outlet" in the middle.

Develop install error: Missing `lib/richdem/common/random.cpp`

First of all, thanks for the great library! I wanted to delineate a catchment, for which there is a C++ function in methods, which is not exposed. So when trying to install, I got the above error. I could also not find any .cpp files in the pyrichdem/libs folder, so I don;t really understand why the setup.py points to files there.

steps to reproduce

git clone [email protected]/r-barnes/richdem.git
cd richdem
conda create -n richdem-dev pip numpy
conda activate richdem-dev
pip install -e wrappers/pyrichdem

gives the error that setup.py looks for random.cpp and richdem.cpp here.

Now, if I remove those by commenting them out, compilation works (it actually takes quite some time, but I get a NOTHING WILL WORK! error when I
import richdem. Then, if I import _richdem, I get the following obscure error:

ImportError: /miniconda3/envs/richdem-dev/lib/python3.10/site-packages/_richdem.cpython-310-x86_64-linux-gnu.so: undefined symbol: _ZN7richdem9RDLOGfuncENS_7LogFlagEPKcS2_jNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE

proposed solution

Documentation on how to buidl the python part of RichDem if that's not too difficult?

Unable to build for windows

I am trying to build RichDEM for Windows on an Arch Linux box. I have installed MinGW and am running make as

$ make -f makefile.win

But the makefile expects me to have a dir named "richdem_windows", which does not exist so the build fails.

$ make -f makefile.win 

i686-w64-mingw32-g++ `../../richdem_windows/install/bin/gdal-config --cflags` --std=c++11 -o rd_flood_for_flowdirs.exe flood_for_flowdirs.cpp `../../richdem_windows/install/bin/gdal-config --libs` `../../richdem_windows/install/bin/gdal-config --dep-libs` -static-libgcc -static-libstdc++

/bin/sh: ../../richdem_windows/install/bin/gdal-config: No such file or directory

/bin/sh: ../../richdem_windows/install/bin/gdal-config: No such file or directory

/bin/sh: ../../richdem_windows/install/bin/gdal-config: No such file or directory

In file included from richdem/depressions/priority_flood.hpp:9:0,
             from flood_for_flowdirs.cpp:5:

richdem/depressions/../common/Array2D.hpp:10:23: fatal error: gdal_priv.h: No such file or directory

#include "gdal_priv.h"
                   ^



compilation terminated.

make: *** [makefile.vars:18: flood_for_flowdirs] Error 1

cmake does not produce makefile

I have been unable to build this project, the error comes up after I try to do the command:
make -j 6

It looks like the cmake command does not build the necessary makefile.

I also noticed that the cmake command does not use the 'Released' type variable

Thanks,
James

-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
-- The CXX compiler identification is MSVC 19.29.30138.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found GDAL: C:/Users/12067/anaconda3/envs/richdem/Library/lib/gdal_i.lib (found version "3.4.2")
-- Found OpenMP_CXX: -openmp (found version "2.0")
-- Found OpenMP: TRUE (found version "2.0")
-- Could NOT find MPI_CXX (missing: MPI_CXX_LIB_NAMES MPI_CXX_HEADER_DIR MPI_CXX_WORKS)
-- Could NOT find MPI (missing: MPI_CXX_FOUND)
CMake Warning at CMakeLists.txt:24 (message):
  MPI not found; will not compile parallel programs for large-scale datasets.


-- The C compiler identification is MSVC 19.29.30138.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Compiling RichDEM with GDAL.
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_BUILD_TYPE


-- Build files have been written to: C:/Users/12067/Documents/richdem/build```

Can richdem work with python 2.7 on windows

Hi, I have tried to load richdem and can't because of "Failed building wheel for richdem"
I have windows 10, 64-bit os and x64 based processor
I have downloaded anaconda with python 2.7
upgrade pip "python -m pip install –-upgrade pip setuptools wheel"
install pyhamcrest "pip install PyHamcrest"
install argparse "conda install -c anaconda argparse"
installed "Rtree-0.8.3-cp27-cp27m-win_amd64.whl" that helped with PyDEM didn't think it would hurt
at https://pypi.org/project/richdem/#files the are a number of richdem wheel files I tried the four that said cp27. I assumed that was for python 2.7
Any suggestions or do I give up
Thank you
Rebecca

Multithreading possible for Depression-Filling?

The documentation of RichDEM states that it "uses parallel processing and state of the art algorithms to quickly process even very large DEMs." I'm amazed at how fast it is even with large high resolution DEMs compared to the tools I used before. However, for the tool Depression-Filling for example, it didn't use parallel processing (the progress bar also states 1 thread used). Is there a parameter that I need to set prior to running Depression-Filling or is it that the task cannot be multithreaded (or is not multithreaded yet)? Note that I currently use RichDEM as a Python package on Windows.

Don't get my wrong, RichDEM as it is now is very fast, I'm just on the impression that it can be even faster.

Quiet mode?

Any way to run richdem in quiet/silent mode?

Global DEM

I am using the parallel_priority_flood algorithm to process the global Mars DEM(https://astrogeology.usgs.gov/search/details/Mars/GlobalSurveyor/MOLA/Mars_MGS_MOLA_DEM_mosaic_global_463m/cub). The speed of your program(https://github.com/r-barnes/richdem/tree/master/programs/parallel_priority_flood) is undoubtedly amazing! So far, I still have a small question.

I run the parallel_priority_flood algorithm for delinateing the watersheds. I understad that the algorithm starts with the edge cell, so I think the filled DEM should have some proplems at the edge area becasue the algorithm cannot simulate the water flow from the east edge of DEM to to west edge. Is it correct? For this reason, should I run the algorithm at least two times on the DEM with differenent central meridians(same map projeciton, but differnrent central meridians)?

Thank you for your time.

rd_merge_rasters_by_layout.cpp compile error

When compiling rd_merge_rasters_by_layout.cpp against GDAL 2.0.1 on CentOS 6.6 with GCC 4.8.4 the following error occurs:

rd_merge_rasters_by_layout.cpp: In function int main(int, char**):
rd_merge_rasters_by_layout.cpp:53:56: error: GDALGetDataTypeSizeBytes was not declared in this scope
     int dtype_size = GDALGetDataTypeSizeBytes(file_type);

This is caused by GDALGetDataTypeSizeBytes being not defined in this, and presumably earlier versions of GDAL.

Replacing line 53 with:

int dtype_size = GDALGetDataTypeSize(file_type) / 8;

compiles and should work. GDALGetDataTypeSizeBytes looks to be a convenience function added to later GDAL versions, and although deprecated, using GDALGetDataTypeSize (which returns bits instead of bytes) instead would make the this code usable by a broader range of GDAL versions.

All other applications in the apps directory compile without modification with GDAL 2.0.1

function options do not match python api documentation

In [6]: dem = rd.BreachDepressions(dem, in_place=True, mode='Complete')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-fa98777dc607> in <module>()
----> 1 dem = rd.BreachDepressions(dem, in_place=True, mode='Complete')

TypeError: BreachDepressions() got an unexpected keyword argument 'mode'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.