Skip to content

Commit bc121fc

Browse files
committed
Merge branch 'master' of github.com:makepath/xarray-spatial
2 parents b657995 + 25229a6 commit bc121fc

26 files changed

+4511
-2902
lines changed

.github/workflows/docs-publish.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,7 @@ jobs:
1414
run: |
1515
sudo apt-get -y install pandoc
1616
python -m pip install --upgrade pip
17-
pip install setuptools \
18-
wheel \
19-
geopandas \
20-
nbsphinx \
21-
pandoc \
22-
pydata_sphinx_theme \
23-
sphinx \
24-
sphinx-multiversion \
25-
sphinx-panels \
26-
sphinx_rtd_theme
17+
pip install -r docs/source/requirements.txt
2718
- name: Build
2819
run: |
2920
pip install .

conda.recipe/README.md

Lines changed: 0 additions & 70 deletions
This file was deleted.

conda.recipe/build.sh

Lines changed: 0 additions & 13 deletions
This file was deleted.

conda.recipe/meta.yaml

Lines changed: 0 additions & 34 deletions
This file was deleted.

conda.recipe/run_test.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

docs/source/conf.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
html_theme = 'sphinx_rtd_theme'
8787
else:
8888
html_theme = 'pydata_sphinx_theme'
89+
extensions.append('matplotlib.sphinxext.plot_directive')
8990

9091
html_logo = '_static/img/Xarray-Spatial-logo.svg'
9192

@@ -96,7 +97,11 @@
9697
if os.getenv('THEME') == 'sphinx_rtd_theme':
9798
smv_tag_whitelist = r'^v([0]\.[1]\.[0-5]|[0]\.[0]\.[0-9])'
9899
else:
99-
smv_tag_whitelist = r'^v([0-9]\.[1]\.[6-9]|[1-9]\.[0-9]\.[0-9])'
100+
smv_tag_whitelist = (
101+
r'^v([0-9]\.[1]\.[6-8]|'
102+
r'[0-9]\.[2]\.[1-9]|'
103+
r'[1-9]\.[0-9]\.[0-9])'
104+
)
100105

101106
# Load releases
102107
with open("releases.json") as f:
@@ -210,5 +215,8 @@
210215
# A list of files that should not be packed into the epub file.
211216
epub_exclude_files = ['search.html']
212217

218+
# sphinxext config
219+
plot_html_show_source_link = False
220+
213221
# nbsphinx configuration
214222
nbsphinx_allow_errors = True

docs/source/reference/focal.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ Focal Statistics
3131
.. autosummary::
3232
:toctree: _autosummary
3333

34-
xrspatial.focal.annulus_kernel
35-
xrspatial.focal.calc_cellsize
34+
xrspatial.convolution.annulus_kernel
35+
xrspatial.convolution.calc_cellsize
3636
xrspatial.focal.calc_mean
3737
xrspatial.focal.calc_sum
38-
xrspatial.focal.circle_kernel
38+
xrspatial.convolution.circle_kernel
3939
xrspatial.focal.custom_kernel
40-
xrspatial.focal.upper_bound_p_value

docs/source/requirements.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
geopandas
2+
ipykernel
3+
matplotlib
24
nbsphinx
35
pandoc
46
pydata_sphinx_theme
7+
setuptools
58
sphinx
69
sphinx-multiversion
710
sphinx-panels
8-
sphinx_rtd_theme
11+
sphinx_rtd_theme
12+
wheel

xrspatial/aspect.py

