EOX GitLab Instance
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
VS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ESA
PRISM
VS
Commits
9f74c327
Commit
9f74c327
authored
4 years ago
by
Fabian Schindler
Browse files
Options
Downloads
Patches
Plain Diff
Fixes to calc step
parent
d560b3e2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
preprocessor/preprocessor/steps/calc.py
+14
-7
14 additions, 7 deletions
preprocessor/preprocessor/steps/calc.py
with
14 additions
and
7 deletions
preprocessor/preprocessor/steps/calc.py
+
14
−
7
View file @
9f74c327
...
...
@@ -4,29 +4,36 @@ import subprocess
from
typing
import
List
from
glob
import
glob
import
shutil
import
logging
from
osgeo
import
gdal
,
osr
from
..util
import
replace_ext
logger
=
logging
.
getLogger
(
__name__
)
def
calc_step
(
source_dir
:
os
.
PathLike
,
target_dir
:
os
.
PathLike
,
formulas
:
List
[
dict
]):
for
i
,
item
in
enumerate
(
formulas
):
# get first filename as a base
filename
=
next
(
glob
(
join
(
source_dir
,
item
[
'
inputs
'
][
'
glob
'
]))
)
filename
=
glob
(
join
(
source_dir
,
list
(
item
[
'
inputs
'
]
.
values
())[
0
]
[
'
glob
'
]))
target_filename
=
join
(
target_dir
,
replace_ext
(
basename
(
filename
),
item
.
get
(
'
output_postfix
'
,
'
_proc%d
'
%
i
)
+
'
.tif
'
,
False
)
)
# fail if a file would be overridden
# TODO: maybe just log an error
if
isfile
(
target_filename
):
raise
Exceptio
n
(
'
Calc output filename %s already exists
'
%
target_filename
)
logger
.
war
n
(
'
Calc output filename %s already exists
'
%
target_filename
)
calc_formula
(
source_dir
,
item
[
'
inputs
'
],
target_filename
,
item
[
'
formula
'
],
item
.
get
(
'
data_type
'
,
'
Float32
'
))
# take all original files with from the last step
for
filename
in
glob
(
'
%s/*
'
%
source_dir
):
shutil
.
copy
(
filename
,
join
(
target_dir
,
basename
(
filename
)))
target_filename
=
join
(
target_dir
,
basename
(
filename
))
if
isfile
(
target_filename
):
logger
.
warn
(
'
Calc output filename %s already exists
'
%
target_filename
)
shutil
.
copy
(
filename
,
target_filename
)
def
calc_formula
(
source_dir
:
os
.
PathLike
,
inputs
:
List
[
dict
],
target_filename
:
os
.
PathLike
,
formula
:
str
,
data_type
:
str
=
"
Float32
"
,
nodata_value
:
float
=
None
):
...
...
@@ -39,10 +46,10 @@ def calc_formula(source_dir: os.PathLike, inputs: List[dict], target_filename: o
for
name
,
locator
in
inputs
:
# select first
filename
=
next
(
glob
(
join
(
source_dir
,
locator
[
'
glob
'
]))
)
filename
=
glob
(
join
(
source_dir
,
locator
[
'
glob
'
]))
[
0
]
cmd
.
extend
([
"
-%s
"
%
name
,
filename
,
"
-%s_band=%d
"
%
locator
.
get
(
'
band
'
,
1
),
"
-
-
%s_band=%d
"
%
locator
.
get
(
'
band
'
,
1
),
])
if
nodata_value
is
not
None
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment