-
Notifications
You must be signed in to change notification settings - Fork 1
/
Functions.py
1829 lines (1381 loc) · 89.2 KB
/
Functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# coding: utf-8
# # Biomass Energy Potential Mapping and Analysis Tool (BEPMAT)
# ### This notebook contains all the functions used in the project along with the data. We request you to kindly go through the supporting text on the GitHub repository and the article, available as a preprint (Insert Zenodo doi) to get an idea of the objectives and the methodology.
# ## Loading all the CSVs containing the required raster files
# In[31]:
# Importing a few important libraries essential to the work.
import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt
import numpy as np
import xarray as xr
# Importing the Geoprocessing libraries
import rasterio
from rasterio.mask import mask
from rasterio.plot import show
from rasterio.crs import CRS
from rasterio.transform import from_origin
from rasterio.transform import Affine
from rasterio import transform
from rasterio.enums import Resampling
from rasterio.io import MemoryFile
import geopandas as gpd
from shapely.geometry import Point
# Importing required libraries for plotting interactive rasters
from bokeh.plotting import figure
from bokeh.plotting import show as bokeh_show
from bokeh.models import LinearColorMapper, ColorBar, HoverTool, GeoJSONDataSource
import bokeh.palettes as bp
import bokeh.plotting as bpl
import matplotlib.patches as mpatches
import plotly
import plotly.graph_objects as go
import plotly.io as pio
import seaborn as sns
from bokeh.palettes import magma , Blues8 , plasma
# Importing required libraries to obtain shapefiles
import gadm
from gadm import GADMDownloader
# In[2]:
# Uploading all the CSVs into pandas DataFrmes
potential_yield = pd.read_csv("./dataset/potentialyield.csv")
harvested_area = pd.read_csv("./dataset/harvest_data_actual.csv") #The year is integer type
production_values= pd.read_csv("./dataset/productionvalues_actualyield.csv")
exclusion_areas= pd.read_csv("./dataset/Exclusionareas.csv")
tree_cover_share= pd.read_csv("./dataset/Treecover_share_GAEZ.csv")
aez_classification = pd.read_csv("./dataset/Classificationzones57.csv")
# The production_values defined here will be used for calculating crop residue from the year 2000 and 2010
# under different conditions. The harvested area will be used for future residue from cropland calculations
# and the potential yield will be used for future residue from cropland as well as biomass potential from future
# marginal land. The remaining will be used to find the Total Available Land.
# ## Creating a shapefile generator which can generate the gadm shapefile for any region.
# In[3]:
def shapefile_generator(country, province=None):
downloader = GADMDownloader(version="4.0")
if province:
# Download shapefile for a specific province
ad_level = 1
country_name = country
gdf_country = downloader.get_shape_data_by_country_name(country_name=country_name, ad_level=ad_level)
gdf_province = gdf_country[gdf_country["NAME_1"] == province]
return gdf_province
else:
# Download shapefile for the entire country
ad_level = 0
gdf_country = downloader.get_shape_data_by_country_name(country_name=country, ad_level=ad_level)
return gdf_country
# ## Notebook work flow:
# - We start with the simplest calculations of the raw biomass energy we could have obtained from the harvests in the past using the data for years 2000 and 2010 (This is only applicable for cropland since this was the land that was actually harvested and we are keeping the marginal for maximizing the energy output in the future).
# - Next we will calculate the residue and the raw biomass energy potential from the cropland in the future
# - Finally we will calculate the residue and the raw biomass energy potential from the marginal land in the future
# - We will keep defining helper functions along the way wherever required.
# ## I. Raw Biomass Energy Potential from Agricultural Residues using Actual Yields and Production (2000 and 2010) [GAEZv4 Theme 5 : Actual Yields and Productions]
# Theme 5 spatial layers include mapped distributions of harvested area, yield and production at 5 arc-minute resolution for 26 major crops/crop groups, separately in rain-fed and irrigated cropland. Country totals are based on FAO statistics for the years 2009-2011. Also included are estimates of the spatial distribution of total crop production value and the production values of major crop groups (cereals, root crops, oil crops), all valued at year 2000 international prices, separately for rain-fed and irrigated cropland.
# ### Creating the dataset for calculating the biomass energy potential from the production values
# To be able to calculate the Biomass potential we will need the crop Residue-to-Product Ratio, Surplus Availability Factor/
# Availability Factor and Lower Heating Value. The following table summarizes these values for the crops we have from the
# actual yields and production data:
#
# | Crop | Residue Type | RPR | SAF | LHV (MJ/kg) | Sources |
# |--------------|---------------|-------|-------|-------------|-----------------|
# | Maize | Stalk | 2 | 0.8 | 16.3 | a, b, j |
# | | Cob | 0.273 | 1 | 16.63 | |
# | | Husk | 0.2 | 1 | 15.56 | |
# | Rice | Straw | 1.757 | 0.684 | 8.83 | b, d, e |
# | | Husk | 0.23 | 0.83 | 12.9 | c, e, f |
# | Sorghum | Straw | 1.25 | 0.8 | 12.38 | a, b |
# | | Husk | 1.4 | 1 | 13 | c, j |
# | Millet | Straw | 1.4 | 1 | 13 | c, j |
# | | Stalk | 1.75 | 0.8 | 15.51 | a, b, f |
# | Wheat | Straw | 1.2 | 0.29 | 15.6 | b, j |
# | | Husk | 0.23 | 0.29 | 12.9 | b, f |
# | Cassava | Stalk | 0.062 | 0.407 | 16.99 | a, d, e |
# | | Peelings | 3 | 0.2 | 10.61 | a, i |
# | Cocoyam | Peelings | 0.2 | 0.8 | 10.61 | i, j |
# | Sweet potato | Peelings | 0.6 | 0.8 | 10.61 | b, j |
# | Yam | Peelings | 0.2 | 0.8 | 10.61 | i, j |
# | Potatoes | Peelings | 0.75 | 0.8 | 10.61 | i, j |
# | Groundnuts | Shells/husks | 0.477 | 1 | 15.56 | a, i, c |
# | | Straw | 2.3 | 1 | 17.58 | a |
# | Palm oil | Fiber | 0.147 | 1 | 19.94 | a, i |
# | | Shells | 0.049 | 1 | 21.1 | a, i |
# | | Fronds | 2.604 | 1 | 7.97 | i |
# | | Empty bunches | 0.428 | 1 | 19.41 | a, i |
# | | Male bunches | 0.233 | 1 | 14.86 | i, j |
# | Beans(In Pulses)| Straw | 2.5 | 1 | 12.38 | j |
# | Soybean | Straw | 2.66 | 0.8 | 18 | b, f |
# | | Pods | 1 | 0.8 | 18 | a, b, f |
# | Banana | leaves | 0.35 | 1 | 11.37 | g |
# | | stem | 5.6 | 1 | 11.66 | a, j |
# | | peels | 0.25 | 1 | 17 | h, j |
# | Plantain(With Bananas)| leaves| 0.35 | 0.8 | 12.12 | g, i |
# | | stem | 3.91 | 0.8 | 10.9 | g, i |
# | | peels | 0.25 | 1 | 12.56 | a, h |
# | Sugar Cane | baggase | 0.25 | 1 | 6.43 | b, c |
# | | tops/leaves | 0.32 | 0.8 | 15.8 | b, c |
# | Coffee | husk | 1 | 1 | 12.8 | b, c |
# | Cocoa | pods/husks | 1 | 1 | 15.48 | j |
# | Cotton | stalk | 2.1 | 1 | 15.9 | c, i |
# | Barley | straw | 0.75 | 0.15 | 17.5 | k |
# | | stalk | 1.60 | 0.60 | 18.5 | k |
# | Tobacco | stalk | 1.20 | 0.60 | 16.1 | k |
# | Sunflower | stalk | 2.50 | 0.60 | 14.2 | k |
# | Sugarbeet | residue | 0.66 | 0.09 | 20.85 | p,q |
# | Rapeseed | straw | 1.58 | 0.23 | 14.55 | l |
# | Olives | cake | 0.40 | 0.90 | 19.7 | k |
# | Lettuce | waste |1.2 | 0.50 | 12.8 | l |
# | Tomatoes | stem |0.3 | 0.50 | 13.7 | l |
# | Tomatoes | leaves |0.3 | 0.50 | 13.7 | l |
# | Green peppers| residues |0.45 | 0.50 | 12.0 | l |
# | Red Peppers | residues |0.45 | 0.50 | 12.0 | l |
# | Other Cereals| straw | 1.2 | 0.40 | 16.845 | n,o |
# | Rest of Crops| residue | 0 | 0 | 0 | Not found |
# | Fodder Crops | straw | 0.4 | 0 | 0 | p |
# | Tur | stalk | 2.5 | 0.38 |18.58 | m |
# | Lentils | stalk | 1.8 | 0.38 |14.65 | m |
# | Gaur | stalk | 1.0 | 0.38 |16.02 | m |
# | Gram | stalk | 1.1 | 0.38 |16.02 | m |
# | Fruits and Nuts|pruning | 0 | 0 |0 | Not found |
# So for calculating the biomass potential of residues we have the production values data from GAEZ v4 for the years 2000 and 2010 which we will be using. The data in these rasters gives us the production of the particular crop in 1000 tonnes or 1 mln GK\\$. The other unit present in the data is mln GK\\$ which is used by FAO for crop groups like Fodder Crops, Pulses, Vegetables etc.
#
# The documentation of the GAEZ v4 describes the yield as either tonnes/hectare or 1000 GK\\$/hectare. From this, we derive that 1 million GK\\$ = 1000 tonnes.
#
# The following group contains the following crops according the GAEZ v4 Documentation:
# - Fodder Crops: All commodities in FAOSTAT primary crop production domain ranging from forage and silage, maize to vegetables and roots fodders.
# - Pulses: Bambara beans; beans, dry; broad beans, dry; chick peas; cow peas, dry;lentils; peas, dry; pigeon peas; pulses, other
# - Other cereals: Buckwheat; canary seed; fonio; mixed grain; oats; pop corn; quinoa; rye; triticale;
# - Yams and other roots: Taro; yautia; yams; roots and tubers;
# - Other crops: Includes all other crops from FAOSTAT production domain not covered by 25 crop groups above and excluding coir, vegetable tallow, oil of stillinga, oil of citronella, essential oils and rubber, natural.
#
#
# Assumptions made on the basis of GAEZ V4 documentation, from which we are using actual yield data:
# - Stimulants in the GAEZ v4 includes Cocoa Beans, Coffee, Green Tea, Tea. We have till now considered only Cocoa and Coffee.
# - In Yams and other roots, till now we have only included Yams and Coco Yams(Taro)
# - In Vegetables we have taken Green and Red Peppers (Residues), Tomatoes (Stem and Leaves) and Lettuce (Waste) (We will take their mean value for RPR, SAF, and LHV since individual weightage in the crop yield is not available.)
# - In Pulses, we have taken Tur, Gaur, Gram, Beans and Lentils.(We will use their average based on same reason as above).
# - In Other Cereals, we have taken oats and rye.(We will use their average based on same reason as above).
#
#
# ## References for the above data:
# RPR and LHV values given were obtained from already published studies conducted in other countries, such as Ghana, Uganda, Zambia and China.
#
# A source for most of these references was: https://www.aimspress.com/article/doi/10.3934/energy.2023002?viewType=HTML.
# The references are as follows:
# - a. Jekayinfa SO, Scholz V (2009) Potential availability of energetically usable crop residues in Nigeria. Energy Sources, Part A: Recovery, Util, Environ Effects 31: 687–697. https://doi.org/10.1080/15567030701750549 doi: 10.1080/15567030701750549.
# - b. Gabisa EW, Gheewala SH (2018) Potential of bio-energy production in Ethiopia based on available biomass residues. Biomass Bioenergy 111: 77–87. https://doi.org/10.1016/j.biombioe.2018.02.009 doi: 10.1016/j.biombioe.2018.02.009.
# - c. Okello C, Pindozzi S, Faugno S, et al. (2013) Bioenergy potential of agricultural and forest residues in Uganda. Biomass Bioenergy 56: 515–525. https://doi.org/10.1016/j.biombioe.2013.06.003 doi: 10.1016/j.biombioe.2013.06.003.
# - d. Koopmans A, Koppenjan J (1998) The Resource Base. Reg Consult Mod Appl Biomass Energy, 6–10.
# - e. San V, Ly D, Check NI (2013) Assessment of sustainable energy potential on non-plantation biomass resources in Sameakki Meanchey district in Kampong Chhnan pronice, Cambonia. Int J Environ Rural Dev 4: 173–178.
# - f. Yang J, Wang X, Ma H, et al. (2014) Potential usage, vertical value chain and challenge of biomass resource: Evidence from China's crop residues. Appl Energy 114: 717–723. https://doi.org/10.1016/j.apenergy.2013.10.019 doi: 10.1016/j.apenergy.2013.10.019.
# - g. Patiño FGB, Araque JA, Kafarov DV (2016) Assessment of the energy potential of agricultural residues in non-interconnected zones of Colombia: Case study of Chocó and Putumayo katherine Rodríguez cáceres. Chem Eng Trans 50: 349–354. https://doi.org/10.3303/CET1650059 doi: 10.3303/CET1650059.
# - h. Milbrandt A (2011) Assessment of biomass resources in Liberia. Liberia: Dev Resour, 117–166.
# - i.Kemausuor F, Kamp A, Thomsen ST, et al. (2014) Assessment of biomass residue availability and bioenergy yields in Ghana. Resou Conser Recycl 86: 28–37. https://doi.org/10.1016/j.resconrec.2014.01.007 doi: 10.1016/j.resconrec.2014.01.007.
# - j. Mboumboue E, Njomo D (2018) Biomass resources assessment and bioenergy generation for a clean and sustainable development in Cameroon. Biomass Bioenergy 118: 16–23. https://doi.org/10.1016/j.biombioe.2018.08.002 doi: 10.1016/j.biombioe.2018.08.002.
# - k. https://www.researchgate.net/publication/342000532_Agricultural_Residues_Potential_of_Hatay.
# - l. https://www.ncbi.nlm.nih.gov/pmc/articles/PMC9941997/.
# - m. https://www.saarcenergy.org/wp-content/uploads/2020/03/Final-Draft-SEC-report-on-crop-residue_14022020-1540-IM-1.pdf.
# - n. https://www.sciencedirect.com/science/article/pii/S0956053X10002436?via%3Dihub.
# - o. https://www.sciencedirect.com/science/article/pii/S0921344920305280.
# - p. https://www.diva-portal.org/smash/get/diva2:1208954/FULLTEXT01.pdf.
# - q.https://www.researchgate.net/publication/317490809_VALORIZATION_OF_SUGAR_BEET_PULP_RESIDUE_AS_A_SOLID_FUEL_VIA_TORREFACTION
# Now the final table sorted by crop names which will be converted into a pandas data frame for us to use will contain:
# - All the vegetables combined into Vegetables row.
# - Coffee & Cocoa combined under stimulants row.
# - All the pulses as mentioned above will be grouped under pulses row.
#
# <h2><center>Final Crop Table with RPR, SAF and LHV values</center></h2>
#
# | Crop | Residue Type | RPR | SAF | LHV (MJ/kg) |
# |--------------|---------------|-------|-------|-------------|
# | Banana | leaves | 0.35 | 0.9 | 11.745 |
# | Banana | peels | 0.25 | 1 | 14.78 |
# | Banana | stem | 4.90 | 0.9 | 11.66 |
# | Barley | stalk | 1.60 | 0.60 | 18.5 |
# | Barley | straw | 0.75 | 0.15 | 17.5 |
# | Cassava | Peelings | 3 | 0.2 | 10.61 |
# | Cassava | Stalk | 0.062 | 0.407 | 16.99 |
# | Cotton | stalk | 2.1 | 1 | 15.9 |
# | Fodder Crops | straw | 0.4 | 0 | 0 |
# |Fruits and nuts| pruning | 0 | 0 | 0 |
# | Groundnut | Shells/husks | 0.477 | 1 | 15.56 |
# | Groundnut | Straw | 2.3 | 1 | 17.58 |
# | Maize | Cob | 0.273 | 1 | 16.63 |
# | Maize | Husk | 0.2 | 1 | 15.56 |
# | Maize | Stalk | 2 | 0.8 | 16.3 |
# | Millet | Stalk | 1.75 | 0.8 | 15.51 |
# | Millet | Straw | 1.4 | 1 | 13 |
# | Other Cereals| straw | 1.2 | 0.40 | 16.845 |
# | Oil palm | Empty bunches | 0.428 | 1 | 19.41 |
# | Oil palm | Fiber | 0.147 | 1 | 19.94 |
# | Oil palm | Fronds | 2.604 | 1 | 7.97 |
# | Oil palm | Male bunches | 0.233 | 1 | 14.86 |
# | Oil palm | Shells | 0.049 | 1 | 21.1 |
# | Olive | Cake | 0.40 | 0.9 | 19.7 |
# | Potato and Sweet Potato | Peelings | 0.675 |0.8 |10.61|
# | Pulses | stalk | 1.78 | 0.504 |15.53 |
# | Rapeseed | straw | 1.58 | 0.23 | 14.55 |
# | Wetland rice | Husk | 0.23 | 0.83 | 12.9 |
# | Wetland rice | Straw | 1.757 | 0.684 | 8.83 |
# | Sorghum | Husk | 1.4 | 1 | 13 |
# | Sorghum | Straw | 1.25 | 0.8 | 12.38 |
# | Soybean | Pods | 1 | 0.8 | 18 |
# | Soybean | Straw | 2.66 | 0.8 | 18 |
# | Stimulants | husks | 1 | 1 | 14.14 |
# | Sugar Cane | bagasse | 0.25 | 1 | 6.43 |
# | Sugar Cane | tops/leaves | 0.32 | 0.8 | 15.8 |
# | Sugar beet | residue | 0.66 | 0.09 | 20.85 |
# | Sunflower | stalk | 2.50 | 0.60 | 14.2 |
# | Tobacco | stalk | 1.20 | 0.60 | 16.1 |
# | Vegetables | residue | 0.675 | 0.50 | 12.625 |
# | Wheat | Husk | 0.23 | 0.29 | 12.9 |
# | Wheat | Straw | 1.2 | 0.29 | 15.6 |
# | Yam and others| Peelings | 0.2 | 0.8 | 10.61 |
# | Rest of crops| Residue | 0.0 | 0.0 | 0 |
# |
#
# ### REMARK : Incase you have your own RPR , SAF and LHV values for your region, we request you to fork this repository and modify the values accordingly to obtain more region specific results.
# In[4]:
# Now importing the table in pandas format so that we can use it for geospatial analysis
# Defining the table data
data = [
['Banana', 'leaves', 0.35, 0.9, 11.745],
['Banana', 'peels', 0.25, 1, 14.78],
['Banana', 'stem', 4.90, 0.9, 11.66],
['Barley', 'stalk', 1.60, 0.60, 18.5],
['Barley', 'straw', 0.75, 0.15, 17.5],
['Cassava', 'Peelings', 3, 0.2, 10.61],
['Cassava', 'Stalk', 0.062, 0.407, 16.99],
['Cotton', 'stalk', 2.1, 1, 15.9],
['Fodder crops', 'straw', 0.4, 0, 0],
['Fruits and nuts', 'Pruning' , 0, 0, 0],
['Groundnut', 'Shells/husks', 0.477, 1, 15.56],
['Groundnut', 'Straw', 2.3, 1, 17.58],
['Maize', 'Cob', 0.273, 1, 16.63],
['Maize', 'Husk', 0.2, 1, 15.56],
['Maize', 'Stalk', 2, 0.8, 16.3],
['Millet', 'Stalk', 1.75, 0.8, 15.51],
['Millet', 'Straw', 1.4, 1, 13],
['Other cereals', 'straw', 1.2, 0.40, 16.845],
['Oil palm', 'Empty bunches', 0.428, 1, 19.41],
['Oil palm', 'Fiber', 0.147, 1, 19.94],
['Oil palm', 'Fronds', 2.604, 1, 7.97],
['Oil palm', 'Male bunches', 0.233, 1, 14.86],
['Oil palm', 'Shells', 0.049, 1, 21.1],
['Olive' , 'Cake', 0.4, 0.9, 19.7],
['Potato and Sweet Potato', 'Peelings', 0.675, 0.8, 10.61],
['Pulses', 'stalk', 1.78, 0.504, 15.53],
['Rapeseed', 'straw', 1.58, 0.23, 14.55],
['Wetland rice', 'Husk', 0.23, 0.83, 12.9],
['Wetland rice', 'Straw', 1.757, 0.684, 8.83],
['Sorghum', 'Husk', 1.4, 1, 13],
['Sorghum', 'Straw', 1.25, 0.8, 12.38],
['Soybean', 'Pods', 1, 0.8, 18],
['Soybean', 'Straw', 2.66, 0.8, 18],
['Stimulants', 'husks', 1, 1, 14.14],
['Sugarcane', 'baggase', 0.25, 1, 6.43],
['Sugarcane', 'tops/leaves', 0.32, 0.8, 15.8],
['Sugarbeet', 'residue', 0.66, 0.09, 20.85],
['Sunflower', 'stalk', 2.50, 0.60, 14.2],
['Tobacco', 'stalk', 1.20, 0.60, 16.1],
['Vegetables', 'residue', 0.675, 0.50, 12.625],
['Wheat', 'Husk', 0.23, 0.29, 12.9],
['Wheat', 'Straw', 1.2, 0.29, 15.6],
['Yams and other roots', 'Peelings', 0.2, 0.8, 10.61],
['Rest of crops', 'Residue' , 0, 0, 0]
]
# Defining the column names
columns = ['Crop', 'Residue Type', 'RPR', 'SAF', 'LHV (MJ/kg)']
# Create the DataFrame
residue_values = pd.DataFrame(data, columns=columns)
# ### Defining the function for calculating raw biomass energy potential in the past (years 2000 and 2010)
# This function will output an xarray containing all the crops and their corresponding biomass energy potential in each pixel and a final xarray called 'Combined' which gives the sum of all of these.
# In[5]:
# The band dimension comes up in a lot of places and is not needed for our calculations
def remove_band_dimension(array):
if array.ndim == 3:
return array[0]
return array
# In[6]:
def get_lat_lon_from_transform(transform, shape):
ny, nx = shape
lons , lats = transform * np.mgrid[:nx, :ny]
return lats, lons
# In[7]:
def biomass_potential_past(shapefile, time_period, water_supply):
unique_crops_actual = production_values['Crop'].unique()
filtered_production_values = production_values[(production_values['Time Period'] == time_period) &
(production_values['Water Supply'] == water_supply)]
required_production_values = filtered_production_values[['Crop', 'Download URL']]
# For defining size of the array to be used
with rasterio.open(potential_yield.iloc[2, 14].strip()) as src:
clipped_shapefile_init, transform_init = mask(src, shapefile.geometry, crop=True)
clipped_shapefile_init = remove_band_dimension(clipped_shapefile_init)
lats_init, lons_init = get_lat_lon_from_transform(transform_init, clipped_shapefile_init.shape)
# Create xarray Dataset to store individual biomass potentials for each crop
individual_biomass_potentials = {}
# Variable to hold the net sum of all crops and their residues
net_sum = 0.0
# Initialize 'net_biomass_potential_array' before the loop
net_biomass_potential_array = xr.DataArray(data=np.zeros_like(clipped_shapefile_init, dtype='float32'),
dims=('y', 'x'),
coords={'y': range(clipped_shapefile_init.shape[0]), 'x': range(clipped_shapefile_init.shape[1]),
'latitude': (('x', 'y'), lats_init), 'longitude': (('x', 'y'), lons_init)},
attrs={'units': 'PetaJoules',
'sum production': 0.0}) # Add initial sum as an attribute
for crop in unique_crops_actual:
required_url = required_production_values[required_production_values['Crop'] == crop]['Download URL'].values[0].strip()
with rasterio.open(required_url) as src:
crs_crop = src.crs
clipped_shapefile, clipped_transform = mask(src, shapefile.geometry, crop=True)
clipped_shapefile = remove_band_dimension(clipped_shapefile)
sum_value_shapefile = np.nansum(clipped_shapefile)
# Get the residues for the current crop
residue_rows = residue_values.loc[residue_values['Crop'] == crop]
# Calculate the sum of residues for the current crop
crop_residue_sum = 0.0
crop_residue_shapefile= np.zeros_like(clipped_shapefile)
for _, residue_row in residue_rows.iterrows():
LHV = residue_row['LHV (MJ/kg)']
SAF = residue_row['SAF']
RPR = residue_row['RPR']
crop_residue_sum += sum_value_shapefile * LHV * SAF * RPR # Unit conversion for MJ to J and
# 1000 tonnes to kilograms ; Then multiplying by 10**-12 for PetaJoules
crop_residue_shapefile += clipped_shapefile * LHV * SAF * RPR
# Calculate the net sum for all crops and their residues
net_sum += crop_residue_sum
# Create xarray DataArray to store individual biomass potential for the current crop
crop_biomass_potential_array = xr.DataArray(data=crop_residue_shapefile,
dims=('y', 'x'),
coords={'y': range(clipped_shapefile_init.shape[0]), 'x': range(clipped_shapefile_init.shape[1]),
'latitude': (('x', 'y'), lats_init), 'longitude': (('x', 'y'), lons_init)},
attrs={'units': 'PetaJoules',
'sum_production': crop_residue_sum}) # Add sum as an attribute
# Sum the individual biomass potential with the net biomass potential
net_biomass_potential_array += crop_biomass_potential_array
# Store the individual biomass potential for the current crop in the dictionary
individual_biomass_potentials[crop] = crop_biomass_potential_array
# Create xarray Dataset to hold all the individual biomass potentials for each crop
biomass_potentials_dataset = xr.Dataset(individual_biomass_potentials)
# Add the net sum of all crops and their residues as an attribute to the Dataset
biomass_potentials_dataset.attrs['Net Potential in PetaJ'] = net_sum
# Add the net_biomass_potential_array as a new variable named 'combined' to the biomass_potentials_dataset
biomass_potentials_dataset['Combined'] = net_biomass_potential_array
biomass_potentials_dataset['Combined'].attrs['sum_production'] = net_sum
return biomass_potentials_dataset
# #### Additional functions:
# - The following functions help estimate the final numbers for the raw biomass energy potential for a region. It has two options.
# - Consolidated crop agnostic estimate
# - Crop-specific estimate
# In[8]:
def get_actual_data_biomass_potential_all(shapefile, time_period, water_supply):
value = biomass_potential_past(shapefile, time_period, water_supply)
answer = value.attrs['net_sum']
return answer
def get_actual_data_biomass_potential_crop(shapefile, time_period, water_supply, crop):
value = biomass_potential_past(shapefile, time_period, water_supply)
answer = value[crop].attrs['sum_production']
return answer
# So the above functions and code finishes our task of getting the Raw Biomass Energy Potential from the Cropland in the past. Next we will see the functions for calculating the Raw Biomass Energy Potential from the Cropland in the future.
# ## II. Raw Biomass Energy Potential from Agricultural Residues using Actual Yields and Production for Harvested Area and Agro-Climatic Potential Yield for future yields [GAEZ-V4 Theme 5 and 3 respectively]
#
# Theme 3 provides crop-wise information about: (1) Agro-Climatic Yield, (2) Constraint Factors, (3) Growth Cycle Attributes, and (4) Land Utilization Types (LUT) Selection.
#
# Theme 5 spatial layers include mapped distributions of harvested area, yield and production at 5 arc-minute resolution for 26 major crops/crop groups, separately in rain-fed and irrigated cropland. Country totals are based on FAO statistics for the years 2009-2011. Also included are estimates of the spatial distribution of total crop production value and the production values of major crop groups (cereals, root crops, oil crops), all valued at year 2000 international prices, separately for rain-fed and irrigated cropland.
# Now since the future cropland data area data is not available to us we will be making an assumption. The assumption is that in the future the area under cropland which is required for us to ensure food security will remain the same as is was in the year 2010. So the harvest area data that we had from actual yields and production will serve as the cropland area for all future calculations. But since, with time the yield will vary and so will the residue from each crop.
#
# Assuming that RPR, SAF and LHV values also remain same for the crops in the future we will get the harvested area from the 2010 data for any shapefile and then multiply it with the future yield to get the future production. This will further be multiplied by RPR, SAF and LHV giving us raw biomass energy potential from cropland in the future. These values can then be compared with the past values calculated in part I to give us an idea as to how different future conditions affect the energy poential of the cropland.
# In[9]:
def future_potential_cropland(time_period, climate_model, rcp, water_supply_future, input_level, shapefile_path, water_supply_2010):
merged_df = pd.merge(harvested_area, potential_yield, on='Crop', how='inner')
unique_crops = merged_df['Crop'].unique()
filtered_harvested_area = harvested_area[(harvested_area['Time Period'] == 2010) &
(harvested_area['Water Supply'] == water_supply_2010)]
required_harvested_area = filtered_harvested_area[['Crop', 'Download URL']]
filtered_potential_yield = potential_yield[(potential_yield['Time Period'] == time_period) &
(potential_yield['Climate Model'] == climate_model) &
(potential_yield['RCP'] == rcp) &
(potential_yield['Water Supply'] == water_supply_future) &
(potential_yield['Input Level'] == input_level)]
required_potential_yields = filtered_potential_yield[['Crop', 'Download URL']]
# For defining size of the xarray
with rasterio.open(potential_yield.iloc[2, 14].strip()) as src:
clipped_shapefile_init, transform_init = mask(src, shapefile_path.geometry, crop=True)
clipped_shapefile_init = remove_band_dimension(clipped_shapefile_init)
lats_init, lons_init = get_lat_lon_from_transform(transform_init, clipped_shapefile_init.shape)
# Create xarray DataArray to store the net biomass potential for each pixel
net_biomass_potential_array = xr.DataArray(data=0.0,
dims=('y', 'x'),
coords={'y': range(clipped_shapefile_init.shape[0]), 'x': range(clipped_shapefile_init.shape[1]),
'latitude': (('x', 'y'), lats_init), 'longitude': (('x', 'y'), lons_init)},
attrs={'units': 'PetaJoules'})
# Create xarray Dataset to store individual biomass potentials for each crop
individual_biomass_potentials = {}
# Variable to store the net sum of sum products
net_sum = 0.0
net_multiple = 0
for crop in unique_crops:
harvested_raster_url = required_harvested_area[required_harvested_area['Crop'] == crop]['Download URL'].values[0].strip()
potential_yield_raster_url = required_potential_yields[required_potential_yields['Crop'] == crop]['Download URL'].values[0].strip()
with rasterio.open(harvested_raster_url) as src:
clipped, _ = mask(src, shapefile_path.geometry, crop=True)
with rasterio.open(potential_yield_raster_url.strip()) as src:
clipped_2, _ = mask(src, shapefile_path.geometry, crop=True)
clipped_1 = np.nan_to_num(clipped)
clipped_3 = np.nan_to_num(clipped_2)
# Remove the 'bands' dimension if it exists (since it's not needed)
clipped_1 = remove_band_dimension(clipped_1)
clipped_3 = remove_band_dimension(clipped_3)
product = np.multiply(clipped_1, clipped_3)
sum_product = np.nansum(product)
# Extract RPR, SAF, and LHV values for the crop
residue_rows = residue_values[residue_values['Crop'] == crop]
temp_sum = 0
net_product_array = np.zeros_like(product)
for _, residue_row in residue_rows.iterrows():
LHV = residue_row['LHV (MJ/kg)']
SAF = residue_row['SAF']
RPR = residue_row['RPR']
# Multiply the sum_product with RPR, SAF, and LHV
result = sum_product * RPR * SAF * LHV * (10 ** -3) # Unit conversion factor to PetaJoules
temp_sum += result
product_array = product * RPR * SAF * LHV * (10 ** -3)
net_product_array += product_array
net_sum += temp_sum
# Create xarray DataArray to store individual biomass potential for the current crop
crop_biomass_potential_array = xr.DataArray(data= net_product_array,
dims=('y', 'x'),
coords={'y': range(clipped_shapefile_init.shape[0]), 'x': range(clipped_shapefile_init.shape[1]),
'latitude': (('x', 'y'), lats_init), 'longitude': (('x', 'y'), lons_init)},
attrs={'units': 'PetaJoules',
'sum_production': temp_sum}) # Add sum as an attribute
# Sum the individual biomass potential with the net biomass potential
net_biomass_potential_array += crop_biomass_potential_array
# Store the individual biomass potential for the current crop in the dictionary
individual_biomass_potentials[crop] = crop_biomass_potential_array
# Create xarray Dataset to hold all the individual biomass potentials for each crop
biomass_potentials_dataset = xr.Dataset(individual_biomass_potentials)
# Add the net sum of all crops and their residues as an attribute to the Dataset
biomass_potentials_dataset.attrs['net_sum in PJ'] = net_sum
# Add the net_biomass_potential_array as a new variable named 'combined' to the biomass_potentials_dataset
biomass_potentials_dataset['Combined'] = net_biomass_potential_array
biomass_potentials_dataset['Combined'].attrs['sum_production'] = net_sum
return biomass_potentials_dataset
# #### Additional functions:
# The following functions are available if you just need the final numbers for the biomass energy potential for the
# region. It has two options either it can give you the net or it can give you the values for a specific crop as well.
# In[10]:
# Function doing as described above
def future_residues_all(time_period, climate_model, rcp, water_supply_future, input_level, shapefile_path, water_supply_2010):
value = future_potential_cropland(time_period, climate_model, rcp, water_supply_future, input_level, shapefile_path, water_supply_2010)
answer = value.attrs['net_sum']
return answer
# In[11]:
# We also wanted to create a function that does this for a single crop as well.
def future_residues_crop(crop, time_period, climate_model, rcp, water_supply_future, input_level, shapefile_path, water_supply_2010):
value = future_potential_cropland(time_period, climate_model, rcp, water_supply_future, input_level, shapefile_path, water_supply_2010)
answer = value[crop].attrs['sum_production']
return answer
# So this completes all cropland residue calculations for us. Next we will move to residue and biomass energy potential from the marginal land but before we get into this we will have to generate the marginal land. So we need to extract certain pixels from certain rasters which will be masked later to account for removal of deserts, water, glaciers etc. as described in the paper
# ## III. Raw Biomass Energy Potential from Agricultural Residues using Agro-Climatic Potential Yield for future yields data [GAEZ- V4 Theme: 3]
#
# Theme 3 provides crop-wise information about: (1) Agro-Climatic Yield, (2) Constraint Factors, (3) Growth Cycle Attributes, and (4) Land Utilization Types (LUT) Selection.
# Before moving on to describe the functions, we need to obtain the RPR, SAF and LHV values for the crops available in the potential yield theme in GAEZ. The following is the table followed by the assumptions made and references:
# <h2><center>Final Potential Yield Crop Table with RPR, SAF and LHV values</center></h2>
#
# | Crop | Residue Type | RPR | SAF | LHV (MJ/kg) |
# |:----------------------:|:-----------------:|:-------:|:-------:|:-------------:|
# | Alfalfa | residue | 0.25 | 0.0 | 0.0 |
# | Banana | leaves | 0.35 | 0.9 | 11.745 |
# | Banana | peels | 0.25 | 1 | 14.78 |
# | Banana | stem | 4.90 | 0.9 | 11.66 |
# | Barley | stalk | 1.60 | 0.60 | 18.5 |
# | Barley | straw | 0.75 | 0.15 | 17.5 |
# | Biomass highland sorghum |Husk | 1.4 | 1 | 13 |
# | Biomass highland sorghum | Straw | 1.25 | 0.8 | 12.38 |
# | Biomass lowland sorghum |Husk | 1.4 | 1 | 13 |
# |Biomass lowland sorghum | Straw | 1.25 | 0.8 | 12.38 |
# | Biomass sorghum |Husk | 1.4 | 1 | 13 |
# |Biomass sorghum | Straw | 1.25 | 0.8 | 12.38 |
# | Biomass temperate sorghum | Husk | 1.4 | 1 | 13 |
# | Biomass temperate sorghum | Straw | 1.25 | 0.8 | 12.38 |
# | Buckwheat | straw | 1.2 | 0.40 | 16.845 |
# | Cabbage | residue | 0.675 | 0.50 | 12.625 |
# | Carrot | residue | 0.675 | 0.50 | 12.625 |
# | Cassava | Peelings | 3 | 0.2 | 10.61 |
# | Cassava | Stalk | 0.062 | 0.407 | 16.99 |
# | Chickpea | stalk | 1.78 | 0.504 |15.53 |
# | Citrus | pruning | 0.29 | 0.8 | 17.85 |
# | Cocoa | pods/husks | 1 | 1 | 15.48 |
# | Cocoa cumoun | pods/husks | 1 | 1 | 15.48 |
# | Cocoa hybrid | pods/husks | 1 | 1 | 15.48 |
# | Coconut | Husk | 1.03 | 1 | 18.6 |
# | Coconut | Coir dust | 0.62 | 1 | 13.4 |
# | Cocoyam | Peelings | 0.2 | 0.8 | 10.61 |
# | Coffee | husk | 1 | 1 | 12.8 |
# | Coffee arabica |husk | 1 | 1 | 12.8 |
# | Coffee robusta |husk | 1 | 1 | 12.8 |
# | Cotton | stalk | 2.1 | 1 | 15.9 |
# | Cowpea | stalk | 1.78 | 0.504 |15.53 |
# | Dry pea |stalk | 1.78 | 0.504 |15.53 |
# | Dryland rice | Husk | 0.23 | 0.83 | 12.9 |
# | Dryland rice | Straw | 1.757 | 0.684 | 8.83 |
# | Flax | stalk | 2.50 | 0.60 | 14.2 |
# | Foxtail millet | Stalk | 1.75 | 0.8 | 15.51 |
# | Foxtail millet | Straw | 1.4 | 1 | 13 |
# | Gram |stalk | 1.1 | 0.38 |16.02 |
# | Grass | straw | 0.4 | 0 | 0 |
# | Greater yam |Peelings | 0.2 | 0.8 | 10.61 |
# | Groundnut | Shells/husks | 0.477 | 1 | 15.56 |
# | Groundnut | Straw | 2.3 | 1 | 17.58 |
# | Highland maize | Cob | 0.273 | 1 | 16.63 |
# | Highland maize | Husk | 0.2 | 1 | 15.56|
# | Highland maize | Stalk | 2 | 0.8 | 16.3 |
# | Highland sorghum | Husk | 1.4 | 1 | 13 |
# |Highland sorghum | Straw | 1.25 | 0.8 | 12.38 |
# | Jatropha | Woody Biomass | 0.25 | 0.8 | 15.5 |
# | Jatropha | Leaves | 0.25 | 0.8 | 12 |
# | Jatropha | Pericarp | 0.20 | 0.8 | 10 |
# | Jatropha | Tegument | 0 | 10.8 | 16.9 |
# | Jatropha | Endosperm Cake | 0.2 | 0.8 | 13.6 |
# | Lowland maize | Cob | 0.273 | 1 | 16.63 |
# | Lowland maize | Husk | 0.2 | 1 | 15.56 |
# | Lowland maize | Stalk | 2 | 0.8 | 16.3 |
# | Lowland sorghum |Husk | 1.4 | 1 | 13 |
# |Lowland sorghum | Straw | 1.25 | 0.8 | 12.38 |
# | Maize | Cob | 0.273 | 1 | 16.63 |
# | Maize | Husk | 0.2 | 1 | 15.56 |
# | Maize | Stalk | 2 | 0.8 | 16.3 |
# | Millet | Stalk | 1.75 | 0.8 | 15.51 |
# | Millet | Straw | 1.4 | 1 | 13 |
# | Miscanthus | residue | 0.42 | 1 | 17.44 |
# | Napier grass | straw | 0.4 | 0 | 0 |
# | Oat | straw | 1.15 | 0.40 | 18.45|
# | Oil palm | Empty bunches | 0.428 | 1 | 19.41 |
# | Oil palm | Fiber | 0.147 | 1 | 19.94 |
# | Oil palm | Fronds | 2.604 | 1 | 7.97 |
# | Oil palm | Male bunches | 0.233 | 1 | 14.86 |
# | Oil palm | Shells | 0.049 | 1 | 21.1 |
# | Olive | cake | 0.40 | 0.90 | 19.7 |
# | Onion | residue | 0.675 | 0.50 | 12.625 |
# | Para rubber | residue | 0 | 0 | 0 |
# | Pasture legumes | stalk | 1.78 | 0.504 |15.53 |
# | Pearl millet | Stalk | 1.75 | 0.8 | 15.51 |
# | Pearl millet | Straw | 1.4 | 1 | 13 |
# | Phaseolus bean |stalk | 1.78 | 0.504 |15.53 |
# | Pigeonpea |stalk | 1.78 | 0.504 |15.53 |
# | Rapeseed | straw | 1.58 | 0.23 | 14.55 |
# | Reed canary grass | straw | 0.4 | 0 | 0 |
# | Rye | straw| 1.25| 0.40 | 15.24|
# | Silage maize | Cob | 0.273 | 1 | 16.63 |
# | Silage maize | Husk | 0.2 | 1 | 15.56 |
# | Silage maize | Stalk | 2 | 0.8 | 16.3 |
# | Sorghum | Husk | 1.4 | 1 | 13 |
# | Sorghum | Straw | 1.25 | 0.8 | 12.38 |
# | Soybean | Pods | 1 | 0.8 | 18 |
# | Soybean | Straw | 2.66 | 0.8 | 18 |
# | Spring barley | stalk | 1.60 | 0.60 | 18.5 |
# | Spring barley | straw | 0.75 | 0.15 | 17.5 |
# | Spring rye | straw| 1.25| 0.40 | 15.24|
# | Spring wheat | Husk | 0.23 | 0.29 | 12.9 |
# | Spring wheat | Straw | 1.2 | 0.29 | 15.6 |
# | Sugarbeet | residue | 0.66 | 0.09 | 0 |
# | Sugar Cane | baggase | 0.25 | 1 | 6.43 |
# | Sugar Cane | tops/leaves | 0.32 | 0.8 | 15.8 |
# | Sunflower | stalk | 2.50 | 0.60 | 14.2 |
# | Sweet potato | Peelings | 0.6 | 0.8 | 10.61 |
# | Switchgrass | straw | 0.4 | 0 | 0 |
# | Tea | husks | 1 | 1 | 14.14 |
# | Temperate maize | Cob | 0.273 | 1 | 16.63 |
# | Temperate maize | Husk | 0.2 | 1 | 15.56 |
# | Temperate maize | Stalk | 2 | 0.8 | 16.3 |
# | Temperate sorghum |Husk | 1.4 | 1 | 13 |
# | Temperate sorghum | Straw | 1.25 | 0.8 | 12.38 |
# | Tobacco | stalk | 1.20 | 0.60 | 16.1 |
# | Tomato | stem |0.3 | 0.50 | 13.7 | l |
# | Tomato | leaves |0.3 | 0.50 | 13.7 | l |
# | Wetland rice | Husk | 0.23 | 0.83 | 12.9 |
# | Wetland rice | Straw | 1.757 | 0.684 | 8.83 |
# | Wheat | Husk | 0.23 | 0.29 | 12.9 |
# | Wheat | Straw | 1.2 | 0.29 | 15.6 |
# | White potato | Peelings | 0.75 | 0.8 | 10.61 |
# | White yam | Peelings | 0.2 | 0.8 | 10.61 |
# | Winter barley | stalk | 1.60 | 0.60 | 18.5 |
# | Winter barley | straw | 0.75 | 0.15 | 17.5 |
# | Winter rye | straw| 1.25| 0.40 | 15.24|
# | Winter wheat | Husk | 0.23 | 0.29 | 12.9 |
# | Winter wheat | Straw | 1.2 | 0.29 | 15.6 |
# | Yam |Peelings | 0.2 | 0.8 | 10.61 |
# | Yellow yam | Peelings | 0.2 | 0.8 | 10.61 |
#
# Since some extra crops have been added to this table in comparison to the previous table here are the references and few assumptions that have been made in order to make this table complete:
#
# For a few of the crops I have assigned them value based on the following assumptions:
#
# - Biomass highland sorghum, Biomass lowland sorghum, Biomass temperate sorghum, Highland sorghum, Lowland sorghum, Temperate sorghum will all be assigned just the sorghum value.
# - Buckwheat will take the value of other cereals
# - Onion, Cabbage, Carrot will take the value for vegetables
# - Cocoa, Cocoa cumoun, Cocoa hybrid will take the value of Cocoa.
# - Coffee, Coffee arabica, Coffee robusta will take the value of Coffee.
# - Dryland Rice will take the value of Rice/Wetland Rice.
# - Pearl millet, Foxtail millet, Millet will take the value of Millet.
# - Greater yam, White yam, Yam, Yellow yam will all be assigned the value of Yam.
# - Highland maize, Lowland maize, Silage maize, Temperate maize and Maize will be assigned the value of Maize.
# - Spring barley, Winter barley will take the value of Barley
# - Spring rye, Winter rye will take the value of rye
# - Spring wheat, Winter wheat will take the value of wheat
# - White potato will take the value of Potato
# - Tea will take the value of stimulants.
# - ChickPea, Cowpea, Dry Pea, Pasture Legumes, Phaseolus bean, Pigeonpea will take the value of pulses.
# - Alfalfa, Grass, Napier grass, Para, Rubber, Reed canary grass will take the value of fodder crops.(Alfalfa takes green fodder values which will have different RPR(0.25) but SAF will be 0.)
# - Flax, being similar to sunflower, takes the values of sunflower since they belong to similar crop category.
# - Citrus here includes the average of Oranges and Lemons
#
# For the crops included above and not in the previous table here are the references:
#
# - Coconut : Reference: https://www.aimspress.com/article/doi/10.3934/energy.2023002?viewType=HTML
# - Citrus : Reference:https://www.ncbi.nlm.nih.gov/pmc/articles/PMC9941997/
# - Jatropha : Reference : doi: 10.1016/j.rser.2015.10.009.
# - Miscanthus RPR/SAF & LHV: https://www.sciencedirect.com/science/article/pii/S1161030101001022. & https://www.researchgate.net/publication/338950136_Calorific_values_of_Miscanthus_x_giganteus_biomass_cultivated_under_suboptimal_conditions_in_marginal_soils
# - Para Rubber : None
# In[12]:
# The final crop data being added to a pandas dataframe:
data = [
['Alfalfa', 'residue', 0.25, 0.0, 0.0],
['Banana', 'leaves', 0.35, 0.9, 11.745],
['Banana', 'peels', 0.25, 1, 14.78],
['Banana', 'stem', 4.90, 0.9, 11.66],
['Barley', 'stalk', 1.60, 0.60, 18.5],
['Barley', 'straw', 0.75, 0.15, 17.5],
['Biomass highland sorghum', 'Husk', 1.4, 1, 13],
['Biomass highland sorghum', 'Straw', 1.25, 0.8, 12.38],
['Biomass lowland sorghum', 'Husk', 1.4, 1, 13],
['Biomass lowland sorghum', 'Straw', 1.25, 0.8, 12.38],
['Biomass sorghum', 'Husk', 1.4, 1, 13],
['Biomass sorghum', 'Straw', 1.25, 0.8, 12.38],
['Biomass temperate sorghum', 'Husk', 1.4, 1, 13],
['Biomass temperate sorghum', 'Straw', 1.25, 0.8, 12.38],
['Buckwheat', 'straw', 1.2, 0.40, 16.845],
['Cabbage', 'residue', 0.675, 0.50, 12.625],
['Carrot', 'residue', 0.675, 0.50, 12.625],
['Cassava', 'Peelings', 3, 0.2, 10.61],
['Cassava', 'Stalk', 0.062, 0.407, 16.99],
['Chickpea', 'stalk', 1.78, 0.504, 15.53],
['Citrus', 'prunings', 0.29 , 0.80 , 17.85],
['Cocoa', 'pods/husks', 1, 1, 15.48],
['Cocoa cumoun', 'pods/husks', 1, 1, 15.48],
['Cocoa hybrid', 'pods/husks', 1, 1, 15.48],
['Coconut', 'husk', 1.03, 1, 18.6],
['Coconut','coir dust', 0.62, 1, 13.4],
['Cocoyam', 'Peelings', 0.2, 0.8, 10.61],
['Coffee', 'husk', 1, 1, 12.8],
['Coffee arabica', 'husk', 1, 1, 12.8],
['Coffee robusta', 'husk', 1, 1, 12.8],
['Cotton', 'stalk', 2.1, 1, 15.9],
['Cowpea', 'stalk', 1.78, 0.504, 15.53],
['Dry pea', 'stalk', 1.78, 0.504, 15.53],
['Dryland rice', 'Husk', 0.23, 0.83, 12.9],
['Dryland rice', 'Straw', 1.757, 0.684, 8.83],
['Flax', 'stalk', 2.5, 0.6, 14.2],
['Foxtail millet', 'Stalk', 1.75, 0.8, 15.51],
['Foxtail millet', 'Straw', 1.4, 1, 13],
['Gram', 'stalk', 1.1, 0.38, 16.02],
['Grass', 'straw', 0.4, 0, 0],
['Greater yam', 'Peelings', 0.2, 0.8, 10.61],
['Groundnut', 'Shells/husks', 0.477, 1, 15.56],
['Groundnut', 'Straw', 2.3, 1, 17.58],
['Highland maize', 'Cob', 0.273, 1, 16.63],
['Highland maize', 'Husk', 0.2, 1, 15.56],
['Highland maize', 'Stalk', 2, 0.8, 16.3],
['Highland sorghum', 'Husk', 1.4, 1, 13],
['Highland sorghum', 'Straw', 1.25, 0.8, 12.38],
['Jatropha', 'Woody Biomass', 0.25, 0.8, 15.5],
['Jatropha', 'Leaves', 0.25, 0.8, 12],
['Jatropha', 'Pericarp', 0.20, 0.8, 10],
['Jatropha', 'Tegument', 0, 10.8, 16.9],
['Jatropha', 'Endosperm Cake', 0.2, 0.8, 13.6],
['Lowland maize', 'Cob', 0.273, 1, 16.63],
['Lowland maize', 'Husk', 0.2, 1, 15.56],
['Lowland maize', 'Stalk', 2, 0.8, 16.3],
['Lowland sorghum', 'Husk', 1.4, 1, 13],
['Lowland sorghum', 'Straw', 1.25, 0.8, 12.38],
['Maize', 'Cob', 0.273, 1, 16.63],
['Maize', 'Husk', 0.2, 1, 15.56],
['Maize', 'Stalk', 2, 0.8, 16.3],
['Millet', 'Stalk', 1.75, 0.8, 15.51],
['Millet', 'Straw', 1.4, 1, 13],
['Miscanthus', 'residue', 0.42, 1, 17.44],
['Napier grass', 'straw', 0.4, 0, 0],
['Oat', 'straw', 1.15, 0.4, 18.45],
['Oil palm', 'Empty bunches', 0.428, 1, 19.41],
['Oil palm', 'Fiber', 0.147, 1, 19.94],
['Oil palm', 'Fronds', 2.604, 1, 7.97],
['Oil palm', 'Male bunches', 0.233, 1, 14.86],
['Oil palm', 'Shells', 0.049, 1, 21.1],
['Olive', 'cake', 0.4, 0.9, 19.7],
['Onion', 'residue', 0.675, 0.5, 12.625],
['Para rubber', 'residue', 0, 0, 0],
['Pasture legumes', 'stalk', 0, 0, 0],
['Pearl millet', 'Stalk', 1.75, 0.8, 15.51],
['Pearl millet', 'Straw', 1.4, 1, 13],
['Phaseolus bean', 'stalk', 1.78, 0.504, 15.53],
['Pigeonpea', 'stalk', 1.78, 0.504, 15.53],
['Rapeseed', 'straw', 1.58, 0.23, 14.55],
['Reed canary grass', 'straw', 0.4, 0, 0],
['Rye', 'straw', 1.25, 0.4, 15.24],
['Silage maize', 'Cob', 0.273, 1, 16.63],
['Silage maize', 'Husk', 0.2, 1, 15.56],
['Silage maize', 'Stalk', 2, 0.8, 16.3],
['Sorghum', 'Husk', 1.4, 1, 13],
['Sorghum', 'Straw', 1.25, 0.8, 12.38],
['Soybean', 'Pods', 1, 0.8, 18],
['Soybean', 'Straw', 2.66, 0.8, 18],
['Spring barley', 'stalk', 1.6, 0.6, 18.5],
['Spring barley', 'straw', 0.75, 0.15, 17.5],
['Spring rye', 'straw', 1.25, 0.4, 15.24],
['Spring wheat', 'Husk', 0.23, 0.29, 12.9],
['Spring wheat', 'Straw', 1.2, 0.29, 15.6],
['Sugarbeet', 'residue', 0.66, 0.09, 0],
['Sugar Cane', 'baggase', 0.25, 1, 6.43],
['Sugar Cane', 'tops/leaves', 0.32, 0.8, 15.8],
['Sunflower', 'stalk', 2.5, 0.6, 14.2],
['Sweet potato', 'Peelings', 0.6, 0.8, 10.61],
['Switchgrass', 'straw', 0.4, 0, 0],
['Tea', 'husks', 1, 1, 14.14],
['Temperate maize', 'Cob', 0.273, 1, 16.63],
['Temperate maize', 'Husk', 0.2, 1, 15.56],
['Temperate maize', 'Stalk', 2, 0.8, 16.3],
['Temperate sorghum', 'Husk', 1.4, 1, 13],
['Temperate sorghum', 'Straw', 1.25, 0.8, 12.38],
['Tobacco', 'stalk', 1.2, 0.6, 16.1],
['Tomato', 'stem', 0.3, 0.5, 13.7],
['Tomato', 'leaves', 0.3, 0.5, 13.7],
['Wetland rice', 'Husk', 0.23, 0.83, 12.9],
['Wetland rice', 'Straw', 1.757, 0.684, 8.83],
['Wheat', 'Husk', 0.23, 0.29, 12.9],
['Wheat', 'Straw', 1.2, 0.29, 15.6],
['White potato', 'Peelings', 0.75, 0.8, 10.61],
['White yam', 'Peelings', 0.2, 0.8, 10.61],
['Winter barley', 'stalk', 1.6, 0.6, 18.5],
['Winter barley', 'straw', 0.75, 0.15, 17.5],
['Winter rye', 'straw', 1.25, 0.4, 15.24],
['Winter wheat', 'Husk', 0.23, 0.29, 12.9],
['Winter wheat', 'Straw', 1.2, 0.29, 15.6],
['Yam', 'Peelings', 0.2, 0.8, 10.61],
['Yellow yam', 'Peelings', 0.2, 0.8, 10.61]
]
# Defining the column names
columns = ['Crop', 'Residue Type', 'RPR', 'SAF', 'LHV (MJ/kg)']
# Create the DataFrame
all_residue_values = pd.DataFrame(data, columns=columns)
# ### Helper function for clipping a raster according to the selected region
# In[13]:
def maskingwithshapefile(shapefile, raster_path):
with rasterio.open(raster_path) as src:
crs= src.crs
shapefile.crs=crs
clipped, transform = mask(src, shapefile.geometry, crop=True )
# This returns a numpy array on which we will conduct operations.
return clipped
# ### Helper functions for converting numpy arrays to raster format again to give us a clipped raster ( We have used the memory file data type in rasterio which allows us to create rasters in the active memory without the need to download these to the computer)
# In[14]:
# For clipped arrays :
# The clipped one has extra parameters which ensure that the clipped raster has the correct latitudes and
# longitudes acc. to the chosen CRS. This will be mostly useful when we will try to extract rasters with the
# correct longitude and latitude values.
# Create a function to convert a NumPy array to an in-memory raster
def array_to_inmemory_raster_for_clipped(array, transform, crs, shapefile):
if len(array.shape) == 2:
array = array.reshape((1, array.shape[0], array.shape[1])) # Add a singleton dimension
_, height, width = array.shape # Extract the height and width from the shape
# Reshape the array to 2 dimensions
array = array[0] # Extract the first dimension to remove the extra dimension
# Correcting the transform for correct axes value representation
shapefile.geometry.iloc[0]
xmin = shapefile.bounds.iloc[0,3]
ymax = shapefile.bounds.iloc[0,0]
topleft_corner = (xmin,ymax)
a = transform.a
b = transform.b
d = transform.d
e = transform.e
transform = Affine(a, b, ymax, d, e, xmin)
# Update the transform with corrected values to make sure only the region of shapefile is represented
transform = Affine(transform.a, transform.b, ymax, transform.d, transform.e, xmin)
# Define the raster metadata
meta = {
'count': 1,
'dtype': array.dtype,
'width': width,
'height': height,
'crs': crs,
'transform': transform
}
# Create an in-memory raster file
memory_file = rasterio.MemoryFile()
with memory_file.open(driver='GTiff', **meta) as dst:
dst.write(array, 1)
return memory_file
# In[15]:
# For Non-Clipped :
# This function might not be as used like the above one and will mostly be used only when converting the full