Skip to content

Commit f6920e3

Browse files
committed
Fix pyrichdem to import all cpp source files correctly
Clean up pyrichdem setup.py Add .log files to .gitignore
1 parent 9e26461 commit f6920e3

File tree

5 files changed

+60
-62
lines changed

5 files changed

+60
-62
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ a.out
99
travis.log
1010
build/
1111
.vscode/
12+
.log

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2022-02-11 (2.3.1)
2+
==================
3+
4+
Fix pyrichdem to import all cpp source files correctly
5+
Clean up pyrichdem setup.py
6+
Add .log files to .gitignore
7+
18
2022-02-09 (2.3.0)
29
==================
310

wrappers/pyrichdem/lib/richdem

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../include/richdem
1+
../../../

wrappers/pyrichdem/richdem/__init__.py

+29-28
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import pkg_resources
2-
import datetime
31
import copy
2+
import datetime
43
import numpy as np
4+
import pkg_resources
55

66
try:
77
import _richdem
8-
except ImportError:
8+
except ImportError as e:
99
print('COULD NOT LOAD RichDEM ENGINE! NOTHING WILL WORK!')
10+
raise e
1011

1112
try:
1213
from osgeo import gdal
@@ -90,7 +91,7 @@ def rdShow(rda, ignore_colours=[], show=True, axes=True, cmap='gray', vmin=None,
9091

9192
if all_zoom:
9293
axins = inset_axes(ax, width=2, height=2, loc=zloc, borderpad=0) #, bbox_to_anchor=(0.9, -0.05, 1, 1), bbox_transform=ax.transAxes, borderpad=0)
93-
axins.set_xlim(xmin=zxmin,xmax=zxmax)
94+
axins.set_xlim(xmin=zxmin,xmax=zxmax)
9495
axins.set_ylim(ymin=zymin,ymax=zymax)
9596
plt.setp(axins.get_xticklabels(), visible=False)
9697
plt.setp(axins.get_yticklabels(), visible=False)
@@ -116,8 +117,8 @@ def rdShow(rda, ignore_colours=[], show=True, axes=True, cmap='gray', vmin=None,
116117

117118
class rdarray(np.ndarray):
118119
def __new__(cls, array, meta_obj=None, no_data=None, dtype=None, order=None, **kwargs):
119-
obj = np.asarray(array, dtype=dtype, order=order).view(cls)
120-
120+
obj = np.asarray(array, dtype=dtype, order=order).view(cls)
121+
121122
if meta_obj is not None:
122123
obj.metadata = copy.deepcopy(getattr(meta_obj, 'metadata', dict()))
123124
obj.no_data = copy.deepcopy(getattr(meta_obj, 'no_data', None ))
@@ -155,7 +156,7 @@ def wrap(self):
155156
dtype = str(self.dtype)
156157
if not dtype in richdem_arrs:
157158
raise Exception("No equivalent RichDEM datatype.")
158-
159+
159160
rda = richdem_arrs[dtype](self)
160161

161162
if self.no_data is None:
@@ -170,7 +171,7 @@ def wrap(self):
170171
print("Warning! No geotransform defined. Choosing a standard one! (Top left cell's top let corner at <0,0>; cells are 1x1.)")
171172
rda.geotransform = np.array([0,1,0,0,0,-1], dtype='float64')
172173

173-
return rda
174+
return rda
174175

175176
def copyFromWrapped(self, wrapped):
176177
self.no_data = wrapped.noData()
@@ -181,8 +182,8 @@ def copyFromWrapped(self, wrapped):
181182

182183
class rd3array(np.ndarray):
183184
def __new__(cls, array, meta_obj=None, no_data=None, order=None, **kwargs):
184-
obj = np.asarray(array, dtype=np.float32, order=order).view(cls)
185-
185+
obj = np.asarray(array, dtype=np.float32, order=order).view(cls)
186+
186187
if meta_obj is not None:
187188
obj.metadata = copy.deepcopy(getattr(meta_obj, 'metadata', dict()))
188189
obj.no_data = copy.deepcopy(getattr(meta_obj, 'no_data', None ))
@@ -211,7 +212,7 @@ def wrap(self):
211212
dtype = str(self.dtype)
212213
if not dtype in richdem_arrs:
213214
raise Exception("No equivalent RichDEM datatype.")
214-
215+
215216
rda = richdem_arrs[dtype](self)
216217

217218
if self.no_data is None:
@@ -226,7 +227,7 @@ def wrap(self):
226227
print("Warning! No geotransform defined. Choosing a standard one! (Top left cell's top let corner at <0,0>; cells are 1x1.)")
227228
rda.geotransform = np.array([0,1,0,0,0,-1], dtype='float64')
228229

229-
return rda
230+
return rda
230231

231232
def copyFromWrapped(self, wrapped):
232233
self.no_data = wrapped.noData()
@@ -250,7 +251,7 @@ def LoadGDAL(filename, no_data=None):
250251
251252
Returns:
252253
A RichDEM array
253-
"""
254+
"""
254255
if not GDAL_AVAILABLE:
255256
raise Exception("richdem.LoadGDAL() requires GDAL.")
256257

@@ -333,7 +334,7 @@ def FillDepressions(
333334
epsilon (float): If True, an epsilon gradient is imposed to all flat regions.
334335
This ensures that there is always a local gradient.
335336
in_place (bool): If True, the DEM is modified in place and there is
336-
no return; otherwise, a new, altered DEM is returned.
337+
no return; otherwise, a new, altered DEM is returned.
337338
topology (string): A topology indicator
338339
339340
Returns:
@@ -380,7 +381,7 @@ def BreachDepressions(
380381
Args:
381382
dem (rdarray): An elevation model
382383
in_place (bool): If True, the DEM is modified in place and there is
383-
no return; otherwise, a new, altered DEM is returned.
384+
no return; otherwise, a new, altered DEM is returned.
384385
topology (string): A topology indicator
385386
386387
Returns:
@@ -420,7 +421,7 @@ def ResolveFlats(
420421
Args:
421422
dem (rdarray): An elevation model
422423
in_place (bool): If True, the DEM is modified in place and there is
423-
no return; otherwise, a new, altered DEM is returned.
424+
no return; otherwise, a new, altered DEM is returned.
424425
425426
Returns:
426427
DEM modified such that all flats drain.
@@ -456,15 +457,15 @@ def FlowAccumulation(
456457
Args:
457458
dem (rdarray): An elevation model
458459
method (str): Flow accumulation method to use. (See below.)
459-
exponent (float): Some methods require an exponent; refer to the
460+
exponent (float): Some methods require an exponent; refer to the
460461
relevant publications for details.
461462
weights (rdarray): Flow accumulation weights to use. This is the
462463
amount of flow generated by each cell. If this is
463464
not provided, each cell will generate 1 unit of
464465
flow.
465466
in_place (bool): If True, then `weights` is modified in place. An
466467
accumulation matrix is always returned, but it will
467-
just be a view of the modified data if `in_place`
468+
just be a view of the modified data if `in_place`
468469
is True.
469470
470471
=================== ============================== ===========================
@@ -565,7 +566,7 @@ def FlowAccumFromProps(
565566
flow.
566567
in_place (bool): If True, then `weights` is modified in place. An
567568
accumulation matrix is always returned, but it will
568-
just be a view of the modified data if `in_place`
569+
just be a view of the modified data if `in_place`
569570
is True.
570571
571572
Returns:
@@ -612,7 +613,7 @@ def FlowProportions(
612613
Args:
613614
dem (rdarray): An elevation model
614615
method (str): Flow accumulation method to use. (See below.)
615-
exponent (float): Some methods require an exponent; refer to the
616+
exponent (float): Some methods require an exponent; refer to the
616617
relevant publications for details.
617618
618619
=================== ============================== ===========================
@@ -698,14 +699,14 @@ def TerrainAttribute(
698699
======================= =========
699700
Method Reference
700701
======================= =========
701-
slope_riserun `Horn (1981) doi: 10.1109/PROC.1981.11918 <http://dx.doi.org/10.1109/PROC.1981.11918>`_
702-
slope_percentage `Horn (1981) doi: 10.1109/PROC.1981.11918 <http://dx.doi.org/10.1109/PROC.1981.11918>`_
703-
slope_degrees `Horn (1981) doi: 10.1109/PROC.1981.11918 <http://dx.doi.org/10.1109/PROC.1981.11918>`_
704-
slope_radians `Horn (1981) doi: 10.1109/PROC.1981.11918 <http://dx.doi.org/10.1109/PROC.1981.11918>`_
705-
aspect `Horn (1981) doi: 10.1109/PROC.1981.11918 <http://dx.doi.org/10.1109/PROC.1981.11918>`_
706-
curvature `Zevenbergen and Thorne (1987) doi: 10.1002/esp.3290120107 <http://dx.doi.org/10.1002/esp.3290120107>`_
707-
planform_curvature `Zevenbergen and Thorne (1987) doi: 10.1002/esp.3290120107 <http://dx.doi.org/10.1002/esp.3290120107>`_
708-
profile_curvature `Zevenbergen and Thorne (1987) doi: 10.1002/esp.3290120107 <http://dx.doi.org/10.1002/esp.3290120107>`_
702+
slope_riserun `Horn (1981) doi: 10.1109/PROC.1981.11918 <http://dx.doi.org/10.1109/PROC.1981.11918>`_
703+
slope_percentage `Horn (1981) doi: 10.1109/PROC.1981.11918 <http://dx.doi.org/10.1109/PROC.1981.11918>`_
704+
slope_degrees `Horn (1981) doi: 10.1109/PROC.1981.11918 <http://dx.doi.org/10.1109/PROC.1981.11918>`_
705+
slope_radians `Horn (1981) doi: 10.1109/PROC.1981.11918 <http://dx.doi.org/10.1109/PROC.1981.11918>`_
706+
aspect `Horn (1981) doi: 10.1109/PROC.1981.11918 <http://dx.doi.org/10.1109/PROC.1981.11918>`_
707+
curvature `Zevenbergen and Thorne (1987) doi: 10.1002/esp.3290120107 <http://dx.doi.org/10.1002/esp.3290120107>`_
708+
planform_curvature `Zevenbergen and Thorne (1987) doi: 10.1002/esp.3290120107 <http://dx.doi.org/10.1002/esp.3290120107>`_
709+
profile_curvature `Zevenbergen and Thorne (1987) doi: 10.1002/esp.3290120107 <http://dx.doi.org/10.1002/esp.3290120107>`_
709710
======================= =========
710711
711712
Returns:

wrappers/pyrichdem/setup.py

+22-33
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
from collections import defaultdict
2-
import setuptools
3-
from setuptools.command.build_ext import build_ext as _build_ext
41
import glob
5-
import datetime
6-
import subprocess
72
import re
3+
import setuptools
4+
import subprocess
5+
from setuptools.command.build_ext import build_ext as _build_ext
6+
from typing import Optional
87

98
from pybind11.setup_helpers import Pybind11Extension
109

11-
RICHDEM_COMPILE_TIME = None
12-
RICHDEM_GIT_HASH = None
10+
richdem_compile_time: Optional[str] = None
11+
richdem_git_hash: Optional[str] = None
1312

1413
#Compiler specific arguments
1514
BUILD_ARGS = {
@@ -22,40 +21,40 @@
2221
class build_ext_compiler_check(_build_ext):
2322
def build_extensions(self):
2423
compiler = self.compiler.compiler_type
25-
print('COMPILER',compiler)
24+
print(f'COMPILER {compiler}')
2625
args = BUILD_ARGS[compiler]
2726
for ext in self.extensions:
2827
ext.extra_compile_args = args
29-
print('COMPILER ARGUMENTS',ext.extra_compile_args)
28+
print(f'COMPILER ARGUMENTS: {ext.extra_compile_args}')
3029
_build_ext.build_extensions(self)
3130

32-
if RICHDEM_GIT_HASH is None:
31+
if richdem_git_hash is None:
3332
try:
3433
shash = subprocess.Popen(["git log --pretty=format:'%h' -n 1"], shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).stdout.readlines()[0].decode('utf8').strip()
3534
sdate = subprocess.Popen(["git log -1 --pretty='%ci'"], shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).stdout.readlines()[0].decode('utf8').strip()
3635
if re.match(r'^[0-9a-z]+$', shash) and re.match(r'^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}.*$', sdate):
37-
RICHDEM_COMPILE_TIME = sdate
38-
RICHDEM_GIT_HASH = shash
36+
richdem_compile_time = sdate
37+
richdem_git_hash = shash
3938
except:
4039
print("Warning! Could not find RichDEM version. Software will still work, but reproducibility will be compromised.")
4140
pass
4241

43-
if RICHDEM_GIT_HASH is None:
44-
RICHDEM_COMPILE_TIME = 'Unknown'
45-
RICHDEM_GIT_HASH = 'Unknown'
42+
if richdem_git_hash is None:
43+
richdem_compile_time = 'Unknown'
44+
richdem_git_hash = 'Unknown'
4645

47-
print("Using RichDEM hash={0}, time={1}".format(RICHDEM_GIT_HASH, RICHDEM_COMPILE_TIME))
46+
print("Using RichDEM hash={0}, time={1}".format(richdem_git_hash, richdem_compile_time))
4847

4948
ext_modules = [
5049
Pybind11Extension(
5150
"_richdem",
52-
glob.glob('src/*.cpp') + glob.glob('lib/richdem/*.cpp'),
53-
include_dirs = ['lib/'],
51+
sorted(glob.glob('src/*.cpp') + glob.glob('lib/richdem/src/**/*.cpp', recursive=True)),
52+
include_dirs = ['lib/richdem/include/'],
5453
define_macros = [
55-
('DOCTEST_CONFIG_DISABLE', None ),
56-
('RICHDEM_COMPILE_TIME', '"\\"'+RICHDEM_COMPILE_TIME+'\\""'),
57-
('RICHDEM_GIT_HASH', '"\\"'+RICHDEM_GIT_HASH+'\\""' ),
58-
('RICHDEM_LOGGING', None ),
54+
('DOCTEST_CONFIG_DISABLE', None),
55+
('RICHDEM_COMPILE_TIME', f'"\\"{richdem_compile_time}\\""'),
56+
('RICHDEM_GIT_HASH', f'"\\"{richdem_git_hash}\\""' ),
57+
('RICHDEM_LOGGING', None),
5958
('_USE_MATH_DEFINES', None) #To ensure that `#include <cmath>` imports `M_PI` in MSVC
6059
]
6160
),
@@ -73,7 +72,7 @@ def build_extensions(self):
7372
#TODO: https://packaging.python.org/tutorials/distributing-packages/#configuring-your-project
7473
setuptools.setup(
7574
name = 'richdem',
76-
version = '0.3.4',
75+
version = '0.4.0',
7776
description = 'High-Performance Terrain Analysis',
7877
long_description = long_description,
7978
url = 'https://github.com/r-barnes/richdem',
@@ -93,20 +92,10 @@ def build_extensions(self):
9392
ext_modules = ext_modules,
9493
cmdclass = {'build_ext': build_ext_compiler_check},
9594
keywords = 'GIS terrain hydrology geomorphology raster',
96-
#packages = find_packages(exclude=['contrib', 'docs', 'tests*']),
9795
install_requires = [
9896
"numpy>=1.7,<2; python_version > '3.4' or python_version < '3.0'",
9997
"numpy>=1.7,<1.12; python_version < '3.4' and python_version > '3.0'"
10098
],
101-
# extras_require = {
102-
# ':python_version > "3.4"': [
103-
# 'numpy>=1.7,<2'
104-
# ],
105-
# ':python_version < "3.4"': [
106-
# 'numpy>=1.7,<1.12'
107-
# ]
108-
# },
109-
#python_requires = ' >= 2.6, !=3.0.*, !=3.1.*, !=3.2.*, <4',
11099

111100
#TODO: https://pypi.python.org/pypi?%3Aaction=list_classifiers
112101
classifiers = [

0 commit comments

Comments
 (0)