Skip to content

Commit dbe7ea3

Browse files
committed
initial version of ipxapi
1 parent a051977 commit dbe7ea3

File tree

3 files changed

+181
-10
lines changed

3 files changed

+181
-10
lines changed

sliderule/icesat2.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,20 @@ def __query_servers(max_workers):
275275
# Return Number of Workers #
276276
return max_workers
277277

278+
#
279+
# __emptyframe
280+
#
281+
def __emptyframe():
282+
return geopandas.pd.DataFrame()
283+
278284
#
279285
# __todataframe
280286
#
281287
def __todataframe(columns, delta_time_key="delta_time", lon_key="lon", lat_ley="lat"):
282288

283289
# Check Empty Columns
284290
if len(columns) <= 0:
285-
return geopandas.pd.DataFrame()
291+
return __emptyframe()
286292

287293
# Generate Time Column
288294
delta_time = (columns[delta_time_key]*1000000.0).astype('timedelta64[us]')
@@ -448,7 +454,7 @@ def __parallelize(max_workers, block, function, parm, resources, *args):
448454
if len(results) > 0:
449455
return geopandas.pd.concat(results)
450456
else:
451-
return geopandas.pd.DataFrame()
457+
return __emptyframe()
452458

453459
# For Non-Blocking Calls
454460
else:
@@ -557,20 +563,22 @@ def atl06 (parm, resource, asset="atlas-s3", track=0):
557563
return __atl06(parm, resource, asset, track)[0]
558564
except RuntimeError as e:
559565
logger.critical(e)
560-
return {}
566+
return __emptyframe()
561567

562568
#
563569
# PARALLEL ATL06
564570
#
565-
def atl06p(parm, asset="atlas-s3", track=0, max_workers=0, version='004', block=True):
571+
def atl06p(parm, asset="atlas-s3", track=0, max_workers=0, version='004', block=True, resources=None):
566572

567573
try:
568-
resources = __query_resources(parm, version)
574+
if resources == None:
575+
resources = __query_resources(parm, version)
569576
max_workers = __query_servers(max_workers)
570577
return __parallelize(max_workers, block, __atl06, parm, resources, asset, track)
571578
except RuntimeError as e:
572579
logger.critical(e)
573-
return {}
580+
return __emptyframe()
581+
574582

575583
#
576584
# Subsetted ATL03
@@ -581,20 +589,21 @@ def atl03s (parm, resource, asset="atlas-s3", track=0):
581589
return __atl03s(parm, resource, asset, track)[0]
582590
except RuntimeError as e:
583591
logger.critical(e)
584-
return {}
592+
return __emptyframe()
585593

586594
#
587595
# PARALLEL SUBSETTED ATL03
588596
#
589-
def atl03sp(parm, asset="atlas-s3", track=0, max_workers=0, version='004', block=True):
597+
def atl03sp(parm, asset="atlas-s3", track=0, max_workers=0, version='004', block=True, resources=None):
590598

591599
try:
592-
resources = __query_resources(parm, version)
600+
if resources == None:
601+
resources = __query_resources(parm, version)
593602
max_workers = __query_servers(max_workers)
594603
return __parallelize(max_workers, block, __atl03s, parm, resources, asset, track)
595604
except RuntimeError as e:
596605
logger.critical(e)
597-
return {}
606+
return __emptyframe()
598607

599608
#
600609
# H5

sliderule/ipxapi.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
from sliderule import icesat2
31+
import logging
32+
33+
###############################################################################
34+
# GLOBALS
35+
###############################################################################
36+
37+
# create logger
38+
logger = logging.getLogger(__name__)
39+
40+
###############################################################################
41+
# APIs
42+
###############################################################################
43+
44+
#
45+
# ICEPYX ATL06
46+
#
47+
def atl06p(ipx_region, parm, asset="atlas-s3",):
48+
49+
try:
50+
version = ipx_region.product_version
51+
resources = ipx_region.avail_granules(ids=True)[0]
52+
except:
53+
logger.critical("must supply an icepyx query as region")
54+
return icesat2.__emptyframe()
55+
56+
return icesat2.atl06p(parm, asset, version=version, resources=resources)
57+
58+
#
59+
# ICEPYX ATL03
60+
#
61+
def atl03sp(ipx_region, parm, asset="atlas-s3"):
62+
63+
try:
64+
version = ipx_region.product_version
65+
resources = ipx_region.avail_granules(ids=True)[0]
66+
except:
67+
logger.critical("must supply an icepyx query as region")
68+
return icesat2.__emptyframe()
69+
70+
return icesat2.atl03sp(parm, asset, version=version, resources=resources)

utils/icepx_region.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import sys
2+
from datetime import date
3+
from sliderule import ipxapi
4+
from sliderule import icesat2
5+
import icepyx
6+
7+
###############################################################################
8+
# LOCAL FUNCTIONS
9+
###############################################################################
10+
11+
def parse_command_line(args, cfg):
12+
i = 1
13+
while i < len(args):
14+
for entry in cfg:
15+
if args[i] == '--'+entry:
16+
if type(cfg[entry]) is str:
17+
cfg[entry] = args[i + 1]
18+
elif type(cfg[entry]) is list:
19+
l = []
20+
while (i + 1) < len(args) and args[i + 1].isnumeric():
21+
l.append(int(args[i + 1]))
22+
i += 1
23+
cfg[entry] = l
24+
elif type(cfg[entry]) is int:
25+
cfg[entry] = int(args[i + 1])
26+
i += 1
27+
i += 1
28+
return cfg
29+
30+
###############################################################################
31+
# MAIN
32+
###############################################################################
33+
34+
if __name__ == '__main__':
35+
36+
today = date.today()
37+
38+
# set script defaults
39+
scfg = {
40+
"url": ['127.0.0.1'],
41+
"asset": 'atlas-local'
42+
}
43+
44+
# set icepx defaults
45+
icfg = {
46+
"short_name": 'ATL03',
47+
"spatial_extent": 'valgrande.shp',
48+
"date_range": ['2018-01-01', "{}-{}-{}".format(today.year, today.month, today.day)],
49+
"cycles": [],
50+
"tracks": []
51+
}
52+
53+
# set processing parameter defaults
54+
parms = {
55+
"srt": icesat2.SRT_LAND,
56+
"cnf": icesat2.CNF_SURFACE_HIGH,
57+
"ats": 10.0,
58+
"cnt": 10,
59+
"len": 40.0,
60+
"res": 20.0,
61+
"maxi": 1
62+
}
63+
64+
# get command line parameters
65+
parse_command_line(sys.argv, icfg)
66+
parse_command_line(sys.argv, scfg)
67+
parse_command_line(sys.argv, parms)
68+
69+
# massage command line parameters
70+
if len(icfg["cycles"]) == 0:
71+
icfg["cycles"] = None
72+
if len(icfg["tracks"]) == 0:
73+
icfg["tracks"] = None
74+
75+
# create icepx region
76+
iregion = icepyx.Query(icfg["short_name"], icfg["spatial_extent"], icfg["date_range"], cycles=icfg["cycles"], tracks=icfg["tracks"])
77+
78+
# visualize icepx region
79+
iregion.visualize_spatial_extent()
80+
81+
# display summary information
82+
iregion.product_summary_info()
83+
print("Available Granules:", iregion.avail_granules())
84+
print("Available Granule IDs:", iregion.avail_granules(ids=True))
85+
86+
# initialize sliderule api
87+
icesat2.init(scfg["url"], verbose=True)
88+
89+
# generate sliderule atl06 elevations
90+
parms["poly"] = icesat2.toregion(icfg["spatial_extent"])
91+
ipxapi.atl06p(iregion, parms, scfg["asset"])
92+

0 commit comments

Comments
 (0)