Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ESPACE-DEV
pyrasta
Commits
79dbe24e
Commit
79dbe24e
authored
Jun 30, 2021
by
Benjamin Pillot
Browse files
Fix bug in raster calculation
parent
265bb07d
Changes
1
Hide whitespace changes
Inline
Side-by-side
pyrasta/tools/calculator.py
View file @
79dbe24e
...
...
@@ -10,6 +10,7 @@ import numpy as np
from
pyrasta.io_.files
import
RasterTempFile
from
pyrasta.tools
import
_gdal_temp_dataset
,
_return_raster
from
pyrasta.tools.mapping
import
GDAL_TO_NUMPY
from
pyrasta.tools.windows
import
get_block_windows
,
get_xy_block_windows
from
pyrasta.utils
import
split_into_chunks
from
tqdm
import
tqdm
...
...
@@ -59,7 +60,7 @@ def _op(raster1, out_file, raster2, op_type):
def
_raster_calculation
(
raster_class
,
sources
,
fhandle
,
window_size
,
gdal_driver
,
data_type
,
no_data
,
nb_processes
,
chunksize
):
chunksize
,
description
):
""" Calculate raster expression
"""
...
...
@@ -67,10 +68,14 @@ def _raster_calculation(raster_class, sources, fhandle, window_size,
window_size
=
(
window_size
,
window_size
)
master_raster
=
sources
[
0
]
window_gen
=
([
src
.
_gdal_dataset
.
ReadAsArray
(
*
w
)
for
src
in
sources
]
for
w
in
get_xy_block_windows
(
window_size
,
master_raster
.
x_size
,
master_raster
.
y_size
))
width
=
int
(
master_raster
.
x_size
/
window_size
[
0
])
+
min
(
1
,
master_raster
.
x_size
%
window_size
[
0
])
height
=
int
(
master_raster
.
y_size
/
window_size
[
1
])
+
min
(
1
,
master_raster
.
y_size
%
window_size
[
1
])
window_gen
=
([
src
.
_gdal_dataset
.
ReadAsArray
(
*
w
).
astype
(
GDAL_TO_NUMPY
[
data_type
])
for
src
in
sources
]
for
w
in
get_xy_block_windows
(
window_size
,
master_raster
.
x_size
,
master_raster
.
y_size
))
width
=
int
(
master_raster
.
x_size
/
window_size
[
0
])
+
min
(
1
,
master_raster
.
x_size
%
window_size
[
0
])
height
=
int
(
master_raster
.
y_size
/
window_size
[
1
])
+
min
(
1
,
master_raster
.
y_size
%
window_size
[
1
])
with
RasterTempFile
(
gdal_driver
.
GetMetadata
()[
'DMD_EXTENSION'
])
as
out_file
:
...
...
@@ -79,7 +84,7 @@ def _raster_calculation(raster_class, sources, fhandle, window_size,
for
win_gen
in
tqdm
(
split_into_chunks
(
window_gen
,
width
),
total
=
height
,
desc
=
"Calculate raster express
ion
"
):
desc
=
descript
ion
):
with
mp
.
Pool
(
processes
=
nb_processes
)
as
pool
:
list_of_arrays
=
list
(
pool
.
map
(
fhandle
,
...
...
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