natcap.invest.coastal_blue_carbon package

Submodules

natcap.invest.coastal_blue_carbon.coastal_blue_carbon module

Coastal Blue Carbon Model.

natcap.invest.coastal_blue_carbon.coastal_blue_carbon.execute(args)

Coastal Blue Carbon.

Parameters:
  • workspace_dir (str) – location into which all intermediate and output files should be placed.
  • results_suffix (str) – a string to append to output filenames.
  • lulc_lookup_uri (str) – filepath to a CSV table used to convert the lulc code to a name. Also used to determine if a given lulc type is a coastal blue carbon habitat.
  • lulc_transition_matrix_uri (str) – generated by the preprocessor. This file must be edited before it can be used by the main model. The left-most column represents the source lulc class, and the top row represents the destination lulc class.
  • carbon_pool_initial_uri (str) – the provided CSV table contains information related to the initial conditions of the carbon stock within each of the three pools of a habitat. Biomass includes carbon stored above and below ground. All non-coastal blue carbon habitat lulc classes are assumed to contain no carbon. The values for ‘biomass’, ‘soil’, and ‘litter’ should be given in terms of Megatonnes CO2 e/ ha.
  • carbon_pool_transient_uri (str) – the provided CSV table contains information related to the transition of carbon into and out of coastal blue carbon pools. All non-coastal blue carbon habitat lulc classes are assumed to neither sequester nor emit carbon as a result of change. The ‘yearly_accumulation’ values should be given in terms of Megatonnes of CO2 e/ha-yr. The ‘half-life’ values must be given in terms of years. The ‘disturbance’ values must be given as a decimal (e.g. 0.5 for 50%) of stock distrubed given a transition occurs away from a lulc-class.
  • lulc_baseline_map_uri (str) – a GDAL-supported raster representing the baseline landscape/seascape.
  • lulc_baseline_year (int) – The year of the baseline snapshot.
  • lulc_transition_maps_list (list) – a list of GDAL-supported rasters representing the landscape/seascape at particular points in time. Provided in chronological order.
  • lulc_transition_years_list (list) – a list of years that respectively correspond to transition years of the rasters. Provided in chronological order.
  • analysis_year (int) – optional. Indicates how many timesteps to run the transient analysis beyond the last transition year. Must come chronologically after the last transition year if provided. Otherwise, the final timestep of the model will be set to the last transition year.
  • do_economic_analysis (bool) – boolean value indicating whether model should run economic analysis.
  • do_price_table (bool) – boolean value indicating whether a price table is included in the arguments and to be used or a price and interest rate is provided and to be used instead.
  • price (float) – the price per Megatonne CO2 e at the base year.
  • inflation_rate (float) – the interest rate on the price per Megatonne CO2e, compounded yearly. Provided as a percentage (e.g. 3.0 for 3%).
  • price_table_uri (bool) – if args[‘do_price_table’] is set to True the provided CSV table is used in place of the initial price and interest rate inputs. The table contains the price per Megatonne CO2e sequestered for a given year, for all years from the original snapshot to the analysis year, if provided.
  • discount_rate (float) – the discount rate on future valuations of sequestered carbon, compounded yearly. Provided as a percentage (e.g. 3.0 for 3%).

Example Args:

args = {
    'workspace_dir': 'path/to/workspace/',
    'results_suffix': '',
    'lulc_lookup_uri': 'path/to/lulc_lookup_uri',
    'lulc_transition_matrix_uri': 'path/to/lulc_transition_uri',
    'carbon_pool_initial_uri': 'path/to/carbon_pool_initial_uri',
    'carbon_pool_transient_uri': 'path/to/carbon_pool_transient_uri',
    'lulc_baseline_map_uri': 'path/to/baseline_map.tif',
    'lulc_baseline_year': <int>,
    'lulc_transition_maps_list': [raster1_uri, raster2_uri, ...],
    'lulc_transition_years_list': [2000, 2005, ...],
    'analysis_year': 2100,
    'do_economic_analysis': '<boolean>',
    'do_price_table': '<boolean>',
    'price': '<float>',
    'inflation_rate': '<float>',
    'price_table_uri': 'path/to/price_table',
    'discount_rate': '<float>'
}
natcap.invest.coastal_blue_carbon.coastal_blue_carbon.get_inputs(args)

Get Inputs.

Parameters:
  • workspace_dir (str) – workspace directory
  • results_suffix (str) – optional suffix appended to results
  • lulc_lookup_uri (str) – lulc lookup table filepath
  • lulc_transition_matrix_uri (str) – lulc transition table filepath
  • carbon_pool_initial_uri (str) – initial conditions table filepath
  • carbon_pool_transient_uri (str) – transient conditions table filepath
  • lulc_baseline_map_uri (str) – baseline map filepath
  • lulc_transition_maps_list (list) – ordered list of transition map filepaths
  • lulc_transition_years_list (list) – ordered list of transition years
  • analysis_year (int) – optional final year to extend the analysis beyond the last transition year
  • do_economic_analysis (bool) – whether to run economic component of the analysis
  • do_price_table (bool) – whether to use the price table for the economic component of the analysis
  • price (float) – the price of net sequestered carbon
  • inflation_rate (float) – the interest rate on the price of carbon
  • price_table_uri (str) – price table filepath
  • discount_rate (float) – the discount rate on future valuations of carbon
Returns:

data dictionary.

Return type:

d (dict)