Lines changed: 106 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -155,70 +155,119 @@ def _run_dask_numpy(data: da.Array) -> da.Array:
155155
def aspect(agg: xr.DataArray,
156156
name: Optional[str] = 'aspect') -> xr.DataArray:
157157
"""
158-
Calculates, for all cells in the array,
159-
the downward slope direction of each cell
160-
based on the elevation of its neighbors in a 3x3 grid.
161-
The value is measured clockwise in degrees with 0 and 360 at due north.
162-
Flat areas are given a value of -1.
163-
Values along the edges are not calculated.
164-
165-
Parameters:
158+
Calculates the aspect value of an elevation aggregate.
159+
160+
Calculates, for all cells in the array, the downward slope direction
161+
of each cell based on the elevation of its neighbors in a 3x3 grid.
162+
The value is measured clockwise in degrees with 0 and 360 at due
163+
north. Flat areas are given a value of -1. Values along the edges
164+
are not calculated.
165+
166+
Parameters
166167
----------
167-
agg: xarray.DataArray
168-
2D array of elevation values. NumPy, CuPy, NumPy-backed Dask,
169-
or Cupy-backed Dask array.
170-
name: str, optional (default = "aspect")
168+
agg : xarray.DataArray
169+
2D NumPy, CuPy, NumPy-backed Dask, or Cupy-backed Dask array
170+
of elevation values.
171+
name : str, default='aspect'
171172
Name of ouput DataArray.
172173
173-
Returns:
174-
----------
175-
xarray.DataArray
176-
2D array, of the same type as the input, of calculated aspect values.
174+
Returns
175+
-------
176+
aspect_agg : xarray.DataArray of the same type as `agg`
177+
2D aggregate array of calculated aspect values.
177178
All other input attributes are preserved.
178179
179-
Notes:
180+
References
180181
----------
181-
Algorithm References:
182-
- esri, How Aspect Works, http://desktop.arcgis.com/en/arcmap/10.3/tools/spatial-analyst-toolbox/how-aspect-works.htm#ESRI_SECTION1_4198691F8852475A9F4BC71246579FAA, Accessed Apr. 21, 2021. # noqa
183-
- Burrough, P. A., McDonnell, R., McDonnell, R. A., & Lloyd, C. D. (2015). Principles of geographical information systems. Oxford university press. pp 406. # noqa
184-
185-
Examples:
186-
----------
187-
Imports
188-
>>> import numpy as np
189-
>>> import xarray as xr
190-
>>> import xrspatial
191-
192-
Create Elevation DataArray
193-
>>> agg = xr.DataArray(np.array([[0, 1, 0, 0],
194-
>>> [1, 1, 0, 0],
195-
>>> [0, 1, 2, 2],
196-
>>> [1, 0, 2, 0],
197-
>>> [0, 2, 2, 2]]),
198-
>>> dims = ["lat", "lon"])
199-
>>> height, width = agg.shape
200-
>>> _lon = np.linspace(0, width - 1, width)
201-
>>> _lat = np.linspace(0, height - 1, height)
202-
>>> agg["lon"] = _lon
203-
>>> agg["lat"] = _lat
204-
205-
Create Aspect DataArray
206-
>>> aspect = xrspatial.aspect(agg)
207-
>>> print(aspect)
208-
<xarray.DataArray 'aspect' (lat: 5, lon: 4)>
209-
array([[nan, nan, nan, nan],
210-
[nan, 0., 18.43494882, nan],
211-
[nan, 270., 341.56505118, nan],
212-
[nan, 288.43494882, 315., nan],
213-
[nan, nan, nan, nan]])
214-
Coordinates:
215-
* lon (lon) float64 0.0 1.0 2.0 3.0
216-
* lat (lat) float64 0.0 1.0 2.0 3.0 4.0
217-
218-
Terrain Example:
219-
- makepath, User Guide, https://makepath.github.io/xarray-spatial/assets/examples/user-guide.html, Accessed Apr. 21, 2021 # noqa
182+
- arcgis: http://desktop.arcgis.com/en/arcmap/10.3/tools/spatial-analyst-toolbox/how-aspect-works.htm#ESRI_SECTION1_4198691F8852475A9F4BC71246579FAA # noqa
183+
184+
Examples
185+
--------
186+
.. plot::
187+
:include-source:
188+
189+
import datashader as ds
190+
import matplotlib.pyplot as plt
191+
from xrspatial import generate_terrain, aspect
192+
193+
# Create Canvas
194+
W = 500
195+
H = 300
196+
cvs = ds.Canvas(plot_width = W,
197+
plot_height = H,
198+
x_range = (-20e6, 20e6),
199+
y_range = (-20e6, 20e6))
200+
201+
# Generate Example Terrain
202+
terrain_agg = generate_terrain(canvas = cvs)
203+
204+
# Edit Attributes
205+
terrain_agg = terrain_agg.assign_attrs(
206+
{
207+
'Description': 'Example Terrain',
208+
'units': 'km',
209+
'Max Elevation': '4000',
210+
}
211+
)
212+
213+
terrain_agg = terrain_agg.rename({'x': 'lon', 'y': 'lat'})
214+
terrain_agg = terrain_agg.rename('Elevation')
215+
216+
# Create Aspect Aggregate Array
217+
aspect_agg = aspect(agg = terrain_agg, name = 'Aspect')
218+
219+
# Edit Attributes
220+
aspect_agg = aspect_agg.assign_attrs(
221+
{
222+
'Description': 'Example Aspect',
223+
'units': 'deg',
224+
}
225+
)
226+
227+
# Plot Terrain
228+
terrain_agg.plot(cmap = 'terrain', aspect = 2, size = 4)
229+
plt.title("Terrain")
230+
plt.ylabel("latitude")
231+
plt.xlabel("longitude")
232+
233+
# Plot Aspect
234+
aspect_agg.plot(aspect = 2, size = 4)
235+
plt.title("Aspect")
236+
plt.ylabel("latitude")
237+
plt.xlabel("longitude")
238+
239+
.. sourcecode:: python
240+
241+
>>> print(terrain_agg[200:203, 200:202])
242+
<xarray.DataArray 'Elevation' (lat: 3, lon: 2)>
243+
array([[1264.02249454, 1261.94748873],
244+
[1285.37061171, 1282.48046696],
245+
[1306.02305679, 1303.40657515]])
246+
Coordinates:
247+
* lon (lon) float64 -3.96e+06 -3.88e+06
248+
* lat (lat) float64 6.733e+06 6.867e+06 7e+06
249+
Attributes:
250+
res: 1
251+
Description: Example Terrain
252+
units: km
253+
Max Elevation: 4000
254+
255+
.. sourcecode:: python
256+
257+
>>> print(aspect_agg[200:203, 200:202])
258+
<xarray.DataArray 'Aspect' (lat: 3, lon: 2)>
259+
array([[ 8.18582638, 8.04675084],
260+
[ 5.49302641, 9.86625477],
261+
[12.04270534, 16.87079619]])
262+
Coordinates:
263+
* lon (lon) float64 -3.96e+06 -3.88e+06
264+
* lat (lat) float64 6.733e+06 6.867e+06 7e+06
265+
Attributes:
266+
res: 1
267+
Description: Example Aspect
268+
units: deg
269+
Max Elevation: 4000
220270
"""
221-
222271
# numpy case
223272
if isinstance(agg.data, np.ndarray):
224273
out = _run_numpy(agg.data)

0 commit comments

Comments
 (0)