diff --git a/sardem/cli.py b/sardem/cli.py index 70ca322..10312bf 100644 --- a/sardem/cli.py +++ b/sardem/cli.py @@ -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() @@ -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" @@ -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, ) diff --git a/sardem/cop_dem.py b/sardem/cop_dem.py index 0fcfa37..a205d7b 100644 --- a/sardem/cop_dem.py +++ b/sardem/cop_dem.py @@ -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. @@ -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, diff --git a/sardem/dem.py b/sardem/dem.py index f0ce5ce..63448da 100644 --- a/sardem/dem.py +++ b/sardem/dem.py @@ -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` @@ -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: @@ -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") @@ -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) @@ -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) \ No newline at end of file + utils.shift_rsc_file(rsc_filename, to_gdal=False) diff --git a/setup.py b/setup.py index 776c28a..2b32904 100644 --- a/setup.py +++ b/setup.py @@ -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",