<commit_before>### This script calculates the cumulative above and belowground carbon dioxide gain in mangrove forest pixels from 2001-2015.
### It multiplies the annual biomass gain rate by the number of years of gain by the biomass-to-carbon conversion and
### by to the C to CO2 conversion.

import datetime
import subprocess
import sys
sys.path.append('../')
import constants_and_names as cn
import universal_util as uu

# Calculates cumulative aboveground carbon dioxide gain in mangroves
def cumulative_gain_AGCO2(tile_id, pattern, sensit_type):

    print "Calculating cumulative aboveground CO2 gain:", tile_id

    # Start time
    start = datetime.datetime.now()

    gain_rate_AGB = '{0}_{1}_{2}.tif'.format(tile_id, cn.pattern_annual_gain_AGB_mangrove, sensit_type)
    gain_year_count = '{0}_{1}_{2}.tif'.format(tile_id, cn.pattern_gain_year_count_mangrove, sensit_type)

    gain_rate_AGB = uu.sensit_rename(sensit_type, tile_id, cn.pattern_annual_gain_AGB_mangrove, 'false')
    gain_year_count = uu.sensit_rename(sensit_type, tile_id, cn.pattern_gain_year_count_mangrove, 'false')

    # Creates input file names differently depending on whether it's a sensitivity analysis run or not
    # Names of the annual gain rate and gain year count tiles
    if sensit_type != 'std':
        gain_rate_AGB = '{0}_{1}_{2}.tif'.format(tile_id, cn.pattern_annual_gain_AGB_mangrove, sensit_type)
        gain_year_count = '{0}_{1}_{2}.tif'.format(tile_id, cn.pattern_gain_year_count_mangrove, sensit_type)
    else:
        gain_rate_AGB = '{0}_{1}.tif'.format(tile_id, cn.pattern_annual_gain_AGB_mangrove)
        gain_year_count = '{0}_{1}.tif'.format(tile_id, cn.pattern_gain_year_count_mangrove)

    # Carbon gain uses special mangrove biomass:carbon ratio
    accum_calc = '--calc=A*B*{0}*{1}'.format(cn.biomass_to_c_mangrove, cn.c_to_co2)
    AGCO2_accum_outfilename = '{0}_{1}.tif'.format(tile_id, pattern)
    AGCO2_accum_outfilearg = '--outfile={}'.format(AGCO2_accum_outfilename)
    cmd = ['gdal_calc.py', '-A', gain_rate_AGB, '-B', gain_year_count, accum_calc, AGCO2_accum_outfilearg, '--NoDataValue=0', '--overwrite', '--co', 'COMPRESS=LZW']
    subprocess.check_call(cmd)

    # Prints information about the tile that was just processed
    uu.end_of_fx_summary(start, tile_id, pattern)


# Calculates cumulative belowground carbon dioxide gain in mangroves
def cumulative_gain_BGCO2(tile_id, pattern, sensit_type):

    print "Calculating cumulative belowground CO2 gain:", tile_id

    # Start time
    start = datetime.datetime.now()

    # Creates input file names differently depending on whether it's a sensitivity analysis run or not
    # Names of the annual gain rate and gain year count tiles
    if sensit_type != 'std':
        gain_rate_BGB = '{0}_{1}_{2}.tif'.format(tile_id, cn.pattern_annual_gain_BGB_mangrove, sensit_type)
        gain_year_count = '{0}_{1}_{2}.tif'.format(tile_id, cn.pattern_gain_year_count_mangrove, sensit_type)
    else:
        gain_rate_BGB = '{0}_{1}.tif'.format(tile_id, cn.pattern_annual_gain_BGB_mangrove)
        gain_year_count = '{0}_{1}.tif'.format(tile_id, cn.pattern_gain_year_count_mangrove)

    # Carbon gain uses special mangrove biomass:carbon ratio
    accum_calc = '--calc=A*B*{0}*{1}'.format(cn.biomass_to_c_mangrove, cn.c_to_co2)<commit_msg>Testing the cumulative gain script for mangroves for the maxgain sensitivity analysis.<commit_after>### This script calculates the cumulative above and belowground carbon dioxide gain in mangrove forest pixels from 2001-2015.
