Commit 48fb8fa3 authored by Romulo Pereira Goncalves's avatar Romulo Pereira Goncalves

Merge branch 'add-compression-option' into 'master'

add compression option to client

See merge request !15
parents d4d4381b 964e5321
Pipeline #17682 passed with stages
in 16 minutes and 26 seconds
...@@ -397,7 +397,8 @@ def mk_rgb(basedir, outdir, rgb_comb=("B04", "B03", "B02"), rgb_gamma=(1.0, 1.0, ...@@ -397,7 +397,8 @@ def mk_rgb(basedir, outdir, rgb_comb=("B04", "B03", "B02"), rgb_gamma=(1.0, 1.0,
return fnout_list return fnout_list
def json_to_tiff(out_mode, api_result, only_tile, outpath, out_prefix, wl, level, stack_resolution, bands, logger=None): def json_to_tiff(out_mode, api_result, only_tile, outpath, out_prefix, wl,
level, stack_resolution, bands, tif_opts, logger=None):
""" """
Get data from json dict and save if as singletif files OR: Get data from json dict and save if as singletif files OR:
save all requested bands plus cloudmask as one tiff file per date and tile. save all requested bands plus cloudmask as one tiff file per date and tile.
...@@ -410,6 +411,7 @@ def json_to_tiff(out_mode, api_result, only_tile, outpath, out_prefix, wl, level ...@@ -410,6 +411,7 @@ def json_to_tiff(out_mode, api_result, only_tile, outpath, out_prefix, wl, level
:type level: string :type level: string
:type stack_resolution: string :type stack_resolution: string
:type bands: string :type bands: string
:type tif_opts: list of string
:type logger: logger :type logger: logger
:return: List of written tifs (list of strings) :return: List of written tifs (list of strings)
""" """
...@@ -445,7 +447,7 @@ def json_to_tiff(out_mode, api_result, only_tile, outpath, out_prefix, wl, level ...@@ -445,7 +447,7 @@ def json_to_tiff(out_mode, api_result, only_tile, outpath, out_prefix, wl, level
outfile = "{path}/{sensor}_{level}_{pref}_{date}_{tile}_{band}_{res}m.tif".format( outfile = "{path}/{sensor}_{level}_{pref}_{date}_{tile}_{band}_{res}m.tif".format(
path=outpath, pref=out_prefix, date=ac_date, tile=tile_key, band=band, level=level, path=outpath, pref=out_prefix, date=ac_date, tile=tile_key, band=band, level=level,
res=res, sensor=sensor) res=res, sensor=sensor)
img = driver.Create(outfile, cols, rows, 1, gdal.GDT_Int32) img = driver.Create(outfile, cols, rows, 1, gdal.GDT_Int32, options=tif_opts)
img.SetGeoTransform(geotrans) img.SetGeoTransform(geotrans)
img.SetProjection(geo_proj) img.SetProjection(geo_proj)
img.GetRasterBand(1).WriteArray(arr) img.GetRasterBand(1).WriteArray(arr)
...@@ -741,7 +743,7 @@ def __get_auth(logger=None): ...@@ -741,7 +743,7 @@ def __get_auth(logger=None):
return {"auth": auth, "port": port} return {"auth": auth, "port": port}
def client(outpath="", out_prefix="", out_mode="json", geo_ll=(), geo_ur=(), sensor="S2A", bands="", max_cloudy="0.5", def client(outpath="", out_prefix="", out_mode="json", compress="ZSTD-2" , geo_ll=(), geo_ur=(), sensor="S2A", bands="", max_cloudy="0.5",
level="L2A", start_date="", end_date="", version="0.15", suffix="", minimum_fill="0.8", level="L2A", start_date="", end_date="", version="0.15", suffix="", minimum_fill="0.8",
only_tile="", stack_resolution="10", quiet=False, rgb_extension="jpg", rgb_bands_selection="realistic", only_tile="", stack_resolution="10", quiet=False, rgb_extension="jpg", rgb_bands_selection="realistic",
merge_tifs=False, merge_tile=None, onlytime=False, timeout=None): merge_tifs=False, merge_tile=None, onlytime=False, timeout=None):
...@@ -758,6 +760,7 @@ def client(outpath="", out_prefix="", out_mode="json", geo_ll=(), geo_ur=(), sen ...@@ -758,6 +760,7 @@ def client(outpath="", out_prefix="", out_mode="json", geo_ll=(), geo_ur=(), sen
:type outpath: string :type outpath: string
:type out_prefix: string :type out_prefix: string
:type out_mode: string :type out_mode: string
:type compress: string
:type geo_ll: tuple of floats :type geo_ll: tuple of floats
:type geo_ur: tuple of floats :type geo_ur: tuple of floats
:type sensor: string :type sensor: string
...@@ -801,6 +804,11 @@ def client(outpath="", out_prefix="", out_mode="json", geo_ll=(), geo_ur=(), sen ...@@ -801,6 +804,11 @@ def client(outpath="", out_prefix="", out_mode="json", geo_ll=(), geo_ur=(), sen
if onlytime and out_mode not in ["json", "python"]: if onlytime and out_mode not in ["json", "python"]:
raise AssertionError("Invalid output mode. If onlytime==True, choose either 'python' or 'json'") raise AssertionError("Invalid output mode. If onlytime==True, choose either 'python' or 'json'")
if compress:
tif_opts = "COMPRESS={}_PREDICTOR={}".format(*compress.split("-")).split("_")
else:
tif_opts = None
valid_out_modes = ["json", "nc", "single", "stack", "python", "rgb"] valid_out_modes = ["json", "nc", "single", "stack", "python", "rgb"]
try: try:
assert out_mode in valid_out_modes assert out_mode in valid_out_modes
...@@ -860,7 +868,7 @@ def client(outpath="", out_prefix="", out_mode="json", geo_ll=(), geo_ur=(), sen ...@@ -860,7 +868,7 @@ def client(outpath="", out_prefix="", out_mode="json", geo_ll=(), geo_ur=(), sen
elif out_mode == "single" or out_mode == "stack": elif out_mode == "single" or out_mode == "stack":
logger.info("Converting data to %s tif-files ..." % out_mode, ) logger.info("Converting data to %s tif-files ..." % out_mode, )
tif_list = json_to_tiff(out_mode, api_result, only_tile, outpath, out_prefix, wl, level, stack_resolution, tif_list = json_to_tiff(out_mode, api_result, only_tile, outpath, out_prefix, wl, level, stack_resolution,
bands, logger=logger) bands, tif_opts=tif_opts, logger=logger)
if merge_tifs is True: if merge_tifs is True:
merge_tiles(tif_list, out_mode=out_mode, target_tile=merge_tile) merge_tiles(tif_list, out_mode=out_mode, target_tile=merge_tile)
...@@ -869,7 +877,7 @@ def client(outpath="", out_prefix="", out_mode="json", geo_ll=(), geo_ur=(), sen ...@@ -869,7 +877,7 @@ def client(outpath="", out_prefix="", out_mode="json", geo_ll=(), geo_ur=(), sen
with tempfile.TemporaryDirectory(dir=outpath) as tmp_dir: with tempfile.TemporaryDirectory(dir=outpath) as tmp_dir:
tif_list = json_to_tiff("stack", api_result, only_tile, tmp_dir, out_prefix, wl, level, stack_resolution, tif_list = json_to_tiff("stack", api_result, only_tile, tmp_dir, out_prefix, wl, level, stack_resolution,
bands, logger=logger) bands, tif_opts=tif_opts, logger=logger)
if merge_tifs is True: if merge_tifs is True:
merge_tiles(tif_list, out_mode="stack", target_tile=merge_tile) merge_tiles(tif_list, out_mode="stack", target_tile=merge_tile)
......
...@@ -17,7 +17,7 @@ if not_installed != []: ...@@ -17,7 +17,7 @@ if not_installed != []:
', '.join(not_installed))) ', '.join(not_installed)))
setup(name='gts2_client', setup(name='gts2_client',
version='1.1.1', version='1.1.2',
packages=find_packages(exclude=['tests*']), packages=find_packages(exclude=['tests*']),
url='https://gitext.gfz-potsdam.de/gts2/gts2_client.git', url='https://gitext.gfz-potsdam.de/gts2/gts2_client.git',
license='GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007', license='GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment