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
Kies, Jacqueline
ACT - Time Series Analysis in Flood-Prone Areas
Commits
9b4006bf
Commit
9b4006bf
authored
2 years ago
by
Verouden, Niels
Browse files
Options
Downloads
Patches
Plain Diff
Improve code
Improve code for plotting images Solve typo
parent
6ec0d448
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
Thresholding/thresholding_functions.py
+9
-10
9 additions, 10 deletions
Thresholding/thresholding_functions.py
Thresholding/thresholding_main.py
+3
-5
3 additions, 5 deletions
Thresholding/thresholding_main.py
with
12 additions
and
15 deletions
Thresholding/thresholding_functions.py
+
9
−
10
View file @
9b4006bf
...
...
@@ -25,7 +25,7 @@ def thresholding(array):
threshold
=
(
cluster_center
[
0
]
+
cluster_center
[
1
])
/
2
threshold
=
threshold
[
0
]
# crate binary flood map
# cr
e
ate binary flood map
# all pixels below the threshold (1) are flooded, all pixels above (0) are non-flooded
output
=
copy
.
copy
(
array
)
output
[
np
.
where
(
output
<
threshold
)]
=
0.0001
...
...
@@ -41,10 +41,10 @@ def apply_thresholding(dest_name):
for
i
in
os
.
listdir
(
dest_name
):
dates
.
append
(
i
[
0
:
10
])
data
=
os
.
path
.
join
(
dest_name
,
i
)
# open and read tif files
data2
=
rio
.
open
(
data
)
data2
=
data2
.
read
(
1
)
# get only first band (vv)
images
.
append
(
data2
)
output
.
append
(
thresholding
(
data2
))
# call thresholding function on all files
sar
=
rio
.
open
(
data
)
array
=
sar
.
read
(
1
)
# get only first band (vv)
images
.
append
(
array
)
output
.
append
(
thresholding
(
array
))
# call thresholding function on all files
return
output
,
images
,
dates
...
...
@@ -52,14 +52,14 @@ def apply_thresholding(dest_name):
# STEP 2: VISUALISE
# =============================================================================
def
show_stats
(
image
):
def
show_stats
(
image
,
bins
,
title
):
"""
Function that computes statistics and shows histogram for one image
"""
stats
=
[]
stats
.
append
({
'
min
'
:
np
.
nanmin
(
image
),
'
mean
'
:
np
.
nanmean
(
image
),
'
median
'
:
np
.
nanmedian
(
image
),
'
max
'
:
np
.
nanmax
(
image
)})
hist
=
show_hist
(
image
,
bins
=
50
,
lw
=
0.0
,
stacked
=
False
,
alpha
=
0.3
,
histtype
=
'
stepfilled
'
,
title
=
"
Histogram
"
)
hist
=
show_hist
(
image
,
bins
=
bins
,
lw
=
0.0
,
stacked
=
True
,
histtype
=
'
stepfilled
'
,
title
=
title
)
return
stats
,
hist
def
visualise
(
images
,
nrows
,
ncols
,
dates
,
title
=
'
Title
'
):
...
...
@@ -67,8 +67,7 @@ def visualise(images, nrows, ncols, dates, title='Title'):
plt
.
figure
()
plt
.
suptitle
(
title
,
fontsize
=
18
,
x
=
0.51
,
y
=
0.98
)
for
n
,
image
in
enumerate
(
images
):
ax
=
plt
.
subplot
(
nrows
,
ncols
,
n
+
1
)
ax
=
plt
.
subplot
(
2
,
2
,
n
+
1
)
ax
.
imshow
(
image
)
ax
.
set_title
(
dates
[
n
])
ax
.
set_xticks
([])
ax
.
set_yticks
([])
plt
.
axis
(
'
off
'
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Thresholding/thresholding_main.py
+
3
−
5
View file @
9b4006bf
...
...
@@ -8,15 +8,13 @@ an impression of the situation in a certain area.
# IMPORTS
# =============================================================================
from
thresholding_functions
import
apply_thresholding
from
thresholding_functions
import
show_stats
from
thresholding_functions
import
visualise
from
Thresholding.thresholding_functions
import
apply_thresholding
,
show_stats
,
visualise
# =============================================================================
# FILE SETUP
# =============================================================================
folder_name
=
'
data/
SentinelTimeSeriesStacked
'
# folder with unzipped, stacked and filtered SAR images
folder_name
=
'
data/
CapHaitien_Flood2021
'
# folder with unzipped, stacked and filtered SAR images
# =============================================================================
# STEP 1: APPLY THRESHOLDING
...
...
@@ -28,6 +26,6 @@ thresholding, images, dates = apply_thresholding(folder_name)
# STEP 2: VISUALISE
# =============================================================================
show_stats
(
image
s
[
1
]
)
show_stats
(
image
=
images
[
0
],
bins
=
50
,
title
=
'
Histogram
'
)
visualise
(
thresholding
,
2
,
3
,
dates
,
'
Thresholding method
'
)
# 2 = nrows, 3 = ncols
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