Git Product home page Git Product logo

pydem's Introduction

pyDEM: A python digital elevation model analysis package


PyDEM is a package for topographic (terrain) analysis written in Python (with a bit of Cython). It takes in digital elevation model (DEM) rasters, and it outputs quantities like slope, aspect, upstream area, and topographic wetness index. PyDEM closely follows the approach taken by TauDEM to calculate these quantities. It is designed to be fast, easily extensible, and capable of handling very large datasets.

PyDEM can be used both from the command-line, or programmatically via its Python API. Examples of both usages are given below and in the examples directory. It can operate on individual elevation rasters, or on entire directories simultaneously. Most processing steps can be performed in parallel with any number of independent pyDEM processes. Note that pyDEM depends on TauDEM for certain steps (e.g., pitfilling) and it also makes extensive use of the GDAL library for working with geospatial rasters.

1. Installation

For installation notes, see install.md

2. Basic Usage

Examples and tests can be found in the pydem\examples directory.

2.1 Python Module Usage

2.1.1. Calculate quantities on a single elevation tile

Import the DEMProcessor class:

from pydem.dem_processing import DEMProcessor

Set the path to a pit filled elevation file in WGS84 coordinates:

filename_to_elevation_geotiff = 'test.tiff'

Instantiate an instance of the DEMProcessor class:

dem_proc = DEMProcessor(filename_to_elevation_geotiff)

The following three commands do not need to be called in order.

Calculate the aspect and slope magnitude:

mag, aspect = dem_proc.calc_slopes_directions()

Calculate the upstream contributing area:

uca = dem_proc.calc_uca()

Calculate the TWI:

twi = dem_proc.calc_twi()

2.1.2 Calculate TWI on a directory of elevation tiles

The ProcessManager class orchestrates multiple processes to compute TWI over multiple tiles in parallel on the same machine. Example usage is as follows:

  from pydem.processing_manager import ProcessManager
  elevation_source_path = r'/home/twi-users/elevation'
  manager = ProcessManager(
    n_workers=64, # Number of worker processes to use
    in_path=elevation_source_path,
    out_path='/home/twi-users/temporary_compute_storage/'  # Where to save intermediate data
    dem_proc_kwargs={},  # dictionary of values used to initialize DemProcessor
  )
  # Start the processing
  manager.process_twi()  # If this fails (e.g. machine goes down), can restart to pick up where it left off

You can also call individual parts of the processing:

manager.compute_grid()  # Figures out how elevation in folder are tiled
manager.process_elevation()  # Fills flats, handles pits, fixes artifacts in elevation data
manager.process_aspect_slope()
manager.process_uca() # Computes upstream contributing area (UCA) for individual tiles (embarassingly parallel)
manager.process_uca_edges() # Fixes upstream flow contribution accross tile edges -- iteratively
manager.process_twi()  # Call all the above functions internally, but skips any work already done

Finally, to export results to a single GeoTiff with overviews, use:

manager.save_non_overlap_data_geotiff(
  'float32',  # Numpy recognized filetype
  new_path=output_path,
  keys=['elev', 'uca', 'aspect', 'slope', 'twi'], # list can contain a subset of these
  overview_type='average')

Note: The name non_overlap_data comes from an implementation quirk. The temporary data is saved as a zarr file. This zarr file OVERLAPS data at the edges of tiles to make it easier to compute UCA across edges

2.1.3 DEMProcessor options

The following options are used by the DEMProcess object. They can be modified by setting the value before processing.

dem_proc = DEMProcessor(filename_to_elevation_geotiff)
dem_proc.fill_flats = False

Slopes & Directions

  • chunk_size_slp_dir: Chunk size for slopes_directions calculation. Default 512.
  • chunk_overlap_slp_dir: Overlap to use for resolving slopes and directions at chunk edges. Default 4.
  • fill_flats: Fill/interpolate the elevation for flat regions before calculating slopes and directions. The direction cannot be calculated in regions where the slope is 0 because the nominal elevation is all the same. This can happen in very gradual terrain or in lake and river beds, particularly when the input elevation is composed of integers. When True, the elevation is interpolated in those regions so that a reasonable slope and direction can be calculated. Default True.
  • fill_flats_below_sea: Interpolate the elevation for flat regions that are below sea level. Water will never flow out of these "pits", so in many cases you can ignore these regions and achieve faster processing times. Default False.
  • fill_flats_source_tol: When filling flats, the algorithm finds adjacent "source" pixels and "drain" pixels for each flat region and interpolates the elevation using these data points. This sets the tolerance for the elevation of source pixels above the flat region (i.e. shallow sources are used as sources but not steep cliffs). Default 1.
  • fill_flats_peaks: Interpolate the elevation for flat regions that are "peaks" (local maxima). These regions have a higher elevation than all adjacent pixels, so there are no "source" pixels to use for interpolation. When True, a single pixel is selected approximately in the center of the flat region as the "peak"/"source". Default True.
  • fill_flats_pits: Interpolate the elevation for flat regions that are "pits" (local minima). These regions have a lower elevation than all adjacent pixels, so there are no "drain" pixels to use for interpolation. When True, a single pixel is selected approximately in the center of the flat region as the "pit"/"drain". Default True.

