|
63 | 63 | },
|
64 | 64 | {
|
65 | 65 | "cell_type": "code",
|
66 |
| - "execution_count": 12, |
| 66 | + "execution_count": 5, |
67 | 67 | "metadata": {},
|
68 | 68 | "outputs": [],
|
69 | 69 | "source": [
|
|
75 | 75 | },
|
76 | 76 | {
|
77 | 77 | "cell_type": "code",
|
78 |
| - "execution_count": 9, |
| 78 | + "execution_count": 6, |
79 | 79 | "metadata": {},
|
80 | 80 | "outputs": [],
|
81 | 81 | "source": [
|
|
87 | 87 | },
|
88 | 88 | {
|
89 | 89 | "cell_type": "code",
|
90 |
| - "execution_count": 10, |
| 90 | + "execution_count": 7, |
91 | 91 | "metadata": {},
|
92 | 92 | "outputs": [],
|
93 | 93 | "source": [
|
|
98 | 98 | ]
|
99 | 99 | },
|
100 | 100 | {
|
101 |
| - "cell_type": "markdown", |
| 101 | + "cell_type": "code", |
| 102 | + "execution_count": 10, |
102 | 103 | "metadata": {},
|
| 104 | + "outputs": [ |
| 105 | + { |
| 106 | + "name": "stdout", |
| 107 | + "output_type": "stream", |
| 108 | + "text": [ |
| 109 | + "{'driver': 'GTiff', 'dtype': 'int16', 'nodata': -1.0, 'width': 20381, 'height': 22512, 'count': 1, 'crs': CRS.from_epsg(4326), 'transform': Affine(0.00026949458523585647, 0.0, -62.64186038139295,\n", |
| 110 | + " 0.0, -0.00026949458523585647, -19.287457970745013), 'tiled': False, 'interleave': 'band'}\n", |
| 111 | + "{'driver': 'GTiff', 'dtype': 'float32', 'nodata': -1.0, 'width': 20381, 'height': 22512, 'count': 1, 'crs': CRS.from_epsg(4326), 'transform': Affine(0.00026949458523585647, 0.0, -62.64186038139295,\n", |
| 112 | + " 0.0, -0.00026949458523585647, -19.287457970745013), 'tiled': False, 'interleave': 'band'}\n" |
| 113 | + ] |
| 114 | + } |
| 115 | + ], |
103 | 116 | "source": [
|
104 |
| - "# 25" |
| 117 | + "# Open the land use raster file\n", |
| 118 | + "with rasterio.open(sim25_lup) as src:\n", |
| 119 | + " land_use_array = src.read(1)\n", |
| 120 | + " p1 = src.profile\n", |
| 121 | + "\n", |
| 122 | + "# Open the deforestation probability raster file\n", |
| 123 | + "with rasterio.open(sim25_lup_prediction) as src:\n", |
| 124 | + " deforestation_probability_array = src.read(1)\n", |
| 125 | + " p2 = src.profile\n", |
| 126 | + "print(p1)\n", |
| 127 | + "print(p2)" |
105 | 128 | ]
|
106 | 129 | },
|
107 | 130 | {
|
108 |
| - "cell_type": "code", |
109 |
| - "execution_count": null, |
| 131 | + "cell_type": "markdown", |
110 | 132 | "metadata": {},
|
111 |
| - "outputs": [], |
112 |
| - "source": [] |
| 133 | + "source": [ |
| 134 | + "# 25" |
| 135 | + ] |
113 | 136 | },
|
114 | 137 | {
|
115 | 138 | "cell_type": "code",
|
116 |
| - "execution_count": 20, |
| 139 | + "execution_count": 11, |
117 | 140 | "metadata": {},
|
118 | 141 | "outputs": [
|
119 | 142 | {
|
120 | 143 | "name": "stdout",
|
121 | 144 | "output_type": "stream",
|
122 | 145 | "text": [
|
123 |
| - "Area of land use type 0: 0 square meters\n", |
124 |
| - "Area of land use type 1: 13140840600 square meters\n", |
125 |
| - "Area of land use type 2: 25707976200 square meters\n", |
126 |
| - "Area of land use type 3: 59036355000 square meters\n", |
127 |
| - "Area of land use type 4: 912870900 square meters\n", |
| 146 | + "Area of land use type 0: 0.0 square meters\n", |
| 147 | + "Area of land use type 1: 12236239734.029999 square meters\n", |
| 148 | + "Area of land use type 2: 23938267682.809998 square meters\n", |
| 149 | + "Area of land use type 3: 54972357917.75 square meters\n", |
| 150 | + "Area of land use type 4: 850029881.545 square meters\n", |
128 | 151 | "Area of land use type 0: 0.0 hectares\n",
|
129 |
| - "Area of land use type 1: 1314084.06 hectares\n", |
130 |
| - "Area of land use type 2: 2570797.62 hectares\n", |
131 |
| - "Area of land use type 3: 5903635.5 hectares\n", |
132 |
| - "Area of land use type 4: 91287.09 hectares\n" |
| 152 | + "Area of land use type 1: 1223623.9734029998 hectares\n", |
| 153 | + "Area of land use type 2: 2393826.7682809997 hectares\n", |
| 154 | + "Area of land use type 3: 5497235.791775 hectares\n", |
| 155 | + "Area of land use type 4: 85002.9881545 hectares\n" |
133 | 156 | ]
|
134 | 157 | }
|
135 | 158 | ],
|
|
152 | 175 | "counts = np.bincount(land_use_array_flat)\n",
|
153 | 176 | "\n",
|
154 | 177 | "# Calculate the area of each land use type\n",
|
155 |
| - "pixel_area = 900 # replace this with the actual area represented by each pixel\n", |
| 178 | + "pixel_area = 838.045 # 28.94785483442850804 m * 28.94785483442850804 m = 838.045 square meters EPSG:32721\n", |
156 | 179 | "areas = counts * pixel_area\n",
|
157 | 180 | "\n",
|
158 | 181 | "# Print the area of each land use type\n",
|
159 | 182 | "for i, area in enumerate(areas):\n",
|
160 | 183 | " print(f\"Area of land use type {i}: {area} square meters\")\n",
|
161 | 184 | "# Calculate the deforested area for each pixel\n",
|
162 |
| - "deforested_area_array = deforestation_probability_array * 900 # replace 900 with the actual area represented by each pixel\n", |
| 185 | + "deforested_area_array = deforestation_probability_array * 838.045 # replace 900 with the actual area represented by each pixel\n", |
163 | 186 | "\n",
|
164 | 187 | "# Initialize arrays to hold the total deforested area, non-deforested area, and total area for each land use type\n",
|
165 | 188 | "deforested_areas = np.zeros(4) # number of land use types\n",
|
|
230 | 253 | },
|
231 | 254 | {
|
232 | 255 | "cell_type": "code",
|
233 |
| - "execution_count": 21, |
| 256 | + "execution_count": 13, |
234 | 257 | "metadata": {},
|
235 | 258 | "outputs": [
|
236 | 259 | {
|
237 | 260 | "name": "stdout",
|
238 | 261 | "output_type": "stream",
|
239 | 262 | "text": [
|
240 |
| - "Area of land use type 0: 0 square meters\n", |
241 |
| - "Area of land use type 1: 8532334800 square meters\n", |
242 |
| - "Area of land use type 2: 50576823000 square meters\n", |
243 |
| - "Area of land use type 3: 38781358200 square meters\n", |
244 |
| - "Area of land use type 4: 912873600 square meters\n", |
| 263 | + "Area of land use type 0: 0.0 square meters\n", |
| 264 | + "Area of land use type 1: 7944978352.74 square meters\n", |
| 265 | + "Area of land use type 2: 47095170701.149994 square meters\n", |
| 266 | + "Area of land use type 3: 36111692591.909996 square meters\n", |
| 267 | + "Area of land use type 4: 850032395.68 square meters\n", |
245 | 268 | "Area of land use type 0: 0.0 hectares\n",
|
246 |
| - "Area of land use type 1: 853233.48 hectares\n", |
247 |
| - "Area of land use type 2: 5057682.3 hectares\n", |
248 |
| - "Area of land use type 3: 3878135.82 hectares\n", |
249 |
| - "Area of land use type 4: 91287.36 hectares\n" |
| 269 | + "Area of land use type 1: 794497.835274 hectares\n", |
| 270 | + "Area of land use type 2: 4709517.070114999 hectares\n", |
| 271 | + "Area of land use type 3: 3611169.2591909994 hectares\n", |
| 272 | + "Area of land use type 4: 85003.23956799999 hectares\n" |
250 | 273 | ]
|
251 | 274 | }
|
252 | 275 | ],
|
|
269 | 292 | "counts = np.bincount(land_use_array_flat)\n",
|
270 | 293 | "\n",
|
271 | 294 | "# Calculate the area of each land use type\n",
|
272 |
| - "pixel_area = 900 # replace this with the actual area represented by each pixel\n", |
| 295 | + "pixel_area = 838.045 # replace this with the actual area represented by each pixel\n", |
273 | 296 | "areas = counts * pixel_area\n",
|
274 | 297 | "\n",
|
275 | 298 | "# Print the area of each land use type\n",
|
276 | 299 | "for i, area in enumerate(areas):\n",
|
277 | 300 | " print(f\"Area of land use type {i}: {area} square meters\")\n",
|
278 | 301 | "# Calculate the deforested area for each pixel\n",
|
279 |
| - "deforested_area_array = deforestation_probability_array * 900 # replace 900 with the actual area represented by each pixel\n", |
| 302 | + "deforested_area_array = deforestation_probability_array * 838.045 # replace 900 with the actual area represented by each pixel\n", |
280 | 303 | "\n",
|
281 | 304 | "# Initialize arrays to hold the total deforested area, non-deforested area, and total area for each land use type\n",
|
282 | 305 | "deforested_areas = np.zeros(4) # number of land use types\n",
|
|
338 | 361 | "df_hectares.to_csv(output_file_hectares, index=False)"
|
339 | 362 | ]
|
340 | 363 | },
|
| 364 | + { |
| 365 | + "cell_type": "markdown", |
| 366 | + "metadata": {}, |
| 367 | + "source": [ |
| 368 | + "# 5%" |
| 369 | + ] |
| 370 | + }, |
341 | 371 | {
|
342 | 372 | "cell_type": "code",
|
343 |
| - "execution_count": 22, |
| 373 | + "execution_count": 14, |
344 | 374 | "metadata": {},
|
345 | 375 | "outputs": [
|
346 | 376 | {
|
347 | 377 | "name": "stdout",
|
348 | 378 | "output_type": "stream",
|
349 | 379 | "text": [
|
350 |
| - "Area of land use type 0: 0 square meters\n", |
351 |
| - "Area of land use type 1: 17575208100 square meters\n", |
352 |
| - "Area of land use type 2: 5497432200 square meters\n", |
353 |
| - "Area of land use type 3: 74801823300 square meters\n", |
354 |
| - "Area of land use type 4: 912858300 square meters\n", |
| 380 | + "Area of land use type 0: 0.0 square meters\n", |
| 381 | + "Area of land use type 1: 16365350302.404999 square meters\n", |
| 382 | + "Area of land use type 2: 5118995075.61 square meters\n", |
| 383 | + "Area of land use type 3: 69652548897.165 square meters\n", |
| 384 | + "Area of land use type 4: 850018148.915 square meters\n", |
355 | 385 | "Area of land use type 0: 0.0 hectares\n",
|
356 |
| - "Area of land use type 1: 1757520.81 hectares\n", |
357 |
| - "Area of land use type 2: 549743.22 hectares\n", |
358 |
| - "Area of land use type 3: 7480182.33 hectares\n", |
359 |
| - "Area of land use type 4: 91285.83 hectares\n" |
| 386 | + "Area of land use type 1: 1636535.0302404999 hectares\n", |
| 387 | + "Area of land use type 2: 511899.50756099995 hectares\n", |
| 388 | + "Area of land use type 3: 6965254.8897164995 hectares\n", |
| 389 | + "Area of land use type 4: 85001.81489149999 hectares\n" |
360 | 390 | ]
|
361 | 391 | }
|
362 | 392 | ],
|
|
379 | 409 | "counts = np.bincount(land_use_array_flat)\n",
|
380 | 410 | "\n",
|
381 | 411 | "# Calculate the area of each land use type\n",
|
382 |
| - "pixel_area = 900 # replace this with the actual area represented by each pixel\n", |
| 412 | + "pixel_area = 838.045 # replace this with the actual area represented by each pixel\n", |
383 | 413 | "areas = counts * pixel_area\n",
|
384 | 414 | "\n",
|
385 | 415 | "# Print the area of each land use type\n",
|
386 | 416 | "for i, area in enumerate(areas):\n",
|
387 | 417 | " print(f\"Area of land use type {i}: {area} square meters\")\n",
|
388 | 418 | "# Calculate the deforested area for each pixel\n",
|
389 |
| - "deforested_area_array = deforestation_probability_array * 900 # replace 900 with the actual area represented by each pixel\n", |
| 419 | + "deforested_area_array = deforestation_probability_array * 838.045 # replace 900 with the actual area represented by each pixel\n", |
390 | 420 | "\n",
|
391 | 421 | "# Initialize arrays to hold the total deforested area, non-deforested area, and total area for each land use type\n",
|
392 | 422 | "deforested_areas = np.zeros(4) # number of land use types\n",
|
|
447 | 477 | "# Export the DataFrame to a CSV file\n",
|
448 | 478 | "df_hectares.to_csv(output_file_hectares, index=False)"
|
449 | 479 | ]
|
| 480 | + }, |
| 481 | + { |
| 482 | + "cell_type": "markdown", |
| 483 | + "metadata": {}, |
| 484 | + "source": [ |
| 485 | + "# Hedgerows" |
| 486 | + ] |
| 487 | + }, |
| 488 | + { |
| 489 | + "cell_type": "code", |
| 490 | + "execution_count": 15, |
| 491 | + "metadata": {}, |
| 492 | + "outputs": [ |
| 493 | + { |
| 494 | + "name": "stdout", |
| 495 | + "output_type": "stream", |
| 496 | + "text": [ |
| 497 | + "Area of land use type 0: 0.0 square meters\n", |
| 498 | + "Area of land use type 1: 20277853893.765 square meters\n", |
| 499 | + "Area of land use type 2: 2886681200.39 square meters\n", |
| 500 | + "Area of land use type 3: 67989778784.395 square meters\n", |
| 501 | + "Area of land use type 4: 850034071.77 square meters\n", |
| 502 | + "Area of land use type 0: 0.0 hectares\n", |
| 503 | + "Area of land use type 1: 2027785.3893765 hectares\n", |
| 504 | + "Area of land use type 2: 288668.120039 hectares\n", |
| 505 | + "Area of land use type 3: 6798977.8784395 hectares\n", |
| 506 | + "Area of land use type 4: 85003.407177 hectares\n" |
| 507 | + ] |
| 508 | + } |
| 509 | + ], |
| 510 | + "source": [ |
| 511 | + "# Open the land use raster file\n", |
| 512 | + "with rasterio.open(simhedges_lup) as src:\n", |
| 513 | + " land_use_array = src.read(1)\n", |
| 514 | + "\n", |
| 515 | + "# Open the deforestation probability raster file\n", |
| 516 | + "with rasterio.open(simhedges_lup_prediction) as src:\n", |
| 517 | + " deforestation_probability_array = src.read(1)\n", |
| 518 | + "\n", |
| 519 | + "# Mask the NoData values\n", |
| 520 | + "'''This line is creating a masked array from the land_use_array. \n", |
| 521 | + "A masked array is a numpy array that has a separate Boolean mask that \n", |
| 522 | + "indicates whether each value in the array is valid or not. \n", |
| 523 | + "In this case, the masked_less function is used to create a mask \n", |
| 524 | + "that is True for all values in the array that are less than 0, \n", |
| 525 | + "and False for all other values. This effectively ignores all values less than 0 in the \n", |
| 526 | + "subsequent calculations.'''\n", |
| 527 | + "land_use_array_masked = np.ma.masked_less(land_use_array, 0)\n", |
| 528 | + "\n", |
| 529 | + "# Flatten the array\n", |
| 530 | + "land_use_array_flat = land_use_array_masked.compressed()\n", |
| 531 | + "\n", |
| 532 | + "# Count the number of pixels of each land use type\n", |
| 533 | + "counts = np.bincount(land_use_array_flat)\n", |
| 534 | + "\n", |
| 535 | + "# Calculate the area of each land use type\n", |
| 536 | + "pixel_area = 838.045 # replace this with the actual area represented by each pixel\n", |
| 537 | + "areas = counts * pixel_area\n", |
| 538 | + "\n", |
| 539 | + "# Print the area of each land use type\n", |
| 540 | + "for i, area in enumerate(areas):\n", |
| 541 | + " print(f\"Area of land use type {i}: {area} square meters\")\n", |
| 542 | + "# Calculate the deforested area for each pixel\n", |
| 543 | + "deforested_area_array = deforestation_probability_array * 838.045 # replace 900 with the actual area represented by each pixel\n", |
| 544 | + "\n", |
| 545 | + "# Initialize arrays to hold the total deforested area, non-deforested area, and total area for each land use type\n", |
| 546 | + "deforested_areas = np.zeros(4) # number of land use types\n", |
| 547 | + "non_deforested_areas = np.zeros(4) # number of land use types\n", |
| 548 | + "total_areas = np.zeros(4) # number of land use types\n", |
| 549 | + "\n", |
| 550 | + "# Loop over the land use types\n", |
| 551 | + "for i in range(4): # number of land use types\n", |
| 552 | + " # Select the deforested area for the pixels of the current land use type\n", |
| 553 | + " deforested_area = deforested_area_array[land_use_array == i+1]\n", |
| 554 | + " \n", |
| 555 | + " # Sum the deforested area\n", |
| 556 | + " deforested_areas[i] = deforested_area.sum()\n", |
| 557 | + " \n", |
| 558 | + " # Calculate the total area\n", |
| 559 | + " total_areas[i] = (land_use_array == i+1).sum() * pixel_area\n", |
| 560 | + "\n", |
| 561 | + " # Calculate the non-deforested area\n", |
| 562 | + " non_deforested_areas[i] = total_areas[i] - deforested_areas[i]\n", |
| 563 | + " # Calculate the area of each land use type in hectares\n", |
| 564 | + "areas_hectares = areas / 10000 # 1 hectare = 10,000 square meters\n", |
| 565 | + "\n", |
| 566 | + "# Print the area of each land use type in hectares\n", |
| 567 | + "for i, area in enumerate(areas_hectares):\n", |
| 568 | + " print(f\"Area of land use type {i}: {area} hectares\")\n", |
| 569 | + "\n", |
| 570 | + "# Calculate the deforested area for each pixel in hectares\n", |
| 571 | + "deforested_area_array_hectares = deforestation_probability_array * pixel_area / 10000\n", |
| 572 | + "\n", |
| 573 | + "# Initialize arrays to hold the total deforested area, non-deforested area, and total area for each land use type in hectares\n", |
| 574 | + "deforested_areas_hectares = np.zeros(4) # number of land use types\n", |
| 575 | + "non_deforested_areas_hectares = np.zeros(4) # number of land use types\n", |
| 576 | + "total_areas_hectares = np.zeros(4) # number of land use types\n", |
| 577 | + "\n", |
| 578 | + "# Loop over the land use types\n", |
| 579 | + "for i in range(4): # number of land use types\n", |
| 580 | + " # Select the deforested area for the pixels of the current land use type\n", |
| 581 | + " deforested_area_hectares = deforested_area_array_hectares[land_use_array == i+1]\n", |
| 582 | + " \n", |
| 583 | + " # Sum the deforested area\n", |
| 584 | + " deforested_areas_hectares[i] = deforested_area_hectares.sum()\n", |
| 585 | + " \n", |
| 586 | + " # Calculate the total area in hectares\n", |
| 587 | + " total_areas_hectares[i] = (land_use_array == i+1).sum() * pixel_area / 10000\n", |
| 588 | + "\n", |
| 589 | + " # Calculate the non-deforested area in hectares\n", |
| 590 | + " non_deforested_areas_hectares[i] = total_areas_hectares[i] - deforested_areas_hectares[i]\n", |
| 591 | + " \n", |
| 592 | + "# Create a DataFrame with the deforested area of each land use type in hectares\n", |
| 593 | + "df_hectares = pd.DataFrame({\n", |
| 594 | + " 'LandUseType': ['Hedgerow', 'Forest Reserve', 'Paddocks', 'Riparian Corridor'],\n", |
| 595 | + " 'DeforestedArea': deforested_areas_hectares,\n", |
| 596 | + " 'NonDeforestedArea': non_deforested_areas_hectares,\n", |
| 597 | + " 'TotalArea': total_areas_hectares\n", |
| 598 | + "})\n", |
| 599 | + "\n", |
| 600 | + "output_file_hectares = os.path.join(output_folder, \"sim-hedges-log-lut-area-hectares.csv\")\n", |
| 601 | + "# Export the DataFrame to a CSV file\n", |
| 602 | + "df_hectares.to_csv(output_file_hectares, index=False)" |
| 603 | + ] |
450 | 604 | }
|
451 | 605 | ],
|
452 | 606 | "metadata": {
|
|
0 commit comments