Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
manuscript_code
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
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
Maria Voigt
manuscript_code
Commits
dd2f3c51
Commit
dd2f3c51
authored
7 years ago
by
Maria Voigt
Browse files
Options
Downloads
Patches
Plain Diff
adding province and updating
parent
074dc765
Branches
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
src/validation/grid_mapping_for_resource_use.py
+50
-27
50 additions, 27 deletions
src/validation/grid_mapping_for_resource_use.py
with
50 additions
and
27 deletions
src/validation/grid_mapping_for_resource_use.py
+
50
−
27
View file @
dd2f3c51
...
@@ -4,10 +4,12 @@ Spyder Editor
...
@@ -4,10 +4,12 @@ Spyder Editor
# script to prepare the grid with the resource use information
# script to prepare the grid with the resource use information
# in the output file we will have a
# in the output file we will have a
# a 1 at the first position if pixel has to be
discard
ed
# a 1 at the first position if pixel has to be
consider
ed
# a 2 at the first position if the pixel is
consider
ed
# a 2 at the first position if the pixel is
discard
ed
# a 1 at the second position for IDN
# a 1 at the second position for IDN
# a 2 at the second position for MYS
# a 2 at the second position for MYS
# a 10 at the third position for SAB
# an 11 at the third position for SAW + also for others
# a 0 - 5 at the 3rd position depending on the resource use category
# a 0 - 5 at the 3rd position depending on the resource use category
# the grid_id from the 4rth to the 10th position (6 positions)
# the grid_id from the 4rth to the 10th position (6 positions)
#
#
...
@@ -16,13 +18,12 @@ Spyder Editor
...
@@ -16,13 +18,12 @@ Spyder Editor
# 0 - absence
# 0 - absence
# 1 - plantation
# 1 - plantation
# 2 - deforestation
# 2 - deforestation
# 3 - landcover change
# 3 - logging
# 4 - logging
# 4 - primary forest < 750m
# 5 - primary forest < 750m
# 5 - primary forest > 750
# 6 - primary forest > 750
# 6 - regrowth
# 7 - regrowth
# 7 - plantations before 2000
# 8 - plantations before 2000
# 8 - other
# 9 - other
"""
"""
...
@@ -73,8 +74,11 @@ os.system("gdalwarp \
...
@@ -73,8 +74,11 @@ os.system("gdalwarp \
"""
"""
absence_path
=
"
/homes/mv39zilo/work/Borneo/data/response/cleaned_data/absence_shape/absence_shape_expanded_22_08_17_repro_res.tif
"
#absence_path = "/homes/mv39zilo/work/Borneo/data/response/cleaned_data/absence_shape/absence_shape_expanded_22_08_17_repro_res.tif"
absence
=
mp
.
tiff
.
read_tif
(
absence_path
,
1
)
#absence = mp.tiff.read_tif(absence_path, 1)
populations
=
mp
.
tiff
.
read_tif
(
"
/homes/mv39zilo/work/Borneo/data/populations_phva/meta_kalsarsab_20002015_diss_no_reintro_repro_res.tif
"
,
1
)
# input grid with grid_ids as values
# input grid with grid_ids as values
...
@@ -86,15 +90,31 @@ np.unique(resource_use)
...
@@ -86,15 +90,31 @@ np.unique(resource_use)
country_layer_path
=
"
/homes/mv39zilo/work/Borneo/data/auxiliary_additional_data/Borneo_shape/cleaned_data/Borneo_country_repro_res.tif
"
country_layer_path
=
"
/homes/mv39zilo/work/Borneo/data/auxiliary_additional_data/Borneo_shape/cleaned_data/Borneo_country_repro_res.tif
"
borneo
=
mp
.
tiff
.
read_tif
(
country_layer_path
,
1
)
borneo
=
mp
.
tiff
.
read_tif
(
country_layer_path
,
1
)
province_layer_path
=
"
/homes/mv39zilo/work/Borneo/data/auxiliary_additional_data/Borneo_shape/cleaned_data/Borneo_province_repro_res.tif
"
borneo_province
=
mp
.
tiff
.
read_tif
(
province_layer_path
,
1
)
np
.
unique
(
borneo_province
)
"""
"""
# format
# format
1 0 0 0 0 0 000 000
1 0 10 0 000 001
(1 / 2) 0 (3 / 6) 0 (1-9) 0 700 000
(1 / 2) (3 / 6) 10-16 (1-9) 700 000
out/in, MYS/IDN, category,grid_id
in/out, MYS/IDN, Province, category, grid_id
in/out
10000000000
country
1000000000
province
10000000
category
1000000
grid
100000
"""
"""
# pixel is
out / out
# pixel is
in / out (in when 1, out when 2)
resource_grid_1
=
np
.
where
(
absence
=
=
1
,
10000000000
0
,
20000000000
0
)
resource_grid_1
=
np
.
where
(
populations
!
=
0
,
10000000000
,
20000000000
)
# country
# country
resource_grid_2
=
np
.
where
(
borneo
==
136
,
(
resource_grid_1
+
3
*
1000000000
),
resource_grid_2
=
np
.
where
(
borneo
==
136
,
(
resource_grid_1
+
3
*
1000000000
),
...
@@ -103,26 +123,29 @@ resource_grid_3 = np.where(borneo == 106, (resource_grid_2 + 6 * 1000000000),
...
@@ -103,26 +123,29 @@ resource_grid_3 = np.where(borneo == 106, (resource_grid_2 + 6 * 1000000000),
resource_grid_2
)
resource_grid_2
)
resource_grid_4
=
np
.
where
(
resource_use
>
0
,
(
resource_grid_3
+
resource_use
*
10000000
),
# province
resource_grid_3
)
# excluding Brunei (1-4)
np
.
unique
(
resource_grid_4
)
resource_grid_4
=
np
.
where
(
borneo_province
>
4
,
(
resource_grid_3
+
(
borneo_province
*
10000000
)),
resource_grid_3
)
# now assigning number for each resource use
# now assigning number for each resource use
resource_grid_5
=
np
.
where
(
resource_use
>
0
,
(
resource_grid_4
+
resource_use
*
1000000
),
resource_grid_5
=
np
.
where
(
grid
>
0
,
(
resource_grid_4
+
grid
),
resource_grid_4
)
resource_grid_4
)
np
.
unique
(
resource_grid_5
)
np
.
unique
(
resource_grid_5
)
resource_grid_6
=
np
.
where
(
grid
>
0
,
(
resource_grid_5
+
grid
),
resource_grid_5
)
np
.
unique
(
resource_grid_6
)
mp
.
tiff
.
write_tif
(
file_with_srid
=
"
/homes/mv39zilo/work/Borneo/analysis/model_prep_and_running/results/future/grid_with_id_repro_res.tif
"
,
mp
.
tiff
.
write_tif
(
file_with_srid
=
"
/homes/mv39zilo/work/Borneo/analysis/model_prep_and_running/results/future/grid_with_id_repro_res.tif
"
,
full_output_name
=
"
/homes/mv39zilo/work/Borneo/analysis/model_prep_and_running/results/resource_use/resource_grid_absence_country_category_id.tif
"
,
full_output_name
=
"
/homes/mv39zilo/work/Borneo/analysis/model_prep_and_running/results/resource_use/resource_grid_absence_country_category_id.tif
"
,
data
=
resource_grid_
5
,
data
=
resource_grid_
6
,
dtype
=
5
)
dtype
=
5
)
# use this in R script "prepare_boot_grid.R"
# use this in R script "prepare_boot_grid
_resource_use
.R"
"""
"""
...
@@ -137,8 +160,8 @@ test = np.where((grid == 0) &
...
@@ -137,8 +160,8 @@ test = np.where((grid == 0) &
np.sum(test)
np.sum(test)
mp.tiff.write_tif(file_with_srid = grid_layer_path,
mp.tiff.write_tif(file_with_srid = grid_layer_path,
full_output_name =
"
/homes/mv39zilo/work/Borneo/data/bootstrap/test.tif
"
,
full_output_name =
"
/homes/mv39zilo/work/Borneo/data/bootstrap/test.tif
"
,
data =
t
es
t
,
data =
r
es
ource_grid_6
,
dtype =
4
)
dtype =
5
)
"""
"""
# rasterize borneo with info on country or province
# rasterize borneo with info on country or province
...
...
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