Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ACT - Time Series Analysis in Flood-Prone Areas
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Verouden, Niels
ACT - Time Series Analysis in Flood-Prone Areas
Commits
68214db4
Commit
68214db4
authored
3 years ago
by
Verouden, Niels
Browse files
Options
Downloads
Patches
Plain Diff
normalize data from EO Learn API
parent
59abc0fa
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
eo_learn/py/s7RewriteTIF.py
+10
-7
10 additions, 7 deletions
eo_learn/py/s7RewriteTIF.py
eo_learn/py/s8Visualise.py
+28
-27
28 additions, 27 deletions
eo_learn/py/s8Visualise.py
with
38 additions
and
34 deletions
eo_learn/py/s7RewriteTIF.py
+
10
−
7
View file @
68214db4
...
...
@@ -28,14 +28,17 @@ def rewriteTIF(eopatch, file_name, vv_path, vh_path, dem_path):
with
rio
.
open
(
dem_path
,
'
r
'
)
as
dst
:
dem
=
dst
.
read
()
#Scale to range 0-1
vv_data
/=
np
.
amax
(
vv_data
)
vh_data
/=
np
.
amax
(
vh_data
)
#
Calculate
VV/VH ratio from VV and VH data
#VV/VH ratio is calculated as VV/VH, since our data is measured on a linear scale
vvvh_
ratio
=
np
.
empty
(
vv_data
.
shape
,
dtype
=
rio
.
float64
)
vvvh_
ratio
=
np
.
divide
(
vv
_data
,
vh_data
,
out
=
np
.
zeros_like
(
vv
_data
),
where
=
vh_data
!=
0
)
#Calculate
an index that highlights water bodies as third band:
vvvh_sum
=
np
.
add
(
vv_data
,
vh_data
)
vvvh_
dif
=
np
.
subtract
(
vv_data
,
vh_data
)
vvvh_
index
=
np
.
divide
(
vv
vh_dif
,
vvvh_sum
,
out
=
np
.
zeros_like
(
vv
vh_sum
),
where
=
vvvh_sum
!=
0
)
# Zip VV, VH, and VV/VH arrays together into one array
stack
=
[[
x
]
+
[
y
]
+
[
z
]
for
x
,
y
,
z
in
zip
(
vv_data
,
vh_data
,
vvvh_
ratio
)]
stack
=
[[
x
]
+
[
y
]
+
[
z
]
for
x
,
y
,
z
in
zip
(
vv_data
,
vh_data
,
vvvh_
index
)]
names
=
[]
# Write arrays to tif based on their data
...
...
@@ -47,7 +50,7 @@ def rewriteTIF(eopatch, file_name, vv_path, vh_path, dem_path):
dst
.
write_band
(
2
,
stack
[
i
][
1
])
dst
.
write_band
(
3
,
stack
[
i
][
2
])
dst
.
write_band
(
4
,
dem
[
0
])
dst
.
descriptions
=
tuple
([
'
VV
'
,
'
VH
'
,
'
VV/VH_
ratio
'
,
'
DEM
'
])
dst
.
descriptions
=
tuple
([
'
VV
'
,
'
VH
'
,
'
VV/VH_
index
'
,
'
DEM
'
])
names
.
append
(
stack_filename
)
# Remove temporary VV and VH files
...
...
This diff is collapsed.
Click to expand it.
eo_learn/py/s8Visualise.py
+
28
−
27
View file @
68214db4
...
...
@@ -7,40 +7,41 @@ import matplotlib.pyplot as plt
import
os
def
visualiseResults
(
visualise
,
bands
,
names
,
file_name
):
for
i
in
range
(
len
(
bands
)):
if
bands
[
i
]
==
'
VV
'
:
band
=
0
elif
bands
[
i
]
==
'
VH
'
:
band
=
1
elif
bands
[
i
]
==
'
VVVH
'
:
band
=
2
elif
bands
[
i
]
==
'
DEM
'
:
band
=
3
# Plot all images for each band in bands, expect for DEM (only plot DEM once)
if
band
!=
3
:
for
x
in
range
(
len
(
names
)):
path_stacked
=
os
.
path
.
join
(
'
data
'
,
file_name
,
names
[
x
])
if
visualise
==
'
y
'
:
for
i
in
range
(
len
(
bands
)):
if
bands
[
i
]
==
'
VV
'
:
band
=
0
elif
bands
[
i
]
==
'
VH
'
:
band
=
1
elif
bands
[
i
]
==
'
VVVH
'
:
band
=
2
elif
bands
[
i
]
==
'
DEM
'
:
band
=
3
# Plot all images for each band in bands, expect for DEM (only plot DEM once)
if
band
!=
3
:
for
x
in
range
(
len
(
names
)):
path_stacked
=
os
.
path
.
join
(
'
data
'
,
file_name
,
names
[
x
])
SAR
=
rio
.
open
(
path_stacked
)
SARi
=
SAR
.
read
(
band
+
1
)
date
=
names
[
x
][
0
:
10
]
fig
,
ax
=
plt
.
subplots
(
figsize
=
(
10
,
10
))
rio
.
plot
.
show
(
SARi
,
ax
=
ax
)
plt
.
title
(
f
'
{
bands
[
i
]
}
{
date
}
'
,
fontdict
=
{
'
fontsize
'
:
20
})
plt
.
axis
(
False
)
del
SAR
else
:
path_stacked
=
os
.
path
.
join
(
'
data
'
,
file_name
,
names
[
0
])
SAR
=
rio
.
open
(
path_stacked
)
SARi
=
SAR
.
read
(
band
+
1
)
date
=
names
[
x
][
0
:
10
]
date
=
names
[
0
][
0
:
10
]
fig
,
ax
=
plt
.
subplots
(
figsize
=
(
10
,
10
))
rio
.
plot
.
show
(
SARi
,
ax
=
ax
)
plt
.
title
(
f
'
{
bands
[
i
]
}
{
date
}
'
,
fontdict
=
{
'
fontsize
'
:
20
})
plt
.
axis
(
False
)
del
SAR
else
:
path_stacked
=
os
.
path
.
join
(
'
data
'
,
file_name
,
names
[
0
])
SAR
=
rio
.
open
(
path_stacked
)
SARi
=
SAR
.
read
(
band
+
1
)
date
=
names
[
0
][
0
:
10
]
fig
,
ax
=
plt
.
subplots
(
figsize
=
(
10
,
10
))
rio
.
plot
.
show
(
SARi
,
ax
=
ax
)
plt
.
title
(
f
'
{
bands
[
i
]
}
{
date
}
'
,
fontdict
=
{
'
fontsize
'
:
20
})
plt
.
axis
(
False
)
del
SAR
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