Commit 9fd7973d authored by tsanona's avatar tsanona

add compression option to client

parent d4d4381b
Pipeline #17505 canceled with stages
...@@ -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
...@@ -859,8 +862,10 @@ def client(outpath="", out_prefix="", out_mode="json", geo_ll=(), geo_ur=(), sen ...@@ -859,8 +862,10 @@ 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, )
if compress:
tif_opts = "COMPRESS={}_PREDICTOR={}".format(*compress.split("-")).split("_")
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)
......
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