UCA

  • resolve_edges: Ensure edge UCA is continuous across chunks. Default True.
  • chunk_size_uca: Chunk size for uca calculation. Default 512.
  • chunk_overlap_uca: Overlap to use for resolving uca at chunk edges. Default 32.
  • drain_pits: Drain from "pits" to nearby but non-adjacent pixels. Pits have no lower adjacent pixels to drain to directly. Note that with fill_flats_pits off, this setting will still drain each pixel in large flat regions, but it may be slower and produces less reasonable results. Default True.
  • drain_pits_max_iter: Maximum number of iterations to look for drain pixels for pits. Generally, "nearby drains" for a pit/flat region are found by expanding the region upward/outward iteratively. Default 100.
  • drain_pits_max_dist: Maximum distance in coordnate-space to (non-adjacent) drains for pits. Pits that are too far from another pixel with a lower elevation will not drain. Default 20.
  • drain_pits_max_dist_XY: Maximum distance in real-space to (non-adjacent) drains for pits. Pits that are too far from another pixel with a lower elevation will not drain. This filter is applied after drain_pits_max_dist; if the X and Y resolution are similar, this filter is generally unnecessary. Default None.
  • drain_flats: [Deprecated, replaced by drain_pits] Drains flat regions and pits by draining all pixels in the region to an arbitrary pixel in the region and then draining that pixel to the border of the flat region. Ignored if drain_pits is True. Default False.
  • apply_uca_limit_edges: Mark edges as completed if the maximum UCA is reached when resolving drainage across edges. Default False. If True, it may speed up large calculations.
  • uca_saturaion_limit: Default 32.

TWI

  • apply_twi_limits: When calculating TWI, limit TWI to max value. Default False.
  • apply_twi_limits_on_uca: When calculating TWI, limit UCA to max value. Default False.

Other

  • save_projection: Default EPSG:4326.

2.2 Commandline Usage

When installing pydem using the provided setup.py file, the commandline utilities TWIDinf, AreaDinf, and DinfFlowDir are registered with the operating system.

TWIDinf :

usage: TWIDinf-script.py [-h] [--save-all]
                     Input_Pit_Filled_Elevation [Input_Number_of_Chunks]
                     [Output_D_Infinity_TWI]

Calculates a grid of topographic wetness index which is the log_e(uca / mag),
that is, the natural log of the ratio of contributing area per unit contour
length and the magnitude of the slope. Note, this function takes the elevation
as an input, and it calculates the slope, direction, and contributing area as
intermediate steps.

positional arguments:
  Input_Pit_Filled_Elevation
                    The input pit-filled elevation file in geotiff format.
  Input_Number_of_Chunks
                    The approximate number of chunks that the input file
                    will be divided into for processing (potentially on
                    multiple processors).
  Output_D_Infinity_TWI
                    Output filename for the topographic wetness index.
                    Default value = twi.tif .

optional arguments:
  -h, --help            show this help message and exit
  --save-all, --sa      If set, will save all intermediate files as well.

AreaDinf :

usage: AreaDinf-script.py [-h] [--save-all]
                      Input_Pit_Filled_Elevation [Input_Number_of_Chunks]
                      [Output_D_Infinity_Specific_Catchment_Area]

Calculates a grid of specific catchment area which is the contributing area
per unit contour length using the multiple flow direction D-infinity approach.
Note, this is different from the equivalent tauDEM function, in that it takes
the elevation (not the flow direction) as an input, and it calculates the
slope and direction as intermediate steps.

positional arguments:
  Input_Pit_Filled_Elevation
                    The input pit-filled elevation file in geotiff format.
  Input_Number_of_Chunks
                    The approximate number of chunks that the input file
                    will be divided into for processing (potentially on
                    multiple processors).
  Output_D_Infinity_Specific_Catchment_Area
                    Output filename for the flow direction. Default value = uca.tif .

optional arguments:
  -h, --help            show this help message and exit
  --save-all, --sa      If set, will save all intermediate files as well.

DinfFlowDir :

usage: DinfFlowDir-script.py [-h]
                         Input_Pit_Filled_Elevation
                         [Input_Number_of_Chunks]
                         [Output_D_Infinity_Flow_Direction]
                         [Output_D_Infinity_Slope]

Assigns a flow direction based on the D-infinity flow method using the
steepest slope of a triangular facet (Tarboton, 1997, "A New Method for the
Determination of Flow Directions and Contributing Areas in Grid Digital
Elevation Models," Water Resources Research, 33(2): 309-319).

positional arguments:
  Input_Pit_Filled_Elevation
                    The input pit-filled elevation file in geotiff format.
  Input_Number_of_Chunks
                    The approximate number of chunks that the input file
                    will be divided into for processing (potentially on
                    multiple processors).
  Output_D_Infinity_Flow_Direction
                    Output filename for the flow direction. Default value = ang.tif .
  Output_D_Infinity_Slope
                    Output filename for the flow direction. Default value = mag.tif .

optional arguments:
  -h, --help            show this help message and exit

3. Description of package Contents

  • commandline_utils.py : Contains the functions that wrap the python modules into command line utilities.
  • dem_processing.py: Contains the main algorithms.
    • Re-implements the D-infinity method from Tarboton (1997).
    • Implements a new upstream contributing area algorithm. This performs essentially the same task as previous upstream contributing area algorithms, but with some added functionality. This version deals with areas where the elevation is flat or has no data values and can be updated from the edges without re-calculating the upstream contributing area for the entire tile.
    • Re-implements the calculation of the Topographic Wetness Index.
  • process_manager.py: Implements a class that manages the calculation of TWI for a directory of files.
    • Manages the calculation of the upstream contributing area that drains across tile edges.
    • Stores errors in the processing.
    • Allows multiple processes to work on the same directory without causing conflicts.
  • test_pydem.py: A few helper utilities that create analytic test-cases used to develop/test pyDEM.
  • utils.py: A few helper utility functions.
    • Renames files in a directory (deprecated, no longer needed).
    • Parses file names.
    • Wraps some gdal functions for reading and writing geotiff files.
    • Sorts the rows in an array.
  • cyfuncs: Directory containing cythonized versions of python functions in dem_processing.py. These should be compiled during installation.
    • cyfuncs.cyutils.pyx: Computationally efficient implementations of algorithms used to calculate upstream contributing area.
  • examples: Directory containing a few examples, along with an end-to-end test of the cross-tile calculations.
    • examples.compare_tile_to_chunk.py: Compares the calculation of the upstream contributing area over a full tile compared to multiple chunks in a file. This tests that the upstream contributing area calculation correctly drains across tile edges.
      • examples.process_manager_directory.py: This shows how to use the ProcessingManager to calculate all of the elevation files within a directory.
  • aws: Directory containing experiment for running PyDEM on Amazon Web Services
  • pydem.test.test_end_to_end.py: A few integration tests. Can be run from the commandline using the pytest package: cd pydem; cd test; pytest .

4. References

Tarboton, D. G. (1997). A new method for the determination of flow directions and upslope areas in grid digital elevation models. Water resources research, 33(2), 309-319.

Ueckermann, Mattheus P., et al. (2015). "pyDEM: Global Digital Elevation Model Analysis." In K. Huff & J. Bergstra (Eds.), Scipy 2015: 14th Python in Science Conference. Paper presented at Austin, Texas, 6 - 12 July (pp. 117 - 124). http://conference.scipy.org/proceedings/scipy2015/mattheus_ueckermann.html

5. Attributions

pyDEM uses lib.pyx from the OpenPIV project for inpainting missing values in the final outputs.

pydem's People

Contributors

emilopez avatar empeeu avatar jmilloy avatar leblancfg avatar mirkodandrea avatar mpu-creare avatar mswanson333 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

pydem's Issues

Lowering error using pyDEM dem processor

I'm in Win7 64, Anaconda Python installation, pip installed PyDEM.

I'm getting an error when calling .calc_slopes_directions() on a DEMProcessor instance (see below).

I'm aware of this question; that seems not to be the same problem I have.

This LoweringError: slc0.8 seems to be related to Numba.

This is the code I enter and the error I get:

from pydem.dem_processing import DEMProcessor

os.chdir(r'D:\my_path')

a_tile = r'31an2_clipped_wgs84.tif'

dem_proc = DEMProcessor(a_tile)

mag, aspect = dem_proc.calc_slopes_directions()
starting slope/direction calculation for chunk 1 [0:516, 0:516]
Traceback (most recent call last):

  File "<ipython-input-13-6dc0db5771d2>", line 1, in <module>
    mag, aspect = dem_proc.calc_slopes_directions()

  File "C:\Program Files\Anaconda2\lib\site-packages\pydem\dem_processing.py", line 853, in calc_slopes_directions
    self.dY[te:be-1])

  File "C:\Program Files\Anaconda2\lib\site-packages\pydem\dem_processing.py", line 879, in _slopes_directions
    return self._tarboton_slopes_directions(data, dX, dY)

  File "C:\Program Files\Anaconda2\lib\site-packages\pydem\dem_processing.py", line 890, in _tarboton_slopes_directions
    self.facets, self.ang_adj)

  File "C:\Program Files\Anaconda2\lib\site-packages\numba\dispatcher.py", line 285, in _compile_for_args
    return self.compile(tuple(argtypes))

  File "C:\Program Files\Anaconda2\lib\site-packages\numba\dispatcher.py", line 531, in compile
    cres = self._compiler.compile(args, return_type)

  File "C:\Program Files\Anaconda2\lib\site-packages\numba\dispatcher.py", line 80, in compile
    flags=flags, locals=self.locals)

  File "C:\Program Files\Anaconda2\lib\site-packages\numba\compiler.py", line 725, in compile_extra
    return pipeline.compile_extra(func)

  File "C:\Program Files\Anaconda2\lib\site-packages\numba\compiler.py", line 369, in compile_extra
    return self.compile_bytecode(bc, func_attr=self.func_attr)

  File "C:\Program Files\Anaconda2\lib\site-packages\numba\compiler.py", line 378, in compile_bytecode
    return self._compile_bytecode()

  File "C:\Program Files\Anaconda2\lib\site-packages\numba\compiler.py", line 690, in _compile_bytecode
    return self._compile_core()

  File "C:\Program Files\Anaconda2\lib\site-packages\numba\compiler.py", line 677, in _compile_core
    res = pm.run(self.status)

  File "C:\Program Files\Anaconda2\lib\site-packages\numba\compiler.py", line 257, in run
    raise patched_exception

LoweringError: slc0.8

How to install taudem?

I tried installing taudem through the Windows installer downloaded from original website. Even after installing it, when I run an example code it raises the following exception:
File "C:\Anaconda3\envs\codefundo\lib\site-packages\pydem\taudem\taudem.py", line 33, in _run
raise Exception("Taudem did not complete. Is it installed properly?")
Exception: Taudem did not complete. Is it installed properly?

Runtime Error

I'm able to install package and import functions. I instantiated the instance with the raster file but getting maximum recursion depth error while calculating aspect and slope magnitude. I'm using ASTER-DEM data. Can anyone help me to resolve this one?

Problems with Taudem

Hi, the link in your instructions for the Taudem source for windows: http://svn.mapwindow.org/svnroot/MapWindow4Dev/Bin/Taudem5Exe/ is not working. Trying to go around the problem, I installed Taudem following the instructions in their website for windows, and although Taudem was properly working, when I try to run pydem in one of your examples, i.e. elev, ang, test_data = get_test_data(testnum, NN) it returns the message: "Taudem did not complete. Is it installed properly?". After that I manually copy the executables from the Taudem installation found in the folder C:\Program Files\TauDEM\TauDEM5Exe to a folder you suggested: <ANACONDA_ROOT><lib>\pydem\taudem\taudem_Windows and I still get the message: "Taudem did not complete. Is it installed properly?".

Thanks for your help,

Error in calc_uca()

When I try to run calc_uca, I get the following error:

pydem/cyfuncs/cyutils.pyx in pydem.cyfuncs.cyutils.drain_area (/private/var/folders/1j/r_xd9vp15td_mdt_3rgrx13w0000gp/T/pip-rmLTHG-build/pydem/cyfuncs/cyutils.cpp:2470)() ValueError: Item size of buffer (8 bytes) does not match size of 'int' (4 bytes)

Installed pydem via pip install --ignore-installed git+git://github.com/creare-com/pydem.git@develop as in here https://github.com/creare-com/pydem/issues/7 to solve the same problem: TypeError: Cannot cast ufunc add output from dtype('float64') to dtype('bool') with casting rule 'same_kind'.

Python 2.7.12, MacOS 10.12.3, 64-bit.

