Commit 0ea7ca76 authored by Hannes Diedrich's avatar Hannes Diedrich
Browse files

Added lat lon threshold to API request.

parent 1294461d
Pipeline #1789 passed with stages
in 15 minutes and 10 seconds
......@@ -20,8 +20,6 @@ import netCDF4 as nc4
from glob import glob
from os.path import isfile
from os.path import join
from os.path import dirname
from os import makedirs
from os.path import expanduser
from scipy.ndimage.interpolation import zoom
from skimage.exposure import rescale_intensity, adjust_gamma
......@@ -41,8 +39,24 @@ warnings.filterwarnings("ignore")
class Gts2Request(dict):
def check_geo(self, ll=(), ur=()):
"""
Check if area of request is not too large.
:param ll: tuple
:param ur: tuple
:return:
"""
thres = 0.2
latrange = ur[1]-ll[1]
lonrange = ur[0]-ll[0]
if (lonrange >= thres) | (latrange >= thres):
raise Exception("Your requestst area too large: ({lon}°x{lat}° excedes 0.2°x0.2°)".format(lat=latrange,
lon=lonrange))
def __init__(self, opts, logger=None):
self.check_geo(ll=opts["ll"], ur=opts["ll"])
address = "https://rz-vm175.gfz-potsdam.de:{port}/AC".format(port=opts["auth"]["port"])
# test parameters such that api string formatting wont fail
......@@ -312,7 +326,6 @@ def mk_rgb(basedir, outdir, rgb_comb=("B04", "B03", "B02"), rgb_gamma=(1.0, 1.0,
fn_out = join(outdir, "{pref}_RGB_{bands}.{ext}".format(pref="_".join(split), bands="_".join(rgb_comb),
ext=extension))
if isfile(fn_out) is False:
# logger.info("Reading {fin}".format(fin=fin))
# Create output array
ds = gdal.Open(fin, gdal.GA_ReadOnly)
sdata = ds.GetRasterBand(1)
......@@ -346,31 +359,6 @@ def mk_rgb(basedir, outdir, rgb_comb=("B04", "B03", "B02"), rgb_gamma=(1.0, 1.0,
del data
del ds
import scipy.misc
# Save output rgb image
# makedirs(dirname(fn_out), exist_ok=True)
# sss = np.array(S2_rgb.tolist(), dtype=rgb_type)
# logger.info("imsave")
# print(S2_rgb.min(), S2_rgb.max())
# print(S2_rgb.dtype)
# print(scipy.misc.bytescale(S2_rgb))
# fn_out = "/misc/fluo5/hannesd/tmp//S2_RGB.jpg"
# print(fn_out)
# import pdb;
# pdb.set_trace()
# data = np.asarray(S2_rgb)
# toimage(S2_rgb).save(fn_out)
# imsave(fn_out, sss)
# scipy.misc.toimage(S2_rgb).save(fn_out)
# with open("/home/hannesd/pladde/tmp/S2_RGB.json", "w") as fo:
# json.dump({"s2_rgb":S2_rgb.tolist()}, fo)
imsave(fn_out, S2_rgb)
fnout_list.append(fn_out)
......@@ -679,7 +667,9 @@ def __get_auth(logger=None):
logger.error("You did not save your credentials in %s." % cred_file)
user = input("gts2_client - Please insert username: ")
password = input("gts2_client - Please insert password: ")
port = input("gts2_client - Please insert port for API: ")
port = input("gts2_client - Please insert port for API (for default, type 'yes'): ")
if port == "yes":
port = "80"
auth = (user, password)
return {"auth": auth, "port": port}
......@@ -832,32 +822,8 @@ def str2bool(v):
raise argparse.ArgumentTypeError('Boolean value expected.')
def run_test():
client(outpath="/tmp/",
out_prefix="krh",
out_mode="rgb",
geo_ll=(12.559433, 53.036066),
geo_ur=(12.737961, 53.238058),
sensor="S2A",
level="L2A",
version="0.12",
bands="B04_B03_B02",
max_cloudy="0.2",
suffix="",
start_date="20170501",
end_date="20170530",
minimum_fill="0.9",
merge_tifs=True,
merge_tile="32UQD",
rgb_bands_selection="vegetation")
if __name__ == "__main__":
run_test()
import sys
sys.exit()
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-o", "--out_dir", action="store", required=True, type=str,
......
Supports Markdown
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