Commit 83e96060 authored by Tiago Sanona's avatar Tiago Sanona Committed by Romulo Pereira Goncalves
Browse files

Slight change in dealing with results of requests. The default values should...

Slight change in dealing with results of requests. The default values should be equal across all functions.
Change default minimum_fill. Increment version.
parent d7389d07
......@@ -35,6 +35,33 @@ band_settings = {"realistic": ("B04", "B03", "B02"),
warnings.filterwarnings("ignore")
def get_defaults():
return ({
"out_dir" : "",
"out_prefix" : "",
"out_mode" : "json",
"lat_ll" : 0.0,
"lon_ll" : 0.0,
"lat_ur" : 0.0,
"lon_ur" : 0.0,
"sensor" : "S2A",
"level" : "L2A",
"version" : "0.13",
"bands" : "",
"start_date" : "",
"end_date" : "",
"coreg" : False,
"max_cloudy" : "0.5",
"minimum_fill" : "0.8",
"utm_zone" : "",
"stack_resolution" : "10",
"rgb_extension" : "jpg",
"rgb_bands_selection" : "realistic",
"merge_tifs" : False,
"merge_tile" : None,
"onlytime" : False,
"timeout" : None
})
class Gts2Request(dict):
......@@ -82,9 +109,12 @@ class Gts2Request(dict):
# get data, update dict from json
result = requests.get(self.api_call, verify=False, auth=opts["auth"]["auth"], timeout=opts["timeout"])
status = {"http_code": result.status_code}
status_code = result.status_code
status = {"http_code": status_code}
self.update(result.json())
# if api responds with http error it can't create json
if status_code < 400:
self.update(result.json())
self.update(status)
......@@ -712,7 +742,7 @@ def __get_auth(logger=None):
def client(outpath="", out_prefix="", out_mode="json", geo_ll=(), geo_ur=(), sensor="S2A", bands="", max_cloudy="0.5",
level="L2A", start_date="", end_date="", version="0.13", suffix="", minimum_fill="",
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",
merge_tifs=False, merge_tile=None, onlytime=False, timeout=None):
"""
......@@ -792,21 +822,21 @@ def client(outpath="", out_prefix="", out_mode="json", geo_ll=(), geo_ur=(), sen
"onlytime": onlytime, "timeout": timeout}
# actual API request
logger.info("Requesting data from the GTS2 server ...", )
logger.info("Requesting data from the GTS2 server ...")
a_stime = time.time()
api_result = Gts2Request(opts, logger=logger)
a_runtime = time.time() - a_stime
logger.info(">>>>>> Runtime of API: %7.2f minutes" % (a_runtime / 60.))
if api_result["http_code"] >= 500:
logger.error("##################")
raise ChildProcessError("API call not right or server Problem (http_code={code}).".format(
code=api_result["http_code"]))
if api_result["ControlValues"]["API_status"] == 1:
if "ControlValues" in api_result and api_result["ControlValues"]["API_status"] == 1:
logger.error("##################")
logger.error(str(api_result["ControlValues"]["API_message"]))
raise ChildProcessError("Something went wrong on GTS2 Server (http_code={code}).".format(
code=api_result["http_code"]))
if api_result["http_code"] >= 400:
logger.error("##################")
raise ChildProcessError("API call not right or server Problem (http_code={code}).".format(
code=api_result["http_code"]))
if only_tile != "":
requ_tiles = api_result['Results'].keys()
......@@ -874,7 +904,7 @@ if __name__ == "__main__":
help="output_directory")
parser.add_argument("-r", "--out_prefix", action="store", required=False, type=str,
help="output_prefix for naming the output files, it should not contain '_'.")
parser.add_argument("-m", "--out_mode", action="store", required=False, type=str, default="json",
parser.add_argument("-m", "--out_mode", action="store", required=False, type=str, default=get_defaults()["out_mode"],
help="output_mode, use 'json' for json-file,"
"'single' for single tiffs or 'stack' for band stack "
"'nc' for netcdf-file")
......@@ -886,40 +916,40 @@ if __name__ == "__main__":
help="latitude upper right corner")
parser.add_argument("-j", "--lon_ur", action="store", required=True, type=float,
help="longitude upper right corner")
parser.add_argument("-a", "--sensor", action="store", required=False, type=str, default="S2A",
parser.add_argument("-a", "--sensor", action="store", required=False, type=str, default=get_defaults()["sensor"],
help="sensor name (e.g. S2A) for all: S2all")
parser.add_argument("-t", "--level", action="store", required=False, type=str, default="L2A",
parser.add_argument("-t", "--level", action="store", required=False, type=str, default=get_defaults()["level"],
help="processing level (e.g. L2A)")
parser.add_argument("-v", "--version", action="store", required=False, type=str, default="0.13",
parser.add_argument("-v", "--version", action="store", required=False, type=str, default=get_defaults()["version"],
help="version of atmospheric correction (e.g. 0.10)")
parser.add_argument("-b", "--bands", action="store", required=False, type=str, default="",
parser.add_argument("-b", "--bands", action="store", required=False, type=str, default=get_defaults()["bands"],
help="list of Bands (e.g. -b B02_B03")
parser.add_argument("-s", "--start_date", action="store", required=True, type=str,
help="Startdate e.g. 20160701")
parser.add_argument("-e", "--end_date", action="store", required=True, type=str,
help="Enddate e.g. 20160701")
parser.add_argument("-c", "--coreg", action="store", required=False, type=str2bool, default=False,
parser.add_argument("-c", "--coreg", action="store", required=False, type=str2bool, default=get_defaults()["coreg"],
help="get data with corrected pixel shifts (True or False)")
parser.add_argument("-z", "--max_cloudy", action="store", required=False, type=str, default="0.5",
parser.add_argument("-z", "--max_cloudy", action="store", required=False, type=str, default=get_defaults()["max_cloudy"],
help="maximal percentage of cloudyness of requested scene (e.g. 0.5)")
parser.add_argument("-f", "--minimum_fill", action="store", required=False, type=str, default="0.12",
parser.add_argument("-f", "--minimum_fill", action="store", required=False, type=str, default=get_defaults()["minimum_fill"],
help="minimal percentage of data in scene (e.g. 1.0)")
parser.add_argument("-d", "--utm_zone", action="store", required=False, type=str, default="",
parser.add_argument("-d", "--utm_zone", action="store", required=False, type=str, default=get_defaults()["utm_zone"],
help="only return data for specific utm-zone (MGRS-tile, e.g. 33UUV)")
parser.add_argument("-g", "--stack_resolution", action="store", required=False, type=str, default="10",
parser.add_argument("-g", "--stack_resolution", action="store", required=False, type=str, default=get_defaults()["stack_resolution"],
help="spatial sampling [in meters] of the output stack file, choose from [10,20,60])")
parser.add_argument("-n", "--rgb_extension", action="store", required=False, type=str, default="jpg",
parser.add_argument("-n", "--rgb_extension", action="store", required=False, type=str, default=get_defaults()["rgb_extension"],
help="file extension of rgb files e.g.[jpg, png], default: jpg")
parser.add_argument("-q", "--rgb_bands_selection", action="store", required=False, type=str, default="realistic",
parser.add_argument("-q", "--rgb_bands_selection", action="store", required=False, type=str, default=get_defaults()["rgb_bands_selection"],
help="band selection for rgb production, choose from: [realistic, nice_looking, vegetation, "
"healthy_vegetation_urban, snow, agriculture]")
parser.add_argument("-w", "--merge_tifs", action="store", required=False, type=str2bool, default=False,
parser.add_argument("-w", "--merge_tifs", action="store", required=False, type=str2bool, default=get_defaults()["merge_tifs"],
help="Merge tifs and RGBs if area in two or more MGRS tiles per time step (True or False).")
parser.add_argument("-x", "--merge_tile", action="store", required=False, type=str, default=None,
parser.add_argument("-x", "--merge_tile", action="store", required=False, type=str, default=get_defaults()["merge_tile"],
help="Choose MGRS tile into which the merge of files is performed (e.g. 33UUV).")
parser.add_argument("-p", "--onlytime", action="store", required=False, type=str2bool, default=False,
parser.add_argument("-p", "--onlytime", action="store", required=False, type=str2bool, default=get_defaults()["onlytime"],
help="get the available timestamps for a specific request without downloading any rasterdata")
parser.add_argument("-u", "--timeout", action="store", required=False, type=int, default=None,
parser.add_argument("-u", "--timeout", action="store", required=False, type=int, default=get_defaults()["timeout"],
help="time to wait for a response from gts2 before raising a Timeout exception")
args = parser.parse_args()
......
......@@ -17,7 +17,7 @@ if not_installed != []:
', '.join(not_installed)))
setup(name='gts2_client',
version='1.1.0',
version='1.1.1',
packages=find_packages(exclude=['tests*']),
url='https://gitext.gfz-potsdam.de/gts2/gts2_client.git',
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