Note: GeoTIFFs I provide as an input are of float32 type, but calc_slopes_directions outputs float64.

Trouble saving outputs to file

Hello,

I am a graduate researcher at the University of Virginia and I am working on designing/optimizing a terrain analysis model used to identify wetlands. I am just beginning to move this model out of ArcGIS and I think the pyDEM library is a great tool to calculate the TWI and its derivatives for my study sites. I'm starting off just working with the test_NN064_013_elev.tif file before processing the elevation tiles for my study sites. Using the test tif, I try to create a DEMProcessor object, calculate the slope and directions, plot the slope array, and save the slope array to a file. My code is below:

filename_to_elevation_geotiff = 'test_NN064_013_elev.tif'

dem_proc = DEMProcessor(filename_to_elevation_geotiff)

mag, aspect = dem_proc.calc_slopes_directions()

print dem_proc.mag

plt.imshow(dem_proc.direction)

if not os.path.exists('mag'):
os.mkdir('mag')
dem_proc.save_slope('.')
print 'done'


When I run this code, I get the following output:

starting slope/direction calculation
[[ 1.57748599e-05 1.57748599e-05 1.56843030e-05 ..., 1.56843030e-05
1.57748599e-05 1.57748599e-05]
[ 1.57748599e-05 1.57748599e-05 1.56843030e-05 ..., 1.56843030e-05
1.57748599e-05 1.57748599e-05]
[ 1.58631500e-05 1.58631500e-05 1.57733022e-05 ..., 1.57733022e-05
1.58631500e-05 1.58631500e-05]
...,
[ 1.56804838e-05 1.56804838e-05 1.55954034e-05 ..., 1.55954034e-05
1.56804838e-05 1.56804838e-05]
[ 1.55911111e-05 1.55911111e-05 1.55055366e-05 ..., 1.55055366e-05
1.55911111e-05 1.55911111e-05]
[ 1.55911111e-05 1.55911111e-05 1.55055366e-05 ..., 1.55055366e-05
1.55911111e-05 1.55911111e-05]]
<<<<<<<< gdalwarp -multi -wm 2000 -co BIGTIFF=YES -of GTiff -co compress=lzw -co TILED=YES -wo OPTIMIZE_SIZE=YES -r near -t_srs EPSG:4326 .\mag\N45W-73_N46W-72_mag_tmp.tif .\mag\N45W-73_N46W-72_mag.tif >>>>>>>>
done

A plot is created (attached) and a "mag" folder is created in my directory. However, this folder remains empty and I cannot find the newly created mag geotiff anywhere on my computer.

We think that this line :

https://github.com/creare-com/pydem/blob/master/pydem/dem_processing.py#L682

which removes the tmp file may be deleting the output of the save_slope method. We have tried to edit the dem_processing.py file to comment out line 682, but the edits (or other test edits) do not seem to affect my code, and I get the same result.

What do you think is causing this?

Thanks,
Gina

testtiff_mag

Cannot open source file: 'pydem\cyfuncs\cyutils.c'

Hi there,

I am trying to install pydem on a Windows 7 system, and I am getting the error "Cannot open source file: 'pydem\cyfuncs\cyutils.c'" Is that something that should be copied from my cython installation, or should that come with the pydem download?

Thanks,
Stephanie

How to deal with no place to drain warning

While calculating UCA, I'm getting User warning, "Warning 2416 pits had no place to drain to in this chunk
"chunk" % len(warn_pits))". How to handle this kind of warning. I'm getting this error on many chunks. Any suggestion?

Type casting problems with SRTM DEM

I was hoping to compute slope and aspect for some digital elevation models from the NASA SRTM mission, and ran into a type error that seems to be related to the _find_flats_edges function.

Here's a reproducible example Jupyter notebook that demonstrates the problem: https://gist.github.com/mbjoseph/9934454330b5715db9529502cf415f72#file-pydem-srtm-example-ipynb

A TypeError is raised:

TypeError: Cannot cast ufunc add output from dtype('float64') to dtype('bool') with casting rule 'same_kind'

It seems like similar issues have arisen elsewhere, e.g., numpy/numpy#7225

KeyError upon Instantiating an instance of the DEMProcessor class --Projection

I am running PyDEM (0.2.0) on Python (2.7.14) and trying to follow the instructions on the readme.md file. Below I have listed the commands I used, the output, and the input elevation file. I am getting the KeyError with the third command. It looks like it has something to do with the projection files. Has anyone else had this issue and if so, how did you solve it. I tried to search this error with Google but did not find anything useful.

