Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fireatlas_nrt
Manage
Activity
Members
Labels
Plan
Issues
14
Issue boards
Milestones
Wiki
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
gcorradini
fireatlas_nrt
Commits
bfdb41f7
Commit
bfdb41f7
authored
3 years ago
by
screbec
Browse files
Options
Downloads
Patches
Plain Diff
add check for validity and lower filter value to include smaller islands within water bodies
parent
adae5247
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
polygonise_water_test.py
+24
-5
24 additions, 5 deletions
polygonise_water_test.py
with
24 additions
and
5 deletions
polygonise_water_test.py
+
24
−
5
View file @
bfdb41f7
...
...
@@ -18,6 +18,7 @@ import glob
import
numpy
as
np
import
gdal
#, ogr, osr
import
time
import
gc
#import matplotlib.pyplot as plt
...
...
@@ -116,7 +117,7 @@ def hull_from_pixels(arr, geoTrans):
# we keep large islands since they can also burn (see NWT slave lake 2014)
islands
=
arr_lakes
.
astype
(
int
)
-
arr
.
astype
(
int
)
islands
=
morphology
.
remove_small_objects
(
islands
==
1
,
100
1
)
islands
=
morphology
.
remove_small_objects
(
islands
==
1
,
25
1
)
# we also keep lakes on islands if they fit the size requirements
island_lakes
=
ndimage
.
binary_fill_holes
(
islands
)
island_lakes
=
island_lakes
.
astype
(
int
)
-
islands
.
astype
(
int
)
...
...
@@ -180,7 +181,7 @@ def hull_from_pixels(arr, geoTrans):
# grab the lake geometry and clip the islands
if
len
(
island_hulls
)
>
1
:
island_hulls
=
unary_union
(
island_hulls
)
# buffer to make the polygon valid
island_hulls
=
unary_union
(
island_hulls
)
else
:
island_hulls
=
island_hulls
[
0
]
hulls
[
fid
]
=
hulls
[
fid
].
difference
(
island_hulls
)
...
...
@@ -320,6 +321,23 @@ def save_gdf(gdf,year,tilex,tiley):
# # store pixel value in first field (right now in int, could be changed to dbl)
# gdal.Polygonize(outband, outmask, temp_layer, 0, [], callback=None )
#%% check if all geometries of end product are valid
import
geopandas
as
gpd
from
FireConsts
import
lakedir
year
=
2012
path_out
=
lakedir
+
str
(
year
)
+
'
/
'
files_year
=
glob
.
glob
(
path_out
+
'
*.gpkg
'
)
for
file
in
files_year
:
gdf
=
gpd
.
read_file
(
file
)
if
all
(
gdf
.
is_valid
):
continue
else
:
print
(
file
)
break
#%%
# the minimum output resolution of GSW is 30m,
...
...
@@ -328,13 +346,13 @@ def save_gdf(gdf,year,tilex,tiley):
# we regrid to square 90m pixels first (North Pole LAEA)
# specs
year
=
201
5
year
=
201
8
#coarseness = 5 # has to be multiple of 2 or 5
path_in
=
'
D:/fire_atlas/Data/GlobalSurfaceWater/
'
+
str
(
year
)
+
'
/
'
tempfile
=
'
D:/fire_atlas/Data/GlobalSurfaceWater/vector/temp1
5
.tif
'
tempfile
=
'
D:/fire_atlas/Data/GlobalSurfaceWater/vector/temp1
8
.tif
'
files_year
=
glob
.
glob
(
path_in
+
'
*0.tif
'
)
# files_year = files_year[
61:
]
# files_year = files_year[
:42
]
# loop over files in folder
for
file
in
files_year
:
...
...
@@ -373,6 +391,7 @@ for file in files_year:
if
len
(
gdf
)
>
0
:
save_gdf
(
gdf
,
year
,
tilex
,
tiley
)
warp
=
id_ds
=
None
gc
.
collect
()
### OLD: regrid to coarser resolution using coarseness (no warp)
...
...
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