Example Returns:
d = {
‘do_economic_analysis’: <bool>, ‘lulc_to_Sb’: <dict>, ‘lulc_to_Ss’: <dict> ‘lulc_to_L’: <dict>, ‘lulc_to_Yb’: <dict>, ‘lulc_to_Ys’: <dict>, ‘lulc_to_Hb’: <dict>, ‘lulc_to_Hs’: <dict>, ‘lulc_trans_to_Db’: <dict>, ‘lulc_trans_to_Ds’: <dict>, ‘C_r_rasters’: <list>, ‘transition_years’: <list>, ‘snapshot_years’: <list>, ‘timesteps’: <int>, ‘transitions’: <list>, ‘price_t’: <list>, ‘File_Registry’: <dict>

}

natcap.invest.coastal_blue_carbon.coastal_blue_carbon.get_num_blocks(raster_uri)

Get the number of blocks in a raster file.

Parameters:raster_uri (str) – filepath to raster
Returns:number of blocks in raster
Return type:num_blocks (int)
natcap.invest.coastal_blue_carbon.coastal_blue_carbon.is_transition_year(snapshot_years, transitions, timestep)

Check whether given timestep is a transition year.

Parameters:
  • snapshot_years (list) – list of snapshot years.
  • transitions (int) – number of transitions.
  • timestep (int) – current timestep.
Returns:

whether the year corresponding to the

timestep is a transition year.

Return type:

is_transition_year (bool)

natcap.invest.coastal_blue_carbon.coastal_blue_carbon.read_from_raster(input_raster, offset_block)

Read numpy array from raster block.

Parameters:
  • input_raster (str) – filepath to input raster
  • offset_block (dict) – dictionary of offset information
Returns:

a blocked array of the input raster

Return type:

array (numpy.array)

natcap.invest.coastal_blue_carbon.coastal_blue_carbon.reclass(array, d, out_dtype=None, nodata_mask=None)

Reclassify values in array.

If a nodata value is not provided, the function will return an array with NaN values in its place to mark cells that could not be reclassed.​

Parameters:
  • array (numpy.array) – input data
  • d (dict) – reclassification map
  • out_dtype (numpy.dtype) – a numpy datatype for the reclass_array
  • nodata_mask (number) – for floats, a nodata value that is set to numpy.nan if provided to make reclass_array nodata values consistent
Returns:

reclassified array

Return type:

reclass_array (numpy.array)

natcap.invest.coastal_blue_carbon.coastal_blue_carbon.reclass_transition(a_prev, a_next, trans_dict, out_dtype=None, nodata_mask=None)

Reclass arrays based on element-wise combinations between two arrays.

Parameters:
  • a_prev (numpy.array) – previous lulc array
  • a_next (numpy.array) – next lulc array
  • trans_dict (dict) – reclassification map
  • out_dtype (numpy.dtype) – a numpy datatype for the reclass_array
  • nodata_mask (number) – for floats, a nodata value that is set to numpy.nan if provided to make reclass_array nodata values consistent
Returns:

reclassified array

Return type:

reclass_array (numpy.array)

natcap.invest.coastal_blue_carbon.coastal_blue_carbon.s_to_timestep(snapshot_years, snapshot_idx)

Convert snapshot index position to timestep.

Parameters:
  • snapshot_years (list) – list of snapshot years.
  • snapshot_idx (int) – index of snapshot
Returns:

timestep of the snapshot

Return type:

snapshot_timestep (int)

natcap.invest.coastal_blue_carbon.coastal_blue_carbon.timestep_to_transition_idx(snapshot_years, transitions, timestep)

Convert timestep to transition index.

Parameters:
  • snapshot_years (list) – a list of years corresponding to the provided rasters
  • transitions (int) – the number of transitions in the scenario
  • timestep (int) – the current timestep
Returns:

the current transition

Return type:

transition_idx (int)

natcap.invest.coastal_blue_carbon.coastal_blue_carbon.write_to_raster(output_raster, array, xoff, yoff)

Write numpy array to raster block.

Parameters:
  • output_raster (str) – filepath to output raster
  • array (numpy.array) – block to save to raster
  • xoff (int) – offset index for x-dimension
  • yoff (int) – offset index for y-dimension

natcap.invest.coastal_blue_carbon.preprocessor module

Coastal Blue Carbon Preprocessor.

natcap.invest.coastal_blue_carbon.preprocessor.execute(args)

Coastal Blue Carbon Preprocessor.

The preprocessor accepts a list of rasters and checks for cell-transitions across the rasters. The preprocessor outputs a CSV file representing a matrix of land cover transitions, each cell prefilled with a string indicating whether carbon accumulates or is disturbed as a result of the transition, if a transition occurs.

Parameters:
  • workspace_dir (string) – directory path to workspace
  • results_suffix (string) – append to outputs directory name if provided
  • lulc_lookup_uri (string) – filepath of lulc lookup table
  • lulc_snapshot_list (list) – a list of filepaths to lulc rasters

Example Args:

args = {
    'workspace_dir': 'path/to/workspace_dir/',
    'results_suffix': '',
    'lulc_lookup_uri': 'path/to/lookup.csv',
    'lulc_snapshot_list': ['path/to/raster1', 'path/to/raster2', ...]
}
natcap.invest.coastal_blue_carbon.preprocessor.read_from_raster(input_raster, offset_block)

Read block from raster.

Parameters:
  • input_raster (str) – filepath to raster.
  • offset_block (dict) – where the block is indexed.
Returns:

the raster block.

Return type:

a (np.array)

Module contents

Coastal Blue Carbon package.