Here are the commands I typed in the Python Console:

from pydem.dem_processing import DEMProcessor
boy = 'elevationUTM.tif'
dem_proc = DEMProcessor(boy)

Then I receive the messages including the key error at the end:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Python27\lib\site-packages\pydem\dem_processing.py", line 565, in __init__
    elev, = elev_file.raster_layers
  File "C:\Python27\lib\site-packages\traits\has_traits.py", line 895, in decorator
    self.__dict__[ name ] = result = function( self )
  File "C:\Python27\lib\site-packages\pydem\reader\gdal_reader.py", line 195, in _get_raster_layers
    for raster_band in raster_bands]
  File "C:\Python27\lib\site-packages\pydem\reader\gdal_reader.py", line 143, in _raster_layer_from_raster_band
    layer.grid_coordinates = self.grid_coordinates
  File "C:\Python27\lib\site-packages\traits\has_traits.py", line 895, in decorator
    self.__dict__[ name ] = result = function( self )
  File "C:\Python27\lib\site-packages\pydem\reader\gdal_reader.py", line 130, in _get_grid_coordinates
    wkt = d_wkt_to_name[wkt_]
KeyError: 'PROJCS["WGS_1984_UTM_Zone_16N",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"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-87],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","32616"]]'

Here is the input elevation model I used (this file was created with ArcGISPro using the project raster command and the projection was WGS_1984_UTM_Zone_16N):
elevationUTM.tif.zip

I have tried the solution recommended by mpu-creare but this did not work. Here is the link for that GitHub Issue.
https://github.com/creare-com/pydem/issues/1

Installation issue

I am encountering a problem during pydem installation.

I've tried to install it using python 2.7 and python3 on windows and wsl.

Python=3.12.4

error

  Using cached pyDEM-1.0.0.tar.gz (136 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [6 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:\Users\wojciech.kaczan\AppData\Local\Temp\pip-install-xvce4z5x\pydem_030c095be18b4af795ec6f1d6dcafe74\setup.py", line 27, in <module>
          from Cython.Build import cythonize
      ModuleNotFoundError: No module named 'Cython'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

after installing cython:

Building wheels for collected packages: pydem, asciitree
  Building wheel for pydem (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [17 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-cpython-312
      creating build\lib.win-amd64-cpython-312\pydem
      copying pydem\commandline_utils.py -> build\lib.win-amd64-cpython-312\pydem
      copying pydem\dem_processing.py -> build\lib.win-amd64-cpython-312\pydem
      copying pydem\process_manager.py -> build\lib.win-amd64-cpython-312\pydem
      copying pydem\utils.py -> build\lib.win-amd64-cpython-312\pydem
      copying pydem\utils_test_pydem.py -> build\lib.win-amd64-cpython-312\pydem
      copying pydem\__init__.py -> build\lib.win-amd64-cpython-312\pydem
      creating build\lib.win-amd64-cpython-312\pydem\cyfuncs
      copying pydem\cyfuncs\__init__.py -> build\lib.win-amd64-cpython-312\pydem\cyfuncs
      running build_ext
      building 'pydem.cyfuncs.cyutils' extension
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pydem
  Running setup.py clean for pydem
  Building wheel for asciitree (setup.py) ... done
  Created wheel for asciitree: filename=asciitree-0.3.3-py3-none-any.whl size=5048 sha256=9eaf147b42d2c64c38d17b3707c7f619237605de5bf7ff239254c0051e527529
  Stored in directory: c:\users\wojciech.kaczan\appdata\local\pip\cache\wheels\a5\d7\98\f56ae733748cd0fa577172bda0e73e0b1f1793c98e09b9e458
Successfully built asciitree
Failed to build pydem
ERROR: Could not build wheels for pydem, which is required to install pyproject.toml-based projects`

The environment:

name: wet-dem
channels:
  - defaults
dependencies:
  - affine=2.3.0=pyhd3eb1b0_0
  - attrs=23.1.0=py312haa95532_0
  - blas=1.0=mkl
  - bzip2=1.0.8=h2bbff1b_6
  - ca-certificates=2024.3.11=haa95532_0
  - certifi=2024.6.2=py312haa95532_0
  - cfitsio=3.470=h2bbff1b_7
  - click=8.1.7=py312haa95532_0
  - click-plugins=1.1.1=pyhd3eb1b0_0
  - cligj=0.7.2=pyhd3eb1b0_0
  - colorama=0.4.6=py312haa95532_0
  - curl=8.7.1=he2ea4bf_0
  - expat=2.6.2=hd77b12b_0
  - freexl=1.0.6=h2bbff1b_0
  - geos=3.8.0=h33f27b4_0
  - geotiff=1.7.0=h4545760_1
  - hdf4=4.2.13=h712560f_2
  - hdf5=1.10.6=h1756f20_1
  - icc_rt=2022.1.0=h6049295_2
  - intel-openmp=2023.1.0=h59b6b97_46320
  - jpeg=9e=h2bbff1b_1
  - kealib=1.4.14=hde4a422_1
  - krb5=1.20.1=h5b6d351_0
  - lerc=3.0=hd77b12b_0
  - libcurl=8.7.1=h86230a5_0
  - libdeflate=1.17=h2bbff1b_1
  - libffi=3.4.4=hd77b12b_1
  - libgdal=3.0.2=hc12e7b7_6
  - libiconv=1.16=h2bbff1b_3
  - libnetcdf=4.8.1=h6685c40_2
  - libpng=1.6.39=h8cc25b3_0
  - libpq=12.17=h906ac69_0
  - libspatialite=4.3.0a=h6ec8781_23
  - libssh2=1.11.0=h291bd65_0
  - libtiff=4.5.1=hd77b12b_0
  - libxml2=2.10.4=h0ad7f3c_2
  - libzip=1.8.0=h289538f_1
  - lz4-c=1.9.4=h2bbff1b_1
  - m2w64-expat=2.1.1=2
  - m2w64-gcc-libgfortran=5.3.0=6
  - m2w64-gcc-libs=5.3.0=7
  - m2w64-gcc-libs-core=5.3.0=7
  - m2w64-gettext=0.19.7=2
  - m2w64-gmp=6.1.0=2
  - m2w64-libiconv=1.14=6
  - m2w64-libwinpthread-git=5.0.0.4634.697f757=2
  - m2w64-xz=5.2.2=2
  - mkl=2023.1.0=h6b88ed4_46358
  - mkl-service=2.4.0=py312h2bbff1b_1
  - mkl_fft=1.3.8=py312h2bbff1b_0
  - mkl_random=1.2.4=py312h59b6b97_0
  - msys2-conda-epoch=20160418=1
  - numpy=1.26.4=py312hfd52020_0
  - numpy-base=1.26.4=py312h4dde369_0
  - openjpeg=2.4.0=h4afccc4_1
  - openssl=3.0.14=h827c3e9_0
  - pip=24.0=py312haa95532_0
  - proj=6.2.1=h3758d61_0
  - pyparsing=3.0.9=py312haa95532_0
  - python=3.12.4=h14ffc60_1
  - rasterio=1.2.10=py312hf4cbf27_0
  - setuptools=69.5.1=py312haa95532_0
  - snuggs=1.4.7=pyhd3eb1b0_0
  - sqlite=3.45.3=h2bbff1b_0
  - tbb=2021.8.0=h59b6b97_0
  - tiledb=2.3.3=hd8964de_3
  - tk=8.6.14=h0416ee5_0
  - tzdata=2024a=h04d1e81_0
  - vc=14.2=h2eaa2aa_4
  - vs2015_runtime=14.29.30133=h43f2093_4
  - wheel=0.43.0=py312haa95532_0
  - xerces-c=3.2.4=hd77b12b_1
  - xz=5.4.6=h8cc25b3_1
  - zlib=1.2.13=h8cc25b3_1
  - zstd=1.5.5=hd43e919_2
  - pip:
      - cython==3.0.10

Working with Nan values

I tried pyDEM on SRTM data, I'm able to calculate TWI, but in the final output, I'm getting Nan values as well. Can you please help me how to resolve this issue or is there any pre-processing required? Also can you please add a comment on visualization part of the TWI on the map, like Folium etc?

Installation error: Microsoft Visual C++ 14.0 is required.

Hi all. I get the following errors when trying to install PyDEM from pip on Windows, with the Anaconda distribution of Python:

Running setup.py bdist_wheel for pyDEM: finished with status 'error'
[...]
building 'pydem.cyfuncs.cyutils' extension
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

...which I can't install on this corporate computer. I assume I'll get the same issue trying to build from source too.

Might I suggest you look into the following for an eventual release? Would be interesting to:

  1. Upload pre-built wheels to pypi, and/or
  2. Create a conda-forge recipe for the anaconda distribution.

Cheers!

Python 3 release open issues

  • Need to fix Geotiff write out when the tiles are not contiguous
  • Need mechanism to pass parameters through compute manager to demprocessor
  • Need a helper function to compute everything needed to run any of the process functions
  • Need to fix the order of operations for the edge-fixing so that each tile is at least visited once before any other tile is processed a second time. That just gets 99% of the tile-to-tile errors

cl.exe failed with exit status 2

I am attempting to install pyDEM via pip.

I have Python 2.7.9. I have also installed the necessary numpy, scipy, and GDAL packages.

When I try to install it, I get the following error. Anyone have know how to make this work?

traits/ctraits.c(956) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', possible loss of data

traits/ctraits.c(2221) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', possible loss of data

traits/ctraits.c(2254) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', possible loss of data

traits/ctraits.c(3167) : warning C4244: 'initializing' : conversion from 'Py_ssize_t' to 'int', possible loss of data

traits/ctraits.c(3189) : warning C4244: 'initializing' : conversion from 'Py_ssize_t' to 'int', possible loss of data

traits/ctraits.c(3513) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', possible loss of data

traits/ctraits.c(3597) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', possible loss of data

traits/ctraits.c(3808) : warning C4244: 'initializing' : conversion from 'Py_ssize_t' to 'int', possible loss of data

traits/ctraits.c(3814) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', possible loss of data

traits/ctraits.c(3824) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', possible loss of data

traits/ctraits.c(3927) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', possible loss of data

traits/ctraits.c(4131) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', possible loss of data

traits/ctraits.c(5477) : error C2079: 'ctraitsmodule' uses undefined struct 'PyModuleDef'

traits/ctraits.c(5478) : error C2065: 'PyModuleDef_HEAD_INIT' : undeclared identifier

traits/ctraits.c(5478) : error C2099: initializer is not a constant

traits/ctraits.c(5478) : warning C4047: 'initializing' : 'int' differs in levels of indirection from 'char [8]'

traits/ctraits.c(5478) : error C2078: too many initializers

traits/ctraits.c(5488) : warning C4013: 'PyModule_Create' undefined; assuming extern returning int

traits/ctraits.c(5488) : warning C4047: '=' : 'PyObject *' differs in levels of indirection from 'int'

traits/ctraits.c(5490) : warning C4098: 'PyInit_ctraits' : 'void' function returning a value

traits/ctraits.c(5497) : warning C4098: 'PyInit_ctraits' : 'void' function returning a value

traits/ctraits.c(5503) : warning C4098: 'PyInit_ctraits' : 'void' function returning a value

traits/ctraits.c(5511) : warning C4098: 'PyInit_ctraits' : 'void' function returning a value

traits/ctraits.c(5516) : warning C4098: 'PyInit_ctraits' : 'void' function returning a value

traits/ctraits.c(5537) : warning C4098: 'PyInit_ctraits' : 'void' function returning a value

traits/ctraits.c(5542) : warning C4098: 'PyInit_ctraits' : 'void' function returning a value

traits/ctraits.c(5547) : warning C4098: 'PyInit_ctraits' : 'void' function returning a value

traits/ctraits.c(5554) : warning C4098: 'PyInit_ctraits' : 'void' function returning a value

traits/ctraits.c(5559) : warning C4098: 'PyInit_ctraits' : 'void' function returning a value

traits/ctraits.c(5564) : warning C4098: 'PyInit_ctraits' : 'void' function returning a value

traits/ctraits.c(5568) : warning C4098: 'PyInit_ctraits' : 'void' function returning a value

error: command 'C:\\Users\\User\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64\\cl.exe' failed with exit status 2

Check for python version before installing

Pydem requires python 2.7 but somehow I was able to install and import the library using python 3.5. Needless to say my application failed.

Unrelated feature request: It would be useful to be able to instantiate DEMProcessor from a 2D numpy array rather than passing the name to a tif file.

KeyError reading coordinate strings

I cant read a dem file.

I have installed pydem using pip and all the requirements (numba, etc) via conda.

When I try

dem_proc = DEMProcessor(filename_to_elevation_geotiff)

I am receiving a key error with an etopo dem:

/home/emiliano/anaconda/lib/python2.7/site-packages/pydem/reader/gdal_reader.pyc
in get_grid_coordinates(self)
128
129 wkt
= dataset.GetProjection()
--> 130 wkt = d_wkt_to_name[wkt_]
131
132

KeyError: 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS
84",6378137,298.2572235604902,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4326"]]'

And, similar error message for aster dem:

KeyError: 'GEOGCS["WGS
84",DATUM["unknown",SPHEROID["WGS84",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]]'

I have also tried converting .bil to .tiff using gdal_convert, and I get
the same keyerror message.

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.