Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gts2
gts2_client
Commits
be405d44
Commit
be405d44
authored
Feb 22, 2021
by
tsanona
Browse files
Add option to json_to_tiff to skip mask conversion.
parent
48fb8fa3
Pipeline
#19653
passed with stages
in 41 minutes and 35 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
gts2_client/gts2_client.py
View file @
be405d44
...
...
@@ -398,7 +398,7 @@ def mk_rgb(basedir, outdir, rgb_comb=("B04", "B03", "B02"), rgb_gamma=(1.0, 1.0,
def
json_to_tiff
(
out_mode
,
api_result
,
only_tile
,
outpath
,
out_prefix
,
wl
,
level
,
stack_resolution
,
bands
,
tif_opts
,
logger
=
None
):
level
,
stack_resolution
,
bands
,
tif_opts
,
keep_mask
,
logger
=
None
):
"""
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.
...
...
@@ -464,7 +464,7 @@ def json_to_tiff(out_mode, api_result, only_tile, outpath, out_prefix, wl,
tif_list
.
append
(
outfile
)
# create tif file for clm
if
level
!=
"L1C"
:
if
level
!=
"L1C"
and
keep_mask
:
clm
=
api_result
[
'Metadata'
][
tile_key
][
'MSK_'
+
str
(
res
)
+
'm'
][
'data'
][
ti
]
clm_arr
=
np
.
asarray
(
clm
)
clm_outfile
=
"{path}/{sensor}_{level}_{pref}_{date}_{tile}_MSK_{res}m.tif"
.
format
(
...
...
@@ -540,7 +540,7 @@ def json_to_tiff(out_mode, api_result, only_tile, outpath, out_prefix, wl,
geo_proj
=
api_result
[
'Results'
][
tile_key
][
band_key
][
'mapinfo'
][
'geo_projection'
]
geotrans
=
(
x_min
,
int
(
stack_resolution
),
0
,
y_max
,
0
,
-
int
(
stack_resolution
))
driver
=
gdal
.
GetDriverByName
(
"GTiff"
)
if
level
==
"L1C"
:
if
level
==
"L1C"
or
not
keep_mask
:
outfile
=
"{path}/{sensor}_{level}_{pref}_{date}_{tile}_{band}_{res}m.tif"
.
format
(
path
=
outpath
,
pref
=
out_prefix
,
date
=
ac_date
,
tile
=
tile_key
,
band
=
bands
,
level
=
level
,
res
=
stack_resolution
,
sensor
=
sensor
)
...
...
@@ -548,7 +548,7 @@ def json_to_tiff(out_mode, api_result, only_tile, outpath, out_prefix, wl,
outfile
=
"{path}/{sensor}_{level}_{pref}_{date}_{tile}_{band}_MSK_{res}m.tif"
.
format
(
path
=
outpath
,
pref
=
out_prefix
,
date
=
ac_date
,
tile
=
tile_key
,
band
=
bands
,
level
=
level
,
res
=
stack_resolution
,
sensor
=
sensor
)
img
=
driver
.
Create
(
outfile
,
cols
,
rows
,
count_bands
+
1
,
gdal
.
GDT_Int32
)
img
=
driver
.
Create
(
outfile
,
cols
,
rows
,
count_bands
+
keep_mask
,
gdal
.
GDT_Int32
,
options
=
tif_opts
)
img
.
SetGeoTransform
(
geotrans
)
img
.
SetProjection
(
geo_proj
)
...
...
@@ -564,11 +564,11 @@ def json_to_tiff(out_mode, api_result, only_tile, outpath, out_prefix, wl,
slice
+=
1
# This is done outside of the loop because one can not set a nodata_value for each band
img
.
GetRasterBand
(
slice
).
SetNoDataValue
(
api_result
[
'Results'
][
tile_key
][
band_key
][
"fill_value"
])
img
.
GetRasterBand
(
slice
-
1
).
SetNoDataValue
(
api_result
[
'Results'
][
tile_key
][
band_key
][
"fill_value"
])
img
.
SetMetadata
({
'TIFFTAG_YRESOLUTION'
:
'%s'
%
stack_resolution
,
'TIFFTAG_XRESOLUTION'
:
'%s'
%
stack_resolution
})
if
level
!=
"L1C"
:
if
level
!=
"L1C"
and
keep_mask
:
clm
=
api_result
[
'Metadata'
][
tile_key
][
'MSK_%sm'
%
stack_resolution
][
'data'
][
ti
]
clm_arr
=
np
.
asarray
(
clm
)
img
.
GetRasterBand
(
slice
).
WriteArray
(
clm_arr
)
...
...
@@ -745,7 +745,7 @@ def __get_auth(logger=None):
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"
,
only_tile
=
""
,
stack_resolution
=
"10"
,
quiet
=
False
,
rgb_extension
=
"jpg"
,
rgb_bands_selection
=
"realistic"
,
only_tile
=
""
,
stack_resolution
=
"10"
,
keep_mask
=
True
,
quiet
=
False
,
rgb_extension
=
"jpg"
,
rgb_bands_selection
=
"realistic"
,
merge_tifs
=
False
,
merge_tile
=
None
,
onlytime
=
False
,
timeout
=
None
):
"""
Downloads data via API and saves it in a wanted file format (.json, .tiff or .nc) or alternatively returns a python
...
...
@@ -868,7 +868,7 @@ def client(outpath="", out_prefix="", out_mode="json", compress="ZSTD-2" , geo_l
elif
out_mode
==
"single"
or
out_mode
==
"stack"
:
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
,
bands
,
tif_opts
=
tif_opts
,
logger
=
logger
)
bands
,
tif_opts
=
tif_opts
,
keep_mask
=
keep_mask
,
logger
=
logger
)
if
merge_tifs
is
True
:
merge_tiles
(
tif_list
,
out_mode
=
out_mode
,
target_tile
=
merge_tile
)
...
...
@@ -877,7 +877,7 @@ def client(outpath="", out_prefix="", out_mode="json", compress="ZSTD-2" , geo_l
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
,
bands
,
tif_opts
=
tif_opts
,
logger
=
logger
)
bands
,
tif_opts
=
tif_opts
,
keep_mask
=
keep_mask
,
logger
=
logger
)
if
merge_tifs
is
True
:
merge_tiles
(
tif_list
,
out_mode
=
"stack"
,
target_tile
=
merge_tile
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment