<commit_before>// 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++ ./cpp_util/calc_gross_emissions_biomass_soil.cpp -o ./cpp_util/calc_gross_emissions_biomass_soil.exe -lgdal


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <sys/stat.h>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <stdint.h>
#include <sstream>
#include <iomanip>

#include <gdal/gdal_priv.h>
#include <gdal/cpl_conv.h>
#include <gdal/ogr_spatialref.h>

// These provide constants for the emissions equations
#include "flu_val.cpp"
#include "equations.cpp"

using namespace std;

//to compile:  c++ calc_gross_emissions.cpp -o calc_gross_emissions.exe -lgdal
// to compile on MINGW:  g++ calc_emissions_v3.cpp -o calc_emissions_v3.exe -I /usr/local/include -L /usr/local/lib -lgdal
int main(int argc, char* argv[])
{
// If code is run other than <program name> <tile id> , it will raise this error.
if (argc != 2){cout << "Use <program name> <tile id>" << endl; return 1;}

// Input arguments
string agb_name=argv[1];
string tile_id = argv[1]; // The tile id comes from the second argument. The first argument is the name of this code.

string infolder = "cpp_util/";

// Model constants
int CH4_equiv;      // The CO2 equivalency (global warming potential) of CH4
CH4_equiv = 28;

int N2O_equiv;      // The CO2 equivalency (global warming potential) of N2O
N2O_equiv = 265;

float C_to_CO2;       // The conversion of carbon to CO2
C_to_CO2 = 44.0/12.0;

int model_years;    // How many loss years are in the model
model_years = 15;

int tropical;       // The ecozone code for the tropics
tropical = 1;

int temperate;      // The ecozone code for the temperate zone
temperate = 3;

int boreal;         // The ecozone code for the boreal zone
boreal = 2;

// Input files
// Carbon pools
string agc_name = infolder + tile_id + "_t_AGC_ha_emis_year.tif";
string bgc_name = infolder + tile_id + "_t_BGC_ha_emis_year.tif";
string dead_name = infolder + tile_id + "_t_deadwood_C_ha_emis_year_2000.tif";
string litter_name = infolder + tile_id + "_t_litter_C_ha_emis_year_2000.tif";
string soil_name = infolder + tile_id + "_t_soil_C_ha_emis_year_2000.tif";
<commit_msg>Creating gross emissions tiles based on JPL biomass for biomass_swap sensitivity analysis.<commit_after>// 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++ ./cpp_util/calc_gross_emissions_biomass_soil.cpp -o ./cpp_util/calc_gross_emissions_biomass_soil.exe -lgdal


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <sys/stat.h>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <stdint.h>
#include <sstream>
#include <iomanip>

#include <gdal/gdal_priv.h>
#include <gdal/cpl_conv.h>
#include <gdal/ogr_spatialref.h>

// These provide constants for the emissions equations
#include "flu_val.cpp"
#include "equations.cpp"

using namespace std;

//to compile:  c++ calc_gross_emissions.cpp -o calc_gross_emissions.exe -lgdal
// to compile on MINGW:  g++ calc_emissions_v3.cpp -o calc_emissions_v3.exe -I /usr/local/include -L /usr/local/lib -lgdal
int main(int argc, char* argv[])
{
// If code is run other than <program name> <tile id> , it will raise this error.
if (argc != 2){cout << "Use <program name> <tile id>" << endl; return 1;}

// Input arguments
string agb_name=argv[1];
string tile_id = argv[1]; // The tile id comes from the second argument. The first argument is the name of this code.

string infolder = "cpp_util/";

// Model constants
int CH4_equiv;      // The CO2 equivalency (global warming potential) of CH4
CH4_equiv = 28;

int N2O_equiv;      // The CO2 equivalency (global warming potential) of N2O
N2O_equiv = 265;

float C_to_CO2;       // The conversion of carbon to CO2
C_to_CO2 = 44.0/12.0;

int model_years;    // How many loss years are in the model
model_years = 15;

int tropical;       // The ecozone code for the tropics
tropical = 1;

int temperate;      // The ecozone code for the temperate zone
temperate = 3;

int boreal;         // The ecozone code for the boreal zone
boreal = 2;

// Input files
// Carbon pools
string agc_name = infolder + tile_id + "_t_AGC_ha_emis_year_biomass_swap.tif";
string bgc_name = infolder + tile_id + "_t_BGC_ha_emis_year_biomass_swap.tif";
string dead_name = infolder + tile_id + "_t_deadwood_C_ha_emis_year_2000_biomass_swap.tif";
string litter_name = infolder + tile_id + "_t_litter_C_ha_emis_year_2000_biomass_swap.tif";
string soil_name = infolder + tile_id + "_t_soil_C_ha_emis_year_2000_biomass_swap.tif";

{'fraction_non_alphanumeric': 0.08920882669537136, 'fraction_numerical': 0.013993541442411194, 'mean_word_length': 4.018906144496961, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1458916', 'n_tokens_mistral': 2466, 'n_tokens_neox': 2305, 'n_words': 955}