Skip to content

Commit

Permalink
Commit:
Browse files Browse the repository at this point in the history
- In constants_and_names.py, updated version to 1.4.0, changed drivers to 1km drivers and deleted driver-specific emissions output
- In constants.h, changed drivers to 1km drivers and deleted driver-specific emissions output
- In flu_val.cpp, updated flu values for 1km drivers. Note: Currently using averages for "montane" climate zone, but in the future we will reclassify "montane" as "dry" or "moist/wet" and use those values instead of using averages.
- In calc_gross_emissions_generic.cpp and calc_gross_emissions_soil_only.cpp, updated decision tree for permanent agriculture, shifting cultivation, forest management, wildfire, and settlements & infrastructure. Updated non-co2, fire emissions equation for forest management and wildfire to include litter and deadwood.
TODO: Still need to update decision tree and node codes for  hard commodities, other natural disturbances, and no driver. Also need to update equation.cpp.
  • Loading branch information
melrose-wri committed Nov 15, 2024
1 parent e3d953b commit 2cdafa8
Show file tree
Hide file tree
Showing 8 changed files with 879 additions and 526 deletions.
44 changes: 12 additions & 32 deletions constants_and_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
######## ########

# Model version
version = '1.3.2'
version = '1.4.0'
version_filename = version.replace('.', '_')


Expand Down Expand Up @@ -333,16 +333,16 @@

# 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 = 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/')
#TODO: Delete after successfully running 1km, commenting out for now

# drivers_raw_dir = 's3://gfw2-data/drivers_of_loss/1_km/raw/20241004/'
# pattern_drivers_raw = 'drivers_of_TCL_1_km_20241004.tif'
# pattern_drivers = 'drivers_of_TCL_1_km_20241004'
# drivers_processed_dir = 's3://gfw2-data/drivers_of_loss/1_km/processed/20241004/'
#TODO: Change drivers from 10km to 1km after all code updates are made
drivers_raw_dir = 's3://gfw2-data/drivers_of_loss/1_km/raw/20241004/'
pattern_drivers_raw = 'drivers_of_TCL_1_km_20241004.tif'
pattern_drivers = 'drivers_of_TCL_1_km_20241004'
drivers_processed_dir = 's3://gfw2-data/drivers_of_loss/1_km/processed/20241004/'

# Tree cover loss from fires
TCLF_raw_dir = 's3://gfw2-data/forest_change/hansen_2023_fire/'
Expand Down Expand Up @@ -656,26 +656,6 @@
emis_run_date_biomass_soil = '20248888'
#TODO: Change date when running 1km drivers

# # 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}/'
#
# 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}/'
#TODO: Delete after testing, commenting out for now

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}/'

Expand All @@ -700,8 +680,8 @@
### Emissions from soil only

# Date to include in the output directory
emis_run_date_soil_only = '20240402'

emis_run_date_soil_only = '20248888'
#TODO: Change date when running 1km drivers

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}/'
Expand Down
586 changes: 396 additions & 190 deletions emissions/cpp_util/calc_gross_emissions_generic.cpp

Large diffs are not rendered by default.

554 changes: 378 additions & 176 deletions emissions/cpp_util/calc_gross_emissions_soil_only.cpp

Large diffs are not rendered by default.

14 changes: 2 additions & 12 deletions emissions/cpp_util/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,13 @@ namespace constants
constexpr char burnyear[] = "_tree_cover_loss_fire_processed.tif";
constexpr char fao_ecozones[] = "_fao_ecozones_bor_tem_tro_processed.tif";
constexpr char climate_zones[] = "_climate_zone_processed.tif";
constexpr char tcl_drivers[] = "_tree_cover_loss_driver_processed.tif";
//constexpr char tcl_drivers[] = "_drivers_of_TCL_1_km_20241004.tif"; //TODO: Change drivers from 10km to 1km after all code updates are made
//constexpr char tcl_drivers[] = "_tree_cover_loss_driver_processed.tif"; //TODO: Delete after successfully running 1km, commenting out for now
constexpr char tcl_drivers[] = "_drivers_of_TCL_1_km_20241004.tif";
constexpr char peat_mask[] = "_peat_mask_processed.tif";
constexpr char ifl_primary[] = "_ifl_2000_primary_2001_merged.tif";
constexpr char plantation_type[] = "_plantation_type_oilpalm_woodfiber_other.tif";

// Outputs
// constexpr char permanent_ag_emis[] = "_gross_emis_permanent_ag_Mg_CO2e_ha_biomass_soil_2001_";
// constexpr char hard_commod_emis[] = "_gross_emis_hard_commodities_Mg_CO2e_ha_biomass_soil_2001_";
// constexpr char shifting_cultivation_emis[] = "_gross_emis_shifting_cultivation_Mg_CO2e_ha_biomass_soil_2001_";
// constexpr char forest_management_emis[] = "_gross_emis_forest_management_Mg_CO2e_ha_biomass_soil_2001_";
// constexpr char wildfire_emis[] = "_gross_emis_wildfire_Mg_CO2e_ha_biomass_soil_2001_";
// constexpr char settlements_emis[] = "_gross_emis_settlements_Mg_CO2e_ha_biomass_soil_2001_";
// constexpr char other_disturbance_emis[] = "_gross_emis_other_disturbance_Mg_CO2e_ha_biomass_soil_2001_";
// constexpr char no_driver_emis[] = "_gross_emis_no_driver_Mg_CO2e_ha_biomass_soil_2001_";
//TODO: Delete after testing, commenting out for now

constexpr char all_gases_all_drivers_emis[] = "_gross_emis_all_gases_all_drivers_Mg_CO2e_ha_biomass_soil_2001_";
constexpr char CO2_only_all_drivers_emis[] = "_gross_emis_CO2_only_all_drivers_Mg_CO2e_ha_biomass_soil_2001_";
constexpr char non_CO2_all_drivers_emis[] = "_gross_emis_non_CO2_all_drivers_Mg_CO2e_ha_biomass_soil_2001_";
Expand Down
6 changes: 3 additions & 3 deletions emissions/cpp_util/equations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ void def_variables(float *q, int ecozone, int forestmodel_data, int ifl, int cli
// 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.
// 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.
float Cf;
float CO2;
float CH4;
Expand Down
22 changes: 11 additions & 11 deletions emissions/cpp_util/flu_val.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ float flu_val(int climate_zone, int eco_zone)
{
if (eco_zone == 1) // Dry, tropics
{
flu_value = 0.58;
//flu_value = 0.92; //TODO:Update with new Flu after testing
//flu_value = 0.58; //TODO: Delete after successfully running 1km, commenting out for now
flu_value = 0.92;
}
else if ((eco_zone == 2) || (eco_zone == 3)) // Dry, boreal/temperate
{
flu_value = 0.8;
//flu_value = 0.77; //TODO:Update with new Flu after testing
//flu_value = 0.8; //TODO: Delete after successfully running 1km, commenting out for now
flu_value = 0.77;
}
else
{
Expand All @@ -27,28 +27,28 @@ float flu_val(int climate_zone, int eco_zone)
{
if (eco_zone == 1) // Wet, tropics
{
flu_value = 0.48;
//flu_value = 0.83; //TODO:Update with new Flu after testing
//flu_value = 0.48; //TODO: Delete after successfully running 1km, commenting out for now
flu_value = 0.83;
}
else if ((eco_zone == 2) || (eco_zone == 3)) // Wet, boreal/temperate
{
flu_value = 0.69;
//flu_value = 0.70; //TODO:Update with new Flu after testing
//flu_value = 0.69; //TODO: Delete after successfully running 1km, commenting out for now
flu_value = 0.70;
}
else
{
flu_value = 0;
}
}
else if (climate_zone == 9) // Montane #TODO: What do we do for montane climate domain?
else if (climate_zone == 9) // Montane
{
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
{
Expand Down
44 changes: 9 additions & 35 deletions emissions/mp_calculate_gross_emissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ 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; #TODO
non-CO2 emissions from all drivers; all gases (CO2 and non-CO2 from all drivers);
emissions decision tree nodes (used for QC).
:return: 4 sets of tiles: #TODO: Update after splitting non-co2 emissions
1. all gases (CO2 and non-CO2 from all drivers);
2. CO2 emissions from all drivers;
3. non-CO2 emissions from all drivers;
4. emissions decision tree nodes (used for QC).
Units: Mg CO2e/ha over entire model period.
"""

Expand Down Expand Up @@ -97,27 +99,13 @@ 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,
#TODO: Delete after testing, commenting out for now
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_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,
# TODO: Delete after testing, commenting out for now
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_nodes_biomass_soil]
Expand All @@ -131,26 +119,12 @@ def mp_calculate_gross_emissions(tile_id_list, emitted_pools):
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,
# TODO: Delete after testing, commenting out for now
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_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,
# TODO: Delete after testing, commenting out for now
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_nodes_soil_only]
Expand Down
Loading

1 comment on commit 2cdafa8

@dagibbs22
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Please sign in to comment.