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
Roelofsen, Hans
benb_utils
Commits
1831ed36
Commit
1831ed36
authored
Jan 21, 2022
by
Biersteker, Levi
Browse files
added buffer raster function
parent
ecaee21d
Changes
3
Show whitespace changes
Inline
Side-by-side
benb.py
View file @
1831ed36
...
@@ -148,7 +148,6 @@ def colrow2xy(colrow, rio_object=None, affine_in=None):
...
@@ -148,7 +148,6 @@ def colrow2xy(colrow, rio_object=None, affine_in=None):
return
x
,
y
return
x
,
y
def
progress_bar
(
iterable
,
prefix
=
''
,
suffix
=
''
,
decimals
=
1
,
length
=
100
,
fill
=
'#'
,
printEnd
=
"
\r
"
):
def
progress_bar
(
iterable
,
prefix
=
''
,
suffix
=
''
,
decimals
=
1
,
length
=
100
,
fill
=
'#'
,
printEnd
=
"
\r
"
):
"""
"""
Call in a loop to create terminal progress bar
Call in a loop to create terminal progress bar
...
@@ -230,4 +229,3 @@ def file_of_type(x, ext):
...
@@ -230,4 +229,3 @@ def file_of_type(x, ext):
raise
argparse
.
ArgumentTypeError
(
'{} is not a file'
.
format
(
x
))
raise
argparse
.
ArgumentTypeError
(
'{} is not a file'
.
format
(
x
))
if
not
ext_match
:
if
not
ext_match
:
raise
argparse
.
ArgumentTypeError
(
'{} is not a correct file'
.
format
(
x
))
raise
argparse
.
ArgumentTypeError
(
'{} is not a correct file'
.
format
(
x
))
buffer_raster.py
0 → 100644
View file @
1831ed36
import
rasterio
as
rio
import
numpy
as
np
import
os
def
buffer_raster
(
raster_path
:
str
,
crs
,
padding
:
int
=
100
):
"""
Parameters
----------
raster_path : str
filepath for raster to buffer
crs
crs specification
padding : int
amount of cells to buffer around raster
Returns
-------
buffered raster : rasterio.io.DatasetReader
"""
raster
=
rio
.
open
(
raster_path
)
raster_buffered
=
raster
.
read
(
1
)
for
i
in
range
(
padding
):
raster_buffered
=
np
.
insert
(
raster_buffered
,
[
0
],
-
9999
,
axis
=
1
)
raster_buffered
=
np
.
insert
(
raster_buffered
,
[
0
],
-
9999
,
axis
=
0
)
raster_buffered
=
np
.
insert
(
raster_buffered
,
[
-
1
],
-
9999
,
axis
=
1
)
raster_buffered
=
np
.
insert
(
raster_buffered
,
[
-
1
],
-
9999
,
axis
=
0
)
raster_buffered
=
np
.
where
(
raster_buffered
==
-
9999
,
np
.
nan
,
raster_buffered
)
origin_x
,
origin_y
=
raster
.
xy
(
-
padding
,
-
padding
)
outputpath
=
os
.
path
.
splitext
(
raster_path
)[
0
]
+
".tif"
with
rio
.
open
(
outputpath
,
"w"
,
driver
=
"GTiff"
,
height
=
raster_buffered
.
shape
[
0
],
width
=
raster_buffered
.
shape
[
1
],
count
=
1
,
dtype
=
raster_buffered
.
dtype
,
crs
=
crs
,
transform
=
rio
.
transform
.
from_origin
(
origin_x
-
12.5
,
origin_y
+
12.5
,
25
,
25
),
)
as
outputraster
:
outputraster
.
write
(
raster_buffered
,
1
)
return
rio
.
open
(
outputpath
)
mnp_hokaggregation.py
View file @
1831ed36
...
@@ -9,7 +9,7 @@ from mpl_toolkits.axes_grid1 import make_axes_locatable
...
@@ -9,7 +9,7 @@ from mpl_toolkits.axes_grid1 import make_axes_locatable
import
os
import
os
def
mnp_hokaggregation
(
hok_csv
,
hokken_polygon_path
,
background_raster_path
,
outputdir
):
def
mnp_hokaggregation
(
hok_csv
,
hokken_polygon_path
,
background_raster_path
,
outputdir
,
gridcell_count
=
False
):
"""
"""
make aggregationplots for use in manual validation of mnp runs. can both aggregate validation data and species
make aggregationplots for use in manual validation of mnp runs. can both aggregate validation data and species
model gridcells per hok.
model gridcells per hok.
...
@@ -46,19 +46,26 @@ def mnp_hokaggregation(hok_csv, hokken_polygon_path, background_raster_path, out
...
@@ -46,19 +46,26 @@ def mnp_hokaggregation(hok_csv, hokken_polygon_path, background_raster_path, out
extend
=
"max"
extend
=
"max"
ylabel_text
=
"Number of observations in SOVON"
ylabel_text
=
"Number of observations in SOVON"
elif
"COUNT_KEY_VALUE"
in
colnames
:
elif
"OPS_COUNT"
in
colnames
:
bounds
=
np
.
array
([
1
,
10
,
50
,
100
,
500
,
1000
])
explabel
=
"_validation"
valuecolumn
=
"OPS_COUNT"
extend
=
"max"
ylabel_text
=
"number of observations in NDFF"
elif
gridcell_count
:
bounds
=
np
.
array
([
1
,
10
,
100
,
1000
,
10000
,
40000
])
bounds
=
np
.
array
([
1
,
10
,
100
,
1000
,
10000
,
40000
])
explabel
=
"_"
explabel
=
"_"
valuecolumn
=
"COUNT_KEY_VALUE"
valuecolumn
=
"COUNT_KEY_VALUE"
extend
=
"neither"
extend
=
"neither"
ylabel_text
=
"Number of gridcells in Hok"
ylabel_text
=
"Number of gridcells in Hok"
elif
"
OPS_COUNT
"
in
colnames
:
elif
"
MAX_KEY_VALUE
"
in
colnames
:
bounds
=
np
.
array
([
1
,
10
,
50
,
100
,
500
,
1000
])
bounds
=
np
.
array
([
0
,
0.1
,
0.5
,
1
,
1.5
,
2
])
explabel
=
"_
validation
"
explabel
=
"_"
valuecolumn
=
"
OPS_COUNT
"
valuecolumn
=
"
MAX_KEY_VALUE
"
extend
=
"max"
extend
=
"max"
ylabel_text
=
"
number of observ
ation
s
in
NDFF
"
ylabel_text
=
"
Largest key popul
ation in
cell
"
else
:
else
:
raise
Exception
(
"no value column in columns"
)
raise
Exception
(
"no value column in columns"
)
...
...
Write
Preview
Supports
Markdown
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