Skip to content

Commit 036f457

Browse files
committed
initial commit for arcticdem api
1 parent 4f3f0da commit 036f457

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

sliderule/arcticdem.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Copyright (c) 2021, University of Washington
2+
# All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# 1. Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
#
10+
# 2. Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation
12+
# and/or other materials provided with the distribution.
13+
#
14+
# 3. Neither the name of the University of Washington nor the names of its
15+
# contributors may be used to endorse or promote products derived from this
16+
# software without specific prior written permission.
17+
#
18+
# THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF WASHINGTON AND CONTRIBUTORS
19+
# “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF WASHINGTON OR
22+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
30+
import logging
31+
import sliderule
32+
33+
###############################################################################
34+
# GLOBALS
35+
###############################################################################
36+
37+
# create logger
38+
logger = logging.getLogger(__name__)
39+
40+
# default asset
41+
DEFAULT_ASSET="arcticdem-s3"
42+
43+
###############################################################################
44+
# APIs
45+
###############################################################################
46+
47+
#
48+
# Get Elevation
49+
#
50+
def elevation (coordinate, asset=DEFAULT_ASSET):
51+
'''
52+
Get elevation from ArcticDEM at provided coordinate
53+
54+
Parameters
55+
----------
56+
coordinate : list
57+
[<longitude>, <latitude>]
58+
asset: str
59+
data source asset (see `Assets <../user_guide/ArcticDEM.html#assets>`_)
60+
61+
Examples
62+
--------
63+
>>> from sliderule import arcticdem
64+
>>> arcticdem.elevation([23.14333, 70.3211])
65+
'''
66+
return elevations([coordinate])
67+
68+
#
69+
# Get Elevations
70+
#
71+
def elevations (coordinates, asset=DEFAULT_ASSET):
72+
'''
73+
Get elevations from ArcticDEM at provided coordinates
74+
75+
Parameters
76+
----------
77+
coordinates : list
78+
[[<longitude>, <latitude>], [<longitude>, <latitude>], ... ]
79+
asset: str
80+
data source asset (see `Assets <../user_guide/ArcticDEM.html#assets>`_)
81+
82+
Examples
83+
--------
84+
>>> from sliderule import arcticdem
85+
>>> arcticdem.elevations([[164.134, 73.9291], [23.14333, 70.3211]])
86+
'''
87+
# Build Request
88+
rqst = {
89+
"dem-asset" : asset,
90+
"coordinates": coordinates
91+
}
92+
93+
# Make API Processing Request
94+
rsps = sliderule.source("elevation", rqst, stream=False)
95+
96+
# Return Response
97+
return rsps

0 commit comments

Comments
 (0)