Skip to content

Commit 7b42e27

Browse files
committed
Add some missing type annotations
1 parent 9ee45ce commit 7b42e27

File tree

4 files changed

+27
-23
lines changed

4 files changed

+27
-23
lines changed

programs/parallel_d8_accum/test_big.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
VERBOSE = False
2121

22-
def doRaw(cmd):
22+
def doRaw(cmd: str):
2323
if VERBOSE:
2424
print(' '+cmd)
2525
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
@@ -31,7 +31,7 @@ def doRaw(cmd):
3131
print('')
3232
return output, err
3333

34-
def FileInfo(filename):
34+
def FileInfo(filename: str):
3535
"""Returns the NoData value and data type of the specified file"""
3636
src_ds = gdal.Open( filename )
3737
srcband = src_ds.GetRasterBand(1)
@@ -45,7 +45,7 @@ def FillAndTest(
4545
n,
4646
many_or_one,
4747
strat,
48-
inpfile,
48+
inpfile: str,
4949
width = -1,
5050
height = -1
5151
):
@@ -118,7 +118,7 @@ def FillAndTest(
118118
print("Expected: '{0}'".format('Computed Min/Max=0.000,0.000'))
119119

120120

121-
def is_valid_file(parser, arg):
121+
def is_valid_file(parser: argparse.ArgumentParser, arg: str) -> str:
122122
if not os.path.exists(arg):
123123
parser.error("Input file '{0}' does not exist!".format(arg))
124124
else:
@@ -145,7 +145,7 @@ def main():
145145
if not os.path.exists('../../apps/rd_flow_accumulation.exe'):
146146
print("The RichDEM flow accumulation app is missing!")
147147
sys.exit(-1)
148-
148+
149149

150150
print('Ensuring directory "temp" exists')
151151
if not os.path.exists('temp'):

programs/parallel_priority_flood/test.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
import time
1616
import argparse
1717
import multiprocessing
18+
from typing import List, Tuple
1819
from osgeo import gdal
1920

2021
VERBOSE = False
2122

22-
def doRaw(cmd):
23+
def doRaw(cmd: str) -> Tuple[List[str], int]:
2324
if VERBOSE:
2425
print(' '+cmd)
2526
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
@@ -31,7 +32,7 @@ def doRaw(cmd):
3132
print('')
3233
return output, err
3334

34-
def FileInfo(filename):
35+
def FileInfo(filename: str):
3536
"""Returns the NoData value and data type of the specified file"""
3637
src_ds = gdal.Open( filename )
3738
srcband = src_ds.GetRasterBand(1)
@@ -45,7 +46,7 @@ def FillAndTest(
4546
n,
4647
many_or_one,
4748
strat,
48-
inpfile,
49+
inpfile: str,
4950
width = -1,
5051
height = -1
5152
):
@@ -117,7 +118,7 @@ def FillAndTest(
117118
print("Expected: '{0}'".format('Computed Min/Max=0.000,0.000'))
118119

119120

120-
def is_valid_file(parser, arg):
121+
def is_valid_file(parser: argparse.ArgumentParser, arg: str) -> str:
121122
if not os.path.exists(arg):
122123
parser.error("Input file '{0}' does not exist!".format(arg))
123124
else:
@@ -144,7 +145,7 @@ def main():
144145
if not os.path.exists('auth_gen.exe'):
145146
print("You need to run 'make auth_gen' before you can test things.")
146147
sys.exit(-1)
147-
148+
148149

149150
print('Ensuring directory "temp" exists')
150151
if not os.path.exists('temp'):

wrappers/pyrichdem/richdem/__init__.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import copy
22
import datetime
33
import pkg_resources
4-
from typing import Any, Final, List, Iterable, Optional, Tuple, Union
4+
from typing import Any, Dict, Final, List, Iterable, Optional, Tuple, Union
55

66
import numpy as np
7-
import sys
87

98
try:
109
import _richdem
@@ -115,6 +114,10 @@ def rdShow(
115114
ax.set_ylim(ymin=ymin, ymax=ymax)
116115

117116
if all_zoom:
117+
assert zxmin is not None
118+
assert zxmax is not None
119+
assert zymin is not None
120+
assert zymax is not None
118121
axins = inset_axes(
119122
ax, width=2, height=2, loc=zloc, borderpad=0
120123
) # , bbox_to_anchor=(0.9, -0.05, 1, 1), bbox_transform=ax.transAxes, borderpad=0)
@@ -529,7 +532,7 @@ def FlowAccumulation(dem: rdarray, method: Optional[str] = None, exponent: Optio
529532
if type(dem) is not rdarray:
530533
raise Exception("A richdem.rdarray or numpy.ndarray is required!")
531534

532-
facc_methods = {
535+
facc_methods: Dict[str, Any] = {
533536
"Tarboton": _richdem.FA_Tarboton,
534537
"Dinf": _richdem.FA_Tarboton,
535538
"Quinn": _richdem.FA_Quinn,
@@ -543,7 +546,7 @@ def FlowAccumulation(dem: rdarray, method: Optional[str] = None, exponent: Optio
543546
"D4": _richdem.FA_D4,
544547
}
545548

546-
facc_methods_exponent = {
549+
facc_methods_exponent: Dict[str, Any] = {
547550
"Freeman": _richdem.FA_Freeman,
548551
"Holmgren": _richdem.FA_Holmgren,
549552
}
@@ -579,7 +582,7 @@ def FlowAccumulation(dem: rdarray, method: Optional[str] = None, exponent: Optio
579582
elif method in facc_methods_exponent:
580583
if exponent is None:
581584
raise Exception(
582-
'FlowAccumulation method "' + method + '" requires an exponent!'
585+
f'FlowAccumulation method "{method}" requires an exponent!'
583586
)
584587
facc_methods_exponent[method](dem.wrap(), accumw, exponent)
585588
else:

wrappers/pyrichdem/richdem/cli.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import numpy as np
88

99

10-
def DepressionFilling():
10+
def DepressionFilling() -> None:
1111
parser = argparse.ArgumentParser(
1212
formatter_class=RawTextHelpFormatter, description="RichDEM Depression Filling"
1313
)
@@ -31,7 +31,7 @@ def DepressionFilling():
3131
rd.SaveGDAL(args.outname, dem)
3232

3333

34-
def BreachDepressions():
34+
def BreachDepressions() -> None:
3535
parser = argparse.ArgumentParser(
3636
formatter_class=RawTextHelpFormatter,
3737
description="""RichDEM Depression Breaching""",
@@ -50,7 +50,7 @@ def BreachDepressions():
5050
rd.SaveGDAL(args.outname, dem)
5151

5252

53-
def FlowAccumulation():
53+
def FlowAccumulation() -> None:
5454
parser = argparse.ArgumentParser(
5555
formatter_class=RawTextHelpFormatter,
5656
description="""RichDEM Flow Accumulation
@@ -94,7 +94,7 @@ def FlowAccumulation():
9494
rd.SaveGDAL(args.outname, accum)
9595

9696

97-
def TerrainAttribute():
97+
def TerrainAttribute() -> None:
9898
parser = argparse.ArgumentParser(
9999
formatter_class=RawTextHelpFormatter,
100100
description="""RichDEM Terrain Attribute
@@ -140,7 +140,7 @@ def TerrainAttribute():
140140
rd.SaveGDAL(args.outname, tattrib)
141141

142142

143-
def RdInfo():
143+
def RdInfo() -> None:
144144
parser = argparse.ArgumentParser(
145145
formatter_class=RawTextHelpFormatter,
146146
description="""RichDEM Dataset Information
@@ -190,7 +190,7 @@ def RdInfo():
190190
rd.rdShow(rda, cmap=args.cmap, vmin=args.vmin, vmax=args.vmax)
191191

192192

193-
def RdCompare():
193+
def RdCompare() -> None:
194194
parser = argparse.ArgumentParser(
195195
formatter_class=RawTextHelpFormatter,
196196
description="""RichDEM Dataset Comparison
@@ -216,10 +216,10 @@ def RdCompare():
216216
print("Projection differs")
217217

218218
if np.any(np.isnan(ds1)):
219-
print("NaN in '{0}'".format(filename))
219+
print("NaN in '{0}'".format(args.rda1))
220220

221221
if np.any(np.isnan(ds2)):
222-
print("NaN in '{0}'".format(filename))
222+
print("NaN in '{0}'".format(args.rda2))
223223

224224
diff = np.array(ds1 - ds2)
225225

0 commit comments

Comments
 (0)