### It multiplies the annual biomass gain rate by the number of years of gain by the biomass-to-carbon conversion and
### by to the C to CO2 conversion.

import datetime
import subprocess
import sys
sys.path.append('../')
import constants_and_names as cn
import universal_util as uu

# Calculates cumulative aboveground carbon dioxide gain in mangroves
def cumulative_gain_AGCO2(tile_id, pattern, sensit_type):

    print "Calculating cumulative aboveground CO2 gain:", tile_id

    # Start time
    start = datetime.datetime.now()

    # gain_rate_AGB = '{0}_{1}_{2}.tif'.format(tile_id, cn.pattern_annual_gain_AGB_mangrove, sensit_type)
    # gain_year_count = '{0}_{1}_{2}.tif'.format(tile_id, cn.pattern_gain_year_count_mangrove, sensit_type)

    gain_rate_AGB = uu.sensit_rename(sensit_type, tile_id, cn.pattern_annual_gain_AGB_mangrove, 'false')
    gain_year_count = uu.sensit_rename(sensit_type, tile_id, cn.pattern_gain_year_count_mangrove, 'false')

    # # Creates input file names differently depending on whether it's a sensitivity analysis run or not
    # # Names of the annual gain rate and gain year count tiles
    # if sensit_type != 'std':
    #     gain_rate_AGB = '{0}_{1}_{2}.tif'.format(tile_id, cn.pattern_annual_gain_AGB_mangrove, sensit_type)
    #     gain_year_count = '{0}_{1}_{2}.tif'.format(tile_id, cn.pattern_gain_year_count_mangrove, sensit_type)
    # else:
    #     gain_rate_AGB = '{0}_{1}.tif'.format(tile_id, cn.pattern_annual_gain_AGB_mangrove)
    #     gain_year_count = '{0}_{1}.tif'.format(tile_id, cn.pattern_gain_year_count_mangrove)

    # Carbon gain uses special mangrove biomass:carbon ratio
    accum_calc = '--calc=A*B*{0}*{1}'.format(cn.biomass_to_c_mangrove, cn.c_to_co2)
    AGCO2_accum_outfilename = '{0}_{1}.tif'.format(tile_id, pattern)
    AGCO2_accum_outfilearg = '--outfile={}'.format(AGCO2_accum_outfilename)
    cmd = ['gdal_calc.py', '-A', gain_rate_AGB, '-B', gain_year_count, accum_calc, AGCO2_accum_outfilearg, '--NoDataValue=0', '--overwrite', '--co', 'COMPRESS=LZW']
    subprocess.check_call(cmd)

    # Prints information about the tile that was just processed
    uu.end_of_fx_summary(start, tile_id, pattern)


# Calculates cumulative belowground carbon dioxide gain in mangroves
def cumulative_gain_BGCO2(tile_id, pattern, sensit_type):

    print "Calculating cumulative belowground CO2 gain:", tile_id

    # Start time
    start = datetime.datetime.now()

    # Creates input file names differently depending on whether it's a sensitivity analysis run or not
    # Names of the annual gain rate and gain year count tiles
    if sensit_type != 'std':
        gain_rate_BGB = '{0}_{1}_{2}.tif'.format(tile_id, cn.pattern_annual_gain_BGB_mangrove, sensit_type)
        gain_year_count = '{0}_{1}_{2}.tif'.format(tile_id, cn.pattern_gain_year_count_mangrove, sensit_type)
    else:
        gain_rate_BGB = '{0}_{1}.tif'.format(tile_id, cn.pattern_annual_gain_BGB_mangrove)
        gain_year_count = '{0}_{1}.tif'.format(tile_id, cn.pattern_gain_year_count_mangrove)

    # Carbon gain uses special mangrove biomass:carbon ratio
    accum_calc = '--calc=A*B*{0}*{1}'.format(cn.biomass_to_c_mangrove, cn.c_to_co2)
{'fraction_non_alphanumeric': 0.10738155354225457, 'fraction_numerical': 0.015446309223228873, 'mean_word_length': 4.901840490797546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1342244', 'n_tokens_mistral': 2479, 'n_tokens_neox': 2271, 'n_words': 532}