Skip to content

Commit

Permalink
Merge pull request #60 from ICESat2-SlideRule/icepyx
Browse files Browse the repository at this point in the history
add region extraction from icepyx query
  • Loading branch information
jpswinski authored Oct 13, 2021
2 parents e6d0f3a + 74b6412 commit e60e838
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions sliderule/ipxapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,53 @@
# ICEPYX ATL06
#
def atl06p(ipx_region, parm, asset=icesat2.DEFAULT_ASSET):
"""
create a sliderule atl06p query from an icepyx region
"""

try:
version = ipx_region.product_version
resources = ipx_region.avail_granules(ids=True)[0]
except:
logger.critical("must supply an icepyx query as region")
return icesat2.__emptyframe()
# try to get the subsetting region
if ipx_region.extent_type in ('bbox','polygon'):
parm.update('poly', to_region(ipx_region))

return icesat2.atl06p(parm, asset, version=version, resources=resources)

#
# ICEPYX ATL03
#
def atl03sp(ipx_region, parm, asset=icesat2.DEFAULT_ASSET):
"""
create a sliderule atl03sp query from an icepyx region
"""

try:
version = ipx_region.product_version
resources = ipx_region.avail_granules(ids=True)[0]
except:
logger.critical("must supply an icepyx query as region")
return icesat2.__emptyframe()
# try to get the subsetting region
if ipx_region.extent_type in ('bbox','polygon'):
parm.update('poly', to_region(ipx_region))

return icesat2.atl03sp(parm, asset, version=version, resources=resources)

def to_region(ipx_region):
"""
extract subsetting extents from an icepyx region
"""
if (ipx_region.extent_type == 'bbox'):
bbox = ipx_region.spatial_extent[1]
poly = [dict(lon=bbox[1], lat=bbox[2]),
dict(lon=bbox[3], lat=bbox[2]),
dict(lon=bbox[3], lat=bbox[4]),
dict(lon=bbox[1], lat=bbox[4]),
dict(lon=bbox[1], lat=bbox[2])]
elif (ipx_region.extent_type == 'polygon'):
poly = [dict(lon=ln,lat=lt) for ln,lt in zip(*ipx_region.spatial_extent[1])]
return poly
2 changes: 1 addition & 1 deletion utils/icepx_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def parse_command_line(args, cfg):
icesat2.init(scfg["url"], verbose=True)

# generate sliderule atl06 elevations
parms["poly"] = icesat2.toregion(icfg["spatial_extent"])[0]
# parms["poly"] = icesat2.toregion(icfg["spatial_extent"])[0]
atl06_sr = ipxapi.atl06p(iregion, parms, scfg["asset"])

# Create Plot
Expand Down

0 comments on commit e60e838

Please sign in to comment.