Skip to content

Commit 19ab0dc

Browse files
committed
run black, minor improvements
1 parent bad8b97 commit 19ab0dc

25 files changed

+1161
-908
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,19 @@ baseline = pyosp.datasets.get_path("homo_baseline.shp") # the path to baseline s
7777
raster = pyosp.datasets.get_path("homo_mount.tif") # the path to raster file
7878

7979
orig = pyosp.Orig_curv(line, raster, width=100,
80-
line_stepsize=3, cross_stepsize=none)
80+
line_stepsize=3, cross_stepsize=None)
8181

8282
elev = pyosp.Elev_curv(line, raster, width=100,
8383
min_elev=0.01,
84-
line_stepsize=3, cross_stepsize=none)
84+
line_stepsize=3, cross_stepsize=None)
8585

8686
slope = pyosp.Slope_curv(line, raster, width=100,
8787
min_slope=1,
88-
line_stepsize=3, cross_stepsize=none)
88+
line_stepsize=3, cross_stepsize=None)
8989

9090
tpi = pyosp.Tpi_curv(line, raster, width=100,
9191
tpi_radius=50, min_tpi=0,
92-
line_stepsize=3, cross_stepsize=none)
92+
line_stepsize=3, cross_stepsize=None)
9393
```
9494

9595
We can plot with matplotlib, or open in GIS software.

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# -- Project information -----------------------------------------------------
1818

1919
project = 'pyosp'
20-
copyright = '2020, PyOSP developers'
20+
copyright = '2021, PyOSP developers'
2121
author = 'PyOSP developers'
2222

2323
# The full version, including alpha/beta/rc tags

pyosp/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
__version__ = '0.1.5'
3+
__version__ = "0.1.5"
44

55
from .curvsp import *
66
from .cirsp import *

pyosp/_elevation.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# -*- coding: utf-8 -*-
22

3-
class Point_elevation():
3+
4+
class Point_elevation:
45
"""Get point elevation by given raster.
56
67
:param point: point coordinates
78
:type point: array-like
89
:param raster: GeoRaster read by GDAL
910
:type raster: GDAL dataset
1011
"""
12+
1113
def __init__(self, point, raster):
1214
self.p = point
1315
self.raster = raster
@@ -17,7 +19,7 @@ def point_position(self):
1719
x = int((self.p[0] - self.geoTransform[0]) / self.geoTransform[1])
1820
y = int((self.geoTransform[3] - self.p[1]) / -self.geoTransform[5])
1921
return x, y
20-
22+
2123
@property
2224
def value(self):
2325
px, py = self.point_position()

pyosp/_slope.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import numpy as np
44

5-
class Geo_slope():
5+
6+
class Geo_slope:
67
def __init__(self, point, raster, cell_size):
78
"""Return a geo-slope value of the point.
89
@@ -17,32 +18,33 @@ def __init__(self, point, raster, cell_size):
1718
self.raster = raster
1819
self.geoTransform = self.raster.GetGeoTransform()
1920
self.cell_size = cell_size
20-
21+
2122
def point_position(self):
2223
x = int((self.p[0] - self.geoTransform[0]) / self.geoTransform[1])
2324
y = int((self.geoTransform[3] - self.p[1]) / -self.geoTransform[5])
2425
return y, x
25-
26+
2627
def raster_window(self):
2728
py, px = self.point_position()
2829
rasterMatrix = self.raster.ReadAsArray()
29-
30-
#pad to the edge
31-
rasterPad = np.pad(rasterMatrix, (1,), 'edge')
32-
33-
return rasterPad[py:py+3, px:px+3]
34-
30+
31+
# pad to the edge
32+
rasterPad = np.pad(rasterMatrix, (1,), "edge")
33+
34+
return rasterPad[py : py + 3, px : px + 3]
35+
3536
@property
3637
def value(self):
3738
window = self.raster_window()
38-
39-
rise = ((window[0,2] + 2*window[1,2] + window[2,2]) -
40-
(window[0,0] + 2*window[1,0] + window[2,0])) / \
41-
(8 * self.cell_size)
42-
run = ((window[2,0] + 2*window[2,1] + window[2,2]) -
43-
(window[0,0] + 2*window[0,1] + window[0,2])) / \
44-
(8 * self.cell_size)
39+
40+
rise = (
41+
(window[0, 2] + 2 * window[1, 2] + window[2, 2])
42+
- (window[0, 0] + 2 * window[1, 0] + window[2, 0])
43+
) / (8 * self.cell_size)
44+
run = (
45+
(window[2, 0] + 2 * window[2, 1] + window[2, 2])
46+
- (window[0, 0] + 2 * window[0, 1] + window[0, 2])
47+
) / (8 * self.cell_size)
4548
dist = np.sqrt(np.square(rise) + np.square(run))
46-
47-
return np.arctan(dist)*180 / np.pi
48-
49+
50+
return np.arctan(dist) * 180 / np.pi

pyosp/_tpi.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,50 @@
22

33
import numpy as np
44

5-
class Tpi():
5+
6+
class Tpi:
67
def __init__(self, point_coord, raster, radius):
78
"""Calculate the TPI value of the point
89
910
:param point_coord: point coodinates
1011
:type point_coord: array-like
1112
:param raster: GeoRaster read by GDAL
1213
:type raster: GDAL dataset
13-
:param radius: radius of TPI window
14-
:type radius: float
14+
:param radius: radius of TPI window
15+
:type radius: float
1516
"""
1617
self.p = point_coord
1718
self.raster = raster
1819
self.cols = raster.RasterXSize
1920
self.rows = raster.RasterYSize
2021
self.geoTransform = raster.GetGeoTransform()
2122
self.radiusInPixel = int(radius / self.geoTransform[1])
22-
23+
2324
def point_position(self):
2425
" Define the point position on the raster"
2526
x = int((self.p[0] - self.geoTransform[0]) / self.geoTransform[1])
2627
y = int((self.geoTransform[3] - self.p[1]) / -self.geoTransform[5])
2728
return y, x
28-
29+
2930
def avg_window(self):
3031
"Calculate the average raster value within the window, exclude the central point."
3132
py, px = self.point_position()
32-
xmin = max(0, px-self.radiusInPixel)
33-
xmax = min(self.cols, px+self.radiusInPixel+1)
34-
ymin = max(0, py-self.radiusInPixel)
35-
ymax = min(self.rows, py+self.radiusInPixel+1)
36-
arr = self.raster.ReadAsArray(xoff=xmin, yoff=ymin, xsize=xmax-xmin, ysize=ymax-ymin)
33+
xmin = max(0, px - self.radiusInPixel)
34+
xmax = min(self.cols, px + self.radiusInPixel + 1)
35+
ymin = max(0, py - self.radiusInPixel)
36+
ymax = min(self.rows, py + self.radiusInPixel + 1)
37+
arr = self.raster.ReadAsArray(
38+
xoff=xmin, yoff=ymin, xsize=xmax - xmin, ysize=ymax - ymin
39+
)
3740
# Treat small values as no data
3841
arr[arr < -1e20] = np.nan
39-
avg = (np.nansum(arr)-self.point_value()) / (np.sum(~np.isnan(arr))-1)
40-
return avg
41-
42+
avg = (np.nansum(arr) - self.point_value()) / (np.sum(~np.isnan(arr)) - 1)
43+
return avg
44+
4245
def point_value(self):
43-
py, px =self.point_position()
46+
py, px = self.point_position()
4447
return self.raster.ReadAsArray(xoff=px, yoff=py, xsize=1, ysize=1)[0]
45-
48+
4649
@property
4750
def value(self):
48-
return self.point_value() - self.avg_window()
51+
return self.point_value() - self.avg_window()

0 commit comments

Comments
 (0)