Skip to content

Commit

Permalink
Merge pull request #13 from scottstanie/cli-output-args
Browse files Browse the repository at this point in the history
allow output format/output datatype args
  • Loading branch information
scottstanie authored Oct 18, 2022
2 parents 898482e + f6ca776 commit c328312
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
21 changes: 20 additions & 1 deletion sardem/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ def get_cli_args():
"Location to save downloaded files (Default = {})".format(utils.get_cache_dir())
),
)
parser.add_argument(
"--output-format",
"-of",
choices=["ENVI", "GTiff", "ROI_PAC"],
default="ENVI",
help="Output format (for copernicus DEM option, default %(default)s)."
)
parser.add_argument(
"--output-type",
"-ot",
choices=["int16", "float32"],
type=str.lower,
default="int16",
help="Output data type (default %(default)s)."
)
return parser.parse_args()


Expand Down Expand Up @@ -177,7 +192,9 @@ def cli():
bbox = utils.bounding_box(left_lon, top_lat, dlon, dlat)
elif args.bbox:
bbox = args.bbox

else:
bbox = None

if not args.output:
output = (
"watermask.wbd" if args.data_source == "NASA_WATER" else "elevation.dem"
Expand All @@ -197,4 +214,6 @@ def cli():
keep_egm=args.keep_egm,
shift_rsc=args.shift_rsc,
cache_dir=args.cache_dir,
output_format=args.output_format,
output_type=args.output_type,
)
17 changes: 12 additions & 5 deletions sardem/cop_dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@


def download_and_stitch(
output_name, bbox, keep_egm=False, xrate=1, yrate=1, vrt_filename=None
output_name,
bbox,
keep_egm=False,
xrate=1,
yrate=1,
vrt_filename=None,
output_format="ENVI",
output_type="int16"
):
"""Download the COP DEM from AWS.
Expand Down Expand Up @@ -42,21 +49,21 @@ def download_and_stitch(
t_srs = s_srs = None
else:
code = conversions.EPSG_CODES["egm08"]
s_srs = 'epsg:4326+{}'.format(code)
t_srs = 'epsg:4326'
s_srs = "epsg:4326+{}".format(code)
t_srs = "epsg:4326"
xres = DEFAULT_RES / xrate
yres = DEFAULT_RES / yrate
resamp = "bilinear" if (xrate > 1 or yrate > 1) else "nearest"

# access_mode = "overwrite" if overwrite else None
option_dict = dict(
format="ENVI",
format=output_format,
outputBounds=bbox,
dstSRS=t_srs,
srcSRS=s_srs,
xRes=xres,
yRes=yres,
outputType=gdal.GDT_Int16,
outputType=gdal.GetDataTypeByName(output_type.title()),
resampleAlg=resamp,
multithread=True,
warpMemoryLimit=5000,
Expand Down
10 changes: 8 additions & 2 deletions sardem/dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ def main(
keep_egm=False,
shift_rsc=False,
cache_dir=None,
output_type="int16",
output_format="ENVI",
):
"""Function for entry point to create a DEM with `sardem`
Expand All @@ -317,6 +319,8 @@ def main(
X_FIRST and Y_FIRST values represent the pixel *center* (instead of
GDAL's convention of pixel edge). Default = False.
cache_dir (str): directory to cache downloaded tiles
output_type (str): output type for DEM (default = int16)
output_format (str): output format for copernicus DEM (default = ENVI)
"""
if bbox is None:
if geojson:
Expand Down Expand Up @@ -353,6 +357,8 @@ def main(
keep_egm=keep_egm,
xrate=xrate,
yrate=yrate,
output_format=output_format,
output_type=output_type,
)
if make_isce_xml:
logger.info("Creating ISCE2 XML file")
Expand Down Expand Up @@ -382,7 +388,7 @@ def main(
rsc_filename = output_name + ".rsc"

# Upsampling:
dtype = np.int16
dtype = np.dtype(output_type.lower())
if xrate == 1 and yrate == 1:
logger.info("Rate = 1: No upsampling to do")
logger.info("Writing DEM to %s", output_name)
Expand Down Expand Up @@ -461,4 +467,4 @@ def main(

# If the user wants the .rsc file to point to pixel center:
if shift_rsc:
utils.shift_rsc_file(rsc_filename, to_gdal=False)
utils.shift_rsc_file(rsc_filename, to_gdal=False)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="sardem",
version="0.11.0",
version="0.11.1",
author="Scott Staniewicz",
author_email="scott.stanie@gmail.com",
description="Create upsampled DEMs for InSAR processing",
Expand Down

0 comments on commit c328312

Please sign in to comment.