climada.entity.disc_rates package#

climada.entity.disc_rates.base module#

class climada.entity.disc_rates.base.DiscRates(years: ndarray | None = None, rates: ndarray | None = None)[source]#

Bases: object

Defines discount rates and basic methods. Loads from files with format defined in FILE_EXT.

years#

list of years

Type:

np.array

rates#

list of discount rates for each year (between 0 and 1)

Type:

np.array

__init__(years: ndarray | None = None, rates: ndarray | None = None)[source]#

Fill discount rates with values and check consistency data

Parameters:
  • years (numpy.ndarray(int)) – Array of years. Default is numpy.array([]).

  • rates (numpy.ndarray(float)) – Discount rates for each year in years. Default is numpy.array([]). Note: rates given in float, e.g., to set 1% rate use 0.01

clear()[source]#

Reinitialize attributes.

check()[source]#

Check attributes consistency.

Raises:

ValueError

select(year_range)[source]#

Select discount rates in given years.

Parameters:
  • year_range (np.array(int)) – continuous sequence of selected years.

  • Returns (climada.entity.DiscRates) – The selected discrates in the year_range

append(disc_rates)[source]#

Check and append discount rates to current DiscRates. Overwrite discount rate if same year.

Parameters:

disc_rates (climada.entity.DiscRates) – DiscRates instance to append

Raises:

ValueError

net_present_value(ini_year, end_year, val_years)[source]#

Compute net present value between present year and future year.

Parameters:
  • ini_year (float) – initial year

  • end_year (float) – end year

  • val_years (np.array) – cash flow at each year btw ini_year and end_year (both included)

Returns:

net_present_value – net present value between present year and future year.

Return type:

float

plot(axis=None, figsize=(6, 8), **kwargs)[source]#

Plot discount rates per year.

Parameters:
  • axis (matplotlib.axes._subplots.AxesSubplot, optional) – axis to use

  • figsize (tuple(int, int), optional) – size of the figure. The default is (6,8)

  • kwargs (optional) – keyword arguments passed to plotting function axis.plot

Returns:

axis – axis handles of the plot

Return type:

matplotlib.axes._subplots.AxesSubplot

classmethod from_mat(file_name, var_names=None)[source]#

Read MATLAB file generated with previous MATLAB CLIMADA version.

Parameters:
  • file_name (str) – filename including path and extension

  • description (str, optional) – description of the data. The default is ‘’

  • var_names (dict, optional) – name of the variables in the file. Default:

    >>> DEF_VAR_MAT = {
    ...     'sup_field_name': 'entity',
    ...     'field_name': 'discount',
    ...     'var_name': {
    ...         'year': 'year',
    ...         'disc': 'discount_rate',
    ...     }
    ... }
    
Returns:

The disc rates from matlab

Return type:

climada.entity.DiscRates

read_mat(*args, **kwargs)[source]#

This function is deprecated, use DiscRates.from_mat instead.

classmethod from_excel(file_name, var_names=None)[source]#

Read excel file following template and store variables.

Parameters:
  • file_name (str) – filename including path and extension

  • description (str, optional) – description of the data. The default is ‘’

  • var_names (dict, optional) – name of the variables in the file. The Default is

    >>> DEF_VAR_EXCEL = {
    ...     'sheet_name': 'discount',
    ...     'col_name': {
    ...         'year': 'year',
    ...         'disc': 'discount_rate',
    ...     }
    ... }
    
Returns:

The disc rates from excel

Return type:

climada.entity.DiscRates

read_excel(*args, **kwargs)[source]#

This function is deprecated, use DiscRates.from_excel instead.

write_excel(file_name, var_names=None)[source]#

Write excel file following template.

Parameters:
  • file_name (str) – filename including path and extension

  • var_names (dict, optional) – name of the variables in the file. The Default is

    >>> DEF_VAR_EXCEL = {
    ...     'sheet_name': 'discount',
    ...     'col_name': {
    ...         'year': 'year',
    ...         'disc': 'discount_rate',
    ...     }
    ... }
    
classmethod from_csv(file_name, year_column='year', disc_column='discount_rate', **kwargs)[source]#

Read DiscRate from a csv file following template and store variables.

Parameters:
  • file_name (str) – filename including path and extension

  • year_column (str, optional) – name of the column that contains the years, Default: “year”

  • disc_column (str, optional) – name of the column that contains the discount rates, Default: “discount_rate”

  • **kwargs – any additional arguments, e.g., sep, delimiter, head, are forwarded to pandas.read_csv

Returns:

The disc rates from the csv file

Return type:

climada.entity.DiscRates

write_csv(file_name, year_column='year', disc_column='discount_rate', **kwargs)[source]#

Write DiscRate to a csv file following template and store variables.

Parameters:
  • file_name (str) – filename including path and extension

  • year_column (str, optional) – name of the column that contains the years, Default: “year”

  • disc_column (str, optional) – name of the column that contains the discount rates, Default: “discount_rate”

  • **kwargs – any additional arguments, e.g., sep, delimiter, head, are forwarded to pandas.read_csv