diff --git a/.gitignore b/.gitignore index 3016cdb9..f180cb16 100644 --- a/.gitignore +++ b/.gitignore @@ -99,3 +99,6 @@ model_output/ flux_model_log*txt +/analyses/ESSD_figures/ipcc_flux_bar_chart.py + +docker-compose.yaml diff --git a/constants_and_names.py b/constants_and_names.py index 03d0cad2..c6205327 100644 --- a/constants_and_names.py +++ b/constants_and_names.py @@ -8,7 +8,7 @@ ######## ######## # Model version -version = '1.3.2' +version = '1.4.0' version_filename = version.replace('.', '_') @@ -332,10 +332,11 @@ plant_pre_2000_processed_dir = os.path.join(s3_base_dir, 'other_emissions_inputs/IDN_MYS_plantation_pre_2000/processed/20200724/') # Drivers of tree cover loss -drivers_raw_dir = os.path.join(s3_base_dir, 'other_emissions_inputs/tree_cover_loss_drivers/raw/') -pattern_drivers_raw = 'Goode_FinalClassification_2023_wgs84_v20240402.tif' -pattern_drivers = 'tree_cover_loss_driver_processed' -drivers_processed_dir = os.path.join(s3_base_dir, 'other_emissions_inputs/tree_cover_loss_drivers/processed/drivers_2023/20240402/') + +drivers_raw_dir = 's3://gfw2-data/drivers_of_loss/1_km/raw/20241121/' +pattern_drivers_raw = 'drivers_of_TCL_1_km_20241121.tif' +pattern_drivers = 'drivers_of_TCL_1_km_20241121' +drivers_processed_dir = 's3://gfw2-data/drivers_of_loss/1_km/processed/20241121/' # Tree cover loss from fires TCLF_raw_dir = 's3://gfw2-data/forest_change/hansen_2023_fire/' @@ -646,26 +647,12 @@ ### Emissions from biomass and soil (all carbon emitted_pools) # Date to include in the output directory -emis_run_date_biomass_soil = '20240402' - -# pattern_gross_emis_commod_biomass_soil = f'gross_emis_commodity_Mg_CO2e_ha_biomass_soil_2001_{loss_years}' -pattern_gross_emis_commod_biomass_soil = f'gross_emis_commodity_Mg_CO2e_ha_biomass_soil_2001_{loss_years}' -gross_emis_commod_biomass_soil_dir = f'{s3_base_dir}gross_emissions/commodities/biomass_soil/standard/{emis_run_date_biomass_soil}/' - -pattern_gross_emis_forestry_biomass_soil = f'gross_emis_forestry_Mg_CO2e_ha_biomass_soil_2001_{loss_years}' -gross_emis_forestry_biomass_soil_dir = f'{s3_base_dir}gross_emissions/forestry/biomass_soil/standard/{emis_run_date_biomass_soil}/' - -pattern_gross_emis_shifting_ag_biomass_soil = f'gross_emis_shifting_ag_Mg_CO2e_ha_biomass_soil_2001_{loss_years}' -gross_emis_shifting_ag_biomass_soil_dir = f'{s3_base_dir}gross_emissions/shifting_ag/biomass_soil/standard/{emis_run_date_biomass_soil}/' - -pattern_gross_emis_urban_biomass_soil = f'gross_emis_urbanization_Mg_CO2e_ha_biomass_soil_2001_{loss_years}' -gross_emis_urban_biomass_soil_dir = f'{s3_base_dir}gross_emissions/urbanization/biomass_soil/standard/{emis_run_date_biomass_soil}/' - -pattern_gross_emis_wildfire_biomass_soil = f'gross_emis_wildfire_Mg_CO2e_ha_biomass_soil_2001_{loss_years}' -gross_emis_wildfire_biomass_soil_dir = f'{s3_base_dir}gross_emissions/wildfire/biomass_soil/standard/{emis_run_date_biomass_soil}/' +emis_run_date_biomass_soil = '20241122' +pattern_gross_emis_all_gases_all_drivers_biomass_soil = f'gross_emis_all_gases_all_drivers_Mg_CO2e_ha_biomass_soil_2001_{loss_years}' +gross_emis_all_gases_all_drivers_biomass_soil_dir = f'{s3_base_dir}gross_emissions/all_drivers/all_gases/biomass_soil/standard/full_extent/per_hectare/{emis_run_date_biomass_soil}/' -pattern_gross_emis_no_driver_biomass_soil = f'gross_emis_no_driver_Mg_CO2e_ha_biomass_soil_2001_{loss_years}' -gross_emis_no_driver_biomass_soil_dir = f'{s3_base_dir}gross_emissions/no_driver/biomass_soil/standard/{emis_run_date_biomass_soil}/' +pattern_gross_emis_all_gases_all_drivers_biomass_soil_forest_extent = f'gross_emis_all_gases_all_drivers_Mg_CO2e_ha_biomass_soil_forest_extent_2001_{loss_years}' +gross_emis_all_gases_all_drivers_biomass_soil_forest_extent_dir = f'{s3_base_dir}gross_emissions/all_drivers/all_gases/biomass_soil/standard/forest_extent/per_hectare/{emis_run_date_biomass_soil}/' pattern_gross_emis_co2_only_all_drivers_biomass_soil = f'gross_emis_CO2_only_all_drivers_Mg_CO2e_ha_biomass_soil_2001_{loss_years}' gross_emis_co2_only_all_drivers_biomass_soil_dir = f'{s3_base_dir}gross_emissions/all_drivers/CO2_only/biomass_soil/standard/{emis_run_date_biomass_soil}/' @@ -673,11 +660,11 @@ pattern_gross_emis_non_co2_all_drivers_biomass_soil = f'gross_emis_non_CO2_all_drivers_Mg_CO2e_ha_biomass_soil_2001_{loss_years}' gross_emis_non_co2_all_drivers_biomass_soil_dir = f'{s3_base_dir}gross_emissions/all_drivers/non_CO2/biomass_soil/standard/{emis_run_date_biomass_soil}/' -pattern_gross_emis_all_gases_all_drivers_biomass_soil = f'gross_emis_all_gases_all_drivers_Mg_CO2e_ha_biomass_soil_2001_{loss_years}' -gross_emis_all_gases_all_drivers_biomass_soil_dir = f'{s3_base_dir}gross_emissions/all_drivers/all_gases/biomass_soil/standard/full_extent/per_hectare/{emis_run_date_biomass_soil}/' +pattern_gross_emis_ch4_only_all_drivers_biomass_soil = f'gross_emis_CH4_only_all_drivers_Mg_CO2e_ha_biomass_soil_2001_{loss_years}' +gross_emis_ch4_only_all_drivers_biomass_soil_dir = f'{s3_base_dir}gross_emissions/all_drivers/CH4_only/biomass_soil/standard/{emis_run_date_biomass_soil}/' -pattern_gross_emis_all_gases_all_drivers_biomass_soil_forest_extent = f'gross_emis_all_gases_all_drivers_Mg_CO2e_ha_biomass_soil_forest_extent_2001_{loss_years}' -gross_emis_all_gases_all_drivers_biomass_soil_forest_extent_dir = f'{s3_base_dir}gross_emissions/all_drivers/all_gases/biomass_soil/standard/forest_extent/per_hectare/{emis_run_date_biomass_soil}/' +pattern_gross_emis_n2o_only_all_drivers_biomass_soil = f'gross_emis_N2O_only_all_drivers_Mg_CO2e_ha_biomass_soil_2001_{loss_years}' +gross_emis_n2o_only_all_drivers_biomass_soil_dir = f'{s3_base_dir}gross_emissions/all_drivers/N2O_only/biomass_soil/standard/{emis_run_date_biomass_soil}/' pattern_gross_emis_nodes_biomass_soil = f'gross_emis_decision_tree_nodes_biomass_soil_2001_{loss_years}' gross_emis_nodes_biomass_soil_dir = f'{s3_base_dir}gross_emissions/decision_tree_nodes/biomass_soil/standard/{emis_run_date_biomass_soil}/' @@ -685,27 +672,7 @@ ### Emissions from soil only # Date to include in the output directory -emis_run_date_soil_only = '20240402' - - -pattern_gross_emis_commod_soil_only = f'gross_emis_commodity_Mg_CO2e_ha_soil_only_2001_{loss_years}' -gross_emis_commod_soil_only_dir = f'{s3_base_dir}gross_emissions/commodities/soil_only/standard/{emis_run_date_soil_only}/' - -pattern_gross_emis_forestry_soil_only = f'gross_emis_forestry_Mg_CO2e_ha_soil_only_2001_{loss_years}' -gross_emis_forestry_soil_only_dir = f'{s3_base_dir}gross_emissions/forestry/soil_only/standard/{emis_run_date_soil_only}/' - -pattern_gross_emis_shifting_ag_soil_only = f'gross_emis_shifting_ag_Mg_CO2e_ha_soil_only_2001_{loss_years}' -gross_emis_shifting_ag_soil_only_dir = f'{s3_base_dir}gross_emissions/shifting_ag/soil_only/standard/{emis_run_date_soil_only}/' - -pattern_gross_emis_urban_soil_only = f'gross_emis_urbanization_Mg_CO2e_ha_soil_only_2001_{loss_years}' -gross_emis_urban_soil_only_dir = f'{s3_base_dir}gross_emissions/urbanization/soil_only/standard/{emis_run_date_soil_only}/' - -pattern_gross_emis_wildfire_soil_only = f'gross_emis_wildfire_Mg_CO2e_ha_soil_only_2001_{loss_years}' -gross_emis_wildfire_soil_only_dir = f'{s3_base_dir}gross_emissions/wildfire/soil_only/standard/{emis_run_date_soil_only}/' - -pattern_gross_emis_no_driver_soil_only = f'gross_emis_no_driver_Mg_CO2e_ha_soil_only_2001_{loss_years}' -gross_emis_no_driver_soil_only_dir = f'{s3_base_dir}gross_emissions/no_driver/soil_only/standard/{emis_run_date_soil_only}/' - +emis_run_date_soil_only = '20241122' pattern_gross_emis_all_gases_all_drivers_soil_only = f'gross_emis_all_gases_all_drivers_Mg_CO2e_ha_soil_only_2001_{loss_years}' gross_emis_all_gases_all_drivers_soil_only_dir = f'{s3_base_dir}gross_emissions/all_drivers/all_gases/soil_only/standard/{emis_run_date_soil_only}/' @@ -715,6 +682,12 @@ pattern_gross_emis_non_co2_all_drivers_soil_only = f'gross_emis_non_CO2_all_drivers_Mg_CO2e_ha_soil_only_2001_{loss_years}' gross_emis_non_co2_all_drivers_soil_only_dir = f'{s3_base_dir}gross_emissions/all_drivers/non_CO2/soil_only/standard/{emis_run_date_soil_only}/' +pattern_gross_emis_ch4_only_all_drivers_soil_only = f'gross_emis_CH4_only_all_drivers_Mg_CO2e_ha_soil_only_2001_{loss_years}' +gross_emis_ch4_only_all_drivers_soil_only_dir = f'{s3_base_dir}gross_emissions/all_drivers/CH4_only/soil_only/standard/{emis_run_date_soil_only}/' + +pattern_gross_emis_n2o_only_all_drivers_soil_only = f'gross_emis_N2O_only_all_drivers_Mg_CO2e_ha_soil_only_2001_{loss_years}' +gross_emis_n2o_only_all_drivers_soil_only_dir = f'{s3_base_dir}gross_emissions/all_drivers/N2O_only/soil_only/standard/{emis_run_date_soil_only}/' + pattern_gross_emis_nodes_soil_only = f'gross_emis_decision_tree_nodes_soil_only_2001_{loss_years}' gross_emis_nodes_soil_only_dir = f'{s3_base_dir}gross_emissions/decision_tree_nodes/soil_only/standard/{emis_run_date_soil_only}/' @@ -724,11 +697,11 @@ # Net emissions for all forest types and all carbon emitted_pools in all pixels pattern_net_flux = f'net_flux_Mg_CO2e_ha_biomass_soil_2001_{loss_years}' -net_flux_dir = os.path.join(s3_base_dir, 'net_flux_all_forest_types_all_drivers/biomass_soil/standard/full_extent/per_hectare/20240402/') +net_flux_dir = os.path.join(s3_base_dir, 'net_flux_all_forest_types_all_drivers/biomass_soil/standard/full_extent/per_hectare/20241122/') # Net emissions for all forest types and all carbon emitted_pools in forest extent pattern_net_flux_forest_extent = f'net_flux_Mg_CO2e_ha_biomass_soil_forest_extent_2001_{loss_years}' -net_flux_forest_extent_dir = os.path.join(s3_base_dir, 'net_flux_all_forest_types_all_drivers/biomass_soil/standard/forest_extent/per_hectare/20240402/') +net_flux_forest_extent_dir = os.path.join(s3_base_dir, 'net_flux_all_forest_types_all_drivers/biomass_soil/standard/forest_extent/per_hectare/20241122/') ### Per pixel model outputs @@ -736,27 +709,27 @@ # Gross removals per pixel in all pixels pattern_cumul_gain_AGCO2_BGCO2_all_types_per_pixel_full_extent = f'gross_removals_AGCO2_BGCO2_Mg_pixel_all_forest_types_full_extent_2001_{loss_years}' -cumul_gain_AGCO2_BGCO2_all_types_per_pixel_full_extent_dir = os.path.join(s3_base_dir, 'gross_removals_AGCO2_BGCO2_all_forest_types/standard/full_extent/per_pixel/20240308/') +cumul_gain_AGCO2_BGCO2_all_types_per_pixel_full_extent_dir = os.path.join(s3_base_dir, 'gross_removals_AGCO2_BGCO2_all_forest_types/standard/full_extent/per_pixel/20241122/') # Gross removals per pixel in forest extent pattern_cumul_gain_AGCO2_BGCO2_all_types_per_pixel_forest_extent = f'gross_removals_AGCO2_BGCO2_Mg_pixel_all_forest_types_forest_extent_2001_{loss_years}' -cumul_gain_AGCO2_BGCO2_all_types_per_pixel_forest_extent_dir = os.path.join(s3_base_dir, 'gross_removals_AGCO2_BGCO2_all_forest_types/standard/forest_extent/per_pixel/20240308/') +cumul_gain_AGCO2_BGCO2_all_types_per_pixel_forest_extent_dir = os.path.join(s3_base_dir, 'gross_removals_AGCO2_BGCO2_all_forest_types/standard/forest_extent/per_pixel/20241122/') # Gross emissions per pixel in all pixels pattern_gross_emis_all_gases_all_drivers_biomass_soil_per_pixel_full_extent = f'gross_emis_all_gases_all_drivers_Mg_CO2e_pixel_biomass_soil_full_extent_2001_{loss_years}' -gross_emis_all_gases_all_drivers_biomass_soil_per_pixel_full_extent_dir = os.path.join(s3_base_dir, 'gross_emissions/all_drivers/all_gases/biomass_soil/standard/full_extent/per_pixel/20240402/') +gross_emis_all_gases_all_drivers_biomass_soil_per_pixel_full_extent_dir = os.path.join(s3_base_dir, 'gross_emissions/all_drivers/all_gases/biomass_soil/standard/full_extent/per_pixel/20241122/') # Gross emissions per pixel in forest extent pattern_gross_emis_all_gases_all_drivers_biomass_soil_per_pixel_forest_extent = f'gross_emis_all_gases_all_drivers_Mg_CO2e_pixel_biomass_soil_forest_extent_2001_{loss_years}' -gross_emis_all_gases_all_drivers_biomass_soil_per_pixel_forest_extent_dir = os.path.join(s3_base_dir, 'gross_emissions/all_drivers/all_gases/biomass_soil/standard/forest_extent/per_pixel/20240402/') +gross_emis_all_gases_all_drivers_biomass_soil_per_pixel_forest_extent_dir = os.path.join(s3_base_dir, 'gross_emissions/all_drivers/all_gases/biomass_soil/standard/forest_extent/per_pixel/20241122/') # Net flux per pixel in all pixels pattern_net_flux_per_pixel_full_extent = f'net_flux_Mg_CO2e_pixel_biomass_soil_full_extent_2001_{loss_years}' -net_flux_per_pixel_full_extent_dir = os.path.join(s3_base_dir, 'net_flux_all_forest_types_all_drivers/biomass_soil/standard/full_extent/per_pixel/20240402/') +net_flux_per_pixel_full_extent_dir = os.path.join(s3_base_dir, 'net_flux_all_forest_types_all_drivers/biomass_soil/standard/full_extent/per_pixel/20241122/') # Net flux per pixel in forest extent pattern_net_flux_per_pixel_forest_extent = f'net_flux_Mg_CO2e_pixel_biomass_soil_forest_extent_2001_{loss_years}' -net_flux_per_pixel_forest_extent_dir = os.path.join(s3_base_dir, 'net_flux_all_forest_types_all_drivers/biomass_soil/standard/forest_extent/per_pixel/20240402/') +net_flux_per_pixel_forest_extent_dir = os.path.join(s3_base_dir, 'net_flux_all_forest_types_all_drivers/biomass_soil/standard/forest_extent/per_pixel/20241122/') ### 4x4 km aggregation tiles for mapping @@ -766,7 +739,7 @@ pattern_aggreg_sensit_perc_diff = f'net_flux_0_04deg_modelv{version_filename}_perc_diff_std' pattern_aggreg_sensit_sign_change = f'net_flux_0_04deg_modelv{version_filename}_sign_change_std' -output_aggreg_dir = os.path.join(s3_base_dir, '0_04deg_output_aggregation/biomass_soil/standard/20240402/') +output_aggreg_dir = os.path.join(s3_base_dir, '0_04deg_output_aggregation/biomass_soil/standard/20241122/') diff --git a/data_prep/planted_forests_prep/.Rhistory b/data_prep/planted_forests_prep/.Rhistory new file mode 100644 index 00000000..e69de29b diff --git a/emissions/calculate_gross_emissions.py b/emissions/calculate_gross_emissions.py index 82add9f4..ffdd938d 100644 --- a/emissions/calculate_gross_emissions.py +++ b/emissions/calculate_gross_emissions.py @@ -14,9 +14,13 @@ def calc_emissions(tile_id, emitted_pools, folder): :param emitted_pools: Whether emissions from soil only is calculated, or emissions from biomass and soil. Options are: soil_only or biomass_soil. :param folder: - :return: 10 tiles: 6 tiles with emissions for each driver; CO2 emissions from all drivers; - non-CO2 emissions from all drivers; all gases (CO2 and non-CO2 from all drivers); - emissions decision tree nodes (used for QC). + :return: 6 tiles - + 1. all gases (CO2, CH4 and N2O from all drivers); + 2. CO2 emissions from all drivers; + 3. non-CO2 emissions from all drivers (CH4 and N2O from all drivers); + 4. CH4 emissions from all drivers; + 5. N2O emissions from all drivers; + 6. emissions decision tree nodes (used for QC). Units: Mg CO2e/ha over entire model period. """ @@ -27,14 +31,11 @@ def calc_emissions(tile_id, emitted_pools, folder): uu.check_memory() # Runs the correct c++ script given the emitted_pools (biomass+soil or soil_only) and model type selected. - # soil_only, no_shiftin_ag, and convert_to_grassland have special gross emissions C++ scripts. + # soil_only has special gross emissions C++ scripts. # The other sensitivity analyses and the standard model all use the same gross emissions C++ script. if (emitted_pools == 'soil_only') & (cn.SENSIT_TYPE == 'std'): cmd = [f'{cn.c_emis_compile_dst}/calc_gross_emissions_soil_only.exe', tile_id, cn.SENSIT_TYPE, folder] - elif (emitted_pools == 'biomass_soil') & (cn.SENSIT_TYPE in ['convert_to_grassland', 'no_shifting_ag']): - cmd = [f'{cn.c_emis_compile_dst}/calc_gross_emissions_{cn.SENSIT_TYPE}.exe', tile_id, cn.SENSIT_TYPE, folder] - # This C++ script has an extra argument that names the input carbon emitted_pools and output emissions correctly elif (emitted_pools == 'biomass_soil') & (cn.SENSIT_TYPE not in ['no_shifting_ag', 'convert_to_grassland']): cmd = [f'{cn.c_emis_compile_dst}/calc_gross_emissions_generic.exe', tile_id, cn.SENSIT_TYPE, folder] @@ -46,7 +47,7 @@ def calc_emissions(tile_id, emitted_pools, folder): # Identifies which pattern to use for counting tile completion - pattern = cn.pattern_gross_emis_commod_biomass_soil + pattern = cn.pattern_gross_emis_co2_only_all_drivers_biomass_soil if (emitted_pools == 'biomass_soil') & (cn.SENSIT_TYPE == 'std'): pattern = pattern diff --git a/emissions/cpp_util/calc_gross_emissions_convert_to_grassland.cpp b/emissions/cpp_util/calc_gross_emissions_convert_to_grassland.cpp deleted file mode 100644 index 13f85f07..00000000 --- a/emissions/cpp_util/calc_gross_emissions_convert_to_grassland.cpp +++ /dev/null @@ -1,1165 +0,0 @@ -// Implements the calculation of gross emissions from biomass and soil and stores the outputs as rasters. -// This is essentially one large decision tree that iterates pixel by pixel across each Hansen tile. -// The first split is whether the pixel has carbon and loss. -// NOTE: The way I've set up the model, all carbon pixels have loss (i.e. only carbon pixels with loss are input to the model). -// The next split is which driver of tree cover loss the pixel falls in. -// The next split is whether the pixel is on peat, followed by whether there was fire. -// The splits after that depend on the particular tree, but include ecozone (boreal/temperate/tropical), IFL, and plantation status. -// Each series of splits ends with a particular equation that calculates gross emissions in that case. -// The equations sometimes rely on constants, which are calculated for each pixel and are based on properties of -// underlying pixels (e.g., ecozone, climate zone, IFL status) (calculated in equations.cpp). -// Each end point of the decision tree gets its own code, so that it's easier to tell what branch of the decision tree -// each pixel came from. That makes checking the results easier, too. -// These codes are summarized in carbon-budget/emissions/node_codes.txt -// Because emissions are separately output for CO2 and non-CO2 gases (CH4 and N20), each model endpoint has a CO2-only and -// a non-CO2 value. These are summed to create a total emissions (all gases) for each pixel. -// Compile with: -// c++ ../carbon-budget/emissions/cpp_util/calc_gross_emissions_convert_to_grassland.cpp -o ../carbon-budget/emissions/cpp_util/calc_gross_emissions_convert_to_grassland.exe -lgdal - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -// These provide constants for the emissions equations -#include "flu_val.cpp" -#include "equations.cpp" -#include "constants.h" - -using namespace std; - -//to compile: c++ calc_gross_emissions.cpp -o calc_gross_emissions.exe -lgdal -int main(int argc, char* argv[]) -{ -// If code is run other than , it will raise this error. -if (argc != 4){cout << "Use " << endl; return 1;} - -// Input arguments -string tile_id = argv[1]; // The tile id comes from the second argument. The first argument is the name of this code. -string sensit_type = argv[2]; // For standard model or sensitivity analyses that use the standard emissions model. - // Used to name the input carbon pool tiles and output gross emissions tiles. -string infolder = argv[3]; // The folder which has all the input files - -cout << "Gross emissions C++ infolder:" << infolder << endl; - -// Model constants -int model_years; // How many loss years are in the model -model_years = constants::model_years; -string model_years_str; -model_years_str = to_string(model_years); - -int CH4_equiv; // The CO2 equivalency (global warming potential) of CH4 -CH4_equiv = constants::CH4_equiv; - -int N2O_equiv; // The CO2 equivalency (global warming potential) of N2O -N2O_equiv = constants::N2O_equiv; - -float C_to_CO2; // The conversion of carbon to CO2 -C_to_CO2 = constants::C_to_CO2; - -float biomass_to_c; // Fraction of carbon in biomass -biomass_to_c = constants::biomass_to_c; - -int tropical; // The ecozone code for the tropics -tropical = constants::tropical; - -int temperate; // The ecozone code for the temperate zone -temperate = constants::temperate; - -int boreal; // The ecozone code for the boreal zone -boreal = constants::boreal; - -int soil_emis_period; // The number of years over which soil emissions are calculated (separate from model years) -soil_emis_period = constants::soil_emis_period; - - -// Input files -// Carbon pools use the standard names for this sensitivity analysis -string agc_name = infolder + tile_id + constants::AGC_emis_year + ".tif"; -string bgc_name = infolder + tile_id + constants::BGC_emis_year + ".tif"; -string dead_name = infolder + tile_id + constants::deadwood_C_emis_year + ".tif"; -string litter_name = infolder + tile_id + constants::litter_C_emis_year + ".tif"; -string soil_name = infolder + tile_id + constants::soil_C_emis_year + ".tif"; - -// Other inputs -string loss_name = infolder + constants::lossyear + tile_id + ".tif"; -string burn_name = infolder + tile_id + constants::burnyear; -string ecozone_name = infolder + tile_id + constants::fao_ecozones; -string climate_name = infolder + tile_id + constants::climate_zones; -string drivermodel_name = infolder + tile_id + constants::tcl_drivers; -string peat_name = infolder + tile_id + constants::peat_mask; -string ifl_primary_name = infolder + tile_id + constants::ifl_primary; -string plant_name = infolder + tile_id + constants::plantation_type; - -// Output files: tonnes CO2/ha for each tree cover loss driver, their total, and the node for the decision tree -// that determines emissions -string out_name1 = tile_id + constants::commod_emis + model_years_str + "_convert_to_grassland.tif"; -string out_name2 = tile_id + constants::shifting_ag_emis + model_years_str + "_convert_to_grassland.tif"; -string out_name3 = tile_id + constants::forestry_emis + model_years_str + "_convert_to_grassland.tif"; -string out_name4 = tile_id + constants::wildfire_emis + model_years_str + "_convert_to_grassland.tif"; -string out_name5 = tile_id + constants::urbanization_emis + model_years_str + "_convert_to_grassland.tif"; -string out_name6 = tile_id + constants::no_driver_emis + model_years_str + "_convert_to_grassland.tif"; -string out_name10 = tile_id + constants::all_gases_all_drivers_emis + model_years_str + "_convert_to_grassland.tif"; -string out_name11 = tile_id + constants::CO2_only_all_drivers_emis + model_years_str + "_convert_to_grassland.tif"; -string out_name12 = tile_id + constants::non_CO2_all_drivers_emis + model_years_str + "_convert_to_grassland.tif"; -string out_name20 = tile_id + constants::decision_tree_all_drivers_emis + model_years_str + "_convert_to_grassland.tif"; - - -// Setting up the variables to hold the pixel location in x/y values -int x, y; -int xsize, ysize; -double GeoTransform[6]; // Fetch the affine transformation coefficients -double ulx, uly; double pixelsize; - -// Initialize GDAL for reading. -// Each of these "INBAND" are later associated with the string variables defined above. -GDALAllRegister(); -GDALDataset *INGDAL1; GDALRasterBand *INBAND1; -GDALDataset *INGDAL2; GDALRasterBand *INBAND2; -GDALDataset *INGDAL3; GDALRasterBand *INBAND3; -GDALDataset *INGDAL4; GDALRasterBand *INBAND4; -GDALDataset *INGDAL5; GDALRasterBand *INBAND5; -GDALDataset *INGDAL6; GDALRasterBand *INBAND6; -GDALDataset *INGDAL7; GDALRasterBand *INBAND7; -GDALDataset *INGDAL8; GDALRasterBand *INBAND8; -GDALDataset *INGDAL9; GDALRasterBand *INBAND9; -GDALDataset *INGDAL10; GDALRasterBand *INBAND10; -GDALDataset *INGDAL11; GDALRasterBand *INBAND11; -GDALDataset *INGDAL12; GDALRasterBand *INBAND12; -GDALDataset *INGDAL13; GDALRasterBand *INBAND13; - -//open file (string variables defined above) and assign it extent and projection -INGDAL1 = (GDALDataset *) GDALOpen(agc_name.c_str(), GA_ReadOnly ); -INBAND1 = INGDAL1->GetRasterBand(1); - -INGDAL2 = (GDALDataset *) GDALOpen(bgc_name.c_str(), GA_ReadOnly ); -INBAND2 = INGDAL2->GetRasterBand(1); - -INGDAL3 = (GDALDataset *) GDALOpen(drivermodel_name.c_str(), GA_ReadOnly ); -INBAND3 = INGDAL3->GetRasterBand(1); - -INGDAL4 = (GDALDataset *) GDALOpen(loss_name.c_str(), GA_ReadOnly ); -INBAND4 = INGDAL4->GetRasterBand(1); - -INGDAL5 = (GDALDataset *) GDALOpen(peat_name.c_str(), GA_ReadOnly ); -INBAND5 = INGDAL5->GetRasterBand(1); - -INGDAL6 = (GDALDataset *) GDALOpen(burn_name.c_str(), GA_ReadOnly ); -INBAND6 = INGDAL6->GetRasterBand(1); - -INGDAL7 = (GDALDataset *) GDALOpen(ifl_primary_name.c_str(), GA_ReadOnly ); -INBAND7 = INGDAL7->GetRasterBand(1); - -INGDAL8 = (GDALDataset *) GDALOpen(ecozone_name.c_str(), GA_ReadOnly ); -INBAND8 = INGDAL8->GetRasterBand(1); - -INGDAL9 = (GDALDataset *) GDALOpen(climate_name.c_str(), GA_ReadOnly ); -INBAND9 = INGDAL9->GetRasterBand(1); - -INGDAL10 = (GDALDataset *) GDALOpen(dead_name.c_str(), GA_ReadOnly ); -INBAND10 = INGDAL10->GetRasterBand(1); - -INGDAL11 = (GDALDataset *) GDALOpen(litter_name.c_str(), GA_ReadOnly ); -INBAND11 = INGDAL11->GetRasterBand(1); - -INGDAL12 = (GDALDataset *) GDALOpen(soil_name.c_str(), GA_ReadOnly ); -INBAND12 = INGDAL12->GetRasterBand(1); - -INGDAL13 = (GDALDataset *) GDALOpen(plant_name.c_str(), GA_ReadOnly ); -INBAND13 = INGDAL13->GetRasterBand(1); - -// The rest of the code runs on the size of INBAND3. This can be changed. -xsize=INBAND1->GetXSize(); -ysize=INBAND1->GetYSize(); -INGDAL1->GetGeoTransform(GeoTransform); - -ulx=GeoTransform[0]; -uly=GeoTransform[3]; -pixelsize=GeoTransform[1]; - -// // Manually change this to test the script on a small part of the raster. This starts at top left of the tile. -//xsize = 6000; -//ysize = 6000; - -// Print the raster size and resolution. Should be 40,000 x 40,000 and pixel size 0.00025. -cout << "Gross emissions convert_to_grassland model C++ parameters: " << xsize <<", "<< ysize <<", "<< ulx <<", "<< uly << ", "<< pixelsize << endl; - -// Initialize GDAL for writing -GDALDriver *OUTDRIVER; -GDALDataset *OUTGDAL1; // Commodities, all gases -GDALDataset *OUTGDAL2; // Shifting ag, all gases -GDALDataset *OUTGDAL3; // Forestry, all gases -GDALDataset *OUTGDAL4; // Wildfire, all gases -GDALDataset *OUTGDAL5; // Urbanization, all gases -GDALDataset *OUTGDAL6; // No driver, all gases -GDALDataset *OUTGDAL10; // All drivers, all gases -GDALDataset *OUTGDAL11; // All drivers, CO2 only -GDALDataset *OUTGDAL12; // All drivers, non-CO2 -GDALDataset *OUTGDAL20; // Decision tree node - -GDALRasterBand *OUTBAND1; -GDALRasterBand *OUTBAND2; -GDALRasterBand *OUTBAND3; -GDALRasterBand *OUTBAND4; -GDALRasterBand *OUTBAND5; -GDALRasterBand *OUTBAND6; -GDALRasterBand *OUTBAND10; -GDALRasterBand *OUTBAND11; -GDALRasterBand *OUTBAND12; -GDALRasterBand *OUTBAND20; - -OGRSpatialReference oSRS; -char *OUTPRJ = NULL; -char **papszOptions = NULL; -papszOptions = CSLSetNameValue( papszOptions, "COMPRESS", "DEFLATE" ); -OUTDRIVER = GetGDALDriverManager()->GetDriverByName("GTIFF"); -if( OUTDRIVER == NULL ) {cout << "no driver" << endl; exit( 1 );}; -oSRS.SetWellKnownGeogCS( "WGS84" ); -oSRS.exportToWkt( &OUTPRJ ); -double adfGeoTransform[6] = { ulx, pixelsize, 0, uly, 0, -1*pixelsize }; - -// Commoditiy gross emissions -OUTGDAL1 = OUTDRIVER->Create( out_name1.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL1->SetGeoTransform(adfGeoTransform); OUTGDAL1->SetProjection(OUTPRJ); -OUTBAND1 = OUTGDAL1->GetRasterBand(1); -OUTBAND1->SetNoDataValue(0); - -// Shifting ag gross emissions -OUTGDAL2 = OUTDRIVER->Create( out_name2.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL2->SetGeoTransform(adfGeoTransform); OUTGDAL2->SetProjection(OUTPRJ); -OUTBAND2 = OUTGDAL2->GetRasterBand(1); -OUTBAND2->SetNoDataValue(0); - -// Forestry gross emissions -OUTGDAL3 = OUTDRIVER->Create( out_name3.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL3->SetGeoTransform(adfGeoTransform); OUTGDAL3->SetProjection(OUTPRJ); -OUTBAND3 = OUTGDAL3->GetRasterBand(1); -OUTBAND3->SetNoDataValue(0); - -// Wildfire gross emissions -OUTGDAL4 = OUTDRIVER->Create( out_name4.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL4->SetGeoTransform(adfGeoTransform); OUTGDAL4->SetProjection(OUTPRJ); -OUTBAND4 = OUTGDAL4->GetRasterBand(1); -OUTBAND4->SetNoDataValue(0); - -// Urbanization gross emissions -OUTGDAL5 = OUTDRIVER->Create( out_name5.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL5->SetGeoTransform(adfGeoTransform); OUTGDAL5->SetProjection(OUTPRJ); -OUTBAND5 = OUTGDAL5->GetRasterBand(1); -OUTBAND5->SetNoDataValue(0); - -// No driver gross emissions -OUTGDAL6 = OUTDRIVER->Create( out_name6.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL6->SetGeoTransform(adfGeoTransform); OUTGDAL6->SetProjection(OUTPRJ); -OUTBAND6 = OUTGDAL6->GetRasterBand(1); -OUTBAND6->SetNoDataValue(0); - -// All gases, all drivers combined -OUTGDAL10 = OUTDRIVER->Create( out_name10.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL10->SetGeoTransform(adfGeoTransform); OUTGDAL10->SetProjection(OUTPRJ); -OUTBAND10 = OUTGDAL10->GetRasterBand(1); -OUTBAND10->SetNoDataValue(0); - -// CO2 only, all drivers combined -OUTGDAL11 = OUTDRIVER->Create( out_name11.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL11->SetGeoTransform(adfGeoTransform); OUTGDAL11->SetProjection(OUTPRJ); -OUTBAND11 = OUTGDAL11->GetRasterBand(1); -OUTBAND11->SetNoDataValue(0); - -// Non-CO2, all drivers combined -OUTGDAL12 = OUTDRIVER->Create( out_name12.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL12->SetGeoTransform(adfGeoTransform); OUTGDAL12->SetProjection(OUTPRJ); -OUTBAND12 = OUTGDAL12->GetRasterBand(1); -OUTBAND12->SetNoDataValue(0); - -// Decision tree node -OUTGDAL20 = OUTDRIVER->Create( out_name20.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL20->SetGeoTransform(adfGeoTransform); OUTGDAL20->SetProjection(OUTPRJ); -OUTBAND20 = OUTGDAL20->GetRasterBand(1); -OUTBAND20->SetNoDataValue(0); - - -// Read/write data -// Inputs -float agc_data[xsize]; -float bgc_data[xsize]; -float loss_data[xsize]; -float peat_data[xsize]; -float drivermodel_data[xsize]; -float burn_data[xsize]; -float ecozone_data[xsize]; -float soil_data[xsize]; -float climate_data[xsize]; -float dead_data[xsize]; -float litter_data[xsize]; -float ifl_primary_data[xsize]; -float plant_data[xsize]; - -// Outputs -float out_data1[xsize]; -float out_data2[xsize]; -float out_data3[xsize]; -float out_data4[xsize]; -float out_data5[xsize]; -float out_data6[xsize]; -float out_data10[xsize]; -float out_data11[xsize]; -float out_data12[xsize]; -float out_data20[xsize]; - -// Loop over the y coordinates, then the x coordinates -for (y=0; yRasterIO(GF_Read, 0, y, xsize, 1, agc_data, xsize, 1, GDT_Float32, 0, 0); -INBAND2->RasterIO(GF_Read, 0, y, xsize, 1, bgc_data, xsize, 1, GDT_Float32, 0, 0); -INBAND3->RasterIO(GF_Read, 0, y, xsize, 1, drivermodel_data, xsize, 1, GDT_Float32, 0, 0); -INBAND4->RasterIO(GF_Read, 0, y, xsize, 1, loss_data, xsize, 1, GDT_Float32, 0, 0); -INBAND5->RasterIO(GF_Read, 0, y, xsize, 1, peat_data, xsize, 1, GDT_Float32, 0, 0); -INBAND6->RasterIO(GF_Read, 0, y, xsize, 1, burn_data, xsize, 1, GDT_Float32, 0, 0); -INBAND7->RasterIO(GF_Read, 0, y, xsize, 1, ifl_primary_data, xsize, 1, GDT_Float32, 0, 0); -INBAND8->RasterIO(GF_Read, 0, y, xsize, 1, ecozone_data, xsize, 1, GDT_Float32, 0, 0); -INBAND9->RasterIO(GF_Read, 0, y, xsize, 1, climate_data, xsize, 1, GDT_Float32, 0, 0); -INBAND10->RasterIO(GF_Read, 0, y, xsize, 1, dead_data, xsize, 1, GDT_Float32, 0, 0); -INBAND11->RasterIO(GF_Read, 0, y, xsize, 1, litter_data, xsize, 1, GDT_Float32, 0, 0); -INBAND12->RasterIO(GF_Read, 0, y, xsize, 1, soil_data, xsize, 1, GDT_Float32, 0, 0); -INBAND13->RasterIO(GF_Read, 0, y, xsize, 1, plant_data, xsize, 1, GDT_Float32, 0, 0); - -for(x=0; x 0 && agc_data[x] > 0) - { - - // From equations.cpp, a function called def_variables, we get back several constants - // based on several input rasters for that pixel. These are later used for calculating emissions. - - // def_variables kept returning the same values for all pixels in a tile as the first pixel in the tile regardless of the inputs to the function; - // it was as if the returned values for the first pixel evaluated couldn't be overwritten. - // The first answer here told me how to solve that: https://stackoverflow.com/questions/51609816/return-float-array-from-a-function-c - float q[8]; - def_variables(&q[0], ecozone_data[x], drivermodel_data[x], ifl_primary_data[x], climate_data[x], plant_data[x], loss_data[x]); - - // The constants needed for calculating emissions - float Cf = q[0]; // Combustion factor - float Gef_CO2 = q[1]; // Emissions factor for CO2 - float Gef_CH4 = q[2]; // Emissions factor for CH4 - float Gef_N2O = q[3]; // Emissions factor for N2O - float peatburn_CO2_only = q[4]; // Emissions from burning peat, CO2 emissions only - float peatburn_non_CO2 = q[5]; // Emissions from burning peat, non-CO2 emissions only - float peat_drain_total_CO2_only = q[6]; // Emissions from draining peat, CO2 emissions only - float peat_drain_total_non_CO2 = q[7]; // Emissions from draining peat, non-CO2 emissions only - - // Define and calculate several values used later - float non_soil_c; - non_soil_c = agc_data[x] + bgc_data[x] + dead_data[x] + litter_data[x]; - - float above_below_c; - above_below_c = agc_data[x] + bgc_data[x]; - - float Biomass_tCO2e_nofire_CO2_only; // Emissions from biomass on pixels without fire- only emits CO2 (no non-CO2 option) - float Biomass_tCO2e_yesfire_CO2_only; // Emissions from biomass on pixels with fire- only the CO2 - float Biomass_tCO2e_yesfire_non_CO2; // Emissions from biomass on pixels with fire- only the non-CO2 gases - float minsoil; // Emissions from mineral soil- all CO2 - float flu; // Emissions fraction from mineral soil - - // Each driver is an output raster and has its own emissions model. outdata20 is the code for each - // combination of outputs. Defined in carbon-budget/emissions/node_codes.txt - - // Emissions model for commodity-driven deforestation - if (drivermodel_data[x] == 1) - { - // For each driver, these values (or a subset of them) are necessary for calculating emissions. - Biomass_tCO2e_nofire_CO2_only = non_soil_c * C_to_CO2; - Biomass_tCO2e_yesfire_CO2_only = non_soil_c * C_to_CO2; - Biomass_tCO2e_yesfire_non_CO2 = ((non_soil_c / biomass_to_c) * Cf * Gef_CH4 * pow(10,-3) * CH4_equiv) + ((non_soil_c / biomass_to_c) * Cf * Gef_N2O * pow(10,-3) * N2O_equiv); - flu = flu_val(climate_data[x], ecozone_data[x]); - minsoil = ((soil_data[x]-(soil_data[x] * flu))/soil_emis_period) * (model_years-loss_data[x]); // Not used in this sensitivity analysis for this driver - - if (peat_data[x] > 0) // Commodity, peat - { - if (burn_data[x] > 0) // Commodity, peat, burned - { - outdata1a = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; - outdata1b = Biomass_tCO2e_yesfire_non_CO2 + peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 10; - } - if (burn_data[x] == 0) // Commodity, peat, not burned - { - if (ecozone_data[x] == tropical) // Commodity, peat, not burned, tropical - { - if (plant_data[x] >= 1) // Commodity, peat, not burned, tropical, plantation - { - outdata1a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata1b = 0 + peat_drain_total_non_CO2; - outdata20 = 11; - } - if (plant_data[x] == 0) // Commodity, peat, not burned, tropical, not plantation - { - outdata1a = Biomass_tCO2e_nofire_CO2_only; - outdata1b = 0; - outdata20 = 111; - } - } - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // Commodity, peat, not burned, temperate/boreal - { - outdata1a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata1b = 0 + peat_drain_total_non_CO2; - outdata20 = 12; - } - } - } - if (peat_data[x] == 0) // Commodity, not peat - { - if (burn_data[x] > 0) // Commodity, not peat, burned - { - if (ecozone_data[x] == tropical) // Commodity, not peat, burned, tropical - { - if (ifl_primary_data[x] == 1) // Commodity, not peat, burned, tropical, IFL - { - if (plant_data[x] >= 1) // Commodity, not peat, burned, tropical, IFL, plantation - { - outdata1a = Biomass_tCO2e_yesfire_CO2_only; - outdata1b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 13; - } - if (plant_data[x] == 0) // Commodity, not peat, burned, tropical, IFL, not plantation - { - outdata1a = Biomass_tCO2e_yesfire_CO2_only; // Standard model adds minsoil emissions here - outdata1b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 131; - } - } - if (ifl_primary_data[x] == 0) // Commodity, not peat, burned, tropical, not IFL - { - if (plant_data[x] >= 1) // Commodity, not peat, burned, tropical, not IFL, plantation - { - outdata1a = Biomass_tCO2e_yesfire_CO2_only; - outdata1b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 14; - } - if (plant_data[x] == 0) // Commodity, not peat, burned, tropical, not IFL, not plantation - { - outdata1a = Biomass_tCO2e_yesfire_CO2_only; // Standard model adds minsoil emissions here - outdata1b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 141; - } - } - } - if (ecozone_data[x] == boreal) // Commodity, not peat, burned, boreal - { - outdata1a = Biomass_tCO2e_yesfire_CO2_only; // Standard model adds minsoil emissions here - outdata1b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 15; - } - if (ecozone_data[x] == temperate) // Commodity, not peat, burned, temperate - { - if (plant_data[x] >= 1) // Commodity, not peat, burned, temperate, plantation - { - outdata1a = Biomass_tCO2e_yesfire_CO2_only; - outdata1b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 16; - } - if (plant_data[x] == 0) // Commodity, not peat, burned, temperate, no plantation - { - outdata1a = Biomass_tCO2e_yesfire_CO2_only; // Standard model adds minsoil emissions here - outdata1b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 161; - } - } - } - if (burn_data[x] == 0) // Commodity, not peat, not burned - { - if (ecozone_data[x] == tropical) // Commodity, not peat, not burned, tropical - { - if (plant_data[x] >= 1) // Commodity, not peat, not burned, tropical, plantation - { - outdata1a = Biomass_tCO2e_nofire_CO2_only; - outdata1b = 0; - outdata20 = 17; - } - if (plant_data[x] == 0) // Commodity, not peat, not burned, tropical, no plantation - { - outdata1a = Biomass_tCO2e_nofire_CO2_only; // Standard model adds minsoil emissions here - outdata1b = 0; - outdata20 = 171; - } - } - if (ecozone_data[x] == boreal) // Commodity, not peat, not burned, boreal - { - outdata1a = Biomass_tCO2e_nofire_CO2_only; // Standard model adds minsoil emissions here - outdata1b = 0; - outdata20 = 18; - } - if (ecozone_data[x] == temperate) // Commodity, not peat, not burned, temperate - { - if (plant_data[x] >= 1) // Commodity, not peat, not burned, temperate, plantation - { - outdata1a = Biomass_tCO2e_nofire_CO2_only; - outdata1b = 0; - outdata20 = 19; - } - if (plant_data[x] == 0) // Commodity, not peat, not burned, temperate, no plantation - { - outdata1a = Biomass_tCO2e_nofire_CO2_only; // Standard model adds minsoil emissions here - outdata1b = 0; - outdata20 = 191; - - ////QC code to get the values of the relevant variables at a particular pixel of interest (based on its values rather than its coordinates) - //double total; - //total = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only + Biomass_tCO2e_yesfire_non_CO2 + peat_drain_total_non_CO2 + peatburn_non_CO2; - //if ((total < 715) && (total > 714) && (agc_data[x] = 26.25) && (soil_data[x] = 216) && (dead_data[x] = 1.44) && (litter_data[x] = 0.5328) && (burn_data[x] = 6)) - //{ - // cout << "total: " << total << endl; - // cout << "Biomass_tCO2e_yesfire_CO2_only: " << Biomass_tCO2e_yesfire_CO2_only << endl; - // cout << "Biomass_tCO2e_yesfire_non_CO2: " << Biomass_tCO2e_yesfire_non_CO2 << endl; - // cout << "peat_drain_total_CO2_only: " << peat_drain_total_CO2_only << endl; - // cout << "peat_drain_total_non_CO2: " << peat_drain_total_non_CO2 << endl; - // cout << "peatburn_CO2_only: " << peatburn_CO2_only << endl; - // cout << "peatburn_non_CO2: " << peatburn_non_CO2 << endl; - // cout << "agc_data[x]: " << agc_data[x] << endl; - // cout << "Cf: " << Cf << endl; - // cout << "Gef_CO2: " << Gef_CO2 << endl; - // cout << "Gef_CH4: " << Gef_CH4 << endl; - // cout << "Gef_N2O: " << Gef_N2O << endl; - // cout << "" << endl; - //} - } - } - } - } - outdata1 = outdata1a + outdata1b; - } - - // Emissions model for shifting agriculture (only difference is flu val) - else if (drivermodel_data[x] == 2) - { - Biomass_tCO2e_nofire_CO2_only = non_soil_c * C_to_CO2; - Biomass_tCO2e_yesfire_CO2_only = (non_soil_c * C_to_CO2); - Biomass_tCO2e_yesfire_non_CO2 = ((non_soil_c / biomass_to_c) * Cf * Gef_CH4 * pow(10,-3) * CH4_equiv) + ((non_soil_c / biomass_to_c) * Cf * Gef_N2O * pow(10,-3) * N2O_equiv); - float shiftag_flu; - shiftag_flu = 0.72; - minsoil = ((soil_data[x]-(soil_data[x] * shiftag_flu))/soil_emis_period) * (model_years-loss_data[x]); // Not used in this sensitivity analysis for this driver - - if (peat_data[x] > 0) // Shifting ag, peat - { - if (burn_data[x] > 0) // Shifting ag, peat, burned - { - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // Shifting ag, peat, burned, temperate/boreal - { - outdata2a = Biomass_tCO2e_yesfire_CO2_only + peatburn_CO2_only; - outdata2b = Biomass_tCO2e_yesfire_non_CO2 + peatburn_non_CO2; - outdata20 = 20; - } - if (ecozone_data[x] == tropical) // Shifting ag, peat, burned, tropical - { - outdata2a = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_non_CO2; - outdata2b = Biomass_tCO2e_yesfire_non_CO2 + peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 21; - } - } - if (burn_data[x] == 0)// Shifting ag, peat, not burned - { - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // Shifting ag, peat, not burned, temperate/boreal - { - outdata2a = Biomass_tCO2e_nofire_CO2_only; - outdata2b = 0; - outdata20 = 22; - } - if (ecozone_data[x] == tropical) // Shifting ag, peat, not burned, tropical - { - if (plant_data[x] >= 1) // Shifting ag, peat, not burned, tropical, plantation - { - outdata2a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata2b = 0 + peat_drain_total_non_CO2; - outdata20 = 23; - } - if (plant_data[x] == 0) // Shifting ag, peat, not burned, tropical, not plantation - { - outdata2a = Biomass_tCO2e_nofire_CO2_only; - outdata2b = 0; - outdata20 = 231; - } - } - } - } - if (peat_data[x] == 0)// Shifting ag, not peat - { - if (burn_data[x] > 0) // Shifting ag, not peat, burned - { - if (ecozone_data[x] == tropical) // Shifting ag, not peat, burned, tropical - { - if (ifl_primary_data[x] == 1) // Shifting ag, not peat, burned, tropical, IFL - { - if (plant_data[x] >= 1) // Shifting ag, not peat, burned, tropical, IFL, plantation - { - outdata2a = Biomass_tCO2e_yesfire_CO2_only; - outdata2b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 24; - } - if (plant_data[x] == 0) // Shifting ag, not peat, burned, tropical, IFL, not plantation - { - outdata2a = Biomass_tCO2e_yesfire_CO2_only; // Standard model adds minsoil emissions here - outdata2b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 241; - } - } - if (ifl_primary_data[x] == 0) // Shifting ag, not peat, burned, tropical, not IFL - { - if (plant_data[x] >= 1) // Shifting ag, not peat, burned, tropical, not IFL, plantation - { - outdata2a = Biomass_tCO2e_yesfire_CO2_only; - outdata2b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 25; - } - if (plant_data[x] == 0) // Shifting ag, not peat, burned, tropical, not IFL, not plantation - { - outdata2a = Biomass_tCO2e_yesfire_CO2_only; // Standard model adds minsoil emissions here - outdata2b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 251; - } - } - } - if (ecozone_data[x] == boreal) // Shifting ag, not peat, burned, boreal - { - outdata2a = Biomass_tCO2e_yesfire_CO2_only; // Standard model adds minsoil emissions here - outdata2b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 26; - } - if (ecozone_data[x] == temperate) // Shifting ag, not peat, burned, temperate - { - if (plant_data[x] >= 1) // Shifting ag, not peat, burned, temperate, plantation - { - outdata2a = Biomass_tCO2e_yesfire_CO2_only; - outdata2b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 27; - } - if (plant_data[x] == 0) // Shifting ag, not peat, burned, temperate, no plantation - { - outdata2a = Biomass_tCO2e_yesfire_CO2_only; // Standard model adds minsoil emissions here - outdata2b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 271; - } - } - } - if (burn_data[x] == 0) // Shifting ag, not peat, not burned - { - if (ecozone_data[x] == tropical) // Shifting ag, not peat, not burned, tropical - { - if (plant_data[x] >= 1) // Shifting ag, not peat, not burned, tropical, plantation - { - outdata2a = Biomass_tCO2e_nofire_CO2_only; - outdata2b = 0; - outdata20 = 28; - } - if (plant_data[x] == 0) // Shifting ag, not peat, not burned, tropical, no plantation - { - outdata2a = Biomass_tCO2e_nofire_CO2_only; // Standard model adds minsoil emissions here - outdata2b = 0; - outdata20 = 281; - } - } - if (ecozone_data[x] == boreal) // Shifting ag, not peat, not burned, boreal - { - outdata2a = Biomass_tCO2e_nofire_CO2_only; // Standard model adds minsoil emissions here - outdata2b = 0; - outdata20 = 29; - } - if (ecozone_data[x] == temperate) // Shifting ag, not peat, not burned, temperate - { - if (plant_data[x] >= 1) // Shifting ag, not peat, not burned, temperate, plantation - { - outdata2a = Biomass_tCO2e_nofire_CO2_only; - outdata2b = 0; - outdata20 = 291; - } - if (plant_data[x] == 0) // Shifting ag, not peat, not burned, temperate, no plantation - { - outdata2a = Biomass_tCO2e_nofire_CO2_only; // Standard model adds minsoil emissions here - outdata2b = 0; - outdata20 = 292; - } - } - } - } - outdata2 = outdata2a + outdata2b; - } - - // Emissions model for forestry - else if (drivermodel_data[x] == 3) - { - Biomass_tCO2e_nofire_CO2_only = above_below_c * C_to_CO2; - Biomass_tCO2e_yesfire_CO2_only = ((agc_data[x] / biomass_to_c) * Cf * Gef_CO2 * pow(10, -3)); - Biomass_tCO2e_yesfire_non_CO2 = ((agc_data[x] / biomass_to_c) * Cf * Gef_CH4 * pow(10, -3) * CH4_equiv) + ((agc_data[x] / biomass_to_c) * Cf * Gef_N2O * pow(10, -3) * N2O_equiv); - - if (peat_data[x] > 0) // Forestry, peat - { - if (burn_data[x] > 0 ) // Forestry, peat, burned - { - outdata3a = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; - outdata3b = Biomass_tCO2e_yesfire_non_CO2 + peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 30; - } - if (burn_data[x] == 0 ) // Forestry, peat, not burned - { - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // Forestry, peat, not burned, temperate/boreal - { - outdata3a = Biomass_tCO2e_nofire_CO2_only; - outdata3b = 0; - outdata20 = 31; - } - if (ecozone_data[x] == tropical)// Forestry, peat, not burned, tropical - { - if (plant_data[x] > 0) // Forestry, peat, not burned, tropical, plantation - { - outdata3a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata3b = 0 + peat_drain_total_non_CO2; - outdata20 = 32; - } - if (plant_data[x] == 0) // Forestry, peat, not burned, tropical, not plantation - { - outdata3a = Biomass_tCO2e_nofire_CO2_only; - outdata3b = 0; - outdata20 = 321; - } - } - } - } - else - { - if (burn_data[x] > 0) // Forestry, not peat, burned - { - outdata3a = Biomass_tCO2e_yesfire_CO2_only; - outdata3b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 33; - } - if (burn_data[x] == 0) // Forestry, not peat, not burned - { - outdata3a = Biomass_tCO2e_nofire_CO2_only; - outdata3b = 0; - outdata20 = 34; - } - } - outdata3 = outdata3a + outdata3b; - } - - // Emissions model for wildfires - else if (drivermodel_data[x] == 4) - { - Biomass_tCO2e_nofire_CO2_only = above_below_c * C_to_CO2; - Biomass_tCO2e_yesfire_CO2_only = ((agc_data[x] / biomass_to_c) * Cf * Gef_CO2 * pow(10, -3)); - Biomass_tCO2e_yesfire_non_CO2 = ((agc_data[x] / biomass_to_c) * Cf * Gef_CH4 * pow(10, -3) * CH4_equiv) + ((agc_data[x] / biomass_to_c) * Cf * Gef_N2O * pow(10, -3) * N2O_equiv); - - if (peat_data[x] > 0) // Wildfire, peat - { - if (burn_data[x] > 0) // Wildfire, peat, burned - { - outdata4a = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; - outdata4b = Biomass_tCO2e_yesfire_non_CO2 + peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 40; - } - if (burn_data[x] == 0) // Wildfire, peat, not burned - { - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // Wildfire, peat, not burned, temperate/boreal - { - outdata4a = Biomass_tCO2e_nofire_CO2_only; - outdata4b = 0; - outdata20 = 41; - } - if (ecozone_data[x] == tropical) // Wildfire, peat, not burned, tropical - { - if (plant_data[x] > 0) // Wildfire, peat, not burned, tropical, plantation - { - outdata4a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata4b = 0 + peat_drain_total_non_CO2; - outdata20 = 42; - } - if (plant_data[x] == 0) // Wildfire, peat, not burned, tropical, not plantation - { - outdata4a = Biomass_tCO2e_nofire_CO2_only; - outdata4b = 0; - outdata20 = 421; - } - } - } - } - else // Wildfire, not peat - { - if (burn_data[x] > 0) // Wildfire, not peat, burned - { - outdata4a = Biomass_tCO2e_yesfire_CO2_only; - outdata4b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 43; - } - else // Wildfire, not peat, not burned - { - outdata4a = Biomass_tCO2e_nofire_CO2_only; - outdata4b = 0; - outdata20 = 44; - } - } - outdata4 = outdata4a + outdata4b; - } - - // Emissions model for urbanization - else if (drivermodel_data[x] == 5) - { - Biomass_tCO2e_nofire_CO2_only = non_soil_c * C_to_CO2; - Biomass_tCO2e_yesfire_CO2_only = (non_soil_c * C_to_CO2); - Biomass_tCO2e_yesfire_non_CO2 = ((non_soil_c / biomass_to_c) * Cf * Gef_CH4 * pow(10,-3) * CH4_equiv) + ((non_soil_c / biomass_to_c) * Cf * Gef_N2O * pow(10,-3) * N2O_equiv); - float urb_flu; - urb_flu = 0.8; - minsoil = ((soil_data[x]-(soil_data[x] * urb_flu))/soil_emis_period) * (model_years-loss_data[x]); - - if (peat_data[x] > 0) // Urbanization, peat - { - if (burn_data[x] > 0) // Urbanization, peat, burned - { - outdata5a = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; - outdata5b = Biomass_tCO2e_yesfire_non_CO2 + peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 50; - } - if (burn_data[x] == 0) // Urbanization, peat, not burned - { - if (ecozone_data[x] == tropical) // Urbanization, peat, not burned, tropical - { - if (plant_data[x] >= 1) // Urbanization, peat, not burned, tropical, plantation - { - outdata5a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata5b = 0 + peat_drain_total_non_CO2; - outdata20 = 51; - } - if (plant_data[x] == 0) // Urbanization, peat, not burned, tropical, not plantation - { - outdata5a = Biomass_tCO2e_nofire_CO2_only; - outdata5b = 0; - outdata20 = 511; - } - } - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // Urbanization, peat, not burned, temperate/boreal - { - outdata5a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata5b = 0 + peat_drain_total_non_CO2; - outdata20 = 52; - } - } - } - if (peat_data[x] == 0)// Urbanization, not peat - { - if (burn_data[x] > 0) // Urbanization, not peat, burned - { - if (ecozone_data[x] == tropical) // Urbanization, not peat, burned, tropical - { - if (ifl_primary_data[x] == 1) // Urbanization, not peat, burned, tropical, IFL - { - if (plant_data[x] >= 1) // Urbanization, not peat, burned, tropical, IFL, plantation - { - outdata5a = Biomass_tCO2e_yesfire_CO2_only; - outdata5b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 53; - } - if (plant_data[x] == 0) // Urbanization, not peat, burned, tropical, IFL, not plantation - { - outdata5a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata5b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 531; - } - } - if (ifl_primary_data[x] == 0) // Urbanization, not peat, burned, tropical, not IFL - { - if (plant_data[x] >= 1) // Urbanization, not peat, burned, tropical, not IFL, plantation - { - outdata5a = Biomass_tCO2e_yesfire_CO2_only; - outdata5b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 54; - } - if (plant_data[x] == 0) // Urbanization, not peat, burned, tropical, not IFL, not plantation - { - outdata5a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata5b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 541; - } - } - } - if (ecozone_data[x] == boreal) // Urbanization, not peat, burned, boreal - { - outdata5a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata5b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 55; - } - if (ecozone_data[x] == temperate) // Urbanization, not peat, burned, temperate - { - if (plant_data[x] >= 1) // Urbanization, not peat, burned, temperate, plantation - { - outdata5a = Biomass_tCO2e_yesfire_CO2_only; - outdata5b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 56; - } - if (plant_data[x] == 0) // Urbanization, not peat, burned, temperate, no plantation - { - outdata5a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata5b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 561; - } - } - } - if (burn_data[x] == 0) // Urbanization, not peat, not burned - { - if (ecozone_data[x] == tropical) // Urbanization, not peat, not burned, tropical - { - if (plant_data[x] >= 1) // Urbanization, not peat, not burned, tropical, plantation - { - outdata5a = Biomass_tCO2e_nofire_CO2_only; - outdata5b = 0; - outdata20 = 57; - } - if (plant_data[x] == 0) // Urbanization, not peat, not burned, tropical, no plantation - { - outdata5a = Biomass_tCO2e_nofire_CO2_only + minsoil; - outdata5b = 0; - outdata20 = 571; - } - } - if (ecozone_data[x] == boreal) // Urbanization, not peat, not burned, boreal - { - outdata5a = Biomass_tCO2e_nofire_CO2_only + minsoil; - outdata5b = 0; - outdata20 = 58; - } - if (ecozone_data[x] == temperate) // Urbanization, not peat, not burned, temperate - { - if (plant_data[x] >= 1) // Urbanization, not peat, not burned, temperate, plantation - { - outdata5a = Biomass_tCO2e_nofire_CO2_only; - outdata5b = 0; - outdata20 = 59; - } - if (plant_data[x] == 0) // Urbanization, not peat, not burned, temperate, no plantation - { - outdata5a = Biomass_tCO2e_nofire_CO2_only + minsoil; - outdata5b = 0; - outdata20 = 591; - } - } - } - } - outdata5 = outdata5a + outdata5b; - } - - // Emissions for where there is no driver model. - // Nancy said to make this the same as forestry. - else - { - Biomass_tCO2e_nofire_CO2_only = above_below_c * C_to_CO2; - Biomass_tCO2e_yesfire_CO2_only = ((agc_data[x] / biomass_to_c) * Cf * Gef_CO2 * pow(10, -3)); - Biomass_tCO2e_yesfire_non_CO2 = ((agc_data[x] / biomass_to_c) * Cf * Gef_CH4 * pow(10, -3) * CH4_equiv) + ((agc_data[x] / biomass_to_c) * Cf * Gef_N2O * pow(10, -3) * N2O_equiv); - - if (peat_data[x] > 0) // No driver, peat - { - if (burn_data[x] > 0 ) // No driver, peat, burned - { - outdata6a = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; - outdata6b = Biomass_tCO2e_yesfire_non_CO2 + peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 60; - } - if (burn_data[x] == 0 ) // No driver, peat, not burned - { - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // No driver, peat, not burned, temperate/boreal - { - outdata6a = Biomass_tCO2e_nofire_CO2_only; - outdata6b = 0; - outdata20 = 61; - } - if (ecozone_data[x] == tropical)// No driver, peat, not burned, tropical - { - if (plant_data[x] > 0) // No driver, peat, not burned, tropical, plantation - { - outdata6a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata6b = 0 + peat_drain_total_non_CO2; - outdata20 = 62; - } - if (plant_data[x] == 0) // No driver, peat, not burned, tropical, not plantation - { - outdata6a = Biomass_tCO2e_nofire_CO2_only; - outdata6b = 0; - outdata20 = 621; - } - } - } - } - else - { - if (burn_data[x] > 0) // No driver, not peat, burned - { - outdata6a = Biomass_tCO2e_yesfire_CO2_only; - outdata6b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 63; - } - if (burn_data[x] == 0) // No driver, not peat, not burned - { - outdata6a = Biomass_tCO2e_nofire_CO2_only; - outdata6b = 0; - outdata20 = 64; - } - } - outdata6 = outdata6a + outdata6b; - } - - // Write the value to the correct raster - if (drivermodel_data[x] == 1) // Commodities - { - out_data1[x] = outdata1; - out_data2[x] = 0; - out_data3[x] = 0; - out_data4[x] = 0; - out_data5[x] = 0; - out_data6[x] = 0; - } - else if (drivermodel_data[x] == 2) // Shifting ag - { - out_data1[x] = 0; - out_data2[x] = outdata2; - out_data3[x] = 0; - out_data4[x] = 0; - out_data5[x] = 0; - out_data6[x] = 0; - } - else if (drivermodel_data[x] == 3) // Forestry - { - out_data1[x] = 0; - out_data2[x] = 0; - out_data3[x] = outdata3; - out_data4[x] = 0; - out_data5[x] = 0; - out_data6[x] = 0; - } - else if (drivermodel_data[x] == 4) // Wildfire - { - out_data1[x] = 0; - out_data2[x] = 0; - out_data3[x] = 0; - out_data4[x] = outdata4; - out_data5[x] = 0; - out_data6[x] = 0; - } - else if (drivermodel_data[x] == 5) // Urbanization - { - out_data1[x] = 0; - out_data2[x] = 0; - out_data3[x] = 0; - out_data4[x] = 0; - out_data5[x] = outdata5; - out_data6[x] = 0; - } - else // No driver - { - out_data1[x] = 0; - out_data2[x] = 0; - out_data3[x] = 0; - out_data4[x] = 0; - out_data5[x] = 0; - out_data6[x] = outdata6; - } - // Decision tree end node value stored in its raster - out_data20[x] = outdata20; - - - // Add up all drivers for a combined raster. Each pixel only has one driver - outdata10 = outdata1 + outdata2 + outdata3 + outdata4 + outdata5 + outdata6; - outdata11 = outdata1a + outdata2a + outdata3a + outdata4a + outdata5a + outdata6a; - outdata12 = outdata1b + outdata2b + outdata3b + outdata4b + outdata5b + outdata6b; - - if (outdata10 == 0) - { - out_data10[x] = 0; - out_data11[x] = 0; - out_data12[x] = 0; - } - else{ - out_data10[x] = outdata10; - out_data11[x] = outdata11; - out_data12[x] = outdata12; - } - } - - // If pixel is not on loss and carbon, all output rasters get 0 - else - { - - out_data1[x] = 0; - out_data2[x] = 0; - out_data3[x] = 0; - out_data4[x] = 0; - out_data5[x] = 0; - out_data6[x] = 0; - out_data10[x] = 0; - out_data11[x] = 0; - out_data12[x] = 0; - out_data20[x] = 0; - } - } - -OUTBAND1->RasterIO( GF_Write, 0, y, xsize, 1, out_data1, xsize, 1, GDT_Float32, 0, 0 ); -OUTBAND2->RasterIO( GF_Write, 0, y, xsize, 1, out_data2, xsize, 1, GDT_Float32, 0, 0 ); -OUTBAND3->RasterIO( GF_Write, 0, y, xsize, 1, out_data3, xsize, 1, GDT_Float32, 0, 0 ); -OUTBAND4->RasterIO( GF_Write, 0, y, xsize, 1, out_data4, xsize, 1, GDT_Float32, 0, 0 ); -OUTBAND5->RasterIO( GF_Write, 0, y, xsize, 1, out_data5, xsize, 1, GDT_Float32, 0, 0 ); -OUTBAND6->RasterIO( GF_Write, 0, y, xsize, 1, out_data6, xsize, 1, GDT_Float32, 0, 0 ); -OUTBAND10->RasterIO( GF_Write, 0, y, xsize, 1, out_data10, xsize, 1, GDT_Float32, 0, 0 ); -OUTBAND11->RasterIO( GF_Write, 0, y, xsize, 1, out_data11, xsize, 1, GDT_Float32, 0, 0 ); -OUTBAND12->RasterIO( GF_Write, 0, y, xsize, 1, out_data12, xsize, 1, GDT_Float32, 0, 0 ); -OUTBAND20->RasterIO( GF_Write, 0, y, xsize, 1, out_data20, xsize, 1, GDT_Float32, 0, 0 ); -} - -GDALClose(INGDAL1); -GDALClose((GDALDatasetH)OUTGDAL1); -GDALClose((GDALDatasetH)OUTGDAL2); -GDALClose((GDALDatasetH)OUTGDAL3); -GDALClose((GDALDatasetH)OUTGDAL4); -GDALClose((GDALDatasetH)OUTGDAL5); -GDALClose((GDALDatasetH)OUTGDAL6); -GDALClose((GDALDatasetH)OUTGDAL10); -GDALClose((GDALDatasetH)OUTGDAL11); -GDALClose((GDALDatasetH)OUTGDAL12); -GDALClose((GDALDatasetH)OUTGDAL20); -return 0; -} \ No newline at end of file diff --git a/emissions/cpp_util/calc_gross_emissions_generic.cpp b/emissions/cpp_util/calc_gross_emissions_generic.cpp index 8c1ae09d..1e8ce461 100644 --- a/emissions/cpp_util/calc_gross_emissions_generic.cpp +++ b/emissions/cpp_util/calc_gross_emissions_generic.cpp @@ -11,8 +11,8 @@ // Each end point of the decision tree gets its own code, so that it's easier to tell what branch of the decision tree // each pixel came from. That makes checking the results easier, too. // These codes are summarized in carbon-budget/emissions/node_codes.txt -// Because emissions are separately output for CO2 and non-CO2 gases (CH4 and N2O), each model endpoint has a CO2-only and -// a non-CO2 value. These are summed to create a total emissions (all gases) for each pixel. +// Because emissions are separately output for CO2, CH4, and N2O, each model endpoint has an emissions raster for each GHG. +// CH4 and N2O are summed to create a non-CO2 emissions raster and all three GHGs are summed to create a total emissions (all gases) for each pixel. // Compile with: // c++ /usr/local/app/emissions/cpp_util/calc_gross_emissions_generic.cpp -o /usr/local/app/emissions/cpp_util/calc_gross_emissions_generic.exe -lgdal @@ -84,11 +84,14 @@ boreal = constants::boreal; int soil_emis_period; // The number of years over which soil emissions are calculated (separate from model years) soil_emis_period = constants::soil_emis_period; -float shiftag_flu; // F_lu for shifting agriculture (fraction of soil C not emitted over 20 years) -shiftag_flu = constants::shiftag_flu; +float shift_cult_flu; // F_lu for shifting cultivation (fraction of soil C not emitted over 20 years) +shift_cult_flu = constants::shift_cult_flu; -float urb_flu; // F_lu for urbanization (fraction of soil C not emitted over 20 years) -urb_flu = constants::urb_flu; +float settlements_flu; // F_lu for settlements and infrastructure (fraction of soil C not emitted over 20 years) +settlements_flu = constants::settlements_flu; + +float hard_commod_flu; // F_lu for hard_commodities (fraction of soil C not emitted over 20 years) +hard_commod_flu = constants::hard_commod_flu; // Input files @@ -123,31 +126,22 @@ string peat_name = infolder + tile_id + constants::peat_mask; string ifl_primary_name = infolder + tile_id + constants::ifl_primary; string plant_name = infolder + tile_id + constants::plantation_type; -// Output files: tonnes CO2/ha for each tree cover loss driver, their total, and the node for the decision tree -// that determines emissions +// Output files: tonnes CO2/ha for each output and the node for the decision tree that determines emissions // Output files default to the standard model names -string out_name1 = tile_id + constants::commod_emis + model_years_str + ".tif"; -string out_name2 = tile_id + constants::shifting_ag_emis + model_years_str + ".tif"; -string out_name3 = tile_id + constants::forestry_emis + model_years_str + ".tif"; -string out_name4 = tile_id + constants::wildfire_emis + model_years_str + ".tif"; -string out_name5 = tile_id + constants::urbanization_emis + model_years_str + ".tif"; -string out_name6 = tile_id + constants::no_driver_emis + model_years_str + ".tif"; -string out_name10 = tile_id + constants::all_gases_all_drivers_emis + model_years_str + ".tif"; -string out_name11 = tile_id + constants::CO2_only_all_drivers_emis + model_years_str + ".tif"; -string out_name12 = tile_id + constants::non_CO2_all_drivers_emis + model_years_str + ".tif"; -string out_name20 = tile_id + constants::decision_tree_all_drivers_emis + model_years_str + ".tif"; +string out_name_all_gases_all_drivers = tile_id + constants::all_gases_all_drivers_emis + model_years_str + ".tif"; +string out_name_CO2_only_all_drivers = tile_id + constants::CO2_only_all_drivers_emis + model_years_str + ".tif"; +string out_name_non_CO2_all_drivers = tile_id + constants::non_CO2_all_drivers_emis + model_years_str + ".tif"; +string out_name_CH4_only_all_drivers = tile_id + constants::CH4_only_all_drivers_emis + model_years_str + ".tif"; +string out_name_N2O_only_all_drivers = tile_id + constants::N2O_only_all_drivers_emis + model_years_str + ".tif"; +string out_name_node_code = tile_id + constants::decision_tree_all_drivers_emis + model_years_str + ".tif"; if (sensit_type != "std") { - out_name1 = tile_id + constants::commod_emis + model_years_str + "_" + sensit_type + ".tif"; - out_name2 = tile_id + constants::shifting_ag_emis + model_years_str + "_" + sensit_type + ".tif"; - out_name3 = tile_id + constants::forestry_emis + model_years_str + "_" + sensit_type + ".tif"; - out_name4 = tile_id + constants::wildfire_emis + model_years_str + "_" + sensit_type + ".tif"; - out_name5 = tile_id + constants::urbanization_emis + model_years_str + "_" + sensit_type + ".tif"; - out_name6 = tile_id + constants::no_driver_emis + model_years_str + "_" + sensit_type + ".tif"; - out_name10 = tile_id + constants::all_gases_all_drivers_emis + model_years_str + "_" + sensit_type + ".tif"; - out_name11 = tile_id + constants::CO2_only_all_drivers_emis + model_years_str + "_" + sensit_type + ".tif"; - out_name12 = tile_id + constants::non_CO2_all_drivers_emis + model_years_str + "_" + sensit_type + ".tif"; - out_name20 = tile_id + constants::decision_tree_all_drivers_emis + model_years_str + "_" + sensit_type + ".tif"; + out_name_all_gases_all_drivers = tile_id + constants::all_gases_all_drivers_emis + model_years_str + "_" + sensit_type + ".tif"; + out_name_CO2_only_all_drivers = tile_id + constants::CO2_only_all_drivers_emis + model_years_str + "_" + sensit_type + ".tif"; + out_name_non_CO2_all_drivers = tile_id + constants::non_CO2_all_drivers_emis + model_years_str + "_" + sensit_type + ".tif"; + out_name_CH4_only_all_drivers = tile_id + constants::CH4_only_all_drivers_emis + model_years_str + "_" + sensit_type + ".tif"; + out_name_N2O_only_all_drivers = tile_id + constants::N2O_only_all_drivers_emis + model_years_str + "_" + sensit_type + ".tif"; + out_name_node_code = tile_id + constants::decision_tree_all_drivers_emis + model_years_str + "_" + sensit_type + ".tif"; } //// Print input and output tile names @@ -164,17 +158,6 @@ if (sensit_type != "std") { //cout << "peat tile:" << peat_name << endl; //cout << "ifl tile:" << ifl_primary_name << endl; //cout << "plantation tile:" << plant_name << endl; -// -//cout << "commod tile:" << out_name1 << endl; -//cout << "shifting ag tile:" << out_name2 << endl; -//cout << "forestry tile:" << out_name3 << endl; -//cout << "wildfire tile:" << out_name4 << endl; -//cout << "urbanization tile:" << out_name5 << endl; -//cout << "no driver tile:" << out_name6 << endl; -//cout << "all gases tile:" << out_name10 << endl; -//cout << "CO2 only tile:" << out_name11 << endl; -//cout << "non-CO2 tile:" << out_name12 << endl; -//cout << "decision tree tile:" << out_name20 << endl; // Setting up the variables to hold the pixel location in x/y values @@ -186,64 +169,64 @@ double ulx, uly; double pixelsize; // Initialize GDAL for reading. // Each of these "INBAND" are later associated with the string variables defined above. GDALAllRegister(); -GDALDataset *INGDAL1; GDALRasterBand *INBAND1; -GDALDataset *INGDAL2; GDALRasterBand *INBAND2; -GDALDataset *INGDAL3; GDALRasterBand *INBAND3; -GDALDataset *INGDAL4; GDALRasterBand *INBAND4; -GDALDataset *INGDAL5; GDALRasterBand *INBAND5; -GDALDataset *INGDAL6; GDALRasterBand *INBAND6; -GDALDataset *INGDAL7; GDALRasterBand *INBAND7; -GDALDataset *INGDAL8; GDALRasterBand *INBAND8; -GDALDataset *INGDAL9; GDALRasterBand *INBAND9; -GDALDataset *INGDAL10; GDALRasterBand *INBAND10; -GDALDataset *INGDAL11; GDALRasterBand *INBAND11; -GDALDataset *INGDAL12; GDALRasterBand *INBAND12; -GDALDataset *INGDAL13; GDALRasterBand *INBAND13; +GDALDataset *INGDAL_AGC; GDALRasterBand *INBAND_AGC; +GDALDataset *INGDAL_BGC; GDALRasterBand *INBAND_BGC; +GDALDataset *INGDAL_DRIVERMODEL; GDALRasterBand *INBAND_DRIVERMODEL; +GDALDataset *INGDAL_LOSS; GDALRasterBand *INBAND_LOSS; +GDALDataset *INGDAL_PEAT; GDALRasterBand *INBAND_PEAT; +GDALDataset *INGDAL_BURN; GDALRasterBand *INBAND_BURN; +GDALDataset *INGDAL_IFL_PRIMARY; GDALRasterBand *INBAND_IFL_PRIMARY; +GDALDataset *INGDAL_ECOZONE; GDALRasterBand *INBAND_ECOZONE; +GDALDataset *INGDAL_CLIMATE; GDALRasterBand *INBAND_CLIMATE; +GDALDataset *INGDAL_DEAD; GDALRasterBand *INBAND_DEAD; +GDALDataset *INGDAL_LITTER; GDALRasterBand *INBAND_LITTER; +GDALDataset *INGDAL_SOIL; GDALRasterBand *INBAND_SOIL; +GDALDataset *INGDAL_PLANT; GDALRasterBand *INBAND_PLANT; //open file (string variables defined above) and assign it extent and projection -INGDAL1 = (GDALDataset *) GDALOpen(agc_name.c_str(), GA_ReadOnly ); -INBAND1 = INGDAL1->GetRasterBand(1); +INGDAL_AGC = (GDALDataset *) GDALOpen(agc_name.c_str(), GA_ReadOnly ); +INBAND_AGC = INGDAL_AGC->GetRasterBand(1); -INGDAL2 = (GDALDataset *) GDALOpen(bgc_name.c_str(), GA_ReadOnly ); -INBAND2 = INGDAL2->GetRasterBand(1); +INGDAL_BGC = (GDALDataset *) GDALOpen(bgc_name.c_str(), GA_ReadOnly ); +INBAND_BGC = INGDAL_BGC->GetRasterBand(1); -INGDAL3 = (GDALDataset *) GDALOpen(drivermodel_name.c_str(), GA_ReadOnly ); -INBAND3 = INGDAL3->GetRasterBand(1); +INGDAL_DRIVERMODEL = (GDALDataset *) GDALOpen(drivermodel_name.c_str(), GA_ReadOnly ); +INBAND_DRIVERMODEL = INGDAL_DRIVERMODEL->GetRasterBand(1); -INGDAL4 = (GDALDataset *) GDALOpen(loss_name.c_str(), GA_ReadOnly ); -INBAND4 = INGDAL4->GetRasterBand(1); +INGDAL_LOSS = (GDALDataset *) GDALOpen(loss_name.c_str(), GA_ReadOnly ); +INBAND_LOSS = INGDAL_LOSS->GetRasterBand(1); -INGDAL5 = (GDALDataset *) GDALOpen(peat_name.c_str(), GA_ReadOnly ); -INBAND5 = INGDAL5->GetRasterBand(1); +INGDAL_PEAT = (GDALDataset *) GDALOpen(peat_name.c_str(), GA_ReadOnly ); +INBAND_PEAT = INGDAL_PEAT->GetRasterBand(1); -INGDAL6 = (GDALDataset *) GDALOpen(burn_name.c_str(), GA_ReadOnly ); -INBAND6 = INGDAL6->GetRasterBand(1); +INGDAL_BURN = (GDALDataset *) GDALOpen(burn_name.c_str(), GA_ReadOnly ); +INBAND_BURN = INGDAL_BURN->GetRasterBand(1); -INGDAL7 = (GDALDataset *) GDALOpen(ifl_primary_name.c_str(), GA_ReadOnly ); -INBAND7 = INGDAL7->GetRasterBand(1); +INGDAL_IFL_PRIMARY = (GDALDataset *) GDALOpen(ifl_primary_name.c_str(), GA_ReadOnly ); +INBAND_IFL_PRIMARY = INGDAL_IFL_PRIMARY->GetRasterBand(1); -INGDAL8 = (GDALDataset *) GDALOpen(ecozone_name.c_str(), GA_ReadOnly ); -INBAND8 = INGDAL8->GetRasterBand(1); +INGDAL_ECOZONE = (GDALDataset *) GDALOpen(ecozone_name.c_str(), GA_ReadOnly ); +INBAND_ECOZONE = INGDAL_ECOZONE->GetRasterBand(1); -INGDAL9 = (GDALDataset *) GDALOpen(climate_name.c_str(), GA_ReadOnly ); -INBAND9 = INGDAL9->GetRasterBand(1); +INGDAL_CLIMATE = (GDALDataset *) GDALOpen(climate_name.c_str(), GA_ReadOnly ); +INBAND_CLIMATE = INGDAL_CLIMATE->GetRasterBand(1); -INGDAL10 = (GDALDataset *) GDALOpen(dead_name.c_str(), GA_ReadOnly ); -INBAND10 = INGDAL10->GetRasterBand(1); +INGDAL_DEAD = (GDALDataset *) GDALOpen(dead_name.c_str(), GA_ReadOnly ); +INBAND_DEAD = INGDAL_DEAD->GetRasterBand(1); -INGDAL11 = (GDALDataset *) GDALOpen(litter_name.c_str(), GA_ReadOnly ); -INBAND11 = INGDAL11->GetRasterBand(1); +INGDAL_LITTER = (GDALDataset *) GDALOpen(litter_name.c_str(), GA_ReadOnly ); +INBAND_LITTER = INGDAL_LITTER->GetRasterBand(1); -INGDAL12 = (GDALDataset *) GDALOpen(soil_name.c_str(), GA_ReadOnly ); -INBAND12 = INGDAL12->GetRasterBand(1); +INGDAL_SOIL = (GDALDataset *) GDALOpen(soil_name.c_str(), GA_ReadOnly ); +INBAND_SOIL = INGDAL_SOIL->GetRasterBand(1); -INGDAL13 = (GDALDataset *) GDALOpen(plant_name.c_str(), GA_ReadOnly ); -INBAND13 = INGDAL13->GetRasterBand(1); +INGDAL_PLANT = (GDALDataset *) GDALOpen(plant_name.c_str(), GA_ReadOnly ); +INBAND_PLANT = INGDAL_PLANT->GetRasterBand(1); -// The rest of the code runs on the size of INBAND3. This can be changed. -xsize=INBAND1->GetXSize(); -ysize=INBAND1->GetYSize(); -INGDAL1->GetGeoTransform(GeoTransform); +// The rest of the code runs on the size of INBAND_DRIVERMODEL. This can be changed. +xsize=INBAND_AGC->GetXSize(); +ysize=INBAND_AGC->GetYSize(); +INGDAL_AGC->GetGeoTransform(GeoTransform); ulx=GeoTransform[0]; uly=GeoTransform[3]; @@ -258,27 +241,19 @@ cout << "Gross emissions generic model C++ parameters: " << xsize <<", "<< ysize // Initialize GDAL for writing GDALDriver *OUTDRIVER; -GDALDataset *OUTGDAL1; // Commodities, all gases -GDALDataset *OUTGDAL2; // Shifting ag, all gases -GDALDataset *OUTGDAL3; // Forestry, all gases -GDALDataset *OUTGDAL4; // Wildfire, all gases -GDALDataset *OUTGDAL5; // Urbanization, all gases -GDALDataset *OUTGDAL6; // No driver, all gases -GDALDataset *OUTGDAL10; // All drivers, all gases -GDALDataset *OUTGDAL11; // All drivers, CO2 only -GDALDataset *OUTGDAL12; // All drivers, non-CO2 -GDALDataset *OUTGDAL20; // Decision tree node - -GDALRasterBand *OUTBAND1; -GDALRasterBand *OUTBAND2; -GDALRasterBand *OUTBAND3; -GDALRasterBand *OUTBAND4; -GDALRasterBand *OUTBAND5; -GDALRasterBand *OUTBAND6; -GDALRasterBand *OUTBAND10; -GDALRasterBand *OUTBAND11; -GDALRasterBand *OUTBAND12; -GDALRasterBand *OUTBAND20; +GDALDataset *OUTGDAL_ALLDRIVERS_ALLGASSES; // All drivers, all gases +GDALDataset *OUTGDAL_ALLDRIVERS_CO2ONLY; // All drivers, CO2 only +GDALDataset *OUTGDAL_ALLDRIVERS_NONCO2; // All drivers, non-CO2 (methane + nitrous oxide) +GDALDataset *OUTGDAL_ALLDRIVERS_CH4ONLY; // All drivers, methane +GDALDataset *OUTGDAL_ALLDRIVERS_N2OONLY; // All drivers, nitrous oxide +GDALDataset *OUTGDAL_NODE_CODE; // Decision tree node + +GDALRasterBand *OUTBAND_ALLDRIVERS_ALLGASSES; +GDALRasterBand *OUTBAND_ALLDRIVERS_CO2ONLY; +GDALRasterBand *OUTBAND_ALLDRIVERS_NONCO2; +GDALRasterBand *OUTBAND_ALLDRIVERS_CH4ONLY; +GDALRasterBand *OUTBAND_ALLDRIVERS_N2OONLY; +GDALRasterBand *OUTBAND_NODE_CODE; OGRSpatialReference oSRS; char *OUTPRJ = NULL; @@ -290,65 +265,41 @@ oSRS.SetWellKnownGeogCS( "WGS84" ); oSRS.exportToWkt( &OUTPRJ ); double adfGeoTransform[6] = { ulx, pixelsize, 0, uly, 0, -1*pixelsize }; -// Commoditiy gross emissions -OUTGDAL1 = OUTDRIVER->Create( out_name1.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL1->SetGeoTransform(adfGeoTransform); OUTGDAL1->SetProjection(OUTPRJ); -OUTBAND1 = OUTGDAL1->GetRasterBand(1); -OUTBAND1->SetNoDataValue(0); - -// Shifting ag gross emissions -OUTGDAL2 = OUTDRIVER->Create( out_name2.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL2->SetGeoTransform(adfGeoTransform); OUTGDAL2->SetProjection(OUTPRJ); -OUTBAND2 = OUTGDAL2->GetRasterBand(1); -OUTBAND2->SetNoDataValue(0); - -// Forestry gross emissions -OUTGDAL3 = OUTDRIVER->Create( out_name3.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL3->SetGeoTransform(adfGeoTransform); OUTGDAL3->SetProjection(OUTPRJ); -OUTBAND3 = OUTGDAL3->GetRasterBand(1); -OUTBAND3->SetNoDataValue(0); - -// Wildfire gross emissions -OUTGDAL4 = OUTDRIVER->Create( out_name4.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL4->SetGeoTransform(adfGeoTransform); OUTGDAL4->SetProjection(OUTPRJ); -OUTBAND4 = OUTGDAL4->GetRasterBand(1); -OUTBAND4->SetNoDataValue(0); - -// Urbanization gross emissions -OUTGDAL5 = OUTDRIVER->Create( out_name5.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL5->SetGeoTransform(adfGeoTransform); OUTGDAL5->SetProjection(OUTPRJ); -OUTBAND5 = OUTGDAL5->GetRasterBand(1); -OUTBAND5->SetNoDataValue(0); - -// No driver gross emissions -OUTGDAL6 = OUTDRIVER->Create( out_name6.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL6->SetGeoTransform(adfGeoTransform); OUTGDAL6->SetProjection(OUTPRJ); -OUTBAND6 = OUTGDAL6->GetRasterBand(1); -OUTBAND6->SetNoDataValue(0); - // All gases, all drivers combined -OUTGDAL10 = OUTDRIVER->Create( out_name10.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL10->SetGeoTransform(adfGeoTransform); OUTGDAL10->SetProjection(OUTPRJ); -OUTBAND10 = OUTGDAL10->GetRasterBand(1); -OUTBAND10->SetNoDataValue(0); +OUTGDAL_ALLDRIVERS_ALLGASSES = OUTDRIVER->Create( out_name_all_gases_all_drivers.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); +OUTGDAL_ALLDRIVERS_ALLGASSES->SetGeoTransform(adfGeoTransform); OUTGDAL_ALLDRIVERS_ALLGASSES->SetProjection(OUTPRJ); +OUTBAND_ALLDRIVERS_ALLGASSES = OUTGDAL_ALLDRIVERS_ALLGASSES->GetRasterBand(1); +OUTBAND_ALLDRIVERS_ALLGASSES->SetNoDataValue(0); // CO2 only, all drivers combined -OUTGDAL11 = OUTDRIVER->Create( out_name11.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL11->SetGeoTransform(adfGeoTransform); OUTGDAL11->SetProjection(OUTPRJ); -OUTBAND11 = OUTGDAL11->GetRasterBand(1); -OUTBAND11->SetNoDataValue(0); +OUTGDAL_ALLDRIVERS_CO2ONLY = OUTDRIVER->Create( out_name_CO2_only_all_drivers.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); +OUTGDAL_ALLDRIVERS_CO2ONLY->SetGeoTransform(adfGeoTransform); OUTGDAL_ALLDRIVERS_CO2ONLY->SetProjection(OUTPRJ); +OUTBAND_ALLDRIVERS_CO2ONLY = OUTGDAL_ALLDRIVERS_CO2ONLY->GetRasterBand(1); +OUTBAND_ALLDRIVERS_CO2ONLY->SetNoDataValue(0); // Non-CO2, all drivers combined -OUTGDAL12 = OUTDRIVER->Create( out_name12.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL12->SetGeoTransform(adfGeoTransform); OUTGDAL12->SetProjection(OUTPRJ); -OUTBAND12 = OUTGDAL12->GetRasterBand(1); -OUTBAND12->SetNoDataValue(0); +OUTGDAL_ALLDRIVERS_NONCO2 = OUTDRIVER->Create( out_name_non_CO2_all_drivers.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); +OUTGDAL_ALLDRIVERS_NONCO2->SetGeoTransform(adfGeoTransform); OUTGDAL_ALLDRIVERS_NONCO2->SetProjection(OUTPRJ); +OUTBAND_ALLDRIVERS_NONCO2 = OUTGDAL_ALLDRIVERS_NONCO2->GetRasterBand(1); +OUTBAND_ALLDRIVERS_NONCO2->SetNoDataValue(0); + +// CH4 only, all drivers combined +OUTGDAL_ALLDRIVERS_CH4ONLY = OUTDRIVER->Create( out_name_CH4_only_all_drivers.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); +OUTGDAL_ALLDRIVERS_CH4ONLY->SetGeoTransform(adfGeoTransform); OUTGDAL_ALLDRIVERS_CH4ONLY->SetProjection(OUTPRJ); +OUTBAND_ALLDRIVERS_CH4ONLY = OUTGDAL_ALLDRIVERS_CH4ONLY->GetRasterBand(1); +OUTBAND_ALLDRIVERS_CH4ONLY->SetNoDataValue(0); + +// N2O only, all drivers combined +OUTGDAL_ALLDRIVERS_N2OONLY = OUTDRIVER->Create( out_name_N2O_only_all_drivers.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); +OUTGDAL_ALLDRIVERS_N2OONLY->SetGeoTransform(adfGeoTransform); OUTGDAL_ALLDRIVERS_N2OONLY->SetProjection(OUTPRJ); +OUTBAND_ALLDRIVERS_N2OONLY = OUTGDAL_ALLDRIVERS_N2OONLY->GetRasterBand(1); +OUTBAND_ALLDRIVERS_N2OONLY->SetNoDataValue(0); // Decision tree node -OUTGDAL20 = OUTDRIVER->Create( out_name20.c_str(), xsize, ysize, 1, GDT_UInt16, papszOptions ); -OUTGDAL20->SetGeoTransform(adfGeoTransform); OUTGDAL20->SetProjection(OUTPRJ); -OUTBAND20 = OUTGDAL20->GetRasterBand(1); -OUTBAND20->SetNoDataValue(0); +OUTGDAL_NODE_CODE = OUTDRIVER->Create( out_name_node_code.c_str(), xsize, ysize, 1, GDT_UInt16, papszOptions ); +OUTGDAL_NODE_CODE->SetGeoTransform(adfGeoTransform); OUTGDAL_NODE_CODE->SetProjection(OUTPRJ); +OUTBAND_NODE_CODE = OUTGDAL_NODE_CODE->GetRasterBand(1); +OUTBAND_NODE_CODE->SetNoDataValue(0); // Read/write data @@ -368,16 +319,21 @@ float ifl_primary_data[xsize]; float plant_data[xsize]; // Outputs -float out_data1[xsize]; -float out_data2[xsize]; -float out_data3[xsize]; -float out_data4[xsize]; -float out_data5[xsize]; -float out_data6[xsize]; -float out_data10[xsize]; -float out_data11[xsize]; -float out_data12[xsize]; -short int out_data20[xsize]; +float out_data_permanent_agriculture[xsize]; // 1 +float out_data_hard_commodities[xsize]; // 2 +float out_data_shifting_cultivation[xsize]; // 3 +float out_data_forest_management[xsize]; // 4 +float out_data_wildfire[xsize]; // 5 +float out_data_settlements[xsize]; // 6 +float out_data_other_disturbances[xsize]; // 7 +float out_data_no_driver[xsize]; // Null + +float out_data_alldrivers_allgasses[xsize]; +float out_data_alldrivers_CO2only[xsize]; +float out_data_alldrivers_nonCO2[xsize]; +float out_data_alldrivers_CH4only[xsize]; +float out_data_alldrivers_N2Oonly[xsize]; +short int out_data_node_code[xsize]; // Loop over the y coordinates, then the x coordinates for (y=0; yRasterIO(GF_Read, 0, y, xsize, 1, agc_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn2 = INBAND2->RasterIO(GF_Read, 0, y, xsize, 1, bgc_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn3 = INBAND3->RasterIO(GF_Read, 0, y, xsize, 1, drivermodel_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn4 = INBAND4->RasterIO(GF_Read, 0, y, xsize, 1, loss_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn5 = INBAND5->RasterIO(GF_Read, 0, y, xsize, 1, peat_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn6 = INBAND6->RasterIO(GF_Read, 0, y, xsize, 1, burn_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn7 = INBAND7->RasterIO(GF_Read, 0, y, xsize, 1, ifl_primary_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn8 = INBAND8->RasterIO(GF_Read, 0, y, xsize, 1, ecozone_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn9 = INBAND9->RasterIO(GF_Read, 0, y, xsize, 1, climate_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn10 = INBAND10->RasterIO(GF_Read, 0, y, xsize, 1, dead_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn11 = INBAND11->RasterIO(GF_Read, 0, y, xsize, 1, litter_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn12 = INBAND12->RasterIO(GF_Read, 0, y, xsize, 1, soil_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn13 = INBAND13->RasterIO(GF_Read, 0, y, xsize, 1, plant_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn1 = INBAND_AGC->RasterIO(GF_Read, 0, y, xsize, 1, agc_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn2 = INBAND_BGC->RasterIO(GF_Read, 0, y, xsize, 1, bgc_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn3 = INBAND_DRIVERMODEL->RasterIO(GF_Read, 0, y, xsize, 1, drivermodel_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn4 = INBAND_LOSS->RasterIO(GF_Read, 0, y, xsize, 1, loss_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn5 = INBAND_PEAT->RasterIO(GF_Read, 0, y, xsize, 1, peat_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn6 = INBAND_BURN->RasterIO(GF_Read, 0, y, xsize, 1, burn_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn7 = INBAND_IFL_PRIMARY->RasterIO(GF_Read, 0, y, xsize, 1, ifl_primary_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn8 = INBAND_ECOZONE->RasterIO(GF_Read, 0, y, xsize, 1, ecozone_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn9 = INBAND_CLIMATE->RasterIO(GF_Read, 0, y, xsize, 1, climate_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn10 = INBAND_DEAD->RasterIO(GF_Read, 0, y, xsize, 1, dead_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn11 = INBAND_LITTER->RasterIO(GF_Read, 0, y, xsize, 1, litter_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn12 = INBAND_SOIL->RasterIO(GF_Read, 0, y, xsize, 1, soil_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn13 = INBAND_PLANT->RasterIO(GF_Read, 0, y, xsize, 1, plant_data, xsize, 1, GDT_Float32, 0, 0); // Number of input files int inSize = 13; @@ -428,28 +384,61 @@ for(x=0; x 0 && agc_data[x] > 0) @@ -461,7 +450,7 @@ for(x=0; x 0) // Commodity, peat + if (peat_data[x] > 0) // permanent ag, peat { - if (burn_data[x] > 0) // Commodity, peat, burned + if (burn_data[x] > 0) // permanent ag, peat, burned { - outdata1a = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; - outdata1b = Biomass_tCO2e_yesfire_non_CO2 + peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 10; + outdata_permanent_agriculture_CO2only = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; + outdata_permanent_agriculture_CH4only = Biomass_tCO2e_yesfire_CH4_only + peat_drain_total_CH4_only + peatburn_CH4_only; + outdata_permanent_agriculture_N2Oonly = Biomass_tCO2e_yesfire_N2O_only + peat_drain_total_N2O_only; + outdata_node_code = 10; } - if (burn_data[x] == 0) // Commodity, peat, not burned + if (burn_data[x] == 0) // permanent ag, peat, not burned { - if (ecozone_data[x] == tropical) // Commodity, peat, not burned, tropical + if (ecozone_data[x] == tropical) // permanent ag, peat, not burned, tropical { - if (plant_data[x] >= 1) // Commodity, peat, not burned, tropical, plantation + if (plant_data[x] >= 1) // permanent ag, peat, not burned, tropical, plantation { - outdata1a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata1b = 0 + peat_drain_total_non_CO2; - outdata20 = 11; + outdata_permanent_agriculture_CO2only = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; + outdata_permanent_agriculture_CH4only = 0 + peat_drain_total_CH4_only; + outdata_permanent_agriculture_N2Oonly = 0 + peat_drain_total_N2O_only; + outdata_node_code = 11; } - if (plant_data[x] == 0) // Commodity, peat, not burned, tropical, not plantation + if (plant_data[x] == 0) // permanent ag, peat, not burned, tropical, not plantation { - outdata1a = Biomass_tCO2e_nofire_CO2_only; - outdata1b = 0; - outdata20 = 111; + outdata_permanent_agriculture_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_permanent_agriculture_CH4only = 0; + outdata_permanent_agriculture_N2Oonly = 0; + outdata_node_code = 111; } } - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // Commodity, peat, not burned, temperate/boreal + if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // permanent ag, peat, not burned, temperate/boreal { - outdata1a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata1b = 0 + peat_drain_total_non_CO2; - outdata20 = 12; + outdata_permanent_agriculture_CO2only = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; + outdata_permanent_agriculture_CH4only = 0 + peat_drain_total_CH4_only; + outdata_permanent_agriculture_N2Oonly = 0 + peat_drain_total_N2O_only; + outdata_node_code = 12; } } } - if (peat_data[x] == 0) // Commodity, not peat + if (peat_data[x] == 0) // permanent ag, not peat { - if (burn_data[x] > 0) // Commodity, not peat, burned + if (burn_data[x] > 0) // permanent ag, not peat, burned { - if (ecozone_data[x] == tropical) // Commodity, not peat, burned, tropical + if (ecozone_data[x] == tropical) // permanent ag, not peat, burned, tropical { - if (ifl_primary_data[x] == 1) // Commodity, not peat, burned, tropical, IFL + if (ifl_primary_data[x] == 1) // permanent ag, not peat, burned, tropical, IFL { - if (plant_data[x] >= 1) // Commodity, not peat, burned, tropical, IFL, plantation + if (plant_data[x] >= 1) // permanent ag, not peat, burned, tropical, IFL, plantation { - outdata1a = Biomass_tCO2e_yesfire_CO2_only; - outdata1b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 13; + outdata_permanent_agriculture_CO2only = Biomass_tCO2e_yesfire_CO2_only; + outdata_permanent_agriculture_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_permanent_agriculture_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 13; } - if (plant_data[x] == 0) // Commodity, not peat, burned, tropical, IFL, not plantation + if (plant_data[x] == 0) // permanent ag, not peat, burned, tropical, IFL, not plantation { - outdata1a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata1b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 131; + outdata_permanent_agriculture_CO2only = Biomass_tCO2e_yesfire_CO2_only + minsoil; + outdata_permanent_agriculture_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_permanent_agriculture_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 131; } } - if (ifl_primary_data[x] == 0) // Commodity, not peat, burned, tropical, not IFL + if (ifl_primary_data[x] == 0) // permanent ag, not peat, burned, tropical, not IFL { - if (plant_data[x] >= 1) // Commodity, not peat, burned, tropical, not IFL, plantation + if (plant_data[x] >= 1) // permanent ag, not peat, burned, tropical, not IFL, plantation { - outdata1a = Biomass_tCO2e_yesfire_CO2_only; - outdata1b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 14; + outdata_permanent_agriculture_CO2only = Biomass_tCO2e_yesfire_CO2_only; + outdata_permanent_agriculture_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_permanent_agriculture_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 14; } - if (plant_data[x] == 0) // Commodity, not peat, burned, tropical, not IFL, not plantation + if (plant_data[x] == 0) // permanent ag, not peat, burned, tropical, not IFL, not plantation { - outdata1a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata1b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 141; + outdata_permanent_agriculture_CO2only = Biomass_tCO2e_yesfire_CO2_only + minsoil; + outdata_permanent_agriculture_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_permanent_agriculture_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 141; } } } - if (ecozone_data[x] == boreal) // Commodity, not peat, burned, boreal + if (ecozone_data[x] == boreal) // permanent ag, not peat, burned, boreal { - outdata1a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata1b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 15; + outdata_permanent_agriculture_CO2only = Biomass_tCO2e_yesfire_CO2_only + minsoil; + outdata_permanent_agriculture_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_permanent_agriculture_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 15; } - if (ecozone_data[x] == temperate) // Commodity, not peat, burned, temperate + if (ecozone_data[x] == temperate) // permanent ag, not peat, burned, temperate { - if (plant_data[x] >= 1) // Commodity, not peat, burned, temperate, plantation + if (plant_data[x] >= 1) // permanent ag, not peat, burned, temperate, plantation { - outdata1a = Biomass_tCO2e_yesfire_CO2_only; - outdata1b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 16; + outdata_permanent_agriculture_CO2only = Biomass_tCO2e_yesfire_CO2_only; + outdata_permanent_agriculture_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_permanent_agriculture_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 16; } - if (plant_data[x] == 0) // Commodity, not peat, burned, temperate, not plantation + if (plant_data[x] == 0) // permanent ag, not peat, burned, temperate, not plantation { - outdata1a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata1b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 161; + outdata_permanent_agriculture_CO2only = Biomass_tCO2e_yesfire_CO2_only + minsoil; + outdata_permanent_agriculture_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_permanent_agriculture_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 161; } } } - if (burn_data[x] == 0) // Commodity, not peat, not burned + if (burn_data[x] == 0) // permanent ag, not peat, not burned { - if (ecozone_data[x] == tropical) // Commodity, not peat, not burned, tropical + if (ecozone_data[x] == tropical) // permanent ag, not peat, not burned, tropical { - if (plant_data[x] >= 1) // Commodity, not peat, not burned, tropical, plantation + if (plant_data[x] >= 1) // permanent ag, not peat, not burned, tropical, plantation { - outdata1a = Biomass_tCO2e_nofire_CO2_only; - outdata1b = 0; - outdata20 = 17; + outdata_permanent_agriculture_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_permanent_agriculture_CH4only = 0; + outdata_permanent_agriculture_N2Oonly = 0; + outdata_node_code = 17; } - if (plant_data[x] == 0) // Commodity, not peat, not burned, tropical, not plantation + if (plant_data[x] == 0) // permanent ag, not peat, not burned, tropical, not plantation { - outdata1a = Biomass_tCO2e_nofire_CO2_only + minsoil; - outdata1b = 0; - outdata20 = 171; + outdata_permanent_agriculture_CO2only = Biomass_tCO2e_nofire_CO2_only + minsoil; + outdata_permanent_agriculture_CH4only = 0; + outdata_permanent_agriculture_N2Oonly = 0; + outdata_node_code = 171; } } - if (ecozone_data[x] == boreal) // Commodity, not peat, not burned, boreal + if (ecozone_data[x] == boreal) // permanent ag, not peat, not burned, boreal { - outdata1a = Biomass_tCO2e_nofire_CO2_only + minsoil; - outdata1b = 0; - outdata20 = 18; + outdata_permanent_agriculture_CO2only = Biomass_tCO2e_nofire_CO2_only + minsoil; + outdata_permanent_agriculture_CH4only = 0; + outdata_permanent_agriculture_N2Oonly = 0; + outdata_node_code = 18; } - if (ecozone_data[x] == temperate) // Commodity, not peat, not burned, temperate + if (ecozone_data[x] == temperate) // permanent ag, not peat, not burned, temperate { - if (plant_data[x] >= 1) // Commodity, not peat, not burned, temperate, plantation + if (plant_data[x] >= 1) // permanent ag, not peat, not burned, temperate, plantation { - outdata1a = Biomass_tCO2e_nofire_CO2_only; - outdata1b = 0; - outdata20 = 19; + outdata_permanent_agriculture_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_permanent_agriculture_CH4only = 0; + outdata_permanent_agriculture_N2Oonly = 0; + outdata_node_code = 19; } - if (plant_data[x] == 0) // Commodity, not peat, not burned, temperate, not plantation + if (plant_data[x] == 0) // permanent ag, not peat, not burned, temperate, not plantation { - outdata1a = Biomass_tCO2e_nofire_CO2_only + minsoil; - outdata1b = 0; - outdata20 = 191; + outdata_permanent_agriculture_CO2only = Biomass_tCO2e_nofire_CO2_only + minsoil; + outdata_permanent_agriculture_CH4only = 0; + outdata_permanent_agriculture_N2Oonly = 0; + outdata_node_code = 191; ////QC code to get the values of the relevant variables at a particular pixel of interest (based on its values rather than its coordinates) //double total; - //total = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only + Biomass_tCO2e_yesfire_non_CO2 + peat_drain_total_non_CO2 + peatburn_non_CO2; + //total = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only + Biomass_tCO2e_yesfire_CH4_only + Biomass_tCO2e_yesfire_N2O_only + peat_drain_total_CH4_only + peat_drain_total_N2O_only + peatburn_CH4_only; //if ((total < 715) && (total > 714) && (agc_data[x] = 26.25) && (soil_data[x] = 216) && (dead_data[x] = 1.44) && (litter_data[x] = 0.5328) && (burn_data[x] = 6)) //{ // cout << "total: " << total << endl; // cout << "Biomass_tCO2e_yesfire_CO2_only: " << Biomass_tCO2e_yesfire_CO2_only << endl; - // cout << "Biomass_tCO2e_yesfire_non_CO2: " << Biomass_tCO2e_yesfire_non_CO2 << endl; + // cout << "Biomass_tCO2e_yesfire_CH4_only: " << Biomass_tCO2e_yesfire_CH4_only << endl; + // cout << "Biomass_tCO2e_yesfire_N2O_only: " << Biomass_tCO2e_yesfire_N2O_only << endl; // cout << "peat_drain_total_CO2_only: " << peat_drain_total_CO2_only << endl; - // cout << "peat_drain_total_non_CO2: " << peat_drain_total_non_CO2 << endl; + // cout << "peat_drain_total_CH4_only: " << peat_drain_total_CH4_only << endl; + // cout << "peat_drain_total_N2O_only: " << peat_drain_total_N2O_only << endl; // cout << "peatburn_CO2_only: " << peatburn_CO2_only << endl; - // cout << "peatburn_non_CO2: " << peatburn_non_CO2 << endl; + // cout << "peatburn_CH4_only: " << peatburn_CH4_only << endl; // cout << "agc_data[x]: " << agc_data[x] << endl; // cout << "Cf: " << Cf << endl; // cout << "Gef_CO2: " << Gef_CO2 << endl; @@ -652,144 +665,322 @@ for(x=0; x 0) // hard commodities, peat + { + if (burn_data[x] > 0) // hard commodities, peat, burned + { + outdata_hard_commodities_CO2only = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; + outdata_hard_commodities_CH4only = Biomass_tCO2e_yesfire_CH4_only + peat_drain_total_CH4_only + peatburn_CH4_only; + outdata_hard_commodities_N2Oonly = Biomass_tCO2e_yesfire_N2O_only + peat_drain_total_N2O_only; + outdata_node_code = 20; + } + if (burn_data[x] == 0) // hard commodities, peat, not burned + { + if (ecozone_data[x] == tropical) // hard commodities, peat, not burned, tropical + { + if (plant_data[x] >= 1) // hard commodities, peat, not burned, tropical, plantation + { + outdata_hard_commodities_CO2only = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; + outdata_hard_commodities_CH4only = 0 + peat_drain_total_CH4_only; + outdata_hard_commodities_N2Oonly = 0 + peat_drain_total_N2O_only; + outdata_node_code = 21; + } + if (plant_data[x] == 0) // hard commodities, peat, not burned, tropical, not plantation + { + outdata_hard_commodities_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_hard_commodities_CH4only = 0; + outdata_hard_commodities_N2Oonly = 0; + outdata_node_code = 211; + } + } + if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // hard commodities, peat, not burned, temperate/boreal + { + outdata_hard_commodities_CO2only = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; + outdata_hard_commodities_CH4only = 0 + peat_drain_total_CH4_only; + outdata_hard_commodities_N2Oonly = 0 + peat_drain_total_N2O_only; + outdata_node_code = 22; + } + } + } + if (peat_data[x] == 0) // hard commodities, not peat + { + if (burn_data[x] > 0) // hard commodities, not peat, burned + { + if (ecozone_data[x] == tropical) // hard commodities, not peat, burned, tropical + { + if (ifl_primary_data[x] == 1) // hard commodities, not peat, burned, tropical, IFL + { + if (plant_data[x] >= 1) // hard commodities, not peat, burned, tropical, IFL, plantation + { + outdata_hard_commodities_CO2only = Biomass_tCO2e_yesfire_CO2_only; + outdata_hard_commodities_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_hard_commodities_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 23; + } + if (plant_data[x] == 0) // hard commodities, not peat, burned, tropical, IFL, not plantation + { + outdata_hard_commodities_CO2only = Biomass_tCO2e_yesfire_CO2_only + minsoil; + outdata_hard_commodities_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_hard_commodities_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 231; + } + } + if (ifl_primary_data[x] == 0) // hard commodities, not peat, burned, tropical, not IFL + { + if (plant_data[x] >= 1) // hard commodities, not peat, burned, tropical, not IFL, plantation + { + outdata_hard_commodities_CO2only = Biomass_tCO2e_yesfire_CO2_only; + outdata_hard_commodities_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_hard_commodities_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 24; + } + if (plant_data[x] == 0) // hard commodities, not peat, burned, tropical, not IFL, not plantation + { + outdata_hard_commodities_CO2only = Biomass_tCO2e_yesfire_CO2_only + minsoil; + outdata_hard_commodities_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_hard_commodities_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 241; + } + } + } + if (ecozone_data[x] == boreal) // hard commodities, not peat, burned, boreal + { + outdata_hard_commodities_CO2only = Biomass_tCO2e_yesfire_CO2_only + minsoil; + outdata_hard_commodities_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_hard_commodities_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 25; + } + if (ecozone_data[x] == temperate) // hard commodities, not peat, burned, temperate + { + if (plant_data[x] >= 1) // hard commodities, not peat, burned, temperate, plantation + { + outdata_hard_commodities_CO2only = Biomass_tCO2e_yesfire_CO2_only; + outdata_hard_commodities_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_hard_commodities_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 26; + } + if (plant_data[x] == 0) // hard commodities, not peat, burned, temperate, not plantation + { + outdata_hard_commodities_CO2only = Biomass_tCO2e_yesfire_CO2_only + minsoil; + outdata_hard_commodities_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_hard_commodities_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 261; + } + } + } + if (burn_data[x] == 0) // hard commodities, not peat, not burned + { + if (ecozone_data[x] == tropical) // hard commodities, not peat, not burned, tropical + { + if (plant_data[x] >= 1) // hard commodities, not peat, not burned, tropical, plantation + { + outdata_hard_commodities_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_hard_commodities_CH4only = 0; + outdata_hard_commodities_N2Oonly = 0; + outdata_node_code = 27; + } + if (plant_data[x] == 0) // hard commodities, not peat, not burned, tropical, not plantation + { + outdata_hard_commodities_CO2only = Biomass_tCO2e_nofire_CO2_only + minsoil; + outdata_hard_commodities_CH4only = 0; + outdata_hard_commodities_N2Oonly = 0; + outdata_node_code = 271; + } + } + if (ecozone_data[x] == boreal) // hard commodities, not peat, not burned, boreal + { + outdata_hard_commodities_CO2only = Biomass_tCO2e_nofire_CO2_only + minsoil; + outdata_hard_commodities_CH4only = 0; + outdata_hard_commodities_N2Oonly = 0; + outdata_node_code = 28; + } + if (ecozone_data[x] == temperate) // hard commodities, not peat, not burned, temperate + { + if (plant_data[x] >= 1) // hard commodities, not peat, not burned, temperate, plantation + { + outdata_hard_commodities_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_hard_commodities_CH4only = 0; + outdata_hard_commodities_N2Oonly = 0; + outdata_node_code = 29; + } + if (plant_data[x] == 0) // hard commodities, not peat, not burned, temperate, not plantation + { + outdata_hard_commodities_CO2only = Biomass_tCO2e_nofire_CO2_only + minsoil; + outdata_hard_commodities_CH4only = 0; + outdata_hard_commodities_N2Oonly = 0; + outdata_node_code = 291; + } + } + } + } + outdata_hard_commodities_allgases = outdata_hard_commodities_CO2only + outdata_hard_commodities_CH4only + outdata_hard_commodities_N2Oonly; + outdata_hard_commodities_nonCO2 = outdata_hard_commodities_CH4only + outdata_hard_commodities_N2Oonly; + } + + // Emissions model for shifting cultivation (only difference is flu val) + else if (drivermodel_data[x] == 3) { Biomass_tCO2e_nofire_CO2_only = non_soil_c * C_to_CO2; Biomass_tCO2e_yesfire_CO2_only = (non_soil_c * C_to_CO2); - Biomass_tCO2e_yesfire_non_CO2 = ((non_soil_c / biomass_to_c) * Cf * Gef_CH4 * pow(10,-3) * CH4_equiv) + ((non_soil_c / biomass_to_c) * Cf * Gef_N2O * pow(10,-3) * N2O_equiv); - minsoil = ((soil_data[x]-(soil_data[x] * shiftag_flu))/soil_emis_period) * (model_years-loss_data[x]); + Biomass_tCO2e_yesfire_CH4_only = ((non_soil_c / biomass_to_c) * Cf * Gef_CH4 * pow(10,-3) * CH4_equiv); + Biomass_tCO2e_yesfire_N2O_only = ((non_soil_c / biomass_to_c) * Cf * Gef_N2O * pow(10,-3) * N2O_equiv); + minsoil = ((soil_data[x]-(soil_data[x] * shift_cult_flu))/soil_emis_period) * (model_years-loss_data[x]); - if (peat_data[x] > 0) // Shifting ag, peat + if (peat_data[x] > 0) // shifting cultivation, peat { - if (burn_data[x] > 0) // Shifting ag, peat, burned + if (burn_data[x] > 0) // shifting cultivation, peat, burned { - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // Shifting ag, peat, burned, temperate/boreal + if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // shifting cultivation, peat, burned, temperate/boreal { - outdata2a = Biomass_tCO2e_yesfire_CO2_only + peatburn_CO2_only; - outdata2b = Biomass_tCO2e_yesfire_non_CO2 + peatburn_non_CO2; - outdata20 = 20; + outdata_shifting_cultivation_CO2only = Biomass_tCO2e_yesfire_CO2_only + peatburn_CO2_only; + outdata_shifting_cultivation_CH4only = Biomass_tCO2e_yesfire_CH4_only + peatburn_CH4_only; + outdata_shifting_cultivation_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 30; } - if (ecozone_data[x] == tropical) // Shifting ag, peat, burned, tropical + if (ecozone_data[x] == tropical) // shifting cultivation, peat, burned, tropical { - outdata2a = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_non_CO2; - outdata2b = Biomass_tCO2e_yesfire_non_CO2 + peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 21; + outdata_shifting_cultivation_CO2only = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; + outdata_shifting_cultivation_CH4only = Biomass_tCO2e_yesfire_CH4_only + peat_drain_total_CH4_only + peatburn_CH4_only; + outdata_shifting_cultivation_N2Oonly = Biomass_tCO2e_yesfire_N2O_only + peat_drain_total_N2O_only; + outdata_node_code = 31; } } - if (burn_data[x] == 0)// Shifting ag, peat, not burned + if (burn_data[x] == 0)// shifting cultivation, peat, not burned { - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // Shifting ag, peat, not burned, temperate/boreal + if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // shifting cultivation, peat, not burned, temperate/boreal { - outdata2a = Biomass_tCO2e_nofire_CO2_only; - outdata2b = 0; - outdata20 = 22; + outdata_shifting_cultivation_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_shifting_cultivation_CH4only = 0; + outdata_shifting_cultivation_N2Oonly = 0; + outdata_node_code = 32; } - if (ecozone_data[x] == tropical) // Shifting ag, peat, not burned, tropical + if (ecozone_data[x] == tropical) // shifting cultivation, peat, not burned, tropical { - if (plant_data[x] >= 1) // Shifting ag, peat, not burned, tropical, plantation + if (plant_data[x] >= 1) // shifting cultivation, peat, not burned, tropical, plantation { - outdata2a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata2b = 0 + peat_drain_total_non_CO2; - outdata20 = 23; + outdata_shifting_cultivation_CO2only = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; + outdata_shifting_cultivation_CH4only = 0 + peat_drain_total_CH4_only; + outdata_shifting_cultivation_N2Oonly = 0 + peat_drain_total_N2O_only; + outdata_node_code = 33; } - if (plant_data[x] == 0) // Shifting ag, peat, not burned, tropical, not plantation + if (plant_data[x] == 0) // shifting cultivation, peat, not burned, tropical, not plantation { - outdata2a = Biomass_tCO2e_nofire_CO2_only; - outdata2b = 0; - outdata20 = 231; + outdata_shifting_cultivation_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_shifting_cultivation_CH4only = 0; + outdata_shifting_cultivation_N2Oonly = 0; + outdata_node_code = 331; } } } } - if (peat_data[x] == 0)// Shifting ag, not peat + if (peat_data[x] == 0)// shifting cultivation, not peat { - if (burn_data[x] > 0) // Shifting ag, not peat, burned + if (burn_data[x] > 0) // shifting cultivation, not peat, burned { - if (ecozone_data[x] == tropical) // Shifting ag, not peat, burned, tropical + if (ecozone_data[x] == tropical) // shifting cultivation, not peat, burned, tropical { - if (ifl_primary_data[x] == 1) // Shifting ag, not peat, burned, tropical, IFL + if (ifl_primary_data[x] == 1) // shifting cultivation, not peat, burned, tropical, IFL { - if (plant_data[x] >= 1) // Shifting ag, not peat, burned, tropical, IFL, plantation + if (plant_data[x] >= 1) // shifting cultivation, not peat, burned, tropical, IFL, plantation { - outdata2a = Biomass_tCO2e_yesfire_CO2_only; - outdata2b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 24; + outdata_shifting_cultivation_CO2only = Biomass_tCO2e_yesfire_CO2_only; + outdata_shifting_cultivation_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_shifting_cultivation_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 34; } - if (plant_data[x] == 0) // Shifting ag, not peat, burned, tropical, IFL, not plantation + if (plant_data[x] == 0) // shifting cultivation, not peat, burned, tropical, IFL, not plantation { - outdata2a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata2b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 241; + outdata_shifting_cultivation_CO2only = Biomass_tCO2e_yesfire_CO2_only + minsoil; + outdata_shifting_cultivation_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_shifting_cultivation_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 341; } } - if (ifl_primary_data[x] == 0) // Shifting ag, not peat, burned, tropical, not IFL + if (ifl_primary_data[x] == 0) // shifting cultivation, not peat, burned, tropical, not IFL { - if (plant_data[x] >= 1) // Shifting ag, not peat, burned, tropical, not IFL, plantation + if (plant_data[x] >= 1) // shifting cultivation, not peat, burned, tropical, not IFL, plantation { - outdata2a = Biomass_tCO2e_yesfire_CO2_only; - outdata2b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 25; + outdata_shifting_cultivation_CO2only = Biomass_tCO2e_yesfire_CO2_only; + outdata_shifting_cultivation_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_shifting_cultivation_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 35; } - if (plant_data[x] == 0) // Shifting ag, not peat, burned, tropical, not IFL, not plantation + if (plant_data[x] == 0) // shifting cultivation, not peat, burned, tropical, not IFL, not plantation { - outdata2a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata2b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 251; + outdata_shifting_cultivation_CO2only = Biomass_tCO2e_yesfire_CO2_only + minsoil; + outdata_shifting_cultivation_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_shifting_cultivation_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 351; } } } - if (ecozone_data[x] == boreal) // Shifting ag, not peat, burned, boreal + if (ecozone_data[x] == boreal) // shifting cultivation, not peat, burned, boreal { - outdata2a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata2b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 26; + outdata_shifting_cultivation_CO2only = Biomass_tCO2e_yesfire_CO2_only + minsoil; + outdata_shifting_cultivation_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_shifting_cultivation_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 36; } - if (ecozone_data[x] == temperate) // Shifting ag, not peat, burned, temperate + if (ecozone_data[x] == temperate) // shifting cultivation, not peat, burned, temperate { - if (plant_data[x] >= 1) // Shifting ag, not peat, burned, temperate, plantation + if (plant_data[x] >= 1) // shifting cultivation, not peat, burned, temperate, plantation { - outdata2a = Biomass_tCO2e_yesfire_CO2_only; - outdata2b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 27; + outdata_shifting_cultivation_CO2only = Biomass_tCO2e_yesfire_CO2_only; + outdata_shifting_cultivation_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_shifting_cultivation_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 37; } - if (plant_data[x] == 0) // Shifting ag, not peat, burned, temperate, not plantation + if (plant_data[x] == 0) // shifting cultivation, not peat, burned, temperate, not plantation { - outdata2a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata2b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 271; + outdata_shifting_cultivation_CO2only = Biomass_tCO2e_yesfire_CO2_only + minsoil; + outdata_shifting_cultivation_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_shifting_cultivation_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 371; } } } - if (burn_data[x] == 0) // Shifting ag, not peat, not burned + if (burn_data[x] == 0) // shifting cultivation, not peat, not burned { - if (ecozone_data[x] == tropical) // Shifting ag, not peat, not burned, tropical + if (ecozone_data[x] == tropical) // shifting cultivation, not peat, not burned, tropical { - if (plant_data[x] >= 1) // Shifting ag, not peat, not burned, tropical, plantation + if (plant_data[x] >= 1) // shifting cultivation, not peat, not burned, tropical, plantation { - outdata2a = Biomass_tCO2e_nofire_CO2_only; - outdata2b = 0; - outdata20 = 28; + outdata_shifting_cultivation_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_shifting_cultivation_CH4only = 0; + outdata_shifting_cultivation_N2Oonly = 0; + outdata_node_code = 38; } - if (plant_data[x] == 0) // Shifting ag, not peat, not burned, tropical, not plantation + if (plant_data[x] == 0) // shifting cultivation, not peat, not burned, tropical, not plantation { - outdata2a = Biomass_tCO2e_nofire_CO2_only + minsoil; - outdata2b = 0; - outdata20 = 281; + outdata_shifting_cultivation_CO2only = Biomass_tCO2e_nofire_CO2_only + minsoil; + outdata_shifting_cultivation_CH4only = 0; + outdata_shifting_cultivation_N2Oonly = 0; + outdata_node_code = 381; // //QC code to get the values of the relevant variables at a particular pixel of interest (based on its values rather than its coordinates) // double total; // total = Biomass_tCO2e_nofire_CO2_only + minsoil; // double minsoil_pt1; -// minsoil_pt1 = ((soil_data[x]-(soil_data[x] * shiftag_flu))/soil_emis_period); +// minsoil_pt1 = ((soil_data[x]-(soil_data[x] * shift_cult_flu))/soil_emis_period); // double minsoil_pt2; // minsoil_pt2 = (model_years-loss_data[x]); -//// if ((total < 781) && (total > 780) && (agc_data[x] < 155) && (agc_data[x] > 154) && (loss_data[x] = 3) && (soil_data[x] = 135) && (drivermodel_data[x] == 2)) -//// if ((x > 3525) && (x < 3530) && (total < 781) && (total > 780) && (agc_data[x] = 154.354538) && (loss_data[x] = 3) && (soil_data[x] = 135) && (drivermodel_data[x] == 2)) -// if ((x > 3526) && (x < 3528) && (y > 1555) && (y < 1559) && (drivermodel_data[x] == 2) && (loss_data[x] = 3)) +//// if ((total < 781) && (total > 780) && (agc_data[x] < 155) && (agc_data[x] > 154) && (loss_data[x] = 3) && (soil_data[x] = 135) && (drivermodel_data[x] == 3)) +//// if ((x > 3525) && (x < 3530) && (total < 781) && (total > 780) && (agc_data[x] = 154.354538) && (loss_data[x] = 3) && (soil_data[x] = 135) && (drivermodel_data[x] == 3)) +// if ((x > 3526) && (x < 3528) && (y > 1555) && (y < 1559) && (drivermodel_data[x] == 3) && (loss_data[x] = 3)) // { // cout << "x: " << x << endl; // cout << "y: " << y << endl; @@ -801,7 +992,7 @@ for(x=0; x= 1) // Shifting ag, not peat, not burned, temperate, plantation + if (plant_data[x] >= 1) // shifting cultivation, not peat, not burned, temperate, plantation { - outdata2a = Biomass_tCO2e_nofire_CO2_only; - outdata2b = 0; - outdata20 = 291; + outdata_shifting_cultivation_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_shifting_cultivation_CH4only = 0; + outdata_shifting_cultivation_N2Oonly = 0; + outdata_node_code = 391; } - if (plant_data[x] == 0) // Shifting ag, not peat, not burned, temperate, not plantation + if (plant_data[x] == 0) // shifting cultivation, not peat, not burned, temperate, not plantation { - outdata2a = Biomass_tCO2e_nofire_CO2_only + minsoil; - outdata2b = 0; - outdata20 = 292; + outdata_shifting_cultivation_CO2only = Biomass_tCO2e_nofire_CO2_only + minsoil; + outdata_shifting_cultivation_CH4only = 0; + outdata_shifting_cultivation_N2Oonly = 0; + outdata_node_code = 392; } } } } - outdata2 = outdata2a + outdata2b; + outdata_shifting_cultivation_allgases = outdata_shifting_cultivation_CO2only + outdata_shifting_cultivation_CH4only + outdata_shifting_cultivation_N2Oonly; + outdata_shifting_cultivation_nonCO2 = outdata_shifting_cultivation_CH4only + outdata_shifting_cultivation_N2Oonly; } - // Emissions model for forestry - else if (drivermodel_data[x] == 3) + // Emissions model for forest management + else if (drivermodel_data[x] == 4) { Biomass_tCO2e_nofire_CO2_only = above_below_c * C_to_CO2; Biomass_tCO2e_yesfire_CO2_only = ((agc_data[x] / biomass_to_c) * Cf * Gef_CO2 * pow(10, -3)); - Biomass_tCO2e_yesfire_non_CO2 = ((agc_data[x] / biomass_to_c) * Cf * Gef_CH4 * pow(10, -3) * CH4_equiv) + ((agc_data[x] / biomass_to_c) * Cf * Gef_N2O * pow(10, -3) * N2O_equiv); + Biomass_tCO2e_yesfire_CH4_only = ((non_soil_bgc_c / biomass_to_c) * Cf * Gef_CH4 * pow(10, -3) * CH4_equiv); + Biomass_tCO2e_yesfire_N2O_only = ((non_soil_bgc_c / biomass_to_c) * Cf * Gef_N2O * pow(10, -3) * N2O_equiv); - if (peat_data[x] > 0) // Forestry, peat + if (peat_data[x] > 0) // forest management, peat { - if (burn_data[x] > 0 ) // Forestry, peat, burned + if (burn_data[x] > 0 ) // forest management, peat, burned { - outdata3a = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; - outdata3b = Biomass_tCO2e_yesfire_non_CO2 + peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 30; + outdata_forest_management_CO2only = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; + outdata_forest_management_CH4only = Biomass_tCO2e_yesfire_CH4_only + peat_drain_total_CH4_only + peatburn_CH4_only; + outdata_forest_management_N2Oonly = Biomass_tCO2e_yesfire_N2O_only + peat_drain_total_N2O_only; + outdata_node_code = 40; } - if (burn_data[x] == 0 ) // Forestry, peat, not burned + if (burn_data[x] == 0 ) // forest management, peat, not burned { - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // Forestry, peat, not burned, temperate/boreal + if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // forest management, peat, not burned, temperate/boreal { - outdata3a = Biomass_tCO2e_nofire_CO2_only; - outdata3b = 0; - outdata20 = 31; + outdata_forest_management_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_forest_management_CH4only = 0; + outdata_forest_management_N2Oonly = 0; + outdata_node_code = 41; } - if (ecozone_data[x] == tropical)// Forestry, peat, not burned, tropical + if (ecozone_data[x] == tropical)// forest management, peat, not burned, tropical { - if (plant_data[x] > 0) // Forestry, peat, not burned, tropical, plantation + if (plant_data[x] > 0) // forest management, peat, not burned, tropical, plantation { - outdata3a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata3b = 0 + peat_drain_total_non_CO2; - outdata20 = 32; + outdata_forest_management_CO2only = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; + outdata_forest_management_CH4only = 0 + peat_drain_total_CH4_only; + outdata_forest_management_N2Oonly = 0 + peat_drain_total_N2O_only; + outdata_node_code = 42; } - if (plant_data[x] == 0) // Forestry, peat, not burned, tropical, not plantation + if (plant_data[x] == 0) // forest management, peat, not burned, tropical, not plantation { - outdata3a = Biomass_tCO2e_nofire_CO2_only; - outdata3b = 0; - outdata20 = 321; + outdata_forest_management_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_forest_management_CH4only = 0; + outdata_forest_management_N2Oonly = 0; + outdata_node_code = 421; } } } } - else // Forestry, not peat + else // forest management, not peat { - if (burn_data[x] > 0) // Forestry, not peat, burned + if (burn_data[x] > 0) // forest management, not peat, burned { - outdata3a = Biomass_tCO2e_yesfire_CO2_only; - outdata3b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 33; + outdata_forest_management_CO2only = Biomass_tCO2e_yesfire_CO2_only; + outdata_forest_management_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_forest_management_N2Oonly= Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 43; } - if (burn_data[x] == 0) // Forestry, not peat, not burned + if (burn_data[x] == 0) // forest management, not peat, not burned { - outdata3a = Biomass_tCO2e_nofire_CO2_only; - outdata3b = 0; - outdata20 = 34; + outdata_forest_management_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_forest_management_CH4only = 0; + outdata_forest_management_N2Oonly = 0; + outdata_node_code = 44; } } - outdata3 = outdata3a + outdata3b; + outdata_forest_management_allgases = outdata_forest_management_CO2only + outdata_forest_management_CH4only + outdata_forest_management_N2Oonly; + outdata_forest_management_nonCO2 = outdata_forest_management_CH4only + outdata_forest_management_N2Oonly; } // Emissions model for wildfires - else if (drivermodel_data[x] == 4) + else if (drivermodel_data[x] == 5) { Biomass_tCO2e_nofire_CO2_only = above_below_c * C_to_CO2; Biomass_tCO2e_yesfire_CO2_only = ((agc_data[x] / biomass_to_c) * Cf * Gef_CO2 * pow(10, -3)); - Biomass_tCO2e_yesfire_non_CO2 = ((agc_data[x] / biomass_to_c) * Cf * Gef_CH4 * pow(10, -3) * CH4_equiv) + ((agc_data[x] / biomass_to_c) * Cf * Gef_N2O * pow(10, -3) * N2O_equiv); + Biomass_tCO2e_yesfire_CH4_only = ((non_soil_bgc_c / biomass_to_c) * Cf * Gef_CH4 * pow(10, -3) * CH4_equiv); + Biomass_tCO2e_yesfire_N2O_only = ((non_soil_bgc_c / biomass_to_c) * Cf * Gef_N2O * pow(10, -3) * N2O_equiv); - if (peat_data[x] > 0) // Wildfire, peat + if (peat_data[x] > 0) // wildfire, peat { - if (burn_data[x] > 0) // Wildfire, peat, burned + if (burn_data[x] > 0) // wildfire, peat, burned { - outdata4a = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; - outdata4b = Biomass_tCO2e_yesfire_non_CO2 + peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 40; + outdata_wildfire_CO2only = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; + outdata_wildfire_CH4only = Biomass_tCO2e_yesfire_CH4_only + peat_drain_total_CH4_only + peatburn_CH4_only; + outdata_wildfire_N2Oonly = Biomass_tCO2e_yesfire_N2O_only + peat_drain_total_N2O_only; + outdata_node_code = 50; } - if (burn_data[x] == 0) // Wildfire, peat, not burned + if (burn_data[x] == 0) // wildfire, peat, not burned { - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // Wildfire, peat, not burned, temperate/boreal + if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // wildfire, peat, not burned, temperate/boreal { - outdata4a = Biomass_tCO2e_nofire_CO2_only; - outdata4b = 0; - outdata20 = 41; + outdata_wildfire_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_wildfire_CH4only = 0; + outdata_wildfire_N2Oonly = 0; + outdata_node_code = 51; } - if (ecozone_data[x] == tropical) // Wildfire, peat, not burned, tropical + if (ecozone_data[x] == tropical) // wildfire, peat, not burned, tropical { - if (plant_data[x] > 0) // Wildfire, peat, not burned, tropical, plantation + if (plant_data[x] > 0) // wildfire, peat, not burned, tropical, plantation { - outdata4a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata4b = 0 + peat_drain_total_non_CO2; - outdata20 = 42; + outdata_wildfire_CO2only = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; + outdata_wildfire_CH4only = 0 + peat_drain_total_CH4_only; + outdata_wildfire_N2Oonly = 0 + peat_drain_total_N2O_only; + outdata_node_code = 52; } - if (plant_data[x] == 0) // Wildfire, peat, not burned, tropical, not plantation + if (plant_data[x] == 0) // wildfire, peat, not burned, tropical, not plantation { - outdata4a = Biomass_tCO2e_nofire_CO2_only; - outdata4b = 0; - outdata20 = 421; + outdata_wildfire_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_wildfire_CH4only = 0; + outdata_wildfire_N2Oonly = 0; + outdata_node_code = 521; } } } } - else // Wildfire, not peat + else // wildfire, not peat { - if (burn_data[x] > 0) // Wildfire, not peat, burned + if (burn_data[x] > 0) // wildfire, not peat, burned { - outdata4a = Biomass_tCO2e_yesfire_CO2_only; - outdata4b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 43; + outdata_wildfire_CO2only = Biomass_tCO2e_yesfire_CO2_only; + outdata_wildfire_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_wildfire_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 53; } - else // Wildfire, not peat, not burned + else // wildfire, not peat, not burned { - outdata4a = Biomass_tCO2e_nofire_CO2_only; - outdata4b = 0; - outdata20 = 44; + outdata_wildfire_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_wildfire_CH4only = 0; + outdata_wildfire_N2Oonly = 0; + outdata_node_code = 54; } } - outdata4 = outdata4a + outdata4b; + outdata_wildfire_allgases = outdata_wildfire_CO2only + outdata_wildfire_CH4only + outdata_wildfire_N2Oonly; + outdata_wildfire_nonCO2 = outdata_wildfire_CH4only + outdata_wildfire_N2Oonly; } - // Emissions model for urbanization - else if (drivermodel_data[x] == 5) + // Emissions model for settlements & infrastructure + else if (drivermodel_data[x] == 6) { Biomass_tCO2e_nofire_CO2_only = non_soil_c * C_to_CO2; Biomass_tCO2e_yesfire_CO2_only = (non_soil_c * C_to_CO2); - Biomass_tCO2e_yesfire_non_CO2 = ((non_soil_c / biomass_to_c) * Cf * Gef_CH4 * pow(10,-3) * CH4_equiv) + ((non_soil_c / biomass_to_c) * Cf * Gef_N2O * pow(10,-3) * N2O_equiv); - minsoil = ((soil_data[x]-(soil_data[x] * urb_flu))/soil_emis_period) * (model_years-loss_data[x]); + Biomass_tCO2e_yesfire_CH4_only = ((non_soil_c / biomass_to_c) * Cf * Gef_CH4 * pow(10,-3) * CH4_equiv); + Biomass_tCO2e_yesfire_N2O_only = ((non_soil_c / biomass_to_c) * Cf * Gef_N2O * pow(10,-3) * N2O_equiv); + minsoil = ((soil_data[x]-(soil_data[x] * settlements_flu))/soil_emis_period) * (model_years-loss_data[x]); - if (peat_data[x] > 0) // Urbanization, peat + if (peat_data[x] > 0) // settlements & infrastructure, peat { - if (burn_data[x] > 0) // Urbanization, peat, burned + if (burn_data[x] > 0) // settlements & infrastructure, peat, burned { - outdata5a = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; - outdata5b = Biomass_tCO2e_yesfire_non_CO2 + peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 50; + outdata_settlements_CO2only = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; + outdata_settlements_CH4only = Biomass_tCO2e_yesfire_CH4_only + peat_drain_total_CH4_only + peatburn_CH4_only; + outdata_settlements_N2Oonly = Biomass_tCO2e_yesfire_N2O_only + peat_drain_total_N2O_only; + outdata_node_code = 60; } - if (burn_data[x] == 0) // Urbanization, peat, not burned + if (burn_data[x] == 0) // settlements & infrastructure, peat, not burned { - if (ecozone_data[x] == tropical) // Urbanization, peat, not burned, tropical + if (ecozone_data[x] == tropical) // settlements & infrastructure, peat, not burned, tropical { - if (plant_data[x] >= 1) // Urbanization, peat, not burned, tropical, plantation + if (plant_data[x] >= 1) // settlements & infrastructure, peat, not burned, tropical, plantation { - outdata5a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata5b = 0 + peat_drain_total_non_CO2; - outdata20 = 51; + outdata_settlements_CO2only = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; + outdata_settlements_CH4only = 0 + peat_drain_total_CH4_only; + outdata_settlements_N2Oonly = 0 + peat_drain_total_N2O_only; + outdata_node_code = 61; } - if (plant_data[x] == 0) // Urbanization, peat, not burned, tropical, not plantation + if (plant_data[x] == 0) // settlements & infrastructure, peat, not burned, tropical, not plantation { - outdata5a = Biomass_tCO2e_nofire_CO2_only; - outdata5b = 0; - outdata20 = 511; + outdata_settlements_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_settlements_CH4only = 0; + outdata_settlements_N2Oonly = 0; + outdata_node_code = 611; } } - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // Urbanization, peat, not burned, temperate/boreal + if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // settlements & infrastructure, peat, not burned, temperate/boreal { - outdata5a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata5b = 0 + peat_drain_total_non_CO2; - outdata20 = 52; + outdata_settlements_CO2only = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; + outdata_settlements_CH4only = 0 + peat_drain_total_CH4_only; + outdata_settlements_N2Oonly = 0 + peat_drain_total_N2O_only; + outdata_node_code = 62; } } } - if (peat_data[x] == 0)// Urbanization, not peat + if (peat_data[x] == 0)// settlements & infrastructure, not peat { - if (burn_data[x] > 0) // Urbanization, not peat, burned + if (burn_data[x] > 0) // settlements & infrastructure, not peat, burned { - if (ecozone_data[x] == tropical) // Urbanization, not peat, burned, tropical + if (ecozone_data[x] == tropical) // settlements & infrastructure, not peat, burned, tropical { - if (ifl_primary_data[x] == 1) // Urbanization, not peat, burned, tropical, IFL + if (ifl_primary_data[x] == 1) // settlements & infrastructure, not peat, burned, tropical, IFL { - if (plant_data[x] >= 1) // Urbanization, not peat, burned, tropical, IFL, plantation + if (plant_data[x] >= 1) // settlements & infrastructure, not peat, burned, tropical, IFL, plantation { - outdata5a = Biomass_tCO2e_yesfire_CO2_only; - outdata5b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 53; + outdata_settlements_CO2only = Biomass_tCO2e_yesfire_CO2_only; + outdata_settlements_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_settlements_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 63; } - if (plant_data[x] == 0) // Urbanization, not peat, burned, tropical, IFL, not plantation + if (plant_data[x] == 0) // settlements & infrastructure, not peat, burned, tropical, IFL, not plantation { - outdata5a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata5b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 531; + outdata_settlements_CO2only = Biomass_tCO2e_yesfire_CO2_only + minsoil; + outdata_settlements_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_settlements_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 631; } } - if (ifl_primary_data[x] == 0) // Urbanization, not peat, burned, tropical, not IFL + if (ifl_primary_data[x] == 0) // settlements & infrastructure, not peat, burned, tropical, not IFL { - if (plant_data[x] >= 1) // Urbanization, not peat, burned, tropical, not IFL, plantation + if (plant_data[x] >= 1) // settlements & infrastructure, not peat, burned, tropical, not IFL, plantation { - outdata5a = Biomass_tCO2e_yesfire_CO2_only; - outdata5b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 54; + outdata_settlements_CO2only = Biomass_tCO2e_yesfire_CO2_only; + outdata_settlements_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_settlements_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 64; } - if (plant_data[x] == 0) // Urbanization, not peat, burned, tropical, not IFL, not plantation + if (plant_data[x] == 0) // settlements & infrastructure, not peat, burned, tropical, not IFL, not plantation { - outdata5a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata5b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 541; + outdata_settlements_CO2only = Biomass_tCO2e_yesfire_CO2_only + minsoil; + outdata_settlements_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_settlements_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 641; } } } - if (ecozone_data[x] == boreal) // Urbanization, not peat, burned, boreal + if (ecozone_data[x] == boreal) // settlements & infrastructure, not peat, burned, boreal { - outdata5a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata5b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 55; + outdata_settlements_CO2only = Biomass_tCO2e_yesfire_CO2_only + minsoil; + outdata_settlements_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_settlements_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 65; } - if (ecozone_data[x] == temperate) // Urbanization, not peat, burned, temperate + if (ecozone_data[x] == temperate) // settlements & infrastructure, not peat, burned, temperate { - if (plant_data[x] >= 1) // Urbanization, not peat, burned, temperate, plantation + if (plant_data[x] >= 1) // settlements & infrastructure, not peat, burned, temperate, plantation { - outdata5a = Biomass_tCO2e_yesfire_CO2_only; - outdata5b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 56; + outdata_settlements_CO2only = Biomass_tCO2e_yesfire_CO2_only; + outdata_settlements_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_settlements_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 66; } - if (plant_data[x] == 0) // Urbanization, not peat, burned, temperate, not plantation + if (plant_data[x] == 0) // settlements & infrastructure, not peat, burned, temperate, not plantation { - outdata5a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata5b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 561; + outdata_settlements_CO2only = Biomass_tCO2e_yesfire_CO2_only + minsoil; + outdata_settlements_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_settlements_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 661; } } } - if (burn_data[x] == 0) // Urbanization, not peat, not burned + if (burn_data[x] == 0) // settlements & infrastructure, not peat, not burned { - if (ecozone_data[x] == tropical) // Urbanization, not peat, not burned, tropical + if (ecozone_data[x] == tropical) // settlements & infrastructure, not peat, not burned, tropical { - if (plant_data[x] >= 1) // Urbanization, not peat, not burned, tropical, plantation + if (plant_data[x] >= 1) // settlements & infrastructure, not peat, not burned, tropical, plantation { - outdata5a = Biomass_tCO2e_nofire_CO2_only; - outdata5b = 0; - outdata20 = 57; + outdata_settlements_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_settlements_CH4only = 0; + outdata_settlements_N2Oonly = 0; + outdata_node_code = 67; } - if (plant_data[x] == 0) // Urbanization, not peat, not burned, tropical, not plantation + if (plant_data[x] == 0) // settlements & infrastructure, not peat, not burned, tropical, not plantation { - outdata5a = Biomass_tCO2e_nofire_CO2_only + minsoil; - outdata5b = 0; - outdata20 = 571; + outdata_settlements_CO2only = Biomass_tCO2e_nofire_CO2_only + minsoil; + outdata_settlements_CH4only = 0; + outdata_settlements_N2Oonly = 0; + outdata_node_code = 671; } } - if (ecozone_data[x] == boreal) // Urbanization, not peat, not burned, boreal + if (ecozone_data[x] == boreal) // settlements & infrastructure, not peat, not burned, boreal { - outdata5a = Biomass_tCO2e_nofire_CO2_only + minsoil; - outdata5b = 0; - outdata20 = 58; + outdata_settlements_CO2only = Biomass_tCO2e_nofire_CO2_only + minsoil; + outdata_settlements_CH4only = 0; + outdata_settlements_N2Oonly = 0; + outdata_node_code = 68; } - if (ecozone_data[x] == temperate) // Urbanization, not peat, not burned, temperate + if (ecozone_data[x] == temperate) // settlements & infrastructure, not peat, not burned, temperate { - if (plant_data[x] >= 1) // Urbanization, not peat, not burned, temperate, plantation + if (plant_data[x] >= 1) // settlements & infrastructure, not peat, not burned, temperate, plantation { - outdata5a = Biomass_tCO2e_nofire_CO2_only; - outdata5b = 0; - outdata20 = 59; + outdata_settlements_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_settlements_CH4only = 0; + outdata_settlements_N2Oonly = 0; + outdata_node_code = 69; } - if (plant_data[x] == 0) // Urbanization, not peat, not burned, temperate, not plantation + if (plant_data[x] == 0) // settlements & infrastructure, not peat, not burned, temperate, not plantation { - outdata5a = Biomass_tCO2e_nofire_CO2_only + minsoil; - outdata5b = 0; - outdata20 = 591; + outdata_settlements_CO2only = Biomass_tCO2e_nofire_CO2_only + minsoil; + outdata_settlements_CH4only = 0; + outdata_settlements_N2Oonly = 0; + outdata_node_code = 691; } } } } - outdata5 = outdata5a + outdata5b; + outdata_settlements_allgases = outdata_settlements_CO2only + outdata_settlements_CH4only + outdata_settlements_N2Oonly; + outdata_settlements_nonCO2 = outdata_settlements_CH4only + outdata_settlements_N2Oonly; + } + + // Emissions model for other natural disturbances + else if (drivermodel_data[x] == 7) + { + Biomass_tCO2e_nofire_CO2_only = above_below_c * C_to_CO2; + Biomass_tCO2e_yesfire_CO2_only = ((agc_data[x] / biomass_to_c) * Cf * Gef_CO2 * pow(10, -3)); + Biomass_tCO2e_yesfire_CH4_only = ((non_soil_bgc_c / biomass_to_c) * Cf * Gef_CH4 * pow(10, -3) * CH4_equiv); + Biomass_tCO2e_yesfire_N2O_only = ((non_soil_bgc_c / biomass_to_c) * Cf * Gef_N2O * pow(10, -3) * N2O_equiv); + + if (peat_data[x] > 0) // other natural disturbances, peat + { + if (burn_data[x] > 0 ) // other natural disturbances, peat, burned + { + outdata_other_disturbances_CO2only = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; + outdata_other_disturbances_CH4only = Biomass_tCO2e_yesfire_CH4_only + peat_drain_total_CH4_only + peatburn_CH4_only; + outdata_other_disturbances_N2Oonly = Biomass_tCO2e_yesfire_N2O_only + peat_drain_total_N2O_only; + outdata_node_code = 70; + } + if (burn_data[x] == 0 ) // other natural disturbances, peat, not burned + { + if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // other natural disturbances, peat, not burned, temperate/boreal + { + outdata_other_disturbances_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_other_disturbances_CH4only = 0; + outdata_other_disturbances_N2Oonly = 0; + outdata_node_code = 71; + } + if (ecozone_data[x] == tropical)// other natural disturbances, peat, not burned, tropical + { + if (plant_data[x] > 0) // other natural disturbances, peat, not burned, tropical, plantation + { + outdata_other_disturbances_CO2only = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; + outdata_other_disturbances_CH4only = 0 + peat_drain_total_CH4_only; + outdata_other_disturbances_N2Oonly = 0 + peat_drain_total_N2O_only; + outdata_node_code = 72; + } + if (plant_data[x] == 0) // other natural disturbances, peat, not burned, tropical, not plantation + { + outdata_other_disturbances_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_other_disturbances_CH4only = 0; + outdata_other_disturbances_N2Oonly = 0; + outdata_node_code = 721; + } + } + } + } + else // other natural disturbances, not peat + { + if (burn_data[x] > 0) // other natural disturbances, not peat, burned + { + outdata_other_disturbances_CO2only = Biomass_tCO2e_yesfire_CO2_only; + outdata_other_disturbances_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_other_disturbances_N2Oonly= Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 73; + } + if (burn_data[x] == 0) // other natural disturbances, not peat, not burned + { + outdata_other_disturbances_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_other_disturbances_CH4only = 0; + outdata_other_disturbances_N2Oonly = 0; + outdata_node_code = 74; + } + } + outdata_other_disturbances_allgases = outdata_other_disturbances_CO2only + outdata_other_disturbances_CH4only + outdata_other_disturbances_N2Oonly; + outdata_other_disturbances_nonCO2 = outdata_other_disturbances_CH4only + outdata_other_disturbances_N2Oonly; } // Emissions for where there is no driver model. - // Nancy said to make this the same as forestry. + // Radost said to make it the same as other natural disturbances else { Biomass_tCO2e_nofire_CO2_only = above_below_c * C_to_CO2; Biomass_tCO2e_yesfire_CO2_only = ((agc_data[x] / biomass_to_c) * Cf * Gef_CO2 * pow(10, -3)); - Biomass_tCO2e_yesfire_non_CO2 = ((agc_data[x] / biomass_to_c) * Cf * Gef_CH4 * pow(10, -3) * CH4_equiv) + ((agc_data[x] / biomass_to_c) * Cf * Gef_N2O * pow(10, -3) * N2O_equiv); + Biomass_tCO2e_yesfire_CH4_only = ((non_soil_bgc_c / biomass_to_c) * Cf * Gef_CH4 * pow(10, -3) * CH4_equiv); + Biomass_tCO2e_yesfire_N2O_only = ((non_soil_bgc_c / biomass_to_c) * Cf * Gef_N2O * pow(10, -3) * N2O_equiv); if (peat_data[x] > 0) // No driver, peat { if (burn_data[x] > 0 ) // No driver, peat, burned { - outdata6a = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; - outdata6b = Biomass_tCO2e_yesfire_non_CO2 + peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 60; + outdata_no_driver_CO2only = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; + outdata_no_driver_CH4only = Biomass_tCO2e_yesfire_CH4_only + peat_drain_total_CH4_only + peatburn_CH4_only; + outdata_no_driver_N2Oonly = Biomass_tCO2e_yesfire_N2O_only + peat_drain_total_N2O_only; + outdata_node_code = 80; } if (burn_data[x] == 0 ) // No driver, peat, not burned { if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // No driver, peat, not burned, temperate/boreal { - outdata6a = Biomass_tCO2e_nofire_CO2_only; - outdata6b = 0; - outdata20 = 61; + outdata_no_driver_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_no_driver_CH4only = 0; + outdata_no_driver_N2Oonly = 0; + outdata_node_code = 81; } if (ecozone_data[x] == tropical)// No driver, peat, not burned, tropical { if (plant_data[x] > 0) // No driver, peat, not burned, tropical, plantation { - outdata6a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata6b = 0 + peat_drain_total_non_CO2; - outdata20 = 62; + outdata_no_driver_CO2only = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; + outdata_no_driver_CH4only = 0 + peat_drain_total_CH4_only; + outdata_no_driver_N2Oonly = 0 + peat_drain_total_N2O_only; + outdata_node_code = 82; } if (plant_data[x] == 0) // No driver, peat, not burned, tropical, not plantation { - outdata6a = Biomass_tCO2e_nofire_CO2_only; - outdata6b = 0; - outdata20 = 621; + outdata_no_driver_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_no_driver_CH4only = 0; + outdata_no_driver_N2Oonly = 0; + outdata_node_code = 821; } } } @@ -1141,111 +1441,157 @@ for(x=0; x 0) // No driver, not peat, burned { - outdata6a = Biomass_tCO2e_yesfire_CO2_only; - outdata6b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 63; + outdata_no_driver_CO2only = Biomass_tCO2e_yesfire_CO2_only; + outdata_no_driver_CH4only = Biomass_tCO2e_yesfire_CH4_only; + outdata_no_driver_N2Oonly = Biomass_tCO2e_yesfire_N2O_only; + outdata_node_code = 83; } if (burn_data[x] == 0) // No driver, not peat, not burned { - outdata6a = Biomass_tCO2e_nofire_CO2_only; - outdata6b = 0; - outdata20 = 64; + outdata_no_driver_CO2only = Biomass_tCO2e_nofire_CO2_only; + outdata_no_driver_CH4only = 0; + outdata_no_driver_N2Oonly = 0; + outdata_node_code = 84; } } - outdata6 = outdata6a + outdata6b; + outdata_no_driver_allgases = outdata_no_driver_CO2only + outdata_no_driver_CH4only + outdata_no_driver_N2Oonly; + outdata_no_driver_nonCO2 = outdata_no_driver_CH4only + outdata_no_driver_N2Oonly; } // Write the value to the correct raster - if (drivermodel_data[x] == 1) // Commodities + if (drivermodel_data[x] == 1) // permanent ag + { + out_data_permanent_agriculture[x] = outdata_permanent_agriculture_allgases; + out_data_hard_commodities[x] = 0; + out_data_shifting_cultivation[x] = 0; + out_data_forest_management[x] = 0; + out_data_wildfire[x] = 0; + out_data_settlements[x] = 0; + out_data_other_disturbances[x] = 0; + out_data_no_driver[x] = 0; + } + else if (drivermodel_data[x] == 2) // hard commodities { - out_data1[x] = outdata1; - out_data2[x] = 0; - out_data3[x] = 0; - out_data4[x] = 0; - out_data5[x] = 0; - out_data6[x] = 0; + out_data_permanent_agriculture[x] = 0; + out_data_hard_commodities[x] = outdata_hard_commodities_allgases; + out_data_shifting_cultivation[x] = 0; + out_data_forest_management[x] = 0; + out_data_wildfire[x] = 0; + out_data_settlements[x] = 0; + out_data_other_disturbances[x] = 0; + out_data_no_driver[x] = 0; } - else if (drivermodel_data[x] == 2) // Shifting ag + else if (drivermodel_data[x] == 3) // shifting cultivation { - out_data1[x] = 0; - out_data2[x] = outdata2; - out_data3[x] = 0; - out_data4[x] = 0; - out_data5[x] = 0; - out_data6[x] = 0; + out_data_permanent_agriculture[x] = 0; + out_data_hard_commodities[x] = 0; + out_data_shifting_cultivation[x] = outdata_shifting_cultivation_allgases; + out_data_forest_management[x] = 0; + out_data_wildfire[x] = 0; + out_data_settlements[x] = 0; + out_data_other_disturbances[x] = 0; + out_data_no_driver[x] = 0; } - else if (drivermodel_data[x] == 3) // Forestry + else if (drivermodel_data[x] == 4) // forest management { - out_data1[x] = 0; - out_data2[x] = 0; - out_data3[x] = outdata3; - out_data4[x] = 0; - out_data5[x] = 0; - out_data6[x] = 0; + out_data_permanent_agriculture[x] = 0; + out_data_hard_commodities[x] = 0; + out_data_shifting_cultivation[x] = 0; + out_data_forest_management[x] = outdata_forest_management_allgases; + out_data_wildfire[x] = 0; + out_data_settlements[x] = 0; + out_data_other_disturbances[x] = 0; + out_data_no_driver[x] = 0; } - else if (drivermodel_data[x] == 4) // Wildfire + else if (drivermodel_data[x] == 5) // wildfire { - out_data1[x] = 0; - out_data2[x] = 0; - out_data3[x] = 0; - out_data4[x] = outdata4; - out_data5[x] = 0; - out_data6[x] = 0; + out_data_permanent_agriculture[x] = 0; + out_data_hard_commodities[x] = 0; + out_data_shifting_cultivation[x] = 0; + out_data_forest_management[x] = 0; + out_data_wildfire[x] = outdata_wildfire_allgases; + out_data_settlements[x] = 0; + out_data_other_disturbances[x] = 0; + out_data_no_driver[x] = 0; } - else if (drivermodel_data[x] == 5) // Urbanization + else if (drivermodel_data[x] == 6) // settlements & infrastructure { - out_data1[x] = 0; - out_data2[x] = 0; - out_data3[x] = 0; - out_data4[x] = 0; - out_data5[x] = outdata5; - out_data6[x] = 0; + out_data_permanent_agriculture[x] = 0; + out_data_hard_commodities[x] = 0; + out_data_shifting_cultivation[x] = 0; + out_data_forest_management[x] = 0; + out_data_wildfire[x] = 0; + out_data_settlements[x] = outdata_settlements_allgases; + out_data_other_disturbances[x] = 0; + out_data_no_driver[x] = 0; + } + else if (drivermodel_data[x] == 7) // other natural disturbances + { + out_data_permanent_agriculture[x] = 0; + out_data_hard_commodities[x] = 0; + out_data_shifting_cultivation[x] = 0; + out_data_forest_management[x] = 0; + out_data_wildfire[x] = 0; + out_data_settlements[x] = 0; + out_data_other_disturbances[x] = outdata_other_disturbances_allgases; + out_data_no_driver[x] = 0; } else // No driver { - out_data1[x] = 0; - out_data2[x] = 0; - out_data3[x] = 0; - out_data4[x] = 0; - out_data5[x] = 0; - out_data6[x] = outdata6; + out_data_permanent_agriculture[x] = 0; + out_data_hard_commodities[x] = 0; + out_data_shifting_cultivation[x] = 0; + out_data_forest_management[x] = 0; + out_data_wildfire[x] = 0; + out_data_settlements[x] = 0; + out_data_other_disturbances[x] = 0; + out_data_no_driver[x] = outdata_no_driver_allgases; } // Decision tree end node value stored in its raster - out_data20[x] = outdata20; + out_data_node_code[x] = outdata_node_code; // Add up all drivers for a combined raster. Each pixel only has one driver - outdata10 = outdata1 + outdata2 + outdata3 + outdata4 + outdata5 + outdata6; - outdata11 = outdata1a + outdata2a + outdata3a + outdata4a + outdata5a + outdata6a; - outdata12 = outdata1b + outdata2b + outdata3b + outdata4b + outdata5b + outdata6b; + outdata_alldrivers_allgases = outdata_permanent_agriculture_allgases + outdata_hard_commodities_allgases + outdata_shifting_cultivation_allgases + outdata_forest_management_allgases + outdata_wildfire_allgases + outdata_settlements_allgases + outdata_other_disturbances_allgases + outdata_no_driver_allgases; + outdata_alldrivers_CO2only = outdata_permanent_agriculture_CO2only + outdata_hard_commodities_CO2only + outdata_shifting_cultivation_CO2only + outdata_forest_management_CO2only + outdata_wildfire_CO2only + outdata_settlements_CO2only + outdata_other_disturbances_CO2only + outdata_no_driver_CO2only; + outdata_alldrivers_nonCO2 = outdata_permanent_agriculture_nonCO2 + outdata_hard_commodities_nonCO2 +outdata_shifting_cultivation_nonCO2 + outdata_forest_management_nonCO2 + outdata_wildfire_nonCO2 + outdata_settlements_nonCO2 + outdata_other_disturbances_nonCO2 + outdata_no_driver_nonCO2; + outdata_alldrivers_CH4only = outdata_permanent_agriculture_CH4only + outdata_hard_commodities_CH4only +outdata_shifting_cultivation_CH4only + outdata_forest_management_CH4only + outdata_wildfire_CH4only + outdata_settlements_CH4only + outdata_other_disturbances_CH4only + outdata_no_driver_CH4only; + outdata_alldrivers_N2Oonly = outdata_permanent_agriculture_N2Oonly + outdata_hard_commodities_N2Oonly +outdata_shifting_cultivation_N2Oonly + outdata_forest_management_N2Oonly + outdata_wildfire_N2Oonly + outdata_settlements_N2Oonly + outdata_other_disturbances_N2Oonly + outdata_no_driver_N2Oonly; - if (outdata10 == 0) + if (outdata_alldrivers_allgases == 0) { - out_data10[x] = 0; - out_data11[x] = 0; - out_data12[x] = 0; + out_data_alldrivers_allgasses[x] = 0; + out_data_alldrivers_CO2only[x] = 0; + out_data_alldrivers_nonCO2[x] = 0; + out_data_alldrivers_CH4only[x] = 0; + out_data_alldrivers_N2Oonly[x] = 0; } else{ - out_data10[x] = outdata10; - out_data11[x] = outdata11; - out_data12[x] = outdata12; + out_data_alldrivers_allgasses[x] = outdata_alldrivers_allgases; + out_data_alldrivers_CO2only[x] = outdata_alldrivers_CO2only; + out_data_alldrivers_nonCO2[x] = outdata_alldrivers_nonCO2; + out_data_alldrivers_CH4only[x] = outdata_alldrivers_CH4only; + out_data_alldrivers_N2Oonly[x] = outdata_alldrivers_N2Oonly; } } // If pixel is not on loss and carbon, all output rasters get 0 else { - - out_data1[x] = 0; - out_data2[x] = 0; - out_data3[x] = 0; - out_data4[x] = 0; - out_data5[x] = 0; - out_data6[x] = 0; - out_data10[x] = 0; - out_data11[x] = 0; - out_data12[x] = 0; - out_data20[x] = 0; + out_data_permanent_agriculture[x] = 0; + out_data_hard_commodities[x] = 0; + out_data_shifting_cultivation[x] = 0; + out_data_forest_management[x] = 0; + out_data_wildfire[x] = 0; + out_data_settlements[x] = 0; + out_data_other_disturbances[x] = 0; + out_data_no_driver[x] = 0; + out_data_alldrivers_allgasses[x] = 0; + out_data_alldrivers_CO2only[x] = 0; + out_data_alldrivers_nonCO2[x] = 0; + out_data_alldrivers_CH4only[x] = 0; + out_data_alldrivers_N2Oonly[x] = 0; + out_data_node_code[x] = 0; } } @@ -1256,23 +1602,18 @@ for(x=0; xRasterIO( GF_Write, 0, y, xsize, 1, out_data1, xsize, 1, GDT_Float32, 0, 0 ); -CPLErr errcodeOut2 = OUTBAND2->RasterIO( GF_Write, 0, y, xsize, 1, out_data2, xsize, 1, GDT_Float32, 0, 0 ); -CPLErr errcodeOut3 = OUTBAND3->RasterIO( GF_Write, 0, y, xsize, 1, out_data3, xsize, 1, GDT_Float32, 0, 0 ); -CPLErr errcodeOut4 = OUTBAND4->RasterIO( GF_Write, 0, y, xsize, 1, out_data4, xsize, 1, GDT_Float32, 0, 0 ); -CPLErr errcodeOut5 = OUTBAND5->RasterIO( GF_Write, 0, y, xsize, 1, out_data5, xsize, 1, GDT_Float32, 0, 0 ); -CPLErr errcodeOut6 = OUTBAND6->RasterIO( GF_Write, 0, y, xsize, 1, out_data6, xsize, 1, GDT_Float32, 0, 0 ); -CPLErr errcodeOut10 = OUTBAND10->RasterIO( GF_Write, 0, y, xsize, 1, out_data10, xsize, 1, GDT_Float32, 0, 0 ); -CPLErr errcodeOut11 = OUTBAND11->RasterIO( GF_Write, 0, y, xsize, 1, out_data11, xsize, 1, GDT_Float32, 0, 0 ); -CPLErr errcodeOut12 = OUTBAND12->RasterIO( GF_Write, 0, y, xsize, 1, out_data12, xsize, 1, GDT_Float32, 0, 0 ); -CPLErr errcodeOut20 = OUTBAND20->RasterIO( GF_Write, 0, y, xsize, 1, out_data20, xsize, 1, GDT_UInt16, 0, 0 ); +CPLErr errcodeOut_alldrivers_allgasses = OUTBAND_ALLDRIVERS_ALLGASSES->RasterIO( GF_Write, 0, y, xsize, 1, out_data_alldrivers_allgasses, xsize, 1, GDT_Float32, 0, 0 ); +CPLErr errcodeOut_alldrivers_CO2only = OUTBAND_ALLDRIVERS_CO2ONLY->RasterIO( GF_Write, 0, y, xsize, 1, out_data_alldrivers_CO2only, xsize, 1, GDT_Float32, 0, 0 ); +CPLErr errcodeOut_alldrivers_nonCO2 = OUTBAND_ALLDRIVERS_NONCO2->RasterIO( GF_Write, 0, y, xsize, 1, out_data_alldrivers_nonCO2, xsize, 1, GDT_Float32, 0, 0 ); +CPLErr errcodeOut_alldrivers_CH4only = OUTBAND_ALLDRIVERS_CH4ONLY->RasterIO( GF_Write, 0, y, xsize, 1, out_data_alldrivers_CH4only, xsize, 1, GDT_Float32, 0, 0 ); +CPLErr errcodeOut_alldrivers_N2Oonly = OUTBAND_ALLDRIVERS_N2OONLY->RasterIO( GF_Write, 0, y, xsize, 1, out_data_alldrivers_N2Oonly, xsize, 1, GDT_Float32, 0, 0 ); +CPLErr errcodeOut_node_code = OUTBAND_NODE_CODE->RasterIO( GF_Write, 0, y, xsize, 1, out_data_node_code, xsize, 1, GDT_UInt16, 0, 0 ); // Number of output files -int outSize = 10; +int outSize = 6; // Array of error codes returned from each output -CPLErr errcodeOutArray [outSize] = {errcodeOut1, errcodeOut2, errcodeOut3, errcodeOut4, errcodeOut5, errcodeOut6, -errcodeOut10, errcodeOut11, errcodeOut12, errcodeOut20}; +CPLErr errcodeOutArray [outSize] = {errcodeOut_alldrivers_allgasses, errcodeOut_alldrivers_CO2only, errcodeOut_alldrivers_nonCO2, errcodeOut_alldrivers_CH4only, errcodeOut_alldrivers_N2Oonly, errcodeOut_node_code}; // Iterates through the output error codes to make sure that the error code is acceptable int k; @@ -1286,16 +1627,12 @@ for (k=0; k -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -// These provide constants for the emissions equations -#include "flu_val.cpp" -#include "equations.cpp" -#include "constants.h" - -using namespace std; - -//to compile: c++ calc_gross_emissions.cpp -o calc_gross_emissions.exe -lgdal -int main(int argc, char* argv[]) -{ -// If code is run other than , it will raise this error. -if (argc != 4){cout << "Use " << endl; return 1;} - -// Input arguments -string tile_id = argv[1]; // The tile id comes from the second argument. The first argument is the name of this code. -string sensit_type = argv[2]; // For standard model or sensitivity analyses that use the standard emissions model. - // Used to name the input carbon pool tiles and output gross emissions tiles. -string infolder = argv[3]; // The folder which has all the input files - -cout << "Gross emissions C++ infolder:" << infolder << endl; - -// Model constants -int model_years; // How many loss years are in the model -model_years = constants::model_years; -string model_years_str; -model_years_str = to_string(model_years); - -int CH4_equiv; // The CO2 equivalency (global warming potential) of CH4 -CH4_equiv = constants::CH4_equiv; - -int N2O_equiv; // The CO2 equivalency (global warming potential) of N2O -N2O_equiv = constants::N2O_equiv; - -float C_to_CO2; // The conversion of carbon to CO2 -C_to_CO2 = constants::C_to_CO2; - -float biomass_to_c; // Fraction of carbon in biomass -biomass_to_c = constants::biomass_to_c; - -int tropical; // The ecozone code for the tropics -tropical = constants::tropical; - -int temperate; // The ecozone code for the temperate zone -temperate = constants::temperate; - -int boreal; // The ecozone code for the boreal zone -boreal = constants::boreal; - -int soil_emis_period; // The number of years over which soil emissions are calculated (separate from model years) -soil_emis_period = constants::soil_emis_period; - - -// Input files -// Carbon pools use the standard names for this sensitivity analysis -string agc_name = infolder + tile_id + constants::AGC_emis_year + ".tif"; -string bgc_name = infolder + tile_id + constants::BGC_emis_year + ".tif"; -string dead_name = infolder + tile_id + constants::deadwood_C_emis_year + ".tif"; -string litter_name = infolder + tile_id + constants::litter_C_emis_year + ".tif"; -string soil_name = infolder + tile_id + constants::soil_C_emis_year + ".tif"; - -// Other inputs -string loss_name = infolder + constants::lossyear + tile_id + ".tif"; -string burn_name = infolder + tile_id + constants::burnyear; -string ecozone_name = infolder + tile_id + constants::fao_ecozones; -string climate_name = infolder + tile_id + constants::climate_zones; -string drivermodel_name = infolder + tile_id + constants::tcl_drivers; -string peat_name = infolder + tile_id + constants::peat_mask; -string ifl_primary_name = infolder + tile_id + constants::ifl_primary; -string plant_name = infolder + tile_id + constants::plantation_type; - -// Output files: tonnes CO2/ha for each tree cover loss driver, their total, and the node for the decision tree -// that determines emissions -string out_name1 = tile_id + constants::commod_emis + model_years_str + "_no_shifting_ag.tif"; -string out_name2 = tile_id + constants::shifting_ag_emis + model_years_str + "_no_shifting_ag.tif"; -string out_name3 = tile_id + constants::forestry_emis + model_years_str + "_no_shifting_ag.tif"; -string out_name4 = tile_id + constants::wildfire_emis + model_years_str + "_no_shifting_ag.tif"; -string out_name5 = tile_id + constants::urbanization_emis + model_years_str + "_no_shifting_ag.tif"; -string out_name6 = tile_id + constants::no_driver_emis + model_years_str + "_no_shifting_ag.tif"; -string out_name10 = tile_id + constants::all_gases_all_drivers_emis + model_years_str + "_no_shifting_ag.tif"; -string out_name11 = tile_id + constants::CO2_only_all_drivers_emis + model_years_str + "_no_shifting_ag.tif"; -string out_name12 = tile_id + constants::non_CO2_all_drivers_emis + model_years_str + "_no_shifting_ag.tif"; -string out_name20 = tile_id + constants::decision_tree_all_drivers_emis + model_years_str + "_no_shifting_ag.tif"; - - -// Setting up the variables to hold the pixel location in x/y values -int x, y; -int xsize, ysize; -double GeoTransform[6]; // Fetch the affine transformation coefficients -double ulx, uly; double pixelsize; - -// Initialize GDAL for reading. -// Each of these "INBAND" are later associated with the string variables defined above. -GDALAllRegister(); -GDALDataset *INGDAL1; GDALRasterBand *INBAND1; -GDALDataset *INGDAL2; GDALRasterBand *INBAND2; -GDALDataset *INGDAL3; GDALRasterBand *INBAND3; -GDALDataset *INGDAL4; GDALRasterBand *INBAND4; -GDALDataset *INGDAL5; GDALRasterBand *INBAND5; -GDALDataset *INGDAL6; GDALRasterBand *INBAND6; -GDALDataset *INGDAL7; GDALRasterBand *INBAND7; -GDALDataset *INGDAL8; GDALRasterBand *INBAND8; -GDALDataset *INGDAL9; GDALRasterBand *INBAND9; -GDALDataset *INGDAL10; GDALRasterBand *INBAND10; -GDALDataset *INGDAL11; GDALRasterBand *INBAND11; -GDALDataset *INGDAL12; GDALRasterBand *INBAND12; -GDALDataset *INGDAL13; GDALRasterBand *INBAND13; - -//open file (string variables defined above) and assign it extent and projection -INGDAL1 = (GDALDataset *) GDALOpen(agc_name.c_str(), GA_ReadOnly ); -INBAND1 = INGDAL1->GetRasterBand(1); - -INGDAL2 = (GDALDataset *) GDALOpen(bgc_name.c_str(), GA_ReadOnly ); -INBAND2 = INGDAL2->GetRasterBand(1); - -INGDAL3 = (GDALDataset *) GDALOpen(drivermodel_name.c_str(), GA_ReadOnly ); -INBAND3 = INGDAL3->GetRasterBand(1); - -INGDAL4 = (GDALDataset *) GDALOpen(loss_name.c_str(), GA_ReadOnly ); -INBAND4 = INGDAL4->GetRasterBand(1); - -INGDAL5 = (GDALDataset *) GDALOpen(peat_name.c_str(), GA_ReadOnly ); -INBAND5 = INGDAL5->GetRasterBand(1); - -INGDAL6 = (GDALDataset *) GDALOpen(burn_name.c_str(), GA_ReadOnly ); -INBAND6 = INGDAL6->GetRasterBand(1); - -INGDAL7 = (GDALDataset *) GDALOpen(ifl_primary_name.c_str(), GA_ReadOnly ); -INBAND7 = INGDAL7->GetRasterBand(1); - -INGDAL8 = (GDALDataset *) GDALOpen(ecozone_name.c_str(), GA_ReadOnly ); -INBAND8 = INGDAL8->GetRasterBand(1); - -INGDAL9 = (GDALDataset *) GDALOpen(climate_name.c_str(), GA_ReadOnly ); -INBAND9 = INGDAL9->GetRasterBand(1); - -INGDAL10 = (GDALDataset *) GDALOpen(dead_name.c_str(), GA_ReadOnly ); -INBAND10 = INGDAL10->GetRasterBand(1); - -INGDAL11 = (GDALDataset *) GDALOpen(litter_name.c_str(), GA_ReadOnly ); -INBAND11 = INGDAL11->GetRasterBand(1); - -INGDAL12 = (GDALDataset *) GDALOpen(soil_name.c_str(), GA_ReadOnly ); -INBAND12 = INGDAL12->GetRasterBand(1); - -INGDAL13 = (GDALDataset *) GDALOpen(plant_name.c_str(), GA_ReadOnly ); -INBAND13 = INGDAL13->GetRasterBand(1); - -// The rest of the code runs on the size of INBAND3. This can be changed. -xsize=INBAND1->GetXSize(); -ysize=INBAND1->GetYSize(); -INGDAL1->GetGeoTransform(GeoTransform); - -ulx=GeoTransform[0]; -uly=GeoTransform[3]; -pixelsize=GeoTransform[1]; - -// // Manually change this to test the script on a small part of the raster. This starts at top left of the tile. -//xsize = 4500; -//ysize = 3500; - -// Print the raster size and resolution. Should be 40,000 x 40,000 and pixel size 0.00025. -cout << "Gross emissions no_shifting_ag model C++ parameters: " << xsize <<", "<< ysize <<", "<< ulx <<", "<< uly << ", "<< pixelsize << endl; - -// Initialize GDAL for writing -GDALDriver *OUTDRIVER; -GDALDataset *OUTGDAL1; // Commodities, all gases -GDALDataset *OUTGDAL2; // Shifting ag, all gases -GDALDataset *OUTGDAL3; // Forestry, all gases -GDALDataset *OUTGDAL4; // Wildfire, all gases -GDALDataset *OUTGDAL5; // Urbanization, all gases -GDALDataset *OUTGDAL6; // No driver, all gases -GDALDataset *OUTGDAL10; // All drivers, all gases -GDALDataset *OUTGDAL11; // All drivers, CO2 only -GDALDataset *OUTGDAL12; // All drivers, non-CO2 -GDALDataset *OUTGDAL20; // Decision tree node - -GDALRasterBand *OUTBAND1; -GDALRasterBand *OUTBAND2; -GDALRasterBand *OUTBAND3; -GDALRasterBand *OUTBAND4; -GDALRasterBand *OUTBAND5; -GDALRasterBand *OUTBAND6; -GDALRasterBand *OUTBAND10; -GDALRasterBand *OUTBAND11; -GDALRasterBand *OUTBAND12; -GDALRasterBand *OUTBAND20; - -OGRSpatialReference oSRS; -char *OUTPRJ = NULL; -char **papszOptions = NULL; -papszOptions = CSLSetNameValue( papszOptions, "COMPRESS", "DEFLATE" ); -OUTDRIVER = GetGDALDriverManager()->GetDriverByName("GTIFF"); -if( OUTDRIVER == NULL ) {cout << "no driver" << endl; exit( 1 );}; -oSRS.SetWellKnownGeogCS( "WGS84" ); -oSRS.exportToWkt( &OUTPRJ ); -double adfGeoTransform[6] = { ulx, pixelsize, 0, uly, 0, -1*pixelsize }; - -// Commoditiy gross emissions -OUTGDAL1 = OUTDRIVER->Create( out_name1.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL1->SetGeoTransform(adfGeoTransform); OUTGDAL1->SetProjection(OUTPRJ); -OUTBAND1 = OUTGDAL1->GetRasterBand(1); -OUTBAND1->SetNoDataValue(0); - -// Shifting ag gross emissions -OUTGDAL2 = OUTDRIVER->Create( out_name2.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL2->SetGeoTransform(adfGeoTransform); OUTGDAL2->SetProjection(OUTPRJ); -OUTBAND2 = OUTGDAL2->GetRasterBand(1); -OUTBAND2->SetNoDataValue(0); - -// Forestry gross emissions -OUTGDAL3 = OUTDRIVER->Create( out_name3.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL3->SetGeoTransform(adfGeoTransform); OUTGDAL3->SetProjection(OUTPRJ); -OUTBAND3 = OUTGDAL3->GetRasterBand(1); -OUTBAND3->SetNoDataValue(0); - -// Wildfire gross emissions -OUTGDAL4 = OUTDRIVER->Create( out_name4.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL4->SetGeoTransform(adfGeoTransform); OUTGDAL4->SetProjection(OUTPRJ); -OUTBAND4 = OUTGDAL4->GetRasterBand(1); -OUTBAND4->SetNoDataValue(0); - -// Urbanization gross emissions -OUTGDAL5 = OUTDRIVER->Create( out_name5.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL5->SetGeoTransform(adfGeoTransform); OUTGDAL5->SetProjection(OUTPRJ); -OUTBAND5 = OUTGDAL5->GetRasterBand(1); -OUTBAND5->SetNoDataValue(0); - -// No driver gross emissions -OUTGDAL6 = OUTDRIVER->Create( out_name6.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL6->SetGeoTransform(adfGeoTransform); OUTGDAL6->SetProjection(OUTPRJ); -OUTBAND6 = OUTGDAL6->GetRasterBand(1); -OUTBAND6->SetNoDataValue(0); - -// All gases, all drivers combined -OUTGDAL10 = OUTDRIVER->Create( out_name10.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL10->SetGeoTransform(adfGeoTransform); OUTGDAL10->SetProjection(OUTPRJ); -OUTBAND10 = OUTGDAL10->GetRasterBand(1); -OUTBAND10->SetNoDataValue(0); - -// CO2 only, all drivers combined -OUTGDAL11 = OUTDRIVER->Create( out_name11.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL11->SetGeoTransform(adfGeoTransform); OUTGDAL11->SetProjection(OUTPRJ); -OUTBAND11 = OUTGDAL11->GetRasterBand(1); -OUTBAND11->SetNoDataValue(0); - -// Non-CO2, all drivers combined -OUTGDAL12 = OUTDRIVER->Create( out_name12.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL12->SetGeoTransform(adfGeoTransform); OUTGDAL12->SetProjection(OUTPRJ); -OUTBAND12 = OUTGDAL12->GetRasterBand(1); -OUTBAND12->SetNoDataValue(0); - -// Decision tree node -OUTGDAL20 = OUTDRIVER->Create( out_name20.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL20->SetGeoTransform(adfGeoTransform); OUTGDAL20->SetProjection(OUTPRJ); -OUTBAND20 = OUTGDAL20->GetRasterBand(1); -OUTBAND20->SetNoDataValue(0); - - -// Read/write data -// Inputs -float agc_data[xsize]; -float bgc_data[xsize]; -float loss_data[xsize]; -float peat_data[xsize]; -float drivermodel_data[xsize]; -float burn_data[xsize]; -float ecozone_data[xsize]; -float soil_data[xsize]; -float climate_data[xsize]; -float dead_data[xsize]; -float litter_data[xsize]; -float ifl_primary_data[xsize]; -float plant_data[xsize]; - -// Outputs -float out_data1[xsize]; -float out_data2[xsize]; -float out_data3[xsize]; -float out_data4[xsize]; -float out_data5[xsize]; -float out_data6[xsize]; -float out_data10[xsize]; -float out_data11[xsize]; -float out_data12[xsize]; -float out_data20[xsize]; - -// Loop over the y coordinates, then the x coordinates -for (y=0; yRasterIO(GF_Read, 0, y, xsize, 1, agc_data, xsize, 1, GDT_Float32, 0, 0); -INBAND2->RasterIO(GF_Read, 0, y, xsize, 1, bgc_data, xsize, 1, GDT_Float32, 0, 0); -INBAND3->RasterIO(GF_Read, 0, y, xsize, 1, drivermodel_data, xsize, 1, GDT_Float32, 0, 0); -INBAND4->RasterIO(GF_Read, 0, y, xsize, 1, loss_data, xsize, 1, GDT_Float32, 0, 0); -INBAND5->RasterIO(GF_Read, 0, y, xsize, 1, peat_data, xsize, 1, GDT_Float32, 0, 0); -INBAND6->RasterIO(GF_Read, 0, y, xsize, 1, burn_data, xsize, 1, GDT_Float32, 0, 0); -INBAND7->RasterIO(GF_Read, 0, y, xsize, 1, ifl_primary_data, xsize, 1, GDT_Float32, 0, 0); -INBAND8->RasterIO(GF_Read, 0, y, xsize, 1, ecozone_data, xsize, 1, GDT_Float32, 0, 0); -INBAND9->RasterIO(GF_Read, 0, y, xsize, 1, climate_data, xsize, 1, GDT_Float32, 0, 0); -INBAND10->RasterIO(GF_Read, 0, y, xsize, 1, dead_data, xsize, 1, GDT_Float32, 0, 0); -INBAND11->RasterIO(GF_Read, 0, y, xsize, 1, litter_data, xsize, 1, GDT_Float32, 0, 0); -INBAND12->RasterIO(GF_Read, 0, y, xsize, 1, soil_data, xsize, 1, GDT_Float32, 0, 0); -INBAND13->RasterIO(GF_Read, 0, y, xsize, 1, plant_data, xsize, 1, GDT_Float32, 0, 0); - -for(x=0; x 0 && agc_data[x] > 0) - { - - // From equations.cpp, a function called def_variables, we get back several constants - // based on several input rasters for that pixel. These are later used for calculating emissions. - - // def_variables kept returning the same values for all pixels in a tile as the first pixel in the tile regardless of the inputs to the function; - // it was as if the returned values for the first pixel evaluated couldn't be overwritten. - // The first answer here told me how to solve that: https://stackoverflow.com/questions/51609816/return-float-array-from-a-function-c - float q[8]; - def_variables(&q[0], ecozone_data[x], drivermodel_data[x], ifl_primary_data[x], climate_data[x], plant_data[x], loss_data[x]); - - // The constants needed for calculating emissions - float Cf = q[0]; // Combustion factor - float Gef_CO2 = q[1]; // Emissions factor for CO2 - float Gef_CH4 = q[2]; // Emissions factor for CH4 - float Gef_N2O = q[3]; // Emissions factor for N2O - float peatburn_CO2_only = q[4]; // Emissions from burning peat, CO2 emissions only - float peatburn_non_CO2 = q[5]; // Emissions from burning peat, non-CO2 emissions only - float peat_drain_total_CO2_only = q[6]; // Emissions from draining peat, CO2 emissions only - float peat_drain_total_non_CO2 = q[7]; // Emissions from draining peat, non-CO2 emissions only - - // Define and calculate several values used later - float non_soil_c; - non_soil_c = agc_data[x] + bgc_data[x] + dead_data[x] + litter_data[x]; - - float above_below_c; - above_below_c = agc_data[x] + bgc_data[x]; - - float Biomass_tCO2e_nofire_CO2_only; // Emissions from biomass on pixels without fire- only emits CO2 (no non-CO2 option) - float Biomass_tCO2e_yesfire_CO2_only; // Emissions from biomass on pixels with fire- only the CO2 - float Biomass_tCO2e_yesfire_non_CO2; // Emissions from biomass on pixels with fire- only the non-CO2 gases - float minsoil; // Emissions from mineral soil- all CO2 - float flu; // Emissions fraction from mineral soil - - // Each driver is an output raster and has its own emissions model. outdata20 is the code for each - // combination of outputs. Defined in carbon-budget/emissions/node_codes.txt - - // Emissions model for commodity-driven deforestation and shifting ag - // (shifting ag uses commodity decision tree for this sensitivity analysis) - if ((drivermodel_data[x] == 1) || (drivermodel_data[x] == 2)) - { - // For each driver, these values (or a subset of them) are necessary for calculating emissions. - Biomass_tCO2e_nofire_CO2_only = non_soil_c * C_to_CO2; - Biomass_tCO2e_yesfire_CO2_only = non_soil_c * C_to_CO2; - Biomass_tCO2e_yesfire_non_CO2 = ((non_soil_c / biomass_to_c) * Cf * Gef_CH4 * pow(10,-3) * CH4_equiv) + ((non_soil_c / biomass_to_c) * Cf * Gef_N2O * pow(10,-3) * N2O_equiv); - flu = flu_val(climate_data[x], ecozone_data[x]); - minsoil = ((soil_data[x]-(soil_data[x] * flu))/soil_emis_period) * (model_years-loss_data[x]); - - if (peat_data[x] > 0) // Commodity, peat - { - if (burn_data[x] > 0) // Commodity, peat, burned - { - outdata1a = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; - outdata1b = Biomass_tCO2e_yesfire_non_CO2 + peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 10; - } - if (burn_data[x] == 0) // Commodity, peat, not burned - { - if (ecozone_data[x] == tropical) // Commodity, peat, not burned, tropical - { - if (plant_data[x] >= 1) // Commodity, peat, not burned, tropical, plantation - { - outdata1a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata1b = 0 + peat_drain_total_non_CO2; - outdata20 = 11; - } - if (plant_data[x] == 0) // Commodity, peat, not burned, tropical, not plantation - { - outdata1a = Biomass_tCO2e_nofire_CO2_only; - outdata1b = 0; - outdata20 = 111; - } - } - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // Commodity, peat, not burned, temperate/boreal - { - outdata1a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata1b = 0 + peat_drain_total_non_CO2; - outdata20 = 12; - } - } - } - if (peat_data[x] == 0) // Commodity, not peat - { - if (burn_data[x] > 0) // Commodity, not peat, burned - { - if (ecozone_data[x] == tropical) // Commodity, not peat, burned, tropical - { - if (ifl_primary_data[x] == 1) // Commodity, not peat, burned, tropical, IFL - { - if (plant_data[x] >= 1) // Commodity, not peat, burned, tropical, IFL, plantation - { - outdata1a = Biomass_tCO2e_yesfire_CO2_only; - outdata1b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 13; - } - if (plant_data[x] == 0) // Commodity, not peat, burned, tropical, IFL, not plantation - { - outdata1a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata1b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 131; - } - } - if (ifl_primary_data[x] == 0) // Commodity, not peat, burned, tropical, not IFL - { - if (plant_data[x] >= 1) // Commodity, not peat, burned, tropical, not IFL, plantation - { - outdata1a = Biomass_tCO2e_yesfire_CO2_only; - outdata1b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 14; - } - if (plant_data[x] == 0) // Commodity, not peat, burned, tropical, not IFL, not plantation - { - outdata1a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata1b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 141; - } - } - } - if (ecozone_data[x] == boreal) // Commodity, not peat, burned, boreal - { - outdata1a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata1b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 15; - } - if (ecozone_data[x] == temperate) // Commodity, not peat, burned, temperate - { - if (plant_data[x] >= 1) // Commodity, not peat, burned, temperate, plantation - { - outdata1a = Biomass_tCO2e_yesfire_CO2_only; - outdata1b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 16; - } - if (plant_data[x] == 0) // Commodity, not peat, burned, temperate, no plantation - { - outdata1a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata1b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 161; - } - } - } - if (burn_data[x] == 0) // Commodity, not peat, not burned - { - if (ecozone_data[x] == tropical) // Commodity, not peat, not burned, tropical - { - if (plant_data[x] >= 1) // Commodity, not peat, not burned, tropical, plantation - { - outdata1a = Biomass_tCO2e_nofire_CO2_only; - outdata1b = 0; - outdata20 = 17; - } - if (plant_data[x] == 0) // Commodity, not peat, not burned, tropical, no plantation - { - outdata1a = Biomass_tCO2e_nofire_CO2_only + minsoil; - outdata1b = 0; - outdata20 = 171; - } - } - if (ecozone_data[x] == boreal) // Commodity, not peat, not burned, boreal - { - outdata1a = Biomass_tCO2e_nofire_CO2_only + minsoil; - outdata1b = 0; - outdata20 = 18; - } - if (ecozone_data[x] == temperate) // Commodity, not peat, not burned, temperate - { - if (plant_data[x] >= 1) // Commodity, not peat, not burned, temperate, plantation - { - outdata1a = Biomass_tCO2e_nofire_CO2_only; - outdata1b = 0; - outdata20 = 19; - } - if (plant_data[x] == 0) // Commodity, not peat, not burned, temperate, no plantation - { - outdata1a = Biomass_tCO2e_nofire_CO2_only + minsoil; - outdata1b = 0; - outdata20 = 191; - - ////QC code to get the values of the relevant variables at a particular pixel of interest (based on its values rather than its coordinates) - //double total; - //total = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only + Biomass_tCO2e_yesfire_non_CO2 + peat_drain_total_non_CO2 + peatburn_non_CO2; - //if ((total < 715) && (total > 714) && (agc_data[x] = 26.25) && (soil_data[x] = 216) && (dead_data[x] = 1.44) && (litter_data[x] = 0.5328) && (burn_data[x] = 6)) - //{ - // cout << "total: " << total << endl; - // cout << "Biomass_tCO2e_yesfire_CO2_only: " << Biomass_tCO2e_yesfire_CO2_only << endl; - // cout << "Biomass_tCO2e_yesfire_non_CO2: " << Biomass_tCO2e_yesfire_non_CO2 << endl; - // cout << "peat_drain_total_CO2_only: " << peat_drain_total_CO2_only << endl; - // cout << "peat_drain_total_non_CO2: " << peat_drain_total_non_CO2 << endl; - // cout << "peatburn_CO2_only: " << peatburn_CO2_only << endl; - // cout << "peatburn_non_CO2: " << peatburn_non_CO2 << endl; - // cout << "agc_data[x]: " << agc_data[x] << endl; - // cout << "Cf: " << Cf << endl; - // cout << "Gef_CO2: " << Gef_CO2 << endl; - // cout << "Gef_CH4: " << Gef_CH4 << endl; - // cout << "Gef_N2O: " << Gef_N2O << endl; - // cout << "" << endl; - //} - } - } - } - } - outdata1 = outdata1a + outdata1b; - } - - // Emissions model for forestry - else if (drivermodel_data[x] == 3) - { - Biomass_tCO2e_nofire_CO2_only = above_below_c * C_to_CO2; - Biomass_tCO2e_yesfire_CO2_only = ((agc_data[x] / biomass_to_c) * Cf * Gef_CO2 * pow(10, -3)); - Biomass_tCO2e_yesfire_non_CO2 = ((agc_data[x] / biomass_to_c) * Cf * Gef_CH4 * pow(10, -3) * CH4_equiv) + ((agc_data[x] / biomass_to_c) * Cf * Gef_N2O * pow(10, -3) * N2O_equiv); - - if (peat_data[x] > 0) // Forestry, peat - { - if (burn_data[x] > 0 ) // Forestry, peat, burned - { - outdata3a = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; - outdata3b = Biomass_tCO2e_yesfire_non_CO2 + peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 30; - } - if (burn_data[x] == 0 ) // Forestry, peat, not burned - { - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // Forestry, peat, not burned, temperate/boreal - { - outdata3a = Biomass_tCO2e_nofire_CO2_only; - outdata3b = 0; - outdata20 = 31; - } - if (ecozone_data[x] == tropical)// Forestry, peat, not burned, tropical - { - if (plant_data[x] > 0) // Forestry, peat, not burned, tropical, plantation - { - outdata3a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata3b = 0 + peat_drain_total_non_CO2; - outdata20 = 32; - } - if (plant_data[x] == 0) // Forestry, peat, not burned, tropical, not plantation - { - outdata3a = Biomass_tCO2e_nofire_CO2_only; - outdata3b = 0; - outdata20 = 321; - } - } - } - } - else - { - if (burn_data[x] > 0) // Forestry, not peat, burned - { - outdata3a = Biomass_tCO2e_yesfire_CO2_only; - outdata3b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 33; - } - if (burn_data[x] == 0) // Forestry, not peat, not burned - { - outdata3a = Biomass_tCO2e_nofire_CO2_only; - outdata3b = 0; - outdata20 = 34; - } - } - outdata3 = outdata3a + outdata3b; - } - - // Emissions model for wildfires - else if (drivermodel_data[x] == 4) - { - Biomass_tCO2e_nofire_CO2_only = above_below_c * C_to_CO2; - Biomass_tCO2e_yesfire_CO2_only = ((agc_data[x] / biomass_to_c) * Cf * Gef_CO2 * pow(10, -3)); - Biomass_tCO2e_yesfire_non_CO2 = ((agc_data[x] / biomass_to_c) * Cf * Gef_CH4 * pow(10, -3) * CH4_equiv) + ((agc_data[x] / biomass_to_c) * Cf * Gef_N2O * pow(10, -3) * N2O_equiv); - - if (peat_data[x] > 0) // Wildfire, peat - { - if (burn_data[x] > 0) // Wildfire, peat, burned - { - outdata4a = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; - outdata4b = Biomass_tCO2e_yesfire_non_CO2 + peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 40; - } - if (burn_data[x] == 0) // Wildfire, peat, not burned - { - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // Wildfire, peat, not burned, temperate/boreal - { - outdata4a = Biomass_tCO2e_nofire_CO2_only; - outdata4b = 0; - outdata20 = 41; - } - if (ecozone_data[x] == tropical) // Wildfire, peat, not burned, tropical - { - if (plant_data[x] > 0) // Wildfire, peat, not burned, tropical, plantation - { - outdata4a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata4b = 0 + peat_drain_total_non_CO2; - outdata20 = 42; - } - if (plant_data[x] == 0) // Wildfire, peat, not burned, tropical, not plantation - { - outdata4a = Biomass_tCO2e_nofire_CO2_only; - outdata4b = 0; - outdata20 = 421; - } - } - } - } - else // Wildfire, not peat - { - if (burn_data[x] > 0) // Wildfire, not peat, burned - { - outdata4a = Biomass_tCO2e_yesfire_CO2_only; - outdata4b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 43; - } - else // Wildfire, not peat, not burned - { - outdata4a = Biomass_tCO2e_nofire_CO2_only; - outdata4b = 0; - outdata20 = 44; - } - } - outdata4 = outdata4a + outdata4b; - } - - // Emissions model for urbanization - else if (drivermodel_data[x] == 5) - { - Biomass_tCO2e_nofire_CO2_only = non_soil_c * C_to_CO2; - Biomass_tCO2e_yesfire_CO2_only = (non_soil_c * C_to_CO2); - Biomass_tCO2e_yesfire_non_CO2 = ((non_soil_c / biomass_to_c) * Cf * Gef_CH4 * pow(10,-3) * CH4_equiv) + ((non_soil_c / biomass_to_c) * Cf * Gef_N2O * pow(10,-3) * N2O_equiv); - float urb_flu; - urb_flu = 0.8; - minsoil = ((soil_data[x]-(soil_data[x] * urb_flu))/soil_emis_period) * (model_years-loss_data[x]); - - if (peat_data[x] > 0) // Urbanization, peat - { - if (burn_data[x] > 0) // Urbanization, peat, burned - { - outdata5a = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; - outdata5b = Biomass_tCO2e_yesfire_non_CO2 + peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 50; - } - if (burn_data[x] == 0) // Urbanization, peat, not burned - { - if (ecozone_data[x] == tropical) // Urbanization, peat, not burned, tropical - { - if (plant_data[x] >= 1) // Urbanization, peat, not burned, tropical, plantation - { - outdata5a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata5b = 0 + peat_drain_total_non_CO2; - outdata20 = 51; - } - if (plant_data[x] == 0) // Urbanization, peat, not burned, tropical, not plantation - { - outdata5a = Biomass_tCO2e_nofire_CO2_only; - outdata5b = 0; - outdata20 = 511; - } - } - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // Urbanization, peat, not burned, temperate/boreal - { - outdata5a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata5b = 0 + peat_drain_total_non_CO2; - outdata20 = 52; - } - } - } - if (peat_data[x] == 0)// Urbanization, not peat - { - if (burn_data[x] > 0) // Urbanization, not peat, burned - { - if (ecozone_data[x] == tropical) // Urbanization, not peat, burned, tropical - { - if (ifl_primary_data[x] == 1) // Urbanization, not peat, burned, tropical, IFL - { - if (plant_data[x] >= 1) // Urbanization, not peat, burned, tropical, IFL, plantation - { - outdata5a = Biomass_tCO2e_yesfire_CO2_only; - outdata5b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 53; - } - if (plant_data[x] == 0) // Urbanization, not peat, burned, tropical, IFL, not plantation - { - outdata5a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata5b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 531; - } - } - if (ifl_primary_data[x] == 0) // Urbanization, not peat, burned, tropical, not IFL - { - if (plant_data[x] >= 1) // Urbanization, not peat, burned, tropical, not IFL, plantation - { - outdata5a = Biomass_tCO2e_yesfire_CO2_only; - outdata5b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 54; - } - if (plant_data[x] == 0) // Urbanization, not peat, burned, tropical, not IFL, not plantation - { - outdata5a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata5b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 541; - } - } - } - if (ecozone_data[x] == boreal) // Urbanization, not peat, burned, boreal - { - outdata5a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata5b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 55; - } - if (ecozone_data[x] == temperate) // Urbanization, not peat, burned, temperate - { - if (plant_data[x] >= 1) // Urbanization, not peat, burned, temperate, plantation - { - outdata5a = Biomass_tCO2e_yesfire_CO2_only; - outdata5b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 56; - } - if (plant_data[x] == 0) // Urbanization, not peat, burned, temperate, no plantation - { - outdata5a = Biomass_tCO2e_yesfire_CO2_only + minsoil; - outdata5b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 561; - } - } - } - if (burn_data[x] == 0) // Urbanization, not peat, not burned - { - if (ecozone_data[x] == tropical) // Urbanization, not peat, not burned, tropical - { - if (plant_data[x] >= 1) // Urbanization, not peat, not burned, tropical, plantation - { - outdata5a = Biomass_tCO2e_nofire_CO2_only; - outdata5b = 0; - outdata20 = 57; - } - if (plant_data[x] == 0) // Urbanization, not peat, not burned, tropical, no plantation - { - outdata5a = Biomass_tCO2e_nofire_CO2_only + minsoil; - outdata5b = 0; - outdata20 = 571; - } - } - if (ecozone_data[x] == boreal) // Urbanization, not peat, not burned, boreal - { - outdata5a = Biomass_tCO2e_nofire_CO2_only + minsoil; - outdata5b = 0; - outdata20 = 58; - } - if (ecozone_data[x] == temperate) // Urbanization, not peat, not burned, temperate - { - if (plant_data[x] >= 1) // Urbanization, not peat, not burned, temperate, plantation - { - outdata5a = Biomass_tCO2e_nofire_CO2_only; - outdata5b = 0; - outdata20 = 59; - } - if (plant_data[x] == 0) // Urbanization, not peat, not burned, temperate, no plantation - { - outdata5a = Biomass_tCO2e_nofire_CO2_only + minsoil; - outdata5b = 0; - outdata20 = 591; - } - } - } - } - outdata5 = outdata5a + outdata5b; - } - - // Emissions for where there is no driver model. - // Nancy said to make this the same as forestry. - else - { - Biomass_tCO2e_nofire_CO2_only = above_below_c * C_to_CO2; - Biomass_tCO2e_yesfire_CO2_only = ((agc_data[x] / biomass_to_c) * Cf * Gef_CO2 * pow(10, -3)); - Biomass_tCO2e_yesfire_non_CO2 = ((agc_data[x] / biomass_to_c) * Cf * Gef_CH4 * pow(10, -3) * CH4_equiv) + ((agc_data[x] / biomass_to_c) * Cf * Gef_N2O * pow(10, -3) * N2O_equiv); - - if (peat_data[x] > 0) // No driver, peat - { - if (burn_data[x] > 0 ) // No driver, peat, burned - { - outdata6a = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only; - outdata6b = Biomass_tCO2e_yesfire_non_CO2 + peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 60; - } - if (burn_data[x] == 0 ) // No driver, peat, not burned - { - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // No driver, peat, not burned, temperate/boreal - { - outdata6a = Biomass_tCO2e_nofire_CO2_only; - outdata6b = 0; - outdata20 = 61; - } - if (ecozone_data[x] == tropical)// No driver, peat, not burned, tropical - { - if (plant_data[x] > 0) // No driver, peat, not burned, tropical, plantation - { - outdata6a = Biomass_tCO2e_nofire_CO2_only + peat_drain_total_CO2_only; - outdata6b = 0 + peat_drain_total_non_CO2; - outdata20 = 62; - } - if (plant_data[x] == 0) // No driver, peat, not burned, tropical, not plantation - { - outdata6a = Biomass_tCO2e_nofire_CO2_only; - outdata6b = 0; - outdata20 = 621; - } - } - } - } - else - { - if (burn_data[x] > 0) // No driver, not peat, burned - { - outdata6a = Biomass_tCO2e_yesfire_CO2_only; - outdata6b = Biomass_tCO2e_yesfire_non_CO2; - outdata20 = 63; - } - if (burn_data[x] == 0) // No driver, not peat, not burned - { - outdata6a = Biomass_tCO2e_nofire_CO2_only; - outdata6b = 0; - outdata20 = 64; - } - } - outdata6 = outdata6a + outdata6b; - } - - // Write the value to the correct raster - if (drivermodel_data[x] == 1) // Commodities - { - out_data1[x] = outdata1; - out_data2[x] = 0; - out_data3[x] = 0; - out_data4[x] = 0; - out_data5[x] = 0; - out_data6[x] = 0; - } - else if (drivermodel_data[x] == 2) // Shifting ag (actually commodities for this sensitivity analysis) - { - out_data1[x] = outdata1; - out_data2[x] = 0; - out_data3[x] = 0; - out_data4[x] = 0; - out_data5[x] = 0; - out_data6[x] = 0; - } - else if (drivermodel_data[x] == 3) // Forestry - { - out_data1[x] = 0; - out_data2[x] = 0; - out_data3[x] = outdata3; - out_data4[x] = 0; - out_data5[x] = 0; - out_data6[x] = 0; - } - else if (drivermodel_data[x] == 4) // Wildfire - { - out_data1[x] = 0; - out_data2[x] = 0; - out_data3[x] = 0; - out_data4[x] = outdata4; - out_data5[x] = 0; - out_data6[x] = 0; - } - else if (drivermodel_data[x] == 5) // Urbanization - { - out_data1[x] = 0; - out_data2[x] = 0; - out_data3[x] = 0; - out_data4[x] = 0; - out_data5[x] = outdata5; - out_data6[x] = 0; - } - else // No driver - { - out_data1[x] = 0; - out_data2[x] = 0; - out_data3[x] = 0; - out_data4[x] = 0; - out_data5[x] = 0; - out_data6[x] = outdata6; - } - // Decision tree end node value stored in its raster - out_data20[x] = outdata20; - - - // Add up all drivers for a combined raster. Each pixel only has one driver - outdata10 = outdata1 + outdata3 + outdata4 + outdata5 + outdata6; - outdata11 = outdata1a + outdata3a + outdata4a + outdata5a + outdata6a; - outdata12 = outdata1b + outdata3b + outdata4b + outdata5b + outdata6b; - - if (outdata10 == 0) - { - out_data10[x] = 0; - out_data11[x] = 0; - out_data12[x] = 0; - } - else{ - out_data10[x] = outdata10; - out_data11[x] = outdata11; - out_data12[x] = outdata12; - } - } - - // If pixel is not on loss and carbon, all output rasters get 0 - else - { - - out_data1[x] = 0; - out_data2[x] = 0; - out_data3[x] = 0; - out_data4[x] = 0; - out_data5[x] = 0; - out_data6[x] = 0; - out_data10[x] = 0; - out_data11[x] = 0; - out_data12[x] = 0; - out_data20[x] = 0; - } - } - -OUTBAND1->RasterIO( GF_Write, 0, y, xsize, 1, out_data1, xsize, 1, GDT_Float32, 0, 0 ); -OUTBAND2->RasterIO( GF_Write, 0, y, xsize, 1, out_data2, xsize, 1, GDT_Float32, 0, 0 ); -OUTBAND3->RasterIO( GF_Write, 0, y, xsize, 1, out_data3, xsize, 1, GDT_Float32, 0, 0 ); -OUTBAND4->RasterIO( GF_Write, 0, y, xsize, 1, out_data4, xsize, 1, GDT_Float32, 0, 0 ); -OUTBAND5->RasterIO( GF_Write, 0, y, xsize, 1, out_data5, xsize, 1, GDT_Float32, 0, 0 ); -OUTBAND6->RasterIO( GF_Write, 0, y, xsize, 1, out_data6, xsize, 1, GDT_Float32, 0, 0 ); -OUTBAND10->RasterIO( GF_Write, 0, y, xsize, 1, out_data10, xsize, 1, GDT_Float32, 0, 0 ); -OUTBAND11->RasterIO( GF_Write, 0, y, xsize, 1, out_data11, xsize, 1, GDT_Float32, 0, 0 ); -OUTBAND12->RasterIO( GF_Write, 0, y, xsize, 1, out_data12, xsize, 1, GDT_Float32, 0, 0 ); -OUTBAND20->RasterIO( GF_Write, 0, y, xsize, 1, out_data20, xsize, 1, GDT_Float32, 0, 0 ); -} - -GDALClose(INGDAL1); -GDALClose((GDALDatasetH)OUTGDAL1); -GDALClose((GDALDatasetH)OUTGDAL2); -GDALClose((GDALDatasetH)OUTGDAL3); -GDALClose((GDALDatasetH)OUTGDAL4); -GDALClose((GDALDatasetH)OUTGDAL5); -GDALClose((GDALDatasetH)OUTGDAL6); -GDALClose((GDALDatasetH)OUTGDAL10); -GDALClose((GDALDatasetH)OUTGDAL11); -GDALClose((GDALDatasetH)OUTGDAL12); -GDALClose((GDALDatasetH)OUTGDAL20); -return 0; -} \ No newline at end of file diff --git a/emissions/cpp_util/calc_gross_emissions_soil_only.cpp b/emissions/cpp_util/calc_gross_emissions_soil_only.cpp index df0006ef..c8d6b411 100644 --- a/emissions/cpp_util/calc_gross_emissions_soil_only.cpp +++ b/emissions/cpp_util/calc_gross_emissions_soil_only.cpp @@ -11,8 +11,8 @@ // Each end point of the decision tree gets its own code, so that it's easier to tell what branch of the decision tree // each pixel came from. That makes checking the results easier, too. // These codes are summarized in carbon-budget/emissions/node_codes.txt -// Because emissions are separately output for CO2 and non-CO2 gases (CH4 and N20), each model endpoint has a CO2-only and -// a non-CO2 value. These are summed to create a total emissions (all gases) for each pixel. +// Because emissions are separately output for CO2, CH4, and N2O, each model endpoint has an emissions raster for each GHG. +// CH4 and N2O are summed to create a non-CO2 emissions raster and all three GHGs are summed to create a total emissions (all gases) for each pixel. // Compile with: // c++ /usr/local/app/emissions/cpp_util/calc_gross_emissions_soil_only.cpp -o /usr/local/app/emissions/cpp_util/calc_gross_emissions_soil_only.exe -lgdal @@ -34,13 +34,14 @@ #include #include -// These provide constants for the emissions equations +// These provide constants for the emissions equations and universal constants #include "flu_val.cpp" #include "equations.cpp" #include "constants.h" using namespace std; +//to compile: c++ calc_gross_emissions_soil_only.cpp -o calc_gross_emissions_soil_only.exe -lgdal int main(int argc, char* argv[]) { // If code is run other than , it will raise this error. @@ -84,11 +85,14 @@ boreal = constants::boreal; int soil_emis_period; // The number of years over which soil emissions are calculated (separate from model years) soil_emis_period = constants::soil_emis_period; -float shiftag_flu; // F_lu for shifting agriculture (fraction of soil C not emitted over 20 years) -shiftag_flu = constants::shiftag_flu; +float shift_cult_flu; // F_lu for shifting cultivation (fraction of soil C not emitted over 20 years) +shift_cult_flu = constants::shift_cult_flu; -float urb_flu; // F_lu for urbanization (fraction of soil C not emitted over 20 years) -urb_flu = constants::urb_flu; +float settlements_flu; // F_lu for settlements and infrastructure (fraction of soil C not emitted over 20 years) +settlements_flu = constants::settlements_flu; + +float hard_commod_flu; // F_lu for hard_commodities (fraction of soil C not emitted over 20 years) +hard_commod_flu = constants::hard_commod_flu; // Input files @@ -109,48 +113,31 @@ string peat_name = infolder + tile_id + constants::peat_mask; string ifl_primary_name = infolder + tile_id + constants::ifl_primary; string plant_name = infolder + tile_id + constants::plantation_type; -// Output files: tonnes CO2/ha for each tree cover loss driver, their total, and the node for the decision tree -// that determines emissions. -// regex_replace from https://stackoverflow.com/a/41294178 -string out_name1_pre = constants::commod_emis; -out_name1_pre = std::regex_replace(out_name1_pre, std::regex("biomass_soil"), "soil_only"); -string out_name1 = tile_id + out_name1_pre + model_years_str + ".tif"; - -string out_name2_pre = constants::shifting_ag_emis; -out_name2_pre = std::regex_replace(out_name2_pre, std::regex("biomass_soil"), "soil_only"); -string out_name2 = tile_id + out_name2_pre + model_years_str + ".tif"; - -string out_name3_pre = constants::forestry_emis; -out_name3_pre = std::regex_replace(out_name3_pre, std::regex("biomass_soil"), "soil_only"); -string out_name3 = tile_id + out_name3_pre + model_years_str + ".tif"; - -string out_name4_pre = constants::wildfire_emis; -out_name4_pre = std::regex_replace(out_name4_pre, std::regex("biomass_soil"), "soil_only"); -string out_name4 = tile_id + out_name4_pre + model_years_str + ".tif"; +// Output files: tonnes CO2/ha for each output and the node for the decision tree that determines emissions +// regex_replace from https://stackoverflow.com/a/41294178s +string out_name_all_gases_all_drivers_pre = constants::all_gases_all_drivers_emis; +out_name_all_gases_all_drivers_pre = std::regex_replace(out_name_all_gases_all_drivers_pre, std::regex("biomass_soil"), "soil_only"); +string out_name_all_gases_all_drivers = tile_id + out_name_all_gases_all_drivers_pre + model_years_str + ".tif"; -string out_name5_pre = constants::urbanization_emis; -out_name5_pre = std::regex_replace(out_name5_pre, std::regex("biomass_soil"), "soil_only"); -string out_name5 = tile_id + out_name5_pre + model_years_str + ".tif"; +string out_name_CO2_only_all_drivers_pre = constants::CO2_only_all_drivers_emis; +out_name_CO2_only_all_drivers_pre = std::regex_replace(out_name_CO2_only_all_drivers_pre, std::regex("biomass_soil"), "soil_only"); +string out_name_CO2_only_all_drivers = tile_id + out_name_CO2_only_all_drivers_pre + model_years_str + ".tif"; -string out_name6_pre = constants::no_driver_emis; -out_name6_pre = std::regex_replace(out_name6_pre, std::regex("biomass_soil"), "soil_only"); -string out_name6 = tile_id + out_name6_pre + model_years_str + ".tif"; +string out_name_non_CO2_all_drivers_pre = constants::non_CO2_all_drivers_emis; +out_name_non_CO2_all_drivers_pre = std::regex_replace(out_name_non_CO2_all_drivers_pre, std::regex("biomass_soil"), "soil_only"); +string out_name_non_CO2_all_drivers = tile_id + out_name_non_CO2_all_drivers_pre + model_years_str + ".tif"; -string out_name10_pre = constants::all_gases_all_drivers_emis; -out_name10_pre = std::regex_replace(out_name10_pre, std::regex("biomass_soil"), "soil_only"); -string out_name10 = tile_id + out_name10_pre + model_years_str + ".tif"; +string out_name_CH4_only_all_drivers_pre = constants::CH4_only_all_drivers_emis; +out_name_CH4_only_all_drivers_pre = std::regex_replace(out_name_CH4_only_all_drivers_pre, std::regex("biomass_soil"), "soil_only"); +string out_name_CH4_only_all_drivers = tile_id + out_name_CH4_only_all_drivers_pre + model_years_str + ".tif"; -string out_name11_pre = constants::CO2_only_all_drivers_emis; -out_name11_pre = std::regex_replace(out_name11_pre, std::regex("biomass_soil"), "soil_only"); -string out_name11 = tile_id + out_name11_pre + model_years_str + ".tif"; +string out_name_N2O_only_all_drivers_pre = constants::N2O_only_all_drivers_emis; +out_name_N2O_only_all_drivers_pre = std::regex_replace(out_name_N2O_only_all_drivers_pre, std::regex("biomass_soil"), "soil_only"); +string out_name_N2O_only_all_drivers = tile_id + out_name_N2O_only_all_drivers_pre + model_years_str + ".tif"; -string out_name12_pre = constants::non_CO2_all_drivers_emis; -out_name12_pre = std::regex_replace(out_name12_pre, std::regex("biomass_soil"), "soil_only"); -string out_name12 = tile_id + out_name12_pre + model_years_str + ".tif"; - -string out_name20_pre = constants::decision_tree_all_drivers_emis; -out_name20_pre = std::regex_replace(out_name20_pre, std::regex("biomass_soil"), "soil_only"); -string out_name20 = tile_id + out_name20_pre + model_years_str + ".tif"; +string out_name_node_code_pre = constants::decision_tree_all_drivers_emis; +out_name_node_code_pre = std::regex_replace(out_name_node_code_pre, std::regex("biomass_soil"), "soil_only"); +string out_name_node_code = tile_id + out_name_node_code_pre + model_years_str + ".tif"; // Setting up the variables to hold the pixel location in x/y values @@ -162,99 +149,91 @@ double ulx, uly; double pixelsize; // Initialize GDAL for reading. // Each of these "INBAND" are later associated with the string variables defined above. GDALAllRegister(); -GDALDataset *INGDAL1; GDALRasterBand *INBAND1; -GDALDataset *INGDAL2; GDALRasterBand *INBAND2; -GDALDataset *INGDAL3; GDALRasterBand *INBAND3; -GDALDataset *INGDAL4; GDALRasterBand *INBAND4; -GDALDataset *INGDAL5; GDALRasterBand *INBAND5; -GDALDataset *INGDAL6; GDALRasterBand *INBAND6; -GDALDataset *INGDAL7; GDALRasterBand *INBAND7; -GDALDataset *INGDAL8; GDALRasterBand *INBAND8; -GDALDataset *INGDAL9; GDALRasterBand *INBAND9; -GDALDataset *INGDAL10; GDALRasterBand *INBAND10; -GDALDataset *INGDAL11; GDALRasterBand *INBAND11; -GDALDataset *INGDAL12; GDALRasterBand *INBAND12; -GDALDataset *INGDAL13; GDALRasterBand *INBAND13; +GDALDataset *INGDAL_AGC; GDALRasterBand *INBAND_AGC; +GDALDataset *INGDAL_BGC; GDALRasterBand *INBAND_BGC; +GDALDataset *INGDAL_DRIVERMODEL; GDALRasterBand *INBAND_DRIVERMODEL; +GDALDataset *INGDAL_LOSS; GDALRasterBand *INBAND_LOSS; +GDALDataset *INGDAL_PEAT; GDALRasterBand *INBAND_PEAT; +GDALDataset *INGDAL_BURN; GDALRasterBand *INBAND_BURN; +GDALDataset *INGDAL_IFL_PRIMARY; GDALRasterBand *INBAND_IFL_PRIMARY; +GDALDataset *INGDAL_ECOZONE; GDALRasterBand *INBAND_ECOZONE; +GDALDataset *INGDAL_CLIMATE; GDALRasterBand *INBAND_CLIMATE; +GDALDataset *INGDAL_DEAD; GDALRasterBand *INBAND_DEAD; +GDALDataset *INGDAL_LITTER; GDALRasterBand *INBAND_LITTER; +GDALDataset *INGDAL_SOIL; GDALRasterBand *INBAND_SOIL; +GDALDataset *INGDAL_PLANT; GDALRasterBand *INBAND_PLANT; //open file (string variables defined above) and assign it extent and projection -INGDAL1 = (GDALDataset *) GDALOpen(agc_name.c_str(), GA_ReadOnly ); -INBAND1 = INGDAL1->GetRasterBand(1); +INGDAL_AGC = (GDALDataset *) GDALOpen(agc_name.c_str(), GA_ReadOnly ); +INBAND_AGC = INGDAL_AGC->GetRasterBand(1); -INGDAL2 = (GDALDataset *) GDALOpen(bgc_name.c_str(), GA_ReadOnly ); -INBAND2 = INGDAL2->GetRasterBand(1); +INGDAL_BGC = (GDALDataset *) GDALOpen(bgc_name.c_str(), GA_ReadOnly ); +INBAND_BGC = INGDAL_BGC->GetRasterBand(1); -INGDAL3 = (GDALDataset *) GDALOpen(drivermodel_name.c_str(), GA_ReadOnly ); -INBAND3 = INGDAL3->GetRasterBand(1); +INGDAL_DRIVERMODEL = (GDALDataset *) GDALOpen(drivermodel_name.c_str(), GA_ReadOnly ); +INBAND_DRIVERMODEL = INGDAL_DRIVERMODEL->GetRasterBand(1); -INGDAL4 = (GDALDataset *) GDALOpen(loss_name.c_str(), GA_ReadOnly ); -INBAND4 = INGDAL4->GetRasterBand(1); +INGDAL_LOSS = (GDALDataset *) GDALOpen(loss_name.c_str(), GA_ReadOnly ); +INBAND_LOSS = INGDAL_LOSS->GetRasterBand(1); -INGDAL5 = (GDALDataset *) GDALOpen(peat_name.c_str(), GA_ReadOnly ); -INBAND5 = INGDAL5->GetRasterBand(1); +INGDAL_PEAT = (GDALDataset *) GDALOpen(peat_name.c_str(), GA_ReadOnly ); +INBAND_PEAT = INGDAL_PEAT->GetRasterBand(1); -INGDAL6 = (GDALDataset *) GDALOpen(burn_name.c_str(), GA_ReadOnly ); -INBAND6 = INGDAL6->GetRasterBand(1); +INGDAL_BURN = (GDALDataset *) GDALOpen(burn_name.c_str(), GA_ReadOnly ); +INBAND_BURN = INGDAL_BURN->GetRasterBand(1); -INGDAL7 = (GDALDataset *) GDALOpen(ifl_primary_name.c_str(), GA_ReadOnly ); -INBAND7 = INGDAL7->GetRasterBand(1); +INGDAL_IFL_PRIMARY = (GDALDataset *) GDALOpen(ifl_primary_name.c_str(), GA_ReadOnly ); +INBAND_IFL_PRIMARY = INGDAL_IFL_PRIMARY->GetRasterBand(1); -INGDAL8 = (GDALDataset *) GDALOpen(ecozone_name.c_str(), GA_ReadOnly ); -INBAND8 = INGDAL8->GetRasterBand(1); +INGDAL_ECOZONE = (GDALDataset *) GDALOpen(ecozone_name.c_str(), GA_ReadOnly ); +INBAND_ECOZONE = INGDAL_ECOZONE->GetRasterBand(1); -INGDAL9 = (GDALDataset *) GDALOpen(climate_name.c_str(), GA_ReadOnly ); -INBAND9 = INGDAL9->GetRasterBand(1); +INGDAL_CLIMATE = (GDALDataset *) GDALOpen(climate_name.c_str(), GA_ReadOnly ); +INBAND_CLIMATE = INGDAL_CLIMATE->GetRasterBand(1); -INGDAL10 = (GDALDataset *) GDALOpen(dead_name.c_str(), GA_ReadOnly ); -INBAND10 = INGDAL10->GetRasterBand(1); +INGDAL_DEAD = (GDALDataset *) GDALOpen(dead_name.c_str(), GA_ReadOnly ); +INBAND_DEAD = INGDAL_DEAD->GetRasterBand(1); -INGDAL11 = (GDALDataset *) GDALOpen(litter_name.c_str(), GA_ReadOnly ); -INBAND11 = INGDAL11->GetRasterBand(1); +INGDAL_LITTER = (GDALDataset *) GDALOpen(litter_name.c_str(), GA_ReadOnly ); +INBAND_LITTER = INGDAL_LITTER->GetRasterBand(1); -INGDAL12 = (GDALDataset *) GDALOpen(soil_name.c_str(), GA_ReadOnly ); -INBAND12 = INGDAL12->GetRasterBand(1); +INGDAL_SOIL = (GDALDataset *) GDALOpen(soil_name.c_str(), GA_ReadOnly ); +INBAND_SOIL = INGDAL_SOIL->GetRasterBand(1); -INGDAL13 = (GDALDataset *) GDALOpen(plant_name.c_str(), GA_ReadOnly ); -INBAND13 = INGDAL13->GetRasterBand(1); +INGDAL_PLANT = (GDALDataset *) GDALOpen(plant_name.c_str(), GA_ReadOnly ); +INBAND_PLANT = INGDAL_PLANT->GetRasterBand(1); -// The rest of the code runs on the size of INBAND3. This can be changed. -xsize=INBAND1->GetXSize(); -ysize=INBAND1->GetYSize(); -INGDAL1->GetGeoTransform(GeoTransform); +// The rest of the code runs on the size of INBAND_DRIVERMODEL. This can be changed. +xsize=INBAND_AGC->GetXSize(); +ysize=INBAND_AGC->GetYSize(); +INGDAL_AGC->GetGeoTransform(GeoTransform); ulx=GeoTransform[0]; uly=GeoTransform[3]; pixelsize=GeoTransform[1]; // // Manually change this to test the script on a small part of the raster. This starts at top left of the tile. -//xsize = 900; -//ysize = 7900; +//xsize = 40000; +//ysize = 1100; // Print the raster size and resolution. Should be 40,000 x 40,000 and pixel size 0.00025. cout << "Gross emissions soil_only model C++ parameters: " << xsize <<", "<< ysize <<", "<< ulx <<", "<< uly << ", "<< pixelsize << endl; // Initialize GDAL for writing GDALDriver *OUTDRIVER; -GDALDataset *OUTGDAL1; // Commodities, all gases -GDALDataset *OUTGDAL2; // Shifting ag, all gases -GDALDataset *OUTGDAL3; // Forestry, all gases -GDALDataset *OUTGDAL4; // Wildfire, all gases -GDALDataset *OUTGDAL5; // Urbanization, all gases -GDALDataset *OUTGDAL6; // No driver, all gases -GDALDataset *OUTGDAL10; // All drivers, all gases -GDALDataset *OUTGDAL11; // All drivers, CO2 only -GDALDataset *OUTGDAL12; // All drivers, non-CO2 -GDALDataset *OUTGDAL20; // Decision tree node - -GDALRasterBand *OUTBAND1; -GDALRasterBand *OUTBAND2; -GDALRasterBand *OUTBAND3; -GDALRasterBand *OUTBAND4; -GDALRasterBand *OUTBAND5; -GDALRasterBand *OUTBAND6; -GDALRasterBand *OUTBAND10; -GDALRasterBand *OUTBAND11; -GDALRasterBand *OUTBAND12; -GDALRasterBand *OUTBAND20; +GDALDataset *OUTGDAL_ALLDRIVERS_ALLGASSES; // All drivers, all gases +GDALDataset *OUTGDAL_ALLDRIVERS_CO2ONLY; // All drivers, CO2 only +GDALDataset *OUTGDAL_ALLDRIVERS_NONCO2; // All drivers, non-CO2 (methane + nitrous oxide) +GDALDataset *OUTGDAL_ALLDRIVERS_CH4ONLY; // All drivers, methane +GDALDataset *OUTGDAL_ALLDRIVERS_N2OONLY; // All drivers, nitrous oxide +GDALDataset *OUTGDAL_NODE_CODE; // Decision tree node + +GDALRasterBand *OUTBAND_ALLDRIVERS_ALLGASSES; +GDALRasterBand *OUTBAND_ALLDRIVERS_CO2ONLY; +GDALRasterBand *OUTBAND_ALLDRIVERS_NONCO2; +GDALRasterBand *OUTBAND_ALLDRIVERS_CH4ONLY; +GDALRasterBand *OUTBAND_ALLDRIVERS_N2OONLY; +GDALRasterBand *OUTBAND_NODE_CODE; OGRSpatialReference oSRS; char *OUTPRJ = NULL; @@ -266,65 +245,41 @@ oSRS.SetWellKnownGeogCS( "WGS84" ); oSRS.exportToWkt( &OUTPRJ ); double adfGeoTransform[6] = { ulx, pixelsize, 0, uly, 0, -1*pixelsize }; -// Commoditiy gross emissions -OUTGDAL1 = OUTDRIVER->Create( out_name1.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL1->SetGeoTransform(adfGeoTransform); OUTGDAL1->SetProjection(OUTPRJ); -OUTBAND1 = OUTGDAL1->GetRasterBand(1); -OUTBAND1->SetNoDataValue(0); - -// Shifting ag gross emissions -OUTGDAL2 = OUTDRIVER->Create( out_name2.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL2->SetGeoTransform(adfGeoTransform); OUTGDAL2->SetProjection(OUTPRJ); -OUTBAND2 = OUTGDAL2->GetRasterBand(1); -OUTBAND2->SetNoDataValue(0); - -// Forestry gross emissions -OUTGDAL3 = OUTDRIVER->Create( out_name3.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL3->SetGeoTransform(adfGeoTransform); OUTGDAL3->SetProjection(OUTPRJ); -OUTBAND3 = OUTGDAL3->GetRasterBand(1); -OUTBAND3->SetNoDataValue(0); - -// Wildfire gross emissions -OUTGDAL4 = OUTDRIVER->Create( out_name4.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL4->SetGeoTransform(adfGeoTransform); OUTGDAL4->SetProjection(OUTPRJ); -OUTBAND4 = OUTGDAL4->GetRasterBand(1); -OUTBAND4->SetNoDataValue(0); - -// Urbanization gross emissions -OUTGDAL5 = OUTDRIVER->Create( out_name5.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL5->SetGeoTransform(adfGeoTransform); OUTGDAL5->SetProjection(OUTPRJ); -OUTBAND5 = OUTGDAL5->GetRasterBand(1); -OUTBAND5->SetNoDataValue(0); - -// No driver gross emissions -OUTGDAL6 = OUTDRIVER->Create( out_name6.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL6->SetGeoTransform(adfGeoTransform); OUTGDAL6->SetProjection(OUTPRJ); -OUTBAND6 = OUTGDAL6->GetRasterBand(1); -OUTBAND6->SetNoDataValue(0); - // All gases, all drivers combined -OUTGDAL10 = OUTDRIVER->Create( out_name10.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL10->SetGeoTransform(adfGeoTransform); OUTGDAL10->SetProjection(OUTPRJ); -OUTBAND10 = OUTGDAL10->GetRasterBand(1); -OUTBAND10->SetNoDataValue(0); +OUTGDAL_ALLDRIVERS_ALLGASSES = OUTDRIVER->Create( out_name_all_gases_all_drivers.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); +OUTGDAL_ALLDRIVERS_ALLGASSES->SetGeoTransform(adfGeoTransform); OUTGDAL_ALLDRIVERS_ALLGASSES->SetProjection(OUTPRJ); +OUTBAND_ALLDRIVERS_ALLGASSES = OUTGDAL_ALLDRIVERS_ALLGASSES->GetRasterBand(1); +OUTBAND_ALLDRIVERS_ALLGASSES->SetNoDataValue(0); // CO2 only, all drivers combined -OUTGDAL11 = OUTDRIVER->Create( out_name11.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL11->SetGeoTransform(adfGeoTransform); OUTGDAL11->SetProjection(OUTPRJ); -OUTBAND11 = OUTGDAL11->GetRasterBand(1); -OUTBAND11->SetNoDataValue(0); +OUTGDAL_ALLDRIVERS_CO2ONLY = OUTDRIVER->Create( out_name_CO2_only_all_drivers.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); +OUTGDAL_ALLDRIVERS_CO2ONLY->SetGeoTransform(adfGeoTransform); OUTGDAL_ALLDRIVERS_CO2ONLY->SetProjection(OUTPRJ); +OUTBAND_ALLDRIVERS_CO2ONLY = OUTGDAL_ALLDRIVERS_CO2ONLY->GetRasterBand(1); +OUTBAND_ALLDRIVERS_CO2ONLY->SetNoDataValue(0); // Non-CO2, all drivers combined -OUTGDAL12 = OUTDRIVER->Create( out_name12.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); -OUTGDAL12->SetGeoTransform(adfGeoTransform); OUTGDAL12->SetProjection(OUTPRJ); -OUTBAND12 = OUTGDAL12->GetRasterBand(1); -OUTBAND12->SetNoDataValue(0); +OUTGDAL_ALLDRIVERS_NONCO2 = OUTDRIVER->Create( out_name_non_CO2_all_drivers.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); +OUTGDAL_ALLDRIVERS_NONCO2->SetGeoTransform(adfGeoTransform); OUTGDAL_ALLDRIVERS_NONCO2->SetProjection(OUTPRJ); +OUTBAND_ALLDRIVERS_NONCO2 = OUTGDAL_ALLDRIVERS_NONCO2->GetRasterBand(1); +OUTBAND_ALLDRIVERS_NONCO2->SetNoDataValue(0); + +// CH4 only, all drivers combined +OUTGDAL_ALLDRIVERS_CH4ONLY = OUTDRIVER->Create( out_name_CH4_only_all_drivers.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); +OUTGDAL_ALLDRIVERS_CH4ONLY->SetGeoTransform(adfGeoTransform); OUTGDAL_ALLDRIVERS_CH4ONLY->SetProjection(OUTPRJ); +OUTBAND_ALLDRIVERS_CH4ONLY = OUTGDAL_ALLDRIVERS_CH4ONLY->GetRasterBand(1); +OUTBAND_ALLDRIVERS_CH4ONLY->SetNoDataValue(0); + +// N2O only, all drivers combined +OUTGDAL_ALLDRIVERS_N2OONLY = OUTDRIVER->Create( out_name_N2O_only_all_drivers.c_str(), xsize, ysize, 1, GDT_Float32, papszOptions ); +OUTGDAL_ALLDRIVERS_N2OONLY->SetGeoTransform(adfGeoTransform); OUTGDAL_ALLDRIVERS_N2OONLY->SetProjection(OUTPRJ); +OUTBAND_ALLDRIVERS_N2OONLY = OUTGDAL_ALLDRIVERS_N2OONLY->GetRasterBand(1); +OUTBAND_ALLDRIVERS_N2OONLY->SetNoDataValue(0); // Decision tree node -OUTGDAL20 = OUTDRIVER->Create( out_name20.c_str(), xsize, ysize, 1, GDT_UInt16, papszOptions ); -OUTGDAL20->SetGeoTransform(adfGeoTransform); OUTGDAL20->SetProjection(OUTPRJ); -OUTBAND20 = OUTGDAL20->GetRasterBand(1); -OUTBAND20->SetNoDataValue(0); +OUTGDAL_NODE_CODE = OUTDRIVER->Create( out_name_node_code.c_str(), xsize, ysize, 1, GDT_UInt16, papszOptions ); +OUTGDAL_NODE_CODE->SetGeoTransform(adfGeoTransform); OUTGDAL_NODE_CODE->SetProjection(OUTPRJ); +OUTBAND_NODE_CODE = OUTGDAL_NODE_CODE->GetRasterBand(1); +OUTBAND_NODE_CODE->SetNoDataValue(0); // Read/write data @@ -344,16 +299,21 @@ float ifl_primary_data[xsize]; float plant_data[xsize]; // Outputs -float out_data1[xsize]; -float out_data2[xsize]; -float out_data3[xsize]; -float out_data4[xsize]; -float out_data5[xsize]; -float out_data6[xsize]; -float out_data10[xsize]; -float out_data11[xsize]; -float out_data12[xsize]; -short int out_data20[xsize]; +float out_data_permanent_agriculture[xsize]; // 1 +float out_data_hard_commodities[xsize]; // 2 +float out_data_shifting_cultivation[xsize]; // 3 +float out_data_forest_management[xsize]; // 4 +float out_data_wildfire[xsize]; // 5 +float out_data_settlements[xsize]; // 6 +float out_data_other_disturbances[xsize]; // 7 +float out_data_no_driver[xsize]; // Null + +float out_data_alldrivers_allgasses[xsize]; +float out_data_alldrivers_CO2only[xsize]; +float out_data_alldrivers_nonCO2[xsize]; +float out_data_alldrivers_CH4only[xsize]; +float out_data_alldrivers_N2Oonly[xsize]; +short int out_data_node_code[xsize]; // Loop over the y coordinates, then the x coordinates for (y=0; yRasterIO(GF_Read, 0, y, xsize, 1, agc_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn2 = INBAND2->RasterIO(GF_Read, 0, y, xsize, 1, bgc_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn3 = INBAND3->RasterIO(GF_Read, 0, y, xsize, 1, drivermodel_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn4 = INBAND4->RasterIO(GF_Read, 0, y, xsize, 1, loss_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn5 = INBAND5->RasterIO(GF_Read, 0, y, xsize, 1, peat_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn6 = INBAND6->RasterIO(GF_Read, 0, y, xsize, 1, burn_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn7 = INBAND7->RasterIO(GF_Read, 0, y, xsize, 1, ifl_primary_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn8 = INBAND8->RasterIO(GF_Read, 0, y, xsize, 1, ecozone_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn9 = INBAND9->RasterIO(GF_Read, 0, y, xsize, 1, climate_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn10 = INBAND10->RasterIO(GF_Read, 0, y, xsize, 1, dead_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn11 = INBAND11->RasterIO(GF_Read, 0, y, xsize, 1, litter_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn12 = INBAND12->RasterIO(GF_Read, 0, y, xsize, 1, soil_data, xsize, 1, GDT_Float32, 0, 0); -CPLErr errcodeIn13 = INBAND13->RasterIO(GF_Read, 0, y, xsize, 1, plant_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn1 = INBAND_AGC->RasterIO(GF_Read, 0, y, xsize, 1, agc_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn2 = INBAND_BGC->RasterIO(GF_Read, 0, y, xsize, 1, bgc_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn3 = INBAND_DRIVERMODEL->RasterIO(GF_Read, 0, y, xsize, 1, drivermodel_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn4 = INBAND_LOSS->RasterIO(GF_Read, 0, y, xsize, 1, loss_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn5 = INBAND_PEAT->RasterIO(GF_Read, 0, y, xsize, 1, peat_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn6 = INBAND_BURN->RasterIO(GF_Read, 0, y, xsize, 1, burn_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn7 = INBAND_IFL_PRIMARY->RasterIO(GF_Read, 0, y, xsize, 1, ifl_primary_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn8 = INBAND_ECOZONE->RasterIO(GF_Read, 0, y, xsize, 1, ecozone_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn9 = INBAND_CLIMATE->RasterIO(GF_Read, 0, y, xsize, 1, climate_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn10 = INBAND_DEAD->RasterIO(GF_Read, 0, y, xsize, 1, dead_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn11 = INBAND_LITTER->RasterIO(GF_Read, 0, y, xsize, 1, litter_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn12 = INBAND_SOIL->RasterIO(GF_Read, 0, y, xsize, 1, soil_data, xsize, 1, GDT_Float32, 0, 0); +CPLErr errcodeIn13 = INBAND_PLANT->RasterIO(GF_Read, 0, y, xsize, 1, plant_data, xsize, 1, GDT_Float32, 0, 0); // Number of input files int inSize = 13; @@ -404,28 +364,61 @@ for(x=0; x 0 && agc_data[x] > 0) @@ -437,7 +430,7 @@ for(x=0; x 0) // Commodity, peat + if (peat_data[x] > 0) // permanent ag, peat { - if (burn_data[x] > 0) // Commodity, peat, burned + if (burn_data[x] > 0) // permanent ag, peat, burned { - outdata1a = peat_drain_total_CO2_only + peatburn_CO2_only; - outdata1b = peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 10; + outdata_permanent_agriculture_CO2only = peat_drain_total_CO2_only + peatburn_CO2_only; + outdata_permanent_agriculture_CH4only = peat_drain_total_CH4_only + peatburn_CH4_only; + outdata_permanent_agriculture_N2Oonly = peat_drain_total_N2O_only; + outdata_node_code = 10; } - if (burn_data[x] == 0) // Commodity, peat, not burned + if (burn_data[x] == 0) // permanent ag, peat, not burned { - if (ecozone_data[x] == tropical) // Commodity, peat, not burned, tropical + if (ecozone_data[x] == tropical) // permanent ag, peat, not burned, tropical { - if (plant_data[x] >= 1) // Commodity, peat, not burned, tropical, plantation + if (plant_data[x] >= 1) // permanent ag, peat, not burned, tropical, plantation { - outdata1a = peat_drain_total_CO2_only; - outdata1b = peat_drain_total_non_CO2; - outdata20 = 11; + outdata_permanent_agriculture_CO2only = peat_drain_total_CO2_only; + outdata_permanent_agriculture_CH4only = peat_drain_total_CH4_only; + outdata_permanent_agriculture_N2Oonly = peat_drain_total_N2O_only; + outdata_node_code = 11; } - if (plant_data[x] == 0) // Commodity, peat, not burned, tropical, not plantation + if (plant_data[x] == 0) // permanent ag, peat, not burned, tropical, not plantation { - outdata1a = 0; - outdata1b = 0; - outdata20 = 111; + outdata_permanent_agriculture_CO2only = 0; + outdata_permanent_agriculture_CH4only = 0; + outdata_permanent_agriculture_N2Oonly = 0; + outdata_node_code = 111; } } - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // Commodity, peat, not burned, temperate/boreal + if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // permanent ag, peat, not burned, temperate/boreal { - outdata1a = peat_drain_total_CO2_only; - outdata1b = peat_drain_total_non_CO2; - outdata20 = 12; + outdata_permanent_agriculture_CO2only = peat_drain_total_CO2_only; + outdata_permanent_agriculture_CH4only = peat_drain_total_CH4_only; + outdata_permanent_agriculture_N2Oonly = peat_drain_total_N2O_only; + outdata_node_code = 12; } } } - if (peat_data[x] == 0) // Commodity, not peat + if (peat_data[x] == 0) // permanent ag, not peat { - if (burn_data[x] > 0) // Commodity, not peat, burned + if (burn_data[x] > 0) // permanent ag, not peat, burned { - if (ecozone_data[x] == tropical) // Commodity, not peat, burned, tropical + if (ecozone_data[x] == tropical) // permanent ag, not peat, burned, tropical { - if (ifl_primary_data[x] == 1) // Commodity, not peat, burned, tropical, IFL + if (ifl_primary_data[x] == 1) // permanent ag, not peat, burned, tropical, IFL { - if (plant_data[x] >= 1) // Commodity, not peat, burned, tropical, IFL, plantation + if (plant_data[x] >= 1) // permanent ag, not peat, burned, tropical, IFL, plantation { - outdata1a = 0; - outdata1b = 0; - outdata20 = 13; + outdata_permanent_agriculture_CO2only = 0; + outdata_permanent_agriculture_CH4only = 0; + outdata_permanent_agriculture_N2Oonly = 0; + outdata_node_code = 13; } - if (plant_data[x] == 0) // Commodity, not peat, burned, tropical, IFL, not plantation + if (plant_data[x] == 0) // permanent ag, not peat, burned, tropical, IFL, not plantation { - outdata1a = minsoil; - outdata1b = 0; - outdata20 = 131; + outdata_permanent_agriculture_CO2only = minsoil; + outdata_permanent_agriculture_CH4only = 0; + outdata_permanent_agriculture_N2Oonly = 0; + outdata_node_code = 131; } } - if (ifl_primary_data[x] == 0) // Commodity, not peat, burned, tropical, not IFL + if (ifl_primary_data[x] == 0) // permanent ag, not peat, burned, tropical, not IFL { - if (plant_data[x] >= 1) // Commodity, not peat, burned, tropical, not IFL, plantation + if (plant_data[x] >= 1) // permanent ag, not peat, burned, tropical, not IFL, plantation { - outdata1a = 0; - outdata1b = 0; - outdata20 = 14; + outdata_permanent_agriculture_CO2only = 0; + outdata_permanent_agriculture_CH4only = 0; + outdata_permanent_agriculture_N2Oonly = 0; + outdata_node_code = 14; } - if (plant_data[x] == 0) // Commodity, not peat, burned, tropical, not IFL, not plantation + if (plant_data[x] == 0) // permanent ag, not peat, burned, tropical, not IFL, not plantation { - outdata1a = minsoil; - outdata1b = 0; - outdata20 = 141; + outdata_permanent_agriculture_CO2only = minsoil; + outdata_permanent_agriculture_CH4only = 0; + outdata_permanent_agriculture_N2Oonly = 0; + outdata_node_code = 141; } } } - if (ecozone_data[x] == boreal) // Commodity, not peat, burned, boreal + if (ecozone_data[x] == boreal) // permanent ag, not peat, burned, boreal { - outdata1a = minsoil; - outdata1b = 0; - outdata20 = 15; + outdata_permanent_agriculture_CO2only = minsoil; + outdata_permanent_agriculture_CH4only = 0; + outdata_permanent_agriculture_N2Oonly = 0; + outdata_node_code = 15; } - if (ecozone_data[x] == temperate) // Commodity, not peat, burned, temperate + if (ecozone_data[x] == temperate) // permanent ag, not peat, burned, temperate { - if (plant_data[x] >= 1) // Commodity, not peat, burned, temperate, plantation + if (plant_data[x] >= 1) // permanent ag, not peat, burned, temperate, plantation { - outdata1a = 0; - outdata1b = 0; - outdata20 = 16; + outdata_permanent_agriculture_CO2only = 0; + outdata_permanent_agriculture_CH4only = 0; + outdata_permanent_agriculture_N2Oonly = 0; + outdata_node_code = 16; } - if (plant_data[x] == 0) // Commodity, not peat, burned, temperate, no plantation + if (plant_data[x] == 0) // permanent ag, not peat, burned, temperate, not plantation { - outdata1a = minsoil; - outdata1b = 0; - outdata20 = 161; + outdata_permanent_agriculture_CO2only = minsoil; + outdata_permanent_agriculture_CH4only = 0; + outdata_permanent_agriculture_N2Oonly = 0; + outdata_node_code = 161; } } } - if (burn_data[x] == 0) // Commodity, not peat, not burned + if (burn_data[x] == 0) // permanent ag, not peat, not burned { - if (ecozone_data[x] == tropical) // Commodity, not peat, not burned, tropical + if (ecozone_data[x] == tropical) // permanent ag, not peat, not burned, tropical { - if (plant_data[x] >= 1) // Commodity, not peat, not burned, tropical, plantation + if (plant_data[x] >= 1) // permanent ag, not peat, not burned, tropical, plantation { - outdata1a = 0; - outdata1b = 0; - outdata20 = 17; + outdata_permanent_agriculture_CO2only = 0; + outdata_permanent_agriculture_CH4only = 0; + outdata_permanent_agriculture_N2Oonly = 0; + outdata_node_code = 17; } - if (plant_data[x] == 0) // Commodity, not peat, not burned, tropical, no plantation + if (plant_data[x] == 0) // permanent ag, not peat, not burned, tropical, not plantation { - outdata1a = minsoil; - outdata1b = 0; - outdata20 = 171; + outdata_permanent_agriculture_CO2only = minsoil; + outdata_permanent_agriculture_CH4only = 0; + outdata_permanent_agriculture_N2Oonly = 0; + outdata_node_code = 171; } } - if (ecozone_data[x] == boreal) // Commodity, not peat, not burned, boreal + if (ecozone_data[x] == boreal) // permanent ag, not peat, not burned, boreal { - outdata1a = minsoil; - outdata1b = 0; - outdata20 = 18; + outdata_permanent_agriculture_CO2only = minsoil; + outdata_permanent_agriculture_CH4only = 0; + outdata_permanent_agriculture_N2Oonly = 0; + outdata_node_code = 18; } - if (ecozone_data[x] == temperate) // Commodity, not peat, not burned, temperate + if (ecozone_data[x] == temperate) // permanent ag, not peat, not burned, temperate { - if (plant_data[x] >= 1) // Commodity, not peat, not burned, temperate, plantation + if (plant_data[x] >= 1) // permanent ag, not peat, not burned, temperate, plantation { - outdata1a = 0; - outdata1b = 0; - outdata20 = 19; + outdata_permanent_agriculture_CO2only = 0; + outdata_permanent_agriculture_CH4only = 0; + outdata_permanent_agriculture_N2Oonly = 0; + outdata_node_code = 19; } - if (plant_data[x] == 0) // Commodity, not peat, not burned, temperate, no plantation + if (plant_data[x] == 0) // permanent ag, not peat, not burned, temperate, not plantation { - outdata1a = minsoil; - outdata1b = 0; - outdata20 = 191; - - ////QC code to get the values of the relevant variables at a particular pixel of interest (based on its values rather than its coordinates) - //double total; - //total = Biomass_tCO2e_yesfire_CO2_only + peat_drain_total_CO2_only + peatburn_CO2_only + Biomass_tCO2e_yesfire_non_CO2 + peat_drain_total_non_CO2 + peatburn_non_CO2; - //if ((total < 715) && (total > 714) && (agc_data[x] = 26.25) && (soil_data[x] = 216) && (dead_data[x] = 1.44) && (litter_data[x] = 0.5328) && (burn_data[x] = 6)) - //{ - // cout << "total: " << total << endl; - // cout << "Biomass_tCO2e_yesfire_CO2_only: " << Biomass_tCO2e_yesfire_CO2_only << endl; - // cout << "Biomass_tCO2e_yesfire_non_CO2: " << Biomass_tCO2e_yesfire_non_CO2 << endl; - // cout << "peat_drain_total_CO2_only: " << peat_drain_total_CO2_only << endl; - // cout << "peat_drain_total_non_CO2: " << peat_drain_total_non_CO2 << endl; - // cout << "peatburn_CO2_only: " << peatburn_CO2_only << endl; - // cout << "peatburn_non_CO2: " << peatburn_non_CO2 << endl; - // cout << "agc_data[x]: " << agc_data[x] << endl; - // cout << "Cf: " << Cf << endl; - // cout << "Gef_CO2: " << Gef_CO2 << endl; - // cout << "Gef_CH4: " << Gef_CH4 << endl; - // cout << "Gef_N2O: " << Gef_N2O << endl; - // cout << "" << endl; - //} + outdata_permanent_agriculture_CO2only = minsoil; + outdata_permanent_agriculture_CH4only = 0; + outdata_permanent_agriculture_N2Oonly = 0; + outdata_node_code = 191; } } } } - outdata1 = outdata1a + outdata1b; + outdata_permanent_agriculture_allgases = outdata_permanent_agriculture_CO2only + outdata_permanent_agriculture_CH4only + outdata_permanent_agriculture_N2Oonly; + outdata_permanent_agriculture_nonCO2 = outdata_permanent_agriculture_CH4only + outdata_permanent_agriculture_N2Oonly; } - // Emissions model for shifting agriculture (only difference is flu val) + // Emissions model for hard commodities else if (drivermodel_data[x] == 2) { -// Biomass_tCO2e_nofire_CO2_only = non_soil_c * C_to_CO2; -// Biomass_tCO2e_yesfire_CO2_only = (non_soil_c * C_to_CO2); -// Biomass_tCO2e_yesfire_non_CO2 = ((non_soil_c / biomass_to_c) * Cf * Gef_CH4 * pow(10,-3) * CH4_equiv) + ((non_soil_c / biomass_to_c) * Cf * Gef_N2O * pow(10,-3) * N2O_equiv); - minsoil = ((soil_data[x]-(soil_data[x] * shiftag_flu))/soil_emis_period) * (model_years-loss_data[x]); + // For each driver, these values (or a subset of them) are necessary for calculating emissions. + minsoil = ((soil_data[x]-(soil_data[x] * hard_commod_flu))/soil_emis_period) * (model_years-loss_data[x]); - if (peat_data[x] > 0) // Shifting ag, peat + if (peat_data[x] > 0) // hard commodities, peat { - if (burn_data[x] > 0) // Shifting ag, peat, burned + if (burn_data[x] > 0) // hard commodities, peat, burned + { + outdata_hard_commodities_CO2only = peat_drain_total_CO2_only + peatburn_CO2_only; + outdata_hard_commodities_CH4only = peat_drain_total_CH4_only + peatburn_CH4_only; + outdata_hard_commodities_N2Oonly = peat_drain_total_N2O_only; + outdata_node_code = 20; + } + if (burn_data[x] == 0) // hard commodities, peat, not burned { - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // Shifting ag, peat, burned, temperate/boreal + if (ecozone_data[x] == tropical) // hard commodities, peat, not burned, tropical + { + if (plant_data[x] >= 1) // hard commodities, peat, not burned, tropical, plantation + { + outdata_hard_commodities_CO2only = peat_drain_total_CO2_only; + outdata_hard_commodities_CH4only = peat_drain_total_CH4_only; + outdata_hard_commodities_N2Oonly = peat_drain_total_N2O_only; + outdata_node_code = 21; + } + if (plant_data[x] == 0) // hard commodities, peat, not burned, tropical, not plantation + { + outdata_hard_commodities_CO2only = 0; + outdata_hard_commodities_CH4only = 0; + outdata_hard_commodities_N2Oonly = 0; + outdata_node_code = 211; + } + } + if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // hard commodities, peat, not burned, temperate/boreal + { + outdata_hard_commodities_CO2only = peat_drain_total_CO2_only; + outdata_hard_commodities_CH4only = peat_drain_total_CH4_only; + outdata_hard_commodities_N2Oonly = peat_drain_total_N2O_only; + outdata_node_code = 22; + } + } + } + if (peat_data[x] == 0) // hard commodities, not peat + { + if (burn_data[x] > 0) // hard commodities, not peat, burned + { + if (ecozone_data[x] == tropical) // hard commodities, not peat, burned, tropical + { + if (ifl_primary_data[x] == 1) // hard commodities, not peat, burned, tropical, IFL + { + if (plant_data[x] >= 1) // hard commodities, not peat, burned, tropical, IFL, plantation + { + outdata_hard_commodities_CO2only = 0; + outdata_hard_commodities_CH4only = 0; + outdata_hard_commodities_N2Oonly = 0; + outdata_node_code = 23; + } + if (plant_data[x] == 0) // hard commodities, not peat, burned, tropical, IFL, not plantation + { + outdata_hard_commodities_CO2only = minsoil; + outdata_hard_commodities_CH4only = 0; + outdata_hard_commodities_N2Oonly = 0; + outdata_node_code = 231; + } + } + if (ifl_primary_data[x] == 0) // hard commodities, not peat, burned, tropical, not IFL + { + if (plant_data[x] >= 1) // hard commodities, not peat, burned, tropical, not IFL, plantation + { + outdata_hard_commodities_CO2only = 0; + outdata_hard_commodities_CH4only = 0; + outdata_hard_commodities_N2Oonly = 0; + outdata_node_code = 24; + } + if (plant_data[x] == 0) // hard commodities, not peat, burned, tropical, not IFL, not plantation + { + outdata_hard_commodities_CO2only = minsoil; + outdata_hard_commodities_CH4only = 0; + outdata_hard_commodities_N2Oonly = 0; + outdata_node_code = 241; + } + } + } + if (ecozone_data[x] == boreal) // hard commodities, not peat, burned, boreal { - outdata2a = peatburn_CO2_only; - outdata2b = peatburn_non_CO2; - outdata20 = 20; + outdata_hard_commodities_CO2only = minsoil; + outdata_hard_commodities_CH4only = 0; + outdata_hard_commodities_N2Oonly = 0; + outdata_node_code = 25; } - if (ecozone_data[x] == tropical) // Shifting ag, peat, burned, tropical + if (ecozone_data[x] == temperate) // hard commodities, not peat, burned, temperate { - outdata2a = peat_drain_total_CO2_only + peatburn_non_CO2; - outdata2b = peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 21; + if (plant_data[x] >= 1) // hard commodities, not peat, burned, temperate, plantation + { + outdata_hard_commodities_CO2only = 0; + outdata_hard_commodities_CH4only = 0; + outdata_hard_commodities_N2Oonly = 0; + outdata_node_code = 26; + } + if (plant_data[x] == 0) // hard commodities, not peat, burned, temperate, not plantation + { + outdata_hard_commodities_CO2only = minsoil; + outdata_hard_commodities_CH4only = 0; + outdata_hard_commodities_N2Oonly = 0; + outdata_node_code = 261; + } } } - if (burn_data[x] == 0)// Shifting ag, peat, not burned + if (burn_data[x] == 0) // hard commodities, not peat, not burned { - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // Shifting ag, peat, not burned, temperate/boreal + if (ecozone_data[x] == tropical) // hard commodities, not peat, not burned, tropical { - outdata2a = 0; - outdata2b = 0; - outdata20 = 22; + if (plant_data[x] >= 1) // hard commodities, not peat, not burned, tropical, plantation + { + outdata_hard_commodities_CO2only = 0; + outdata_hard_commodities_CH4only = 0; + outdata_hard_commodities_N2Oonly = 0; + outdata_node_code = 27; + } + if (plant_data[x] == 0) // hard commodities, not peat, not burned, tropical, not plantation + { + outdata_hard_commodities_CO2only = minsoil; + outdata_hard_commodities_CH4only = 0; + outdata_hard_commodities_N2Oonly = 0; + outdata_node_code = 271; + } } - if (ecozone_data[x] == tropical) // Shifting ag, peat, not burned, tropical + if (ecozone_data[x] == boreal) // hard commodities, not peat, not burned, boreal { - if (plant_data[x] >= 1) // Shifting ag, peat, not burned, tropical, plantation + outdata_hard_commodities_CO2only = minsoil; + outdata_hard_commodities_CH4only = 0; + outdata_hard_commodities_N2Oonly = 0; + outdata_node_code = 28; + } + if (ecozone_data[x] == temperate) // hard commodities, not peat, not burned, temperate + { + if (plant_data[x] >= 1) // hard commodities, not peat, not burned, temperate, plantation { - outdata2a = peat_drain_total_CO2_only; - outdata2b = peat_drain_total_non_CO2; - outdata20 = 23; + outdata_hard_commodities_CO2only = 0; + outdata_hard_commodities_CH4only = 0; + outdata_hard_commodities_N2Oonly = 0; + outdata_node_code = 29; } - if (plant_data[x] == 0) // Shifting ag, peat, not burned, tropical, not plantation + if (plant_data[x] == 0) // hard commodities, not peat, not burned, temperate, not plantation { - outdata2a = 0; - outdata2b = 0; - outdata20 = 231; + outdata_hard_commodities_CO2only = minsoil; + outdata_hard_commodities_CH4only = 0; + outdata_hard_commodities_N2Oonly = 0; + outdata_node_code = 291; } } - } + } } - if (peat_data[x] == 0)// Shifting ag, not peat + outdata_hard_commodities_allgases = outdata_hard_commodities_CO2only + outdata_hard_commodities_CH4only + outdata_hard_commodities_N2Oonly; + outdata_hard_commodities_nonCO2 = outdata_hard_commodities_CH4only + outdata_hard_commodities_N2Oonly; + } + + // Emissions model for shifting cultivation (only difference is flu val) + else if (drivermodel_data[x] == 3) + { + minsoil = ((soil_data[x]-(soil_data[x] * shift_cult_flu))/soil_emis_period) * (model_years-loss_data[x]); + + if (peat_data[x] > 0) // shifting cultivation, peat { - if (burn_data[x] > 0) // Shifting ag, not peat, burned + if (burn_data[x] > 0) // shifting cultivation, peat, burned { - if (ecozone_data[x] == tropical) // Shifting ag, not peat, burned, tropical + if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // shifting cultivation, peat, burned, temperate/boreal + { + outdata_shifting_cultivation_CO2only = peatburn_CO2_only; + outdata_shifting_cultivation_CH4only = peatburn_CH4_only; + outdata_shifting_cultivation_N2Oonly = 0; + outdata_node_code = 30; + } + if (ecozone_data[x] == tropical) // shifting cultivation, peat, burned, tropical { - if (ifl_primary_data[x] == 1) // Shifting ag, not peat, burned, tropical, IFL + outdata_shifting_cultivation_CO2only = peat_drain_total_CO2_only + peatburn_CO2_only; + outdata_shifting_cultivation_CH4only = peat_drain_total_CH4_only + peatburn_CH4_only; + outdata_shifting_cultivation_N2Oonly = peat_drain_total_N2O_only; + outdata_node_code = 31; + } + } + if (burn_data[x] == 0)// shifting cultivation, peat, not burned + { + if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // shifting cultivation, peat, not burned, temperate/boreal + { + outdata_shifting_cultivation_CO2only = 0; + outdata_shifting_cultivation_CH4only = 0; + outdata_shifting_cultivation_N2Oonly = 0; + outdata_node_code = 32; + } + if (ecozone_data[x] == tropical) // shifting cultivation, peat, not burned, tropical + { + if (plant_data[x] >= 1) // shifting cultivation, peat, not burned, tropical, plantation + { + outdata_shifting_cultivation_CO2only = peat_drain_total_CO2_only; + outdata_shifting_cultivation_CH4only = peat_drain_total_CH4_only; + outdata_shifting_cultivation_N2Oonly = peat_drain_total_N2O_only; + outdata_node_code = 33; + } + if (plant_data[x] == 0) // shifting cultivation, peat, not burned, tropical, not plantation + { + outdata_shifting_cultivation_CO2only = 0; + outdata_shifting_cultivation_CH4only = 0; + outdata_shifting_cultivation_N2Oonly = 0; + outdata_node_code = 331; + } + } + } + } + if (peat_data[x] == 0)// shifting cultivation, not peat + { + if (burn_data[x] > 0) // shifting cultivation, not peat, burned + { + if (ecozone_data[x] == tropical) // shifting cultivation, not peat, burned, tropical + { + if (ifl_primary_data[x] == 1) // shifting cultivation, not peat, burned, tropical, IFL { - if (plant_data[x] >= 1) // Shifting ag, not peat, burned, tropical, IFL, plantation + if (plant_data[x] >= 1) // shifting cultivation, not peat, burned, tropical, IFL, plantation { - outdata2a = 0; - outdata2b = 0; - outdata20 = 24; + outdata_shifting_cultivation_CO2only = 0; + outdata_shifting_cultivation_CH4only = 0; + outdata_shifting_cultivation_N2Oonly = 0; + outdata_node_code = 34; } - if (plant_data[x] == 0) // Shifting ag, not peat, burned, tropical, IFL, not plantation + if (plant_data[x] == 0) // shifting cultivation, not peat, burned, tropical, IFL, not plantation { - outdata2a = minsoil; - outdata2b = 0; - outdata20 = 241; + outdata_shifting_cultivation_CO2only = minsoil; + outdata_shifting_cultivation_CH4only = 0; + outdata_shifting_cultivation_N2Oonly = 0; + outdata_node_code = 341; } } - if (ifl_primary_data[x] == 0) // Shifting ag, not peat, burned, tropical, not IFL + if (ifl_primary_data[x] == 0) // shifting cultivation, not peat, burned, tropical, not IFL { - if (plant_data[x] >= 1) // Shifting ag, not peat, burned, tropical, not IFL, plantation + if (plant_data[x] >= 1) // shifting cultivation, not peat, burned, tropical, not IFL, plantation { - outdata2a = 0; - outdata2b = 0; - outdata20 = 25; + outdata_shifting_cultivation_CO2only = 0; + outdata_shifting_cultivation_CH4only = 0; + outdata_shifting_cultivation_N2Oonly = 0; + outdata_node_code = 35; } - if (plant_data[x] == 0) // Shifting ag, not peat, burned, tropical, not IFL, not plantation + if (plant_data[x] == 0) // shifting cultivation, not peat, burned, tropical, not IFL, not plantation { - outdata2a = minsoil; - outdata2b = 0; - outdata20 = 251; + outdata_shifting_cultivation_CO2only = minsoil; + outdata_shifting_cultivation_CH4only = 0; + outdata_shifting_cultivation_N2Oonly = 0; + outdata_node_code = 351; } } } - if (ecozone_data[x] == boreal) // Shifting ag, not peat, burned, boreal + if (ecozone_data[x] == boreal) // shifting cultivation, not peat, burned, boreal { - outdata2a = minsoil; - outdata2b = 0; - outdata20 = 26; + outdata_shifting_cultivation_CO2only = minsoil; + outdata_shifting_cultivation_CH4only = 0; + outdata_shifting_cultivation_N2Oonly = 0; + outdata_node_code = 36; } - if (ecozone_data[x] == temperate) // Shifting ag, not peat, burned, temperate + if (ecozone_data[x] == temperate) // shifting cultivation, not peat, burned, temperate { - if (plant_data[x] >= 1) // Shifting ag, not peat, burned, temperate, plantation + if (plant_data[x] >= 1) // shifting cultivation, not peat, burned, temperate, plantation { - outdata2a = 0; - outdata2b = 0; - outdata20 = 27; + outdata_shifting_cultivation_CO2only = 0; + outdata_shifting_cultivation_CH4only = 0; + outdata_shifting_cultivation_N2Oonly = 0; + outdata_node_code = 37; } - if (plant_data[x] == 0) // Shifting ag, not peat, burned, temperate, no plantation + if (plant_data[x] == 0) // shifting cultivation, not peat, burned, temperate, not plantation { - outdata2a = minsoil; - outdata2b = 0; - outdata20 = 271; + outdata_shifting_cultivation_CO2only = minsoil; + outdata_shifting_cultivation_CH4only = 0; + outdata_shifting_cultivation_N2Oonly = 0; + outdata_node_code = 371; } } } - if (burn_data[x] == 0) // Shifting ag, not peat, not burned + if (burn_data[x] == 0) // shifting cultivation, not peat, not burned { - if (ecozone_data[x] == tropical) // Shifting ag, not peat, not burned, tropical + if (ecozone_data[x] == tropical) // shifting cultivation, not peat, not burned, tropical { - if (plant_data[x] >= 1) // Shifting ag, not peat, not burned, tropical, plantation + if (plant_data[x] >= 1) // shifting cultivation, not peat, not burned, tropical, plantation { - outdata2a = 0; - outdata2b = 0; - outdata20 = 28; + outdata_shifting_cultivation_CO2only = 0; + outdata_shifting_cultivation_CH4only = 0; + outdata_shifting_cultivation_N2Oonly = 0; + outdata_node_code = 38; } - if (plant_data[x] == 0) // Shifting ag, not peat, not burned, tropical, no plantation + if (plant_data[x] == 0) // shifting cultivation, not peat, not burned, tropical, not plantation { - outdata2a = minsoil; - outdata2b = 0; - outdata20 = 281; + outdata_shifting_cultivation_CO2only = minsoil; + outdata_shifting_cultivation_CH4only = 0; + outdata_shifting_cultivation_N2Oonly = 0; + outdata_node_code = 381; } } - if (ecozone_data[x] == boreal) // Shifting ag, not peat, not burned, boreal + if (ecozone_data[x] == boreal) // shifting cultivation, not peat, not burned, boreal { - outdata2a = minsoil; - outdata2b = 0; - outdata20 = 29; + outdata_shifting_cultivation_CO2only = minsoil; + outdata_shifting_cultivation_CH4only = 0; + outdata_shifting_cultivation_N2Oonly = 0; + outdata_node_code = 39; } - if (ecozone_data[x] == temperate) // Shifting ag, not peat, not burned, temperate + if (ecozone_data[x] == temperate) // shifting cultivation, not peat, not burned, temperate { - if (plant_data[x] >= 1) // Shifting ag, not peat, not burned, temperate, plantation + if (plant_data[x] >= 1) // shifting cultivation, not peat, not burned, temperate, plantation { - outdata2a = 0; - outdata2b = 0; - outdata20 = 291; + outdata_shifting_cultivation_CO2only = 0; + outdata_shifting_cultivation_CH4only = 0; + outdata_shifting_cultivation_N2Oonly = 0; + outdata_node_code = 391; } - if (plant_data[x] == 0) // Shifting ag, not peat, not burned, temperate, no plantation + if (plant_data[x] == 0) // shifting cultivation, not peat, not burned, temperate, not plantation { - outdata2a = minsoil; - outdata2b = 0; - outdata20 = 292; + outdata_shifting_cultivation_CO2only = minsoil; + outdata_shifting_cultivation_CH4only = 0; + outdata_shifting_cultivation_N2Oonly = 0; + outdata_node_code = 392; } } } } - outdata2 = outdata2a + outdata2b; + outdata_shifting_cultivation_allgases = outdata_shifting_cultivation_CO2only + outdata_shifting_cultivation_CH4only + outdata_shifting_cultivation_N2Oonly; + outdata_shifting_cultivation_nonCO2 = outdata_shifting_cultivation_CH4only + outdata_shifting_cultivation_N2Oonly; } - // Emissions model for forestry - else if (drivermodel_data[x] == 3) - { -// Biomass_tCO2e_nofire_CO2_only = above_below_c * C_to_CO2; -// Biomass_tCO2e_yesfire_CO2_only = ((agc_data[x] / biomass_to_c) * Cf * Gef_CO2 * pow(10, -3)); -// Biomass_tCO2e_yesfire_non_CO2 = ((agc_data[x] / biomass_to_c) * Cf * Gef_CH4 * pow(10, -3) * CH4_equiv) + ((agc_data[x] / biomass_to_c) * Cf * Gef_N2O * pow(10, -3) * N2O_equiv); - if (peat_data[x] > 0) // Forestry, peat + // Emissions model for forest management + else if (drivermodel_data[x] == 4) + { + if (peat_data[x] > 0) // forest management, peat { - if (burn_data[x] > 0 ) // Forestry, peat, burned + if (burn_data[x] > 0 ) // forest management, peat, burned { - outdata3a = peat_drain_total_CO2_only + peatburn_CO2_only; - outdata3b = peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 30; + outdata_forest_management_CO2only = peat_drain_total_CO2_only + peatburn_CO2_only; + outdata_forest_management_CH4only = peat_drain_total_CH4_only + peatburn_CH4_only; + outdata_forest_management_N2Oonly = peat_drain_total_N2O_only; + outdata_node_code = 40; } - if (burn_data[x] == 0 ) // Forestry, peat, not burned + if (burn_data[x] == 0 ) // forest management, peat, not burned { - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // Forestry, peat, not burned, temperate/boreal + if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // forest management, peat, not burned, temperate/boreal { - outdata3a = 0; - outdata3b = 0; - outdata20 = 31; + outdata_forest_management_CO2only = 0; + outdata_forest_management_CH4only = 0; + outdata_forest_management_N2Oonly = 0; + outdata_node_code = 41; } - if (ecozone_data[x] == tropical)// Forestry, peat, not burned, tropical + if (ecozone_data[x] == tropical)// forest management, peat, not burned, tropical { - if (plant_data[x] > 0) // Forestry, peat, not burned, tropical, plantation + if (plant_data[x] > 0) // forest management, peat, not burned, tropical, plantation { - outdata3a = peat_drain_total_CO2_only; - outdata3b = peat_drain_total_non_CO2; - outdata20 = 32; + outdata_forest_management_CO2only = peat_drain_total_CO2_only; + outdata_forest_management_CH4only = peat_drain_total_CH4_only; + outdata_forest_management_N2Oonly = peat_drain_total_N2O_only; + outdata_node_code = 42; } - if (plant_data[x] == 0) // Forestry, peat, not burned, tropical, not plantation + if (plant_data[x] == 0) // forest management, peat, not burned, tropical, not plantation { - outdata3a = 0; - outdata3b = 0; - outdata20 = 321; + outdata_forest_management_CO2only = 0; + outdata_forest_management_CH4only = 0; + outdata_forest_management_N2Oonly = 0; + outdata_node_code = 421; } } } } - else + else // forest management, not peat { - if (burn_data[x] > 0) // Forestry, not peat, burned + if (burn_data[x] > 0) // forest management, not peat, burned { - outdata3a = 0; - outdata3b = 0; - outdata20 = 33; + outdata_forest_management_CO2only = 0; + outdata_forest_management_CH4only = 0; + outdata_forest_management_N2Oonly = 0; + outdata_node_code = 43; } - if (burn_data[x] == 0) // Forestry, not peat, not burned + if (burn_data[x] == 0) // forest management, not peat, not burned { - outdata3a = 0; - outdata3b = 0; - outdata20 = 34; + outdata_forest_management_CO2only = 0; + outdata_forest_management_CH4only = 0; + outdata_forest_management_N2Oonly = 0; + outdata_node_code = 44; } } - outdata3 = outdata3a + outdata3b; + outdata_forest_management_allgases = outdata_forest_management_CO2only + outdata_forest_management_CH4only + outdata_forest_management_N2Oonly; + outdata_forest_management_nonCO2 = outdata_forest_management_CH4only + outdata_forest_management_N2Oonly; } // Emissions model for wildfires - else if (drivermodel_data[x] == 4) + else if (drivermodel_data[x] == 5) { -// Biomass_tCO2e_nofire_CO2_only = above_below_c * C_to_CO2; -// Biomass_tCO2e_yesfire_CO2_only = ((agc_data[x] / biomass_to_c) * Cf * Gef_CO2 * pow(10, -3)); -// Biomass_tCO2e_yesfire_non_CO2 = ((agc_data[x] / biomass_to_c) * Cf * Gef_CH4 * pow(10, -3) * CH4_equiv) + ((agc_data[x] / biomass_to_c) * Cf * Gef_N2O * pow(10, -3) * N2O_equiv); - - if (peat_data[x] > 0) // Wildfire, peat + if (peat_data[x] > 0) // wildfire, peat { - if (burn_data[x] > 0) // Wildfire, peat, burned + if (burn_data[x] > 0) // wildfire, peat, burned { - outdata4a = peat_drain_total_CO2_only + peatburn_CO2_only; - outdata4b = peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 40; + outdata_wildfire_CO2only = peat_drain_total_CO2_only + peatburn_CO2_only; + outdata_wildfire_CH4only = peat_drain_total_CH4_only + peatburn_CH4_only; + outdata_wildfire_N2Oonly = peat_drain_total_N2O_only; + outdata_node_code = 50; } - if (burn_data[x] == 0) // Wildfire, peat, not burned + if (burn_data[x] == 0) // wildfire, peat, not burned { - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // Wildfire, peat, not burned, temperate/boreal + if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // wildfire, peat, not burned, temperate/boreal { - outdata4a = 0; - outdata4b = 0; - outdata20 = 41; + outdata_wildfire_CO2only = 0; + outdata_wildfire_CH4only = 0; + outdata_wildfire_N2Oonly = 0; + outdata_node_code = 51; } - if (ecozone_data[x] == tropical) // Wildfire, peat, not burned, tropical + if (ecozone_data[x] == tropical) // wildfire, peat, not burned, tropical { - if (plant_data[x] > 0) // Wildfire, peat, not burned, tropical, plantation + if (plant_data[x] > 0) // wildfire, peat, not burned, tropical, plantation { - outdata4a = peat_drain_total_CO2_only; - outdata4b = peat_drain_total_non_CO2; - outdata20 = 42; + outdata_wildfire_CO2only = peat_drain_total_CO2_only; + outdata_wildfire_CH4only = peat_drain_total_CH4_only; + outdata_wildfire_N2Oonly = peat_drain_total_N2O_only; + outdata_node_code = 52; } - if (plant_data[x] == 0) // Wildfire, peat, not burned, tropical, not plantation + if (plant_data[x] == 0) // wildfire, peat, not burned, tropical, not plantation { - outdata4a = 0; - outdata4b = 0; - outdata20 = 421; + outdata_wildfire_CO2only = 0; + outdata_wildfire_CH4only = 0; + outdata_wildfire_N2Oonly = 0; + outdata_node_code = 521; } } } } - else // Wildfire, not peat + else // wildfire, not peat { - if (burn_data[x] > 0) // Wildfire, not peat, burned + if (burn_data[x] > 0) // wildfire, not peat, burned { - outdata4a = 0; - outdata4b = 0; - outdata20 = 43; + outdata_wildfire_CO2only = 0; + outdata_wildfire_CH4only = 0; + outdata_wildfire_N2Oonly = 0; + outdata_node_code = 53; } - else // Wildfire, not peat, not burned + else // wildfire, not peat, not burned { - outdata4a = 0; - outdata4b = 0; - outdata20 = 44; + outdata_wildfire_CO2only = 0; + outdata_wildfire_CH4only = 0; + outdata_wildfire_N2Oonly = 0; + outdata_node_code = 54; } } - outdata4 = outdata4a + outdata4b; + outdata_wildfire_allgases = outdata_wildfire_CO2only + outdata_wildfire_CH4only + outdata_wildfire_N2Oonly; + outdata_wildfire_nonCO2 = outdata_wildfire_CH4only + outdata_wildfire_N2Oonly; } - // Emissions model for urbanization - else if (drivermodel_data[x] == 5) + // Emissions model for settlements & infrastructure + else if (drivermodel_data[x] == 6) { -// Biomass_tCO2e_nofire_CO2_only = non_soil_c * C_to_CO2; -// Biomass_tCO2e_yesfire_CO2_only = (non_soil_c * C_to_CO2); -// Biomass_tCO2e_yesfire_non_CO2 = ((non_soil_c / biomass_to_c) * Cf * Gef_CH4 * pow(10,-3) * CH4_equiv) + ((non_soil_c / biomass_to_c) * Cf * Gef_N2O * pow(10,-3) * N2O_equiv); - minsoil = ((soil_data[x]-(soil_data[x] * urb_flu))/soil_emis_period) * (model_years-loss_data[x]); + minsoil = ((soil_data[x]-(soil_data[x] * settlements_flu))/soil_emis_period) * (model_years-loss_data[x]); - if (peat_data[x] > 0) // Urbanization, peat + if (peat_data[x] > 0) // settlements & infrastructure, peat { - if (burn_data[x] > 0) // Urbanization, peat, burned + if (burn_data[x] > 0) // settlements & infrastructure, peat, burned { - outdata5a = peat_drain_total_CO2_only + peatburn_CO2_only; - outdata5b = peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 50; + outdata_settlements_CO2only = peat_drain_total_CO2_only + peatburn_CO2_only; + outdata_settlements_CH4only = peat_drain_total_CH4_only + peatburn_CH4_only; + outdata_settlements_N2Oonly = peat_drain_total_N2O_only; + outdata_node_code = 60; } - if (burn_data[x] == 0) // Urbanization, peat, not burned + if (burn_data[x] == 0) // settlements & infrastructure, peat, not burned { - if (ecozone_data[x] == tropical) // Urbanization, peat, not burned, tropical + if (ecozone_data[x] == tropical) // settlements & infrastructure, peat, not burned, tropical { - if (plant_data[x] >= 1) // Urbanization, peat, not burned, tropical, plantation + if (plant_data[x] >= 1) // settlements & infrastructure, peat, not burned, tropical, plantation { - outdata5a = peat_drain_total_CO2_only; - outdata5b = peat_drain_total_non_CO2; - outdata20 = 51; + outdata_settlements_CO2only = peat_drain_total_CO2_only; + outdata_settlements_CH4only = peat_drain_total_CH4_only; + outdata_settlements_N2Oonly = peat_drain_total_N2O_only; + outdata_node_code = 61; } - if (plant_data[x] == 0) // Urbanization, peat, not burned, tropical, not plantation + if (plant_data[x] == 0) // settlements & infrastructure, peat, not burned, tropical, not plantation { - outdata5a = 0; - outdata5b = 0; - outdata20 = 511; + outdata_settlements_CO2only = 0; + outdata_settlements_CH4only = 0; + outdata_settlements_N2Oonly = 0; + outdata_node_code = 611; } } - if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // Urbanization, peat, not burned, temperate/boreal + if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // settlements & infrastructure, peat, not burned, temperate/boreal { - outdata5a = peat_drain_total_CO2_only; - outdata5b = peat_drain_total_non_CO2; - outdata20 = 52; + outdata_settlements_CO2only = peat_drain_total_CO2_only; + outdata_settlements_CH4only = peat_drain_total_CH4_only; + outdata_settlements_N2Oonly = peat_drain_total_N2O_only; + outdata_node_code = 62; } } } - if (peat_data[x] == 0)// Urbanization, not peat + if (peat_data[x] == 0)// settlements & infrastructure, not peat { - if (burn_data[x] > 0) // Urbanization, not peat, burned + if (burn_data[x] > 0) // settlements & infrastructure, not peat, burned { - if (ecozone_data[x] == tropical) // Urbanization, not peat, burned, tropical + if (ecozone_data[x] == tropical) // settlements & infrastructure, not peat, burned, tropical { - if (ifl_primary_data[x] == 1) // Urbanization, not peat, burned, tropical, IFL + if (ifl_primary_data[x] == 1) // settlements & infrastructure, not peat, burned, tropical, IFL { - if (plant_data[x] >= 1) // Urbanization, not peat, burned, tropical, IFL, plantation + if (plant_data[x] >= 1) // settlements & infrastructure, not peat, burned, tropical, IFL, plantation { - outdata5a = 0; - outdata5b = 0; - outdata20 = 53; + outdata_settlements_CO2only = 0; + outdata_settlements_CH4only = 0; + outdata_settlements_N2Oonly = 0; + outdata_node_code = 63; } - if (plant_data[x] == 0) // Urbanization, not peat, burned, tropical, IFL, not plantation + if (plant_data[x] == 0) // settlements & infrastructure, not peat, burned, tropical, IFL, not plantation { - outdata5a = minsoil; - outdata5b = 0; - outdata20 = 531; + outdata_settlements_CO2only = minsoil; + outdata_settlements_CH4only = 0; + outdata_settlements_N2Oonly = 0; + outdata_node_code = 631; } } - if (ifl_primary_data[x] == 0) // Urbanization, not peat, burned, tropical, not IFL + if (ifl_primary_data[x] == 0) // settlements & infrastructure, not peat, burned, tropical, not IFL { - if (plant_data[x] >= 1) // Urbanization, not peat, burned, tropical, not IFL, plantation + if (plant_data[x] >= 1) // settlements & infrastructure, not peat, burned, tropical, not IFL, plantation { - outdata5a = 0; - outdata5b = 0; - outdata20 = 54; + outdata_settlements_CO2only = 0; + outdata_settlements_CH4only = 0; + outdata_settlements_N2Oonly = 0; + outdata_node_code = 64; } - if (plant_data[x] == 0) // Urbanization, not peat, burned, tropical, not IFL, not plantation + if (plant_data[x] == 0) // settlements & infrastructure, not peat, burned, tropical, not IFL, not plantation { - outdata5a = minsoil; - outdata5b = 0; - outdata20 = 541; + outdata_settlements_CO2only = minsoil; + outdata_settlements_CH4only = 0; + outdata_settlements_N2Oonly = 0; + outdata_node_code = 641; } } } - if (ecozone_data[x] == boreal) // Urbanization, not peat, burned, boreal + if (ecozone_data[x] == boreal) // settlements & infrastructure, not peat, burned, boreal { - outdata5a = minsoil; - outdata5b = 0; - outdata20 = 55; + outdata_settlements_CO2only = minsoil; + outdata_settlements_CH4only = 0; + outdata_settlements_N2Oonly = 0; + outdata_node_code = 65; } - if (ecozone_data[x] == temperate) // Urbanization, not peat, burned, temperate + if (ecozone_data[x] == temperate) // settlements & infrastructure, not peat, burned, temperate { - if (plant_data[x] >= 1) // Urbanization, not peat, burned, temperate, plantation + if (plant_data[x] >= 1) // settlements & infrastructure, not peat, burned, temperate, plantation { - outdata5a = 0; - outdata5b = 0; - outdata20 = 56; + outdata_settlements_CO2only = 0; + outdata_settlements_CH4only = 0; + outdata_settlements_N2Oonly = 0; + outdata_node_code = 66; } - if (plant_data[x] == 0) // Urbanization, not peat, burned, temperate, no plantation + if (plant_data[x] == 0) // settlements & infrastructure, not peat, burned, temperate, not plantation { - outdata5a = minsoil; - outdata5b = 0; - outdata20 = 561; + outdata_settlements_CO2only = minsoil; + outdata_settlements_CH4only = 0; + outdata_settlements_N2Oonly = 0; + outdata_node_code = 661; } } } - if (burn_data[x] == 0) // Urbanization, not peat, not burned + if (burn_data[x] == 0) // settlements & infrastructure, not peat, not burned { - if (ecozone_data[x] == tropical) // Urbanization, not peat, not burned, tropical + if (ecozone_data[x] == tropical) // settlements & infrastructure, not peat, not burned, tropical { - if (plant_data[x] >= 1) // Urbanization, not peat, not burned, tropical, plantation + if (plant_data[x] >= 1) // settlements & infrastructure, not peat, not burned, tropical, plantation { - outdata5a = 0; - outdata5b = 0; - outdata20 = 57; + outdata_settlements_CO2only = 0; + outdata_settlements_CH4only = 0; + outdata_settlements_N2Oonly = 0; + outdata_node_code = 67; } - if (plant_data[x] == 0) // Urbanization, not peat, not burned, tropical, no plantation + if (plant_data[x] == 0) // settlements & infrastructure, not peat, not burned, tropical, not plantation { - outdata5a = minsoil; - outdata5b = 0; - outdata20 = 571; + outdata_settlements_CO2only = minsoil; + outdata_settlements_CH4only = 0; + outdata_settlements_N2Oonly = 0; + outdata_node_code = 671; } } - if (ecozone_data[x] == boreal) // Urbanization, not peat, not burned, boreal + if (ecozone_data[x] == boreal) // settlements & infrastructure, not peat, not burned, boreal { - outdata5a = minsoil; - outdata5b = 0; - outdata20 = 58; + outdata_settlements_CO2only = minsoil; + outdata_settlements_CH4only = 0; + outdata_settlements_N2Oonly = 0; + outdata_node_code = 68; } - if (ecozone_data[x] == temperate) // Urbanization, not peat, not burned, temperate + if (ecozone_data[x] == temperate) // settlements & infrastructure, not peat, not burned, temperate { - if (plant_data[x] >= 1) // Urbanization, not peat, not burned, temperate, plantation + if (plant_data[x] >= 1) // settlements & infrastructure, not peat, not burned, temperate, plantation { - outdata5a = 0; - outdata5b = 0; - outdata20 = 59; + outdata_settlements_CO2only = 0; + outdata_settlements_CH4only = 0; + outdata_settlements_N2Oonly = 0; + outdata_node_code = 69; } - if (plant_data[x] == 0) // Urbanization, not peat, not burned, temperate, no plantation + if (plant_data[x] == 0) // settlements & infrastructure, not peat, not burned, temperate, not plantation { - outdata5a = minsoil; - outdata5b = 0; - outdata20 = 591; + outdata_settlements_CO2only = minsoil; + outdata_settlements_CH4only = 0; + outdata_settlements_N2Oonly = 0; + outdata_node_code = 691; } } } } - outdata5 = outdata5a + outdata5b; + outdata_settlements_allgases = outdata_settlements_CO2only + outdata_settlements_CH4only + outdata_settlements_N2Oonly; + outdata_settlements_nonCO2 = outdata_settlements_CH4only + outdata_settlements_N2Oonly; + } + + // Emissions model for other natural disturbances + else if (drivermodel_data[x] == 7) + { + if (peat_data[x] > 0) // other natural disturbances, peat + { + if (burn_data[x] > 0 ) // other natural disturbances, peat, burned + { + outdata_other_disturbances_CO2only = peat_drain_total_CO2_only + peatburn_CO2_only; + outdata_other_disturbances_CH4only = peat_drain_total_CH4_only + peatburn_CH4_only; + outdata_other_disturbances_N2Oonly = peat_drain_total_N2O_only; + outdata_node_code = 70; + } + if (burn_data[x] == 0 ) // other natural disturbances, peat, not burned + { + if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // other natural disturbances, peat, not burned, temperate/boreal + { + outdata_other_disturbances_CO2only = 0; + outdata_other_disturbances_CH4only = 0; + outdata_other_disturbances_N2Oonly = 0; + outdata_node_code = 71; + } + if (ecozone_data[x] == tropical)// other natural disturbances, peat, not burned, tropical + { + if (plant_data[x] > 0) // other natural disturbances, peat, not burned, tropical, plantation + { + outdata_other_disturbances_CO2only = peat_drain_total_CO2_only; + outdata_other_disturbances_CH4only = peat_drain_total_CH4_only; + outdata_other_disturbances_N2Oonly = peat_drain_total_N2O_only; + outdata_node_code = 72; + } + if (plant_data[x] == 0) // other natural disturbances, peat, not burned, tropical, not plantation + { + outdata_other_disturbances_CO2only = 0; + outdata_other_disturbances_CH4only = 0; + outdata_other_disturbances_N2Oonly = 0; + outdata_node_code = 721; + } + } + } + } + else // other natural disturbances, not peat + { + if (burn_data[x] > 0) // other natural disturbances, not peat, burned + { + outdata_other_disturbances_CO2only = 0; + outdata_other_disturbances_CH4only = 0; + outdata_other_disturbances_N2Oonly= 0; + outdata_node_code = 73; + } + if (burn_data[x] == 0) // other natural disturbances, not peat, not burned + { + outdata_other_disturbances_CO2only = 0; + outdata_other_disturbances_CH4only = 0; + outdata_other_disturbances_N2Oonly = 0; + outdata_node_code = 74; + } + } + outdata_other_disturbances_allgases = outdata_other_disturbances_CO2only + outdata_other_disturbances_CH4only + outdata_other_disturbances_N2Oonly; + outdata_other_disturbances_nonCO2 = outdata_other_disturbances_CH4only + outdata_other_disturbances_N2Oonly; } // Emissions for where there is no driver model. - // Nancy said to make this the same as forestry. + // Radost said to make it the same as other natural disturbances else { -// Biomass_tCO2e_nofire_CO2_only = above_below_c * C_to_CO2; -// Biomass_tCO2e_yesfire_CO2_only = ((agc_data[x] / biomass_to_c) * Cf * Gef_CO2 * pow(10, -3)); -// Biomass_tCO2e_yesfire_non_CO2 = ((agc_data[x] / biomass_to_c) * Cf * Gef_CH4 * pow(10, -3) * CH4_equiv) + ((agc_data[x] / biomass_to_c) * Cf * Gef_N2O * pow(10, -3) * N2O_equiv); - if (peat_data[x] > 0) // No driver, peat { if (burn_data[x] > 0 ) // No driver, peat, burned { - outdata6a = peat_drain_total_CO2_only + peatburn_CO2_only; - outdata6b = peat_drain_total_non_CO2 + peatburn_non_CO2; - outdata20 = 60; + outdata_no_driver_CO2only = peat_drain_total_CO2_only + peatburn_CO2_only; + outdata_no_driver_CH4only = peat_drain_total_CH4_only + peatburn_CH4_only; + outdata_no_driver_N2Oonly = peat_drain_total_N2O_only; + outdata_node_code = 80; } if (burn_data[x] == 0 ) // No driver, peat, not burned { if ((ecozone_data[x] == boreal) || (ecozone_data[x] == temperate)) // No driver, peat, not burned, temperate/boreal { - outdata6a = 0; - outdata6b = 0; - outdata20 = 61; + outdata_no_driver_CO2only = 0; + outdata_no_driver_CH4only = 0; + outdata_no_driver_N2Oonly = 0; + outdata_node_code = 81; } if (ecozone_data[x] == tropical)// No driver, peat, not burned, tropical { if (plant_data[x] > 0) // No driver, peat, not burned, tropical, plantation { - outdata6a = peat_drain_total_CO2_only; - outdata6b = peat_drain_total_non_CO2; - outdata20 = 62; + outdata_no_driver_CO2only = peat_drain_total_CO2_only; + outdata_no_driver_CH4only = peat_drain_total_CH4_only; + outdata_no_driver_N2Oonly = peat_drain_total_N2O_only; + outdata_node_code = 82; } if (plant_data[x] == 0) // No driver, peat, not burned, tropical, not plantation { - outdata6a = 0; - outdata6b = 0; - outdata20 = 621; + outdata_no_driver_CO2only = 0; + outdata_no_driver_CH4only = 0; + outdata_no_driver_N2Oonly = 0; + outdata_node_code = 821; } } } @@ -1087,111 +1330,157 @@ for(x=0; x 0) // No driver, not peat, burned { - outdata6a = 0; - outdata6b = 0; - outdata20 = 63; + outdata_no_driver_CO2only = 0; + outdata_no_driver_CH4only = 0; + outdata_no_driver_N2Oonly = 0; + outdata_node_code = 83; } if (burn_data[x] == 0) // No driver, not peat, not burned { - outdata6a = 0; - outdata6b = 0; - outdata20 = 64; + outdata_no_driver_CO2only = 0; + outdata_no_driver_CH4only = 0; + outdata_no_driver_N2Oonly = 0; + outdata_node_code = 84; } } - outdata6 = outdata6a + outdata6b; + outdata_no_driver_allgases = outdata_no_driver_CO2only + outdata_no_driver_CH4only + outdata_no_driver_N2Oonly; + outdata_no_driver_nonCO2 = outdata_no_driver_CH4only + outdata_no_driver_N2Oonly; } // Write the value to the correct raster - if (drivermodel_data[x] == 1) // Commodities + if (drivermodel_data[x] == 1) // permanent ag { - out_data1[x] = outdata1; - out_data2[x] = 0; - out_data3[x] = 0; - out_data4[x] = 0; - out_data5[x] = 0; - out_data6[x] = 0; + out_data_permanent_agriculture[x] = outdata_permanent_agriculture_allgases; + out_data_hard_commodities[x] = 0; + out_data_shifting_cultivation[x] = 0; + out_data_forest_management[x] = 0; + out_data_wildfire[x] = 0; + out_data_settlements[x] = 0; + out_data_other_disturbances[x] = 0; + out_data_no_driver[x] = 0; } - else if (drivermodel_data[x] == 2) // Shifting ag + else if (drivermodel_data[x] == 2) // hard commodities { - out_data1[x] = 0; - out_data2[x] = outdata2; - out_data3[x] = 0; - out_data4[x] = 0; - out_data5[x] = 0; - out_data6[x] = 0; + out_data_permanent_agriculture[x] = 0; + out_data_hard_commodities[x] = outdata_hard_commodities_allgases; + out_data_shifting_cultivation[x] = 0; + out_data_forest_management[x] = 0; + out_data_wildfire[x] = 0; + out_data_settlements[x] = 0; + out_data_other_disturbances[x] = 0; + out_data_no_driver[x] = 0; } - else if (drivermodel_data[x] == 3) // Forestry + else if (drivermodel_data[x] == 3) // shifting cultivation { - out_data1[x] = 0; - out_data2[x] = 0; - out_data3[x] = outdata3; - out_data4[x] = 0; - out_data5[x] = 0; - out_data6[x] = 0; + out_data_permanent_agriculture[x] = 0; + out_data_hard_commodities[x] = 0; + out_data_shifting_cultivation[x] = outdata_shifting_cultivation_allgases; + out_data_forest_management[x] = 0; + out_data_wildfire[x] = 0; + out_data_settlements[x] = 0; + out_data_other_disturbances[x] = 0; + out_data_no_driver[x] = 0; } - else if (drivermodel_data[x] == 4) // Wildfire + else if (drivermodel_data[x] == 4) // forest management { - out_data1[x] = 0; - out_data2[x] = 0; - out_data3[x] = 0; - out_data4[x] = outdata4; - out_data5[x] = 0; - out_data6[x] = 0; + out_data_permanent_agriculture[x] = 0; + out_data_hard_commodities[x] = 0; + out_data_shifting_cultivation[x] = 0; + out_data_forest_management[x] = outdata_forest_management_allgases; + out_data_wildfire[x] = 0; + out_data_settlements[x] = 0; + out_data_other_disturbances[x] = 0; + out_data_no_driver[x] = 0; } - else if (drivermodel_data[x] == 5) // Urbanization + else if (drivermodel_data[x] == 5) // wildfire { - out_data1[x] = 0; - out_data2[x] = 0; - out_data3[x] = 0; - out_data4[x] = 0; - out_data5[x] = outdata5; - out_data6[x] = 0; + out_data_permanent_agriculture[x] = 0; + out_data_hard_commodities[x] = 0; + out_data_shifting_cultivation[x] = 0; + out_data_forest_management[x] = 0; + out_data_wildfire[x] = outdata_wildfire_allgases; + out_data_settlements[x] = 0; + out_data_other_disturbances[x] = 0; + out_data_no_driver[x] = 0; + } + else if (drivermodel_data[x] == 6) // settlements & infrastructure + { + out_data_permanent_agriculture[x] = 0; + out_data_hard_commodities[x] = 0; + out_data_shifting_cultivation[x] = 0; + out_data_forest_management[x] = 0; + out_data_wildfire[x] = 0; + out_data_settlements[x] = outdata_settlements_allgases; + out_data_other_disturbances[x] = 0; + out_data_no_driver[x] = 0; + } + else if (drivermodel_data[x] == 7) // other natural disturbances + { + out_data_permanent_agriculture[x] = 0; + out_data_hard_commodities[x] = 0; + out_data_shifting_cultivation[x] = 0; + out_data_forest_management[x] = 0; + out_data_wildfire[x] = 0; + out_data_settlements[x] = 0; + out_data_other_disturbances[x] = outdata_other_disturbances_allgases; + out_data_no_driver[x] = 0; } else // No driver { - out_data1[x] = 0; - out_data2[x] = 0; - out_data3[x] = 0; - out_data4[x] = 0; - out_data5[x] = 0; - out_data6[x] = outdata6; + out_data_permanent_agriculture[x] = 0; + out_data_hard_commodities[x] = 0; + out_data_shifting_cultivation[x] = 0; + out_data_forest_management[x] = 0; + out_data_wildfire[x] = 0; + out_data_settlements[x] = 0; + out_data_other_disturbances[x] = 0; + out_data_no_driver[x] = outdata_no_driver_allgases; } // Decision tree end node value stored in its raster - out_data20[x] = outdata20; + out_data_node_code[x] = outdata_node_code; // Add up all drivers for a combined raster. Each pixel only has one driver - outdata10 = outdata1 + outdata2 + outdata3 + outdata4 + outdata5 + outdata6; - outdata11 = outdata1a + outdata2a + outdata3a + outdata4a + outdata5a + outdata6a; - outdata12 = outdata1b + outdata2b + outdata3b + outdata4b + outdata5b + outdata6b; + outdata_alldrivers_allgases = outdata_permanent_agriculture_allgases + outdata_hard_commodities_allgases + outdata_shifting_cultivation_allgases + outdata_forest_management_allgases + outdata_wildfire_allgases + outdata_settlements_allgases + outdata_other_disturbances_allgases + outdata_no_driver_allgases; + outdata_alldrivers_CO2only = outdata_permanent_agriculture_CO2only + outdata_hard_commodities_CO2only + outdata_shifting_cultivation_CO2only + outdata_forest_management_CO2only + outdata_wildfire_CO2only + outdata_settlements_CO2only + outdata_other_disturbances_CO2only + outdata_no_driver_CO2only; + outdata_alldrivers_nonCO2 = outdata_permanent_agriculture_nonCO2 + outdata_hard_commodities_nonCO2 +outdata_shifting_cultivation_nonCO2 + outdata_forest_management_nonCO2 + outdata_wildfire_nonCO2 + outdata_settlements_nonCO2 + outdata_other_disturbances_nonCO2 + outdata_no_driver_nonCO2; + outdata_alldrivers_CH4only = outdata_permanent_agriculture_CH4only + outdata_hard_commodities_CH4only +outdata_shifting_cultivation_CH4only + outdata_forest_management_CH4only + outdata_wildfire_CH4only + outdata_settlements_CH4only + outdata_other_disturbances_CH4only + outdata_no_driver_CH4only; + outdata_alldrivers_N2Oonly = outdata_permanent_agriculture_N2Oonly + outdata_hard_commodities_N2Oonly +outdata_shifting_cultivation_N2Oonly + outdata_forest_management_N2Oonly + outdata_wildfire_N2Oonly + outdata_settlements_N2Oonly + outdata_other_disturbances_N2Oonly + outdata_no_driver_N2Oonly; - if (outdata10 == 0) + if (outdata_alldrivers_allgases == 0) { - out_data10[x] = 0; - out_data11[x] = 0; - out_data12[x] = 0; + out_data_alldrivers_allgasses[x] = 0; + out_data_alldrivers_CO2only[x] = 0; + out_data_alldrivers_nonCO2[x] = 0; + out_data_alldrivers_CH4only[x] = 0; + out_data_alldrivers_N2Oonly[x] = 0; } else{ - out_data10[x] = outdata10; - out_data11[x] = outdata11; - out_data12[x] = outdata12; + out_data_alldrivers_allgasses[x] = outdata_alldrivers_allgases; + out_data_alldrivers_CO2only[x] = outdata_alldrivers_CO2only; + out_data_alldrivers_nonCO2[x] = outdata_alldrivers_nonCO2; + out_data_alldrivers_CH4only[x] = outdata_alldrivers_CH4only; + out_data_alldrivers_N2Oonly[x] = outdata_alldrivers_N2Oonly; } } // If pixel is not on loss and carbon, all output rasters get 0 else { - - out_data1[x] = 0; - out_data2[x] = 0; - out_data3[x] = 0; - out_data4[x] = 0; - out_data5[x] = 0; - out_data6[x] = 0; - out_data10[x] = 0; - out_data11[x] = 0; - out_data12[x] = 0; - out_data20[x] = 0; + out_data_permanent_agriculture[x] = 0; + out_data_hard_commodities[x] = 0; + out_data_shifting_cultivation[x] = 0; + out_data_forest_management[x] = 0; + out_data_wildfire[x] = 0; + out_data_settlements[x] = 0; + out_data_other_disturbances[x] = 0; + out_data_no_driver[x] = 0; + out_data_alldrivers_allgasses[x] = 0; + out_data_alldrivers_CO2only[x] = 0; + out_data_alldrivers_nonCO2[x] = 0; + out_data_alldrivers_CH4only[x] = 0; + out_data_alldrivers_N2Oonly[x] = 0; + out_data_node_code[x] = 0; } } @@ -1202,23 +1491,18 @@ for(x=0; xRasterIO( GF_Write, 0, y, xsize, 1, out_data1, xsize, 1, GDT_Float32, 0, 0 ); -CPLErr errcodeOut2 = OUTBAND2->RasterIO( GF_Write, 0, y, xsize, 1, out_data2, xsize, 1, GDT_Float32, 0, 0 ); -CPLErr errcodeOut3 = OUTBAND3->RasterIO( GF_Write, 0, y, xsize, 1, out_data3, xsize, 1, GDT_Float32, 0, 0 ); -CPLErr errcodeOut4 = OUTBAND4->RasterIO( GF_Write, 0, y, xsize, 1, out_data4, xsize, 1, GDT_Float32, 0, 0 ); -CPLErr errcodeOut5 = OUTBAND5->RasterIO( GF_Write, 0, y, xsize, 1, out_data5, xsize, 1, GDT_Float32, 0, 0 ); -CPLErr errcodeOut6 = OUTBAND6->RasterIO( GF_Write, 0, y, xsize, 1, out_data6, xsize, 1, GDT_Float32, 0, 0 ); -CPLErr errcodeOut10 = OUTBAND10->RasterIO( GF_Write, 0, y, xsize, 1, out_data10, xsize, 1, GDT_Float32, 0, 0 ); -CPLErr errcodeOut11 = OUTBAND11->RasterIO( GF_Write, 0, y, xsize, 1, out_data11, xsize, 1, GDT_Float32, 0, 0 ); -CPLErr errcodeOut12 = OUTBAND12->RasterIO( GF_Write, 0, y, xsize, 1, out_data12, xsize, 1, GDT_Float32, 0, 0 ); -CPLErr errcodeOut20 = OUTBAND20->RasterIO( GF_Write, 0, y, xsize, 1, out_data20, xsize, 1, GDT_UInt16, 0, 0 ); +CPLErr errcodeOut_alldrivers_allgasses = OUTBAND_ALLDRIVERS_ALLGASSES->RasterIO( GF_Write, 0, y, xsize, 1, out_data_alldrivers_allgasses, xsize, 1, GDT_Float32, 0, 0 ); +CPLErr errcodeOut_alldrivers_CO2only = OUTBAND_ALLDRIVERS_CO2ONLY->RasterIO( GF_Write, 0, y, xsize, 1, out_data_alldrivers_CO2only, xsize, 1, GDT_Float32, 0, 0 ); +CPLErr errcodeOut_alldrivers_nonCO2 = OUTBAND_ALLDRIVERS_NONCO2->RasterIO( GF_Write, 0, y, xsize, 1, out_data_alldrivers_nonCO2, xsize, 1, GDT_Float32, 0, 0 ); +CPLErr errcodeOut_alldrivers_CH4only = OUTBAND_ALLDRIVERS_CH4ONLY->RasterIO( GF_Write, 0, y, xsize, 1, out_data_alldrivers_CH4only, xsize, 1, GDT_Float32, 0, 0 ); +CPLErr errcodeOut_alldrivers_N2Oonly = OUTBAND_ALLDRIVERS_N2OONLY->RasterIO( GF_Write, 0, y, xsize, 1, out_data_alldrivers_N2Oonly, xsize, 1, GDT_Float32, 0, 0 ); +CPLErr errcodeOut_node_code = OUTBAND_NODE_CODE->RasterIO( GF_Write, 0, y, xsize, 1, out_data_node_code, xsize, 1, GDT_UInt16, 0, 0 ); // Number of output files -int outSize = 10; +int outSize = 6; // Array of error codes returned from each output -CPLErr errcodeOutArray [outSize] = {errcodeOut1, errcodeOut2, errcodeOut3, errcodeOut4, errcodeOut5, errcodeOut6, -errcodeOut10, errcodeOut11, errcodeOut12, errcodeOut20}; +CPLErr errcodeOutArray [outSize] = {errcodeOut_alldrivers_allgasses, errcodeOut_alldrivers_CO2only, errcodeOut_alldrivers_nonCO2, errcodeOut_alldrivers_CH4only, errcodeOut_alldrivers_N2Oonly, errcodeOut_node_code}; // Iterates through the output error codes to make sure that the error code is acceptable int k; @@ -1232,16 +1516,12 @@ for (k=0; k #include #include -//// http://www.math.uaa.alaska.edu/~afkjm/csce211/handouts/SeparateCompilation.pdf -//#ifndef CONSTANTS_H -//#define CONSTANTS_H -////#include "constants.h" -//#endif - using namespace std; void def_variables(float *q, int ecozone, int forestmodel_data, int ifl, int climate, int plant_data, int lossyr) @@ -26,161 +21,171 @@ void def_variables(float *q, int ecozone, int forestmodel_data, int ifl, int cli int boreal; // The ecozone code for the boreal zone boreal = 2; -// int model_years; // How many loss years are in the model -// model_years = constants::model_years; -// -// int tropical; // The ecozone code for the tropics -// tropical = constants::tropical; -// int temperate; // The ecozone code for the temperate zone -// temperate = constants::temperate; -// int boreal; // The ecozone code for the boreal zone -// boreal = constants::boreal; - - // instantiates Cf, CO2, CH4, N2O, peatburn, peat_drain_total. - // peatburn and peat_drain_annual both have CO2 and non-CO2 components. They are calculated separately and - // passed back to the main script as separate values. + // Initiates Cf, CO2, CH4, N2O, peatburn, peat_drain_total. + // peat_drain_annual and peat_drain_total has CO2, CH4, and N2O components. + // peatburn has CO2 and CH4 components but not a N2O component because there are no N2O emissions from burning peat. + // They are calculated separately and passed back to the main script as separate values. float Cf; float CO2; float CH4; float N2O; float peatburn_CO2_only; - float peatburn_non_CO2; + float peatburn_CH4_only; // Note: there are no N2O emissions from burning peat float peat_drain_annual_CO2_only; - float peat_drain_annual_non_CO2; + float peat_drain_annual_CH4_only; + float peat_drain_annual_N2O_only; float peat_drain_total_CO2_only; - float peat_drain_total_non_CO2; + float peat_drain_total_CH4_only; + float peat_drain_total_N2O_only; - if ((forestmodel_data == 1) || (forestmodel_data == 2) || (forestmodel_data == 5)) // Commodities, shifting ag., or urbanization + + if ((forestmodel_data == 1) || (forestmodel_data == 2) || (forestmodel_data == 3) || (forestmodel_data == 6)) // permanent ag, hard commodities, shifting cultivation, settlements & infrastructure { - if (ecozone == boreal) // Commodities/shifting ag/urbanization, boreal + if (ecozone == boreal) // permanent ag, hard commodities, shifting cultivation, settlements & infrastructure { Cf = 0.59; CO2 = 1569; CH4 = 4.7; N2O = 0.26; peatburn_CO2_only = 446; - peatburn_non_CO2 = 82; - peat_drain_annual_CO2_only = 2; - peat_drain_annual_non_CO2 = 1; + peatburn_CH4_only = 82; + peat_drain_annual_CO2_only = 1.8; + peat_drain_annual_CH4_only = 0.33; + peat_drain_annual_N2O_only = 0.19; peat_drain_total_CO2_only = (model_years - lossyr) * peat_drain_annual_CO2_only; - peat_drain_total_non_CO2 = (model_years - lossyr) * peat_drain_annual_non_CO2; + peat_drain_total_CH4_only = (model_years - lossyr) * peat_drain_annual_CH4_only; + peat_drain_total_N2O_only = (model_years - lossyr) * peat_drain_annual_N2O_only; } - else if (ecozone == temperate)// Commodities/shifting ag/urbanization, temperate + else if (ecozone == temperate)// permanent ag, hard commodities, shifting cultivation, settlements & infrastructure { Cf = 0.51; CO2 = 1569; CH4 = 4.7; N2O = 0.26; peatburn_CO2_only = 446; - peatburn_non_CO2 = 82; + peatburn_CH4_only = 82; peat_drain_annual_CO2_only = 11; - peat_drain_annual_non_CO2 = 3; + peat_drain_annual_CH4_only = 0.21; + peat_drain_annual_N2O_only = 2.4; peat_drain_total_CO2_only = (model_years - lossyr) * peat_drain_annual_CO2_only; - peat_drain_total_non_CO2 = (model_years - lossyr) * peat_drain_annual_non_CO2; + peat_drain_total_CH4_only = (model_years - lossyr) * peat_drain_annual_CH4_only; + peat_drain_total_N2O_only = (model_years - lossyr) * peat_drain_annual_N2O_only; } - else // Commodities/shifting ag/urbanization, tropics (or no boreal/temperate/tropical assignment) + else // permanent ag, hard commodities, shifting cultivation, settlements & infrastructure, tropics (or no boreal/temperate/tropical assignment) { CO2 = 1580; CH4 = 6.8; N2O = 0.2; peatburn_CO2_only = 264; - peatburn_non_CO2 = 88; + peatburn_CH4_only = 88; - if (plant_data == 1) // Commodities/shifting ag/urbanization, tropics, oil palm + if (plant_data == 1) // permanent ag, hard commodities, shifting cultivation, settlements & infrastructure, tropics, oil palm { peat_drain_annual_CO2_only = 43; - peat_drain_annual_non_CO2 = 2; + peat_drain_annual_CH4_only = 1.2; + peat_drain_annual_N2O_only = 1.0; } - else if (plant_data == 2) // Commodities/shifting ag/urbanization, tropics, wood fiber + else if (plant_data == 2) // permanent ag, hard commodities, shifting cultivation, settlements & infrastructure, tropics, wood fiber { peat_drain_annual_CO2_only = 76; - peat_drain_annual_non_CO2 = 3; + peat_drain_annual_CH4_only = 1.3; + peat_drain_annual_N2O_only = 2.1; } - else // Commodities/shifting ag/urbanization, tropics, other plantation or no plantation + else // permanent ag, hard commodities, shifting cultivation, settlements & infrastructure, tropics, other plantation or no plantation { peat_drain_annual_CO2_only = 58; - peat_drain_annual_non_CO2 = 3; + peat_drain_annual_CH4_only = 1.3; + peat_drain_annual_N2O_only = 2.1; } peat_drain_total_CO2_only = (model_years - lossyr) * peat_drain_annual_CO2_only; - peat_drain_total_non_CO2 = (model_years - lossyr) * peat_drain_annual_non_CO2; + peat_drain_total_CH4_only = (model_years - lossyr) * peat_drain_annual_CH4_only; + peat_drain_total_N2O_only = (model_years - lossyr) * peat_drain_annual_N2O_only; - if (ifl > 0) // Commodities/shifting ag/urbanization, tropics, in IFL + if (ifl > 0) // permanent ag, hard commodities, shifting cultivation, settlements & infrastructure, tropics, in IFL { Cf = 0.36; } - else // Commodities/shifting ag/urbanization, tropics, outside IFL + else // permanent ag, hard commodities, shifting cultivation, settlements & infrastructure, tropics, outside IFL { Cf = 0.55; } } } - else if (forestmodel_data == 3) // Forestry + else if (forestmodel_data == 4) // Forest management { - if (ecozone == boreal) // Forestry, boreal + if (ecozone == boreal) // Forest management, boreal { Cf = 0.33; CO2 = 1569; CH4 = 4.7; N2O = 0.26; peatburn_CO2_only = 446; - peatburn_non_CO2 = 82; - peat_drain_annual_CO2_only = 2; - peat_drain_annual_non_CO2 = 1; + peatburn_CH4_only = 82; + peat_drain_annual_CO2_only = 1.8; + peat_drain_annual_CH4_only = 0.33; + peat_drain_annual_N2O_only = 0.19; peat_drain_total_CO2_only = (model_years - lossyr) * peat_drain_annual_CO2_only; - peat_drain_total_non_CO2 = (model_years - lossyr) * peat_drain_annual_non_CO2; + peat_drain_total_CH4_only = (model_years - lossyr) * peat_drain_annual_CH4_only; + peat_drain_total_N2O_only = (model_years - lossyr) * peat_drain_annual_N2O_only; } - else if (ecozone == temperate)// Forestry, temperate + else if (ecozone == temperate)// Forest management, temperate { Cf = 0.62; CO2 = 1569; CH4 = 4.7; N2O = 0.26; peatburn_CO2_only = 446; - peatburn_non_CO2 = 82; + peatburn_CH4_only = 82; peat_drain_annual_CO2_only = 11; - peat_drain_annual_non_CO2 = 3; + peat_drain_annual_CH4_only = 0.21; + peat_drain_annual_N2O_only = 2.4; peat_drain_total_CO2_only = (model_years - lossyr) * peat_drain_annual_CO2_only; - peat_drain_total_non_CO2 = (model_years - lossyr) * peat_drain_annual_non_CO2; + peat_drain_total_CH4_only = (model_years - lossyr) * peat_drain_annual_CH4_only; + peat_drain_total_N2O_only = (model_years - lossyr) * peat_drain_annual_N2O_only; } - else // Forestry, tropics (or no boreal/temperate/tropical assignment) + else // Forest management, tropics (or no boreal/temperate/tropical assignment) { CO2 = 1580; CH4 = 6.8; N2O = 0.2; peatburn_CO2_only = 264; - peatburn_non_CO2 = 88; + peatburn_CH4_only = 88; - if (plant_data == 1) // Forestry, tropics, oil palm + if (plant_data == 1) // Forest management, tropics, oil palm { peat_drain_annual_CO2_only = 43; - peat_drain_annual_non_CO2 = 2; + peat_drain_annual_CH4_only = 1.2; + peat_drain_annual_N2O_only = 1.0; } - else if (plant_data == 2) // Forestry, tropics, wood fiber + else if (plant_data == 2) // Forest management, tropics, wood fiber { peat_drain_annual_CO2_only = 76; - peat_drain_annual_non_CO2 = 3; + peat_drain_annual_CH4_only = 1.3; + peat_drain_annual_N2O_only = 2.1; } - else // Forestry, tropics, other plantation or no plantation + else // Forest management, tropics, other plantation or no plantation { peat_drain_annual_CO2_only = 58; - peat_drain_annual_non_CO2 = 3; + peat_drain_annual_CH4_only = 1.3; + peat_drain_annual_N2O_only = 2.1; } peat_drain_total_CO2_only = (model_years - lossyr) * peat_drain_annual_CO2_only; - peat_drain_total_non_CO2 = (model_years - lossyr) * peat_drain_annual_non_CO2; + peat_drain_total_CH4_only = (model_years - lossyr) * peat_drain_annual_CH4_only; + peat_drain_total_N2O_only = (model_years - lossyr) * peat_drain_annual_N2O_only; if (ifl > 0) { - Cf = 0.36; // Forestry, tropics, in IFL + Cf = 0.36; // Forest management, tropics, in IFL } else { - Cf = 0.55; // Forestry, tropics, outside IFL + Cf = 0.55; // Forest management, tropics, outside IFL } } } - else if (forestmodel_data == 4) // Wildfire + else if (forestmodel_data == 5) // Wildfire { if (ecozone == boreal) // Wildfire, boreal { @@ -189,11 +194,13 @@ void def_variables(float *q, int ecozone, int forestmodel_data, int ifl, int cli CH4 = 4.7; N2O = 0.26; peatburn_CO2_only = 446; - peatburn_non_CO2 = 82; - peat_drain_annual_CO2_only = 2; - peat_drain_annual_non_CO2 = 1; + peatburn_CH4_only = 82; + peat_drain_annual_CO2_only = 1.8; + peat_drain_annual_CH4_only = 0.33; + peat_drain_annual_N2O_only = 0.19; peat_drain_total_CO2_only = (model_years - lossyr) * peat_drain_annual_CO2_only; - peat_drain_total_non_CO2 = (model_years - lossyr) * peat_drain_annual_non_CO2; + peat_drain_total_CH4_only = (model_years - lossyr) * peat_drain_annual_CH4_only; + peat_drain_total_N2O_only = (model_years - lossyr) * peat_drain_annual_N2O_only; } else if (ecozone == temperate)// Wildfire, temperate { @@ -202,11 +209,13 @@ void def_variables(float *q, int ecozone, int forestmodel_data, int ifl, int cli CH4 = 4.7; N2O = 0.26; peatburn_CO2_only = 446; - peatburn_non_CO2 = 82; + peatburn_CH4_only = 82; peat_drain_annual_CO2_only = 11; - peat_drain_annual_non_CO2 = 3; + peat_drain_annual_CH4_only = 0.21; + peat_drain_annual_N2O_only = 2.4; peat_drain_total_CO2_only = (model_years - lossyr) * peat_drain_annual_CO2_only; - peat_drain_total_non_CO2 = (model_years - lossyr) * peat_drain_annual_non_CO2; + peat_drain_total_CH4_only = (model_years - lossyr) * peat_drain_annual_CH4_only; + peat_drain_total_N2O_only = (model_years - lossyr) * peat_drain_annual_N2O_only; } else // Wildfire, tropics (or no boreal/temperate/tropical assignment) { @@ -214,25 +223,29 @@ void def_variables(float *q, int ecozone, int forestmodel_data, int ifl, int cli CH4 = 6.8; N2O = 0.2; peatburn_CO2_only = 601; - peatburn_non_CO2 = 200; + peatburn_CH4_only = 200; if (plant_data == 1) // Wildfire, tropics, oil palm { peat_drain_annual_CO2_only = 43; - peat_drain_annual_non_CO2 = 2; + peat_drain_annual_CH4_only = 1.2; + peat_drain_annual_N2O_only = 1.0; } else if (plant_data == 2) // Wildfire, tropics, wood fiber { peat_drain_annual_CO2_only = 76; - peat_drain_annual_non_CO2 = 3; + peat_drain_annual_CH4_only = 1.3; + peat_drain_annual_N2O_only = 2.1; } else // Wildfire, tropics, other plantation or no plantation { peat_drain_annual_CO2_only = 58; - peat_drain_annual_non_CO2 = 3; + peat_drain_annual_CH4_only = 1.3; + peat_drain_annual_N2O_only = 2.1; } peat_drain_total_CO2_only = (model_years - lossyr) * peat_drain_annual_CO2_only; - peat_drain_total_non_CO2 = (model_years - lossyr) * peat_drain_annual_non_CO2; + peat_drain_total_CH4_only = (model_years - lossyr) * peat_drain_annual_CH4_only; + peat_drain_total_N2O_only = (model_years - lossyr) * peat_drain_annual_N2O_only; if (ifl > 0) // Wildfire, tropics, in IFL { @@ -245,33 +258,110 @@ void def_variables(float *q, int ecozone, int forestmodel_data, int ifl, int cli } } - else // No driver-- same as forestry + else if (forestmodel_data == 7) // Other natural disturbances + { + if (ecozone == boreal) // Other natural disturbances, boreal + { + Cf = 0.34; + CO2 = 1569; + CH4 = 4.7; + N2O = 0.26; + peatburn_CO2_only = 446; + peatburn_CH4_only = 82; + peat_drain_annual_CO2_only = 1.8; + peat_drain_annual_CH4_only = 0.33; + peat_drain_annual_N2O_only = 0.19; + peat_drain_total_CO2_only = (model_years - lossyr) * peat_drain_annual_CO2_only; + peat_drain_total_CH4_only = (model_years - lossyr) * peat_drain_annual_CH4_only; + peat_drain_total_N2O_only = (model_years - lossyr) * peat_drain_annual_N2O_only; + } + else if (ecozone == temperate)// Other natural disturbances, temperate + { + Cf = 0.45; + CO2 = 1569; + CH4 = 4.7; + N2O = 0.26; + peatburn_CO2_only = 446; + peatburn_CH4_only = 82; + peat_drain_annual_CO2_only = 11; + peat_drain_annual_CH4_only = 0.21; + peat_drain_annual_N2O_only = 2.4; + peat_drain_total_CO2_only = (model_years - lossyr) * peat_drain_annual_CO2_only; + peat_drain_total_CH4_only = (model_years - lossyr) * peat_drain_annual_CH4_only; + peat_drain_total_N2O_only = (model_years - lossyr) * peat_drain_annual_N2O_only; + } + else // Other natural disturbances, tropics (or no boreal/temperate/tropical assignment) + { + CO2 = 1580; + CH4 = 6.8; + N2O = 0.2; + peatburn_CO2_only = 264; + peatburn_CH4_only = 88; + + if (plant_data == 1) // Other natural disturbances, tropics, oil palm + { + peat_drain_annual_CO2_only = 43; + peat_drain_annual_CH4_only = 1.2; + peat_drain_annual_N2O_only = 1.0; + } + else if (plant_data == 2) // Other natural disturbances, tropics, wood fiber + { + peat_drain_annual_CO2_only = 76; + peat_drain_annual_CH4_only = 1.3; + peat_drain_annual_N2O_only = 2.1; + } + else // Other natural disturbances, tropics, other plantation or no plantation + { + peat_drain_annual_CO2_only = 58; + peat_drain_annual_CH4_only = 1.3; + peat_drain_annual_N2O_only = 2.1; + } + peat_drain_total_CO2_only = (model_years - lossyr) * peat_drain_annual_CO2_only; + peat_drain_total_CH4_only = (model_years - lossyr) * peat_drain_annual_CH4_only; + peat_drain_total_N2O_only = (model_years - lossyr) * peat_drain_annual_N2O_only; + + if (ifl > 0) + { + Cf = 0.36; // Other natural disturbances, tropics, in IFL + } + else + { + Cf = 0.55; // Other natural disturbances, tropics, outside IFL + } + } + } + + else // No driver-- same as other natural disturbances { if (ecozone == boreal) // No driver, boreal { - Cf = 0.33; + Cf = 0.34; CO2 = 1569; CH4 = 4.7; N2O = 0.26; peatburn_CO2_only = 446; - peatburn_non_CO2 = 82; - peat_drain_annual_CO2_only = 2; - peat_drain_annual_non_CO2 = 1; + peatburn_CH4_only = 82; + peat_drain_annual_CO2_only = 1.8; + peat_drain_annual_CH4_only = 0.33; + peat_drain_annual_N2O_only = 0.19; peat_drain_total_CO2_only = (model_years - lossyr) * peat_drain_annual_CO2_only; - peat_drain_total_non_CO2 = (model_years - lossyr) * peat_drain_annual_non_CO2; + peat_drain_total_CH4_only = (model_years - lossyr) * peat_drain_annual_CH4_only; + peat_drain_total_N2O_only = (model_years - lossyr) * peat_drain_annual_N2O_only; } else if (ecozone == temperate)// No driver, temperate { - Cf = 0.62; + Cf = 0.45; CO2 = 1569; CH4 = 4.7; N2O = 0.26; peatburn_CO2_only = 446; - peatburn_non_CO2 = 82; + peatburn_CH4_only = 82; peat_drain_annual_CO2_only = 11; - peat_drain_annual_non_CO2 = 3; + peat_drain_annual_CH4_only = 0.21; + peat_drain_annual_N2O_only = 2.4; peat_drain_total_CO2_only = (model_years - lossyr) * peat_drain_annual_CO2_only; - peat_drain_total_non_CO2 = (model_years - lossyr) * peat_drain_annual_non_CO2; + peat_drain_total_CH4_only = (model_years - lossyr) * peat_drain_annual_CH4_only; + peat_drain_total_N2O_only = (model_years - lossyr) * peat_drain_annual_N2O_only; } else // No driver, tropics (or no boreal/temperate/tropical assignment) { @@ -279,25 +369,29 @@ void def_variables(float *q, int ecozone, int forestmodel_data, int ifl, int cli CH4 = 6.8; N2O = 0.2; peatburn_CO2_only = 264; - peatburn_non_CO2 = 88; + peatburn_CH4_only = 88; - if (plant_data == 1) // Forestry, tropics, oil palm + if (plant_data == 1) // No driver, tropics, oil palm { peat_drain_annual_CO2_only = 43; - peat_drain_annual_non_CO2 = 2; + peat_drain_annual_CH4_only = 1.2; + peat_drain_annual_N2O_only = 1; } - else if (plant_data == 2) // Forestry, tropics, wood fiber + else if (plant_data == 2) // No driver, tropics, wood fiber { peat_drain_annual_CO2_only = 76; - peat_drain_annual_non_CO2 = 3; + peat_drain_annual_CH4_only = 1.3; + peat_drain_annual_N2O_only = 2.1; } - else // Forestry, tropics, other plantation or no plantation + else // No driver, tropics, other plantation or no plantation { peat_drain_annual_CO2_only = 58; - peat_drain_annual_non_CO2 = 3; + peat_drain_annual_CH4_only = 1.3; + peat_drain_annual_N2O_only = 2.1; } peat_drain_total_CO2_only = (model_years - lossyr) * peat_drain_annual_CO2_only; - peat_drain_total_non_CO2 = (model_years - lossyr) * peat_drain_annual_non_CO2; + peat_drain_total_CH4_only = (model_years - lossyr) * peat_drain_annual_CH4_only; + peat_drain_total_N2O_only = (model_years - lossyr) * peat_drain_annual_N2O_only; if (ifl > 0) { @@ -309,12 +403,15 @@ void def_variables(float *q, int ecozone, int forestmodel_data, int ifl, int cli } } } + q[0] = Cf; q[1] = CO2; q[2] = CH4; q[3] = N2O; q[4] = peatburn_CO2_only; - q[5] = peatburn_non_CO2; + q[5] = peatburn_CH4_only; q[6] = peat_drain_total_CO2_only; - q[7] = peat_drain_total_non_CO2; + q[7] = peat_drain_total_CH4_only; + q[8] = peat_drain_total_N2O_only; + } \ No newline at end of file diff --git a/emissions/cpp_util/flu_val.cpp b/emissions/cpp_util/flu_val.cpp index b572d4ac..14c901ba 100644 --- a/emissions/cpp_util/flu_val.cpp +++ b/emissions/cpp_util/flu_val.cpp @@ -1,8 +1,12 @@ +// These values are found in the powerpoint with the emissions model decision trees: +// https://onewri-my.sharepoint.com/:p:/r/personal/david_gibbs_wri_org/Documents/Documents/Projects/Carbon%20model%20phase%201/carbon_budget_flowchart_v8.pptx?d=w701e66825ac24e23a9ba6c7a408f84ad&csf=1&web=1&e=4ufGOx + #include #include #include using namespace std; +//This function is specifically for the permanent agriculture driver class which has several possible flu_values based on eco zone and climate zone float flu_val(int climate_zone, int eco_zone) { float flu_value; @@ -10,11 +14,11 @@ float flu_val(int climate_zone, int eco_zone) { if (eco_zone == 1) // Dry, tropics { - flu_value = 0.58; + flu_value = 0.92; } else if ((eco_zone == 2) || (eco_zone == 3)) // Dry, boreal/temperate { - flu_value = 0.8; + flu_value = 0.77; } else { @@ -25,11 +29,11 @@ float flu_val(int climate_zone, int eco_zone) { if (eco_zone == 1) // Wet, tropics { - flu_value = 0.48; + flu_value = 0.83; } else if ((eco_zone == 2) || (eco_zone == 3)) // Wet, boreal/temperate { - flu_value = 0.69; + flu_value = 0.70; } else { @@ -40,11 +44,11 @@ float flu_val(int climate_zone, int eco_zone) { if (eco_zone == 1) // Montane, tropics { - flu_value = 0.64; + flu_value = 0.88; } else if ((eco_zone == 2) || (eco_zone == 3)) // Montane, boreal/temperate { - flu_value = 0.75; + flu_value = 0.74; } else { diff --git a/emissions/mp_calculate_gross_emissions.py b/emissions/mp_calculate_gross_emissions.py index db3caed4..47c4d0a7 100644 --- a/emissions/mp_calculate_gross_emissions.py +++ b/emissions/mp_calculate_gross_emissions.py @@ -10,17 +10,15 @@ do the following inside the Docker container: c++ /usr/local/app/emissions/cpp_util/calc_gross_emissions_generic.cpp -o /usr/local/app/emissions/cpp_util/calc_gross_emissions_generic.exe -lgdal calc_gross_emissions_generic.exe should appear in the directory if it wasn't already there. -For the sensitivity analyses that use a different gross emissions C++ script (currently, soil_only, no_shifting_ag, -and convert_to_grassland), do: -c++ /usr/local/app/carbon-budget/emissions/cpp_util/calc_gross_emissions_.cpp -o /usr/local/app/emissions/cpp_util/calc_gross_emissions_.exe -lgdal +For the sensitivity analyses that use a different gross emissions C++ script (currently, soil_only), do: +c++ /usr/local/app/carbon-budget/emissions/cpp_util/calc_gross_emissions_soil_only.cpp -o /usr/local/app/emissions/cpp_util/calc_gross_emissions_soil_only.exe -lgdal The other C++ scripts (equations.cpp and flu_val.cpp) do not need to be compiled separately. Run the emissions model with: python -m emissions.mp_calculate_gross_emissions -t [MODEL_TYPE] -p [POOL_OPTION] -l [TILE_LIST] [optional_arguments] The --pools-to-use argument specifies whether to calculate gross emissions from biomass+soil or just from soil. The --model-type argument specifies whether the model run is a sensitivity analysis or standard run. -Emissions from each driver (including loss that had no driver assigned) gets its own tile, as does all emissions combined. -Emissions from all drivers is also output as emissions due to CO2 only and emissions due to non-CO2 GHGs (CH4 and N2O). +Emissions from all drivers is also output as emissions due to CO2, CH4, and N2O. The other output shows which branch of the decision tree that determines the emissions equation applies to each pixel. These codes are summarized in carbon-budget/emissions/node_codes.txt @@ -44,9 +42,13 @@ def mp_calculate_gross_emissions(tile_id_list, emitted_pools): :param tile_id_list: list of tile ids to process :param emitted_pools: Whether emissions from soil only is calculated, or emissions from biomass and soil. Options are: soil_only or biomass_soil. - :return: 10 sets of tiles: 6 sets of tiles with emissions for each driver; CO2 emissions from all drivers; - non-CO2 emissions from all drivers; all gases (CO2 and non-CO2 from all drivers); - emissions decision tree nodes (used for QC). + :return: 6 tiles - + 1. all gases (CO2, CH4 and N2O from all drivers); + 2. CO2 emissions from all drivers; + 3. non-CO2 emissions from all drivers (CH4 and N2O from all drivers); + 4. CH4 emissions from all drivers; + 5. N2O emissions from all drivers; + 6. emissions decision tree nodes (used for QC). Units: Mg CO2e/ha over entire model period. """ @@ -98,64 +100,41 @@ def mp_calculate_gross_emissions(tile_id_list, emitted_pools): if emitted_pools == 'biomass_soil': # Output file directories for biomass+soil. Must be in same order as output pattern directories. - output_dir_list = [cn.gross_emis_commod_biomass_soil_dir, - cn.gross_emis_shifting_ag_biomass_soil_dir, - cn.gross_emis_forestry_biomass_soil_dir, - cn.gross_emis_wildfire_biomass_soil_dir, - cn.gross_emis_urban_biomass_soil_dir, - cn.gross_emis_no_driver_biomass_soil_dir, - cn.gross_emis_all_gases_all_drivers_biomass_soil_dir, + output_dir_list = [cn.gross_emis_all_gases_all_drivers_biomass_soil_dir, cn.gross_emis_co2_only_all_drivers_biomass_soil_dir, cn.gross_emis_non_co2_all_drivers_biomass_soil_dir, + cn.gross_emis_ch4_only_all_drivers_biomass_soil_dir, + cn.gross_emis_n2o_only_all_drivers_biomass_soil_dir, cn.gross_emis_nodes_biomass_soil_dir] - output_pattern_list = [cn.pattern_gross_emis_commod_biomass_soil, - cn.pattern_gross_emis_shifting_ag_biomass_soil, - cn.pattern_gross_emis_forestry_biomass_soil, - cn.pattern_gross_emis_wildfire_biomass_soil, - cn.pattern_gross_emis_urban_biomass_soil, - cn.pattern_gross_emis_no_driver_biomass_soil, - cn.pattern_gross_emis_all_gases_all_drivers_biomass_soil, + output_pattern_list = [cn.pattern_gross_emis_all_gases_all_drivers_biomass_soil, cn.pattern_gross_emis_co2_only_all_drivers_biomass_soil, cn.pattern_gross_emis_non_co2_all_drivers_biomass_soil, + cn.pattern_gross_emis_ch4_only_all_drivers_biomass_soil, + cn.pattern_gross_emis_n2o_only_all_drivers_biomass_soil, cn.pattern_gross_emis_nodes_biomass_soil] - # Some sensitivity analyses have specific gross emissions scripts. - # The rest of the sensitivity analyses and the standard model can all use the same, generic gross emissions script. - if cn.SENSIT_TYPE in ['no_shifting_ag', 'convert_to_grassland']: - uu.print_log(f'Compiling {cn.SENSIT_TYPE} model C++...') - cmd = ['c++', f'/usr/local/app/emissions/cpp_util/calc_gross_emissions_{cn.SENSIT_TYPE}.cpp', - '-o', f'/usr/local/app/emissions/cpp_util/calc_gross_emissions_{cn.SENSIT_TYPE}.exe', '-lgdal'] - uu.log_subprocess_output_full(cmd) - else: - uu.print_log(f'Compiling generic model C++...') - cmd = ['c++', f'/usr/local/app/emissions/cpp_util/calc_gross_emissions_generic.cpp', - '-o', f'/usr/local/app/emissions/cpp_util/calc_gross_emissions_generic.exe', '-lgdal'] - uu.log_subprocess_output_full(cmd) + # The standard model can all use the same, generic gross emissions script. + uu.print_log(f'Compiling generic model C++...') + cmd = ['c++', f'/usr/local/app/emissions/cpp_util/calc_gross_emissions_generic.cpp', + '-o', f'/usr/local/app/emissions/cpp_util/calc_gross_emissions_generic.exe', '-lgdal'] + uu.log_subprocess_output_full(cmd) elif (emitted_pools == 'soil_only') & (cn.SENSIT_TYPE == 'std'): # Output file directories for soil_only. Must be in same order as output pattern directories. - output_dir_list = [cn.gross_emis_commod_soil_only_dir, - cn.gross_emis_shifting_ag_soil_only_dir, - cn.gross_emis_forestry_soil_only_dir, - cn.gross_emis_wildfire_soil_only_dir, - cn.gross_emis_urban_soil_only_dir, - cn.gross_emis_no_driver_soil_only_dir, - cn.gross_emis_all_gases_all_drivers_soil_only_dir, + output_dir_list = [cn.gross_emis_all_gases_all_drivers_soil_only_dir, cn.gross_emis_co2_only_all_drivers_soil_only_dir, cn.gross_emis_non_co2_all_drivers_soil_only_dir, + cn.gross_emis_ch4_only_all_drivers_soil_only_dir, + cn.gross_emis_n2o_only_all_drivers_soil_only_dir, cn.gross_emis_nodes_soil_only_dir] - output_pattern_list = [cn.pattern_gross_emis_commod_soil_only, - cn.pattern_gross_emis_shifting_ag_soil_only, - cn.pattern_gross_emis_forestry_soil_only, - cn.pattern_gross_emis_wildfire_soil_only, - cn.pattern_gross_emis_urban_soil_only, - cn.pattern_gross_emis_no_driver_soil_only, - cn.pattern_gross_emis_all_gases_all_drivers_soil_only, + output_pattern_list = [cn.pattern_gross_emis_all_gases_all_drivers_soil_only, cn.pattern_gross_emis_co2_only_all_drivers_soil_only, cn.pattern_gross_emis_non_co2_all_drivers_soil_only, + cn.pattern_gross_emis_ch4_only_all_drivers_soil_only, + cn.pattern_gross_emis_n2o_only_all_drivers_soil_only, cn.pattern_gross_emis_nodes_soil_only] uu.print_log(f'Compiling soil_only model C++...') @@ -228,6 +207,7 @@ def mp_calculate_gross_emissions(tile_id_list, emitted_pools): else: # count/4 uses about 390 GB on a r4.16xlarge spot machine. # processes=18 uses about 440 GB on an r4.16xlarge spot machine. + # (these values are for the old 10km drivers, might be different with 1km drivers now) if cn.count == 96: if cn.SENSIT_TYPE == 'biomass_swap': processes = 15 # 15 processors = XXX GB peak diff --git a/emissions/node_codes.txt b/emissions/node_codes.txt index 7648feab..0e91cd65 100644 --- a/emissions/node_codes.txt +++ b/emissions/node_codes.txt @@ -1,80 +1,104 @@ Each of these represents a unique combination of loss driver and other contextual variables that determine the correct gross emissions equation. -This can be used to do zonal stats on the gross or net emissions, e.g., gross emissions in commodity-driven deforestation +This can be used to do zonal stats on the gross or net emissions, e.g., gross emissions in permanent agriculture in the tropics on plantations with fires. -10- Commodity, peat, burned -11- Commodity, peat, not burned, tropical, plantation -111- Commodity, peat, not burned, tropical, not plantation -12- Commodty, peat, not burned, temperate/boreal -13- Commodity, not peat, burned, tropical, IFL, plantation -131- Commodity, not peat, burned, tropical, IFL, not plantation -14- Commodity, not peat, burned, tropical, not IFL, plantation -141- Commodity, not peat, burned, tropical, not IFL, not plantation -15- Commodity, not peat, burned, boreal -16- Commodity, not peat, burned, temperate, plantation -161- Commodity, not peat, burned, temperate, not plantation -17- Commodity, not peat, not burned, tropical, plantation -171- Commodity, not peat, not burned, tropical, not plantation -18- Commodity, not peat, not burned, boreal -19- Commodity, not peat, not burned, temperate, plantation -191- Commodity, not peat, not burned, temperate, not plantation - -20- Shifting ag, peat, burned, temperate/boreal -21- Shifting ag, peat, burned, tropical -22- Shifting ag, peat, not burned, temperate/boreal -23- Shifting ag, peat, not burned, tropical, plantation -231- Shifting ag, peat, not burned, tropical, not plantation -24- Shifting ag, not peat, burned, tropical, IFL, plantation -241- Shifting ag, not peat, burned, tropical, IFL, not plantation -25- Shifting ag, not peat, burned, tropical, not IFL, plantation -251- Shifting ag, not peat, burned, tropical, not IFL, not plantation -26- Shifting ag, not peat, burned, boreal -27- Shifting ag, not peat, burned, temperate, plantation -271- Shifting ag, not peat, burned, temperate, not plantation -28- Shifting ag, not peat, not burned, tropical, plantation -281- Shifting ag, not peat, not burned, tropical, not plantation -29- Shifting ag, not peat, not burned, boreal -291- Shifting ag, not peat, not burned, temperate, plantation -292- Shifting ag, not peat, not burned, temperate, not plantation - -30- Forestry, peat, burned -31- Forestry, peat, not burned, temperate/boreal -32- Forestry, peat, not burned, tropical, plantation -321- Forestry, peat, not burned, tropical, not plantation -33- Forestry, not peat, burned -34- Forestry, not peat, not burned - -40- Wildfire, peat, burned -41- Wildfire, peat, not burned, temperate/boreal -42- Wildfire, peat, not burned, tropical, plantation -421- Wildfire, peat, not burned, tropical, not plantation -43- Wildfire, not peat, burned -44- Wildfire, not peat, not burned - -50- Urbanization, peat, burned -51- Urbanization, peat, not burned, tropical, plantation -511- Urbanization, peat, not burned, tropical, not plantation -52- Urbanization, peat, not burned, temperate/boreal -53- Urbanization, not peat, burned, tropical, IFL, plantation -531- Urbanization, not peat, burned, tropical, IFL, not plantation -54- Urbanization, not peat, burned, tropical, not IFL, plantation -541- Urbanization, not peat, burned, tropical, not IFL, not plantation -55- Urbanization, not peat, burned, boreal -56- Urbanization, not peat, burned, temperate, plantation -561- Urbanization, not peat, burned, temperate, not plantation -57- Urbanization, not peat, not burned, tropical, plantation -571- Urbanization, not peat, not burned, tropical, not plantation -58- Urbanization, not peat, not burned, boreal -59- Urbanization, not peat, not burned, temperate, plantation -591- Urbanization, not peat, not burned, temperate, not plantation - -60- No driver, peat, burned -61- No driver, peat, not burned, temperate/boreal -62- No driver, peat, not burned, tropical, plantation -621- No driver, peat, not burned, tropical, not plantation -63- No driver, not peat, burned -64- No driver, not peat, not burned +10 - Permanent agriculture, peat, burned +11 - Permanent agriculture, peat, not burned, tropical, plantation +111 - Permanent agriculture, peat, not burned, tropical, not plantation +12 - Permanent agriculture, peat, not burned, temperate/boreal +13 - Permanent agriculture, not peat, burned, tropical, IFL, plantation +131 - Permanent agriculture, not peat, burned, tropical, IFL, not plantation +14 - Permanent agriculture, not peat, burned, tropical, not IFL, plantation +141 - Permanent agriculture, not peat, burned, tropical, not IFL, not plantation +15 - Permanent agriculture, not peat, burned, boreal +16 - Permanent agriculture, not peat, burned, temperate, plantation +161 - Permanent agriculture, not peat, burned, temperate, not plantation +17 - Permanent agriculture, not peat, not burned, tropical, plantation +171 - Permanent agriculture, not peat, not burned, tropical, not plantation +18 - Permanent agriculture, not peat, not burned, boreal +19 - Permanent agriculture, not peat, not burned, temperate, plantation +191 - Permanent agriculture, not peat, not burned, temperate, not plantation + +20 - Hard commodities, peat, burned +21 - Hard commodities, peat, not burned, tropical, plantation +211 - Hard commodities, peat, not burned, tropical, not plantation +22 - Hard commodities, peat, not burned, temperate/boreal +23 - Hard commodities, not peat, burned, tropical, IFL, plantation +231 - Hard commodities, not peat, burned, tropical, IFL, not plantation +24 - Hard commodities, not peat, burned, tropical, not IFL, plantation +241 - Hard commodities, not peat, burned, tropical, not IFL, not plantation +25 - Hard commodities, not peat, burned, boreal +26 - Hard commodities, not peat, burned, temperate, plantation +261 - Hard commodities, not peat, burned, temperate, not plantation +27 - Hard commodities, not peat, not burned, tropical, plantation +271 - Hard commodities, not peat, not burned, tropical, not plantation +28 - Hard commodities, not peat, not burned, boreal +29 - Hard commodities, not peat, not burned, temperate, plantation +291 - Hard commodities, not peat, not burned, temperate, not plantation + +30 - Shifting cultivation, peat, burned, temperate/boreal +31 - Shifting cultivation, peat, burned, tropical +32 - Shifting cultivation, peat, not burned, temperate/boreal +33 - Shifting cultivation, peat, not burned, tropical, plantation +331 - Shifting cultivation, peat, not burned, tropical, not plantation +34 - Shifting cultivation, not peat, burned, tropical, IFL, plantation +341 - Shifting cultivation, not peat, burned, tropical, IFL, not plantation +35 - Shifting cultivation, not peat, burned, tropical, not IFL, plantation +351 - Shifting cultivation, not peat, burned, tropical, not IFL, not plantation +36 - Shifting cultivation, not peat, burned, boreal +37 - Shifting cultivation, not peat, burned, temperate, plantation +371 - Shifting cultivation, not peat, burned, temperate, not plantation +38 - Shifting cultivation, not peat, not burned, tropical, plantation +381 - Shifting cultivation, not peat, not burned, tropical, not plantation +39 - Shifting cultivation, not peat, not burned, boreal +391 - Shifting cultivation, not peat, not burned, temperate, plantation +392 - Shifting cultivation, not peat, not burned, temperate, not plantation + +40 - Forest management, peat, burned +41 - Forest management, peat, not burned, temperate/boreal +42 - Forest management, peat, not burned, tropical, plantation +421 - Forest management, peat, not burned, tropical, not plantation +43 - Forest management, not peat, burned +44 - Forest management, not peat, not burned + +50 - Wildfire, peat, burned +51 - Wildfire, peat, not burned, temperate/boreal +52 - Wildfire, peat, not burned, tropical, plantation +521 - Wildfire, peat, not burned, tropical, not plantation +53 - Wildfire, not peat, burned +54 - Wildfire, not peat, not burned + +60 - Settlements & infrastructure, peat, burned +61 - Settlements & infrastructure, peat, not burned, tropical, plantation +611 - Settlements & infrastructure, peat, not burned, tropical, not plantation +62 - Settlements & infrastructure, peat, not burned, temperate/boreal +63 - Settlements & infrastructure, not peat, burned, tropical, IFL, plantation +631 - Settlements & infrastructure, not peat, burned, tropical, IFL, not plantation +64 - Settlements & infrastructure, not peat, burned, tropical, not IFL, plantation +641 - Settlements & infrastructure, not peat, burned, tropical, not IFL, not plantation +65 - Settlements & infrastructure, not peat, burned, boreal +66 - Settlements & infrastructure, not peat, burned, temperate, plantation +661 - Settlements & infrastructure, not peat, burned, temperate, not plantation +67 - Settlements & infrastructure, not peat, not burned, tropical, plantation +671 - Settlements & infrastructure, not peat, not burned, tropical, not plantation +68 - Settlements & infrastructure, not peat, not burned, boreal +69 - Settlements & infrastructure, not peat, not burned, temperate, plantation +691 - Settlements & infrastructure, not peat, not burned, temperate, not plantation + +70 - Other natural disturbances, peat, burned +71 - Other natural disturbances, peat, not burned, temperate/boreal +72 - Other natural disturbances, peat, not burned, tropical, plantation +721 - Other natural disturbances, peat, not burned, tropical, not plantation +73 - Other natural disturbances, not peat, burned +74 - Other natural disturbances, not peat, not burned + +80 - No driver, peat, burned +81 - No driver, peat, not burned, temperate/boreal +82 - No driver, peat, not burned, tropical, plantation +821 - No driver, peat, not burned, tropical, not plantation +83 - No driver, not peat, burned +84 - No driver, not peat, not burned diff --git a/readme.md b/readme.md index 06f82c32..4f550995 100644 --- a/readme.md +++ b/readme.md @@ -3,7 +3,7 @@ ### Purpose and scope This framework maps gross greenhouse gas emissions from forests, gross carbon removals (sequestration) by forests, and the difference between them (net flux), all between 2001 and 2023. -Gross emissions includes CO2, CH4, and N20 and all carbon pools (aboveground biomass, belowground biomass, +Gross emissions includes CO2, CH4, and N2O and all carbon pools (aboveground biomass, belowground biomass, dead wood, litter, and soil), and gross removals includes removals into aboveground and belowground biomass carbon. Although the framework is run for all tree canopy densities in 2000 (per Hansen et al. 2013), it is most relevant to pixels with canopy density >30% in 2000 or pixels which subsequently had tree cover gain (per Potapov et al. 2022). diff --git a/run_full_model.py b/run_full_model.py index c28ec74e..1892e3a1 100644 --- a/run_full_model.py +++ b/run_full_model.py @@ -214,26 +214,18 @@ def main (): cn.soil_C_full_extent_2000_dir, cn.total_C_2000_dir] # Adds the biomass_soil output directories and the soil_only output directories - output_dir_list = output_dir_list + [cn.gross_emis_commod_biomass_soil_dir, - cn.gross_emis_shifting_ag_biomass_soil_dir, - cn.gross_emis_forestry_biomass_soil_dir, - cn.gross_emis_wildfire_biomass_soil_dir, - cn.gross_emis_urban_biomass_soil_dir, - cn.gross_emis_no_driver_biomass_soil_dir, - cn.gross_emis_all_gases_all_drivers_biomass_soil_dir, + output_dir_list = [cn.gross_emis_all_gases_all_drivers_biomass_soil_dir, cn.gross_emis_co2_only_all_drivers_biomass_soil_dir, cn.gross_emis_non_co2_all_drivers_biomass_soil_dir, + cn.gross_emis_ch4_only_all_drivers_biomass_soil_dir, + cn.gross_emis_n2o_only_all_drivers_biomass_soil_dir, cn.gross_emis_nodes_biomass_soil_dir] - output_dir_list = output_dir_list + [cn.gross_emis_commod_soil_only_dir, - cn.gross_emis_shifting_ag_soil_only_dir, - cn.gross_emis_forestry_soil_only_dir, - cn.gross_emis_wildfire_soil_only_dir, - cn.gross_emis_urban_soil_only_dir, - cn.gross_emis_no_driver_soil_only_dir, - cn.gross_emis_all_gases_all_drivers_soil_only_dir, + output_dir_list = [cn.gross_emis_all_gases_all_drivers_soil_only_dir, cn.gross_emis_co2_only_all_drivers_soil_only_dir, cn.gross_emis_non_co2_all_drivers_soil_only_dir, + cn.gross_emis_ch4_only_all_drivers_soil_only_dir, + cn.gross_emis_n2o_only_all_drivers_soil_only_dir, cn.gross_emis_nodes_soil_only_dir] # Adds the net flux output directory @@ -486,14 +478,10 @@ def main (): uu.print_log(':::::Freeing up memory for soil_only gross emissions creation by deleting unneeded tiles') tiles_to_delete = [] - tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_non_co2_all_drivers_biomass_soil}*tif')) tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_co2_only_all_drivers_biomass_soil}*tif')) - tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_commod_biomass_soil}*tif')) - tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_shifting_ag_biomass_soil}*tif')) - tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_forestry_biomass_soil}*tif')) - tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_wildfire_biomass_soil}*tif')) - tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_urban_biomass_soil}*tif')) - tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_no_driver_biomass_soil}*tif')) + tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_non_co2_all_drivers_biomass_soil}*tif')) + tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_ch4_only_all_drivers_biomass_soil}*tif')) + tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_n2o_only_all_drivers_biomass_soil}*tif')) tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_nodes_biomass_soil}*tif')) uu.print_log(f' Deleting {len(tiles_to_delete)} tiles...') @@ -524,14 +512,10 @@ def main (): uu.print_log(':::::Freeing up memory for net flux creation by deleting unneeded tiles') tiles_to_delete = [] tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_all_gases_all_drivers_soil_only}*tif')) - tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_non_co2_all_drivers_soil_only}*tif')) tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_co2_only_all_drivers_soil_only}*tif')) - tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_commod_soil_only}*tif')) - tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_shifting_ag_soil_only}*tif')) - tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_forestry_soil_only}*tif')) - tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_wildfire_soil_only}*tif')) - tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_urban_soil_only}*tif')) - tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_no_driver_soil_only}*tif')) + tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_non_co2_all_drivers_soil_only}*tif')) + tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_ch4_only_all_drivers_soil_only}*tif')) + tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_n2o_only_all_drivers_soil_only}*tif')) tiles_to_delete.extend(glob.glob(f'*{cn.pattern_gross_emis_nodes_soil_only}*tif')) uu.print_log(f' Deleting {len(tiles_to_delete)} tiles...') diff --git a/universal_util.py b/universal_util.py index 659a3b42..594092dc 100644 --- a/universal_util.py +++ b/universal_util.py @@ -734,6 +734,18 @@ def s3_folder_download(source, dest, sensit_type, pattern = None): os.rmdir(os.path.join(dest, 'data-lake-downloads')) print_log(f'data-lake tiles with pattern {ec2_pattern} copied to main tile folder...') + # The --no-sign-request in the else statement below was causing the following error when trying to download the 1km drivers: + # "An error occurred (AccessDenied) when calling the GetObject operation: Access Denied" + #TODO update this when we move 1km drivers source to gfw-data-lake after API ingestion + elif 'drivers_of_loss' in source: + print_log(f'Tiles with pattern {pattern} are not on spot machine. Downloading...') + + cmd = ['aws', 's3', 'cp', source, dest, '--exclude', '*tiled/*', + '--exclude', '*geojson', '--exclude', '*vrt', '--exclude', '*csv', '--no-progress', '--recursive'] + + log_subprocess_output_full(cmd) + + # Downloads non-data-lake inputs else: print_log(f'Tiles with pattern {pattern} are not on spot machine. Downloading...')