impax package

Submodules

impax.cli module

Console script for impax.

impax.estimate module

class impax.estimate.MultivariateNormalEstimator(coefficients, vcv, index)[source]

Bases: object

Stores a median and residual VCV matrix for multidimensional variables with named indices and provides multivariate sampling and statistical analysis functions

Parameters:
  • coefficients (array) – length \((m_1*m_2*\cdots*m_n)\) 1-d numpy.ndarray with regression coefficients
  • vcv (array) – \((m_1*m_2*\cdots*m_n) x (m_1*m_2*\cdots*m_n)\) numpy.ndarray with variance-covariance matrix for multivariate distribution
  • index (Index) – Index or \((m_1*m_2*\cdots*m_n)\) 1-d MultiIndex describing the multivariate space
median()[source]

Returns the median values (regression coefficients)

Returns:medianDataArray of coefficients
Return type:DataArray
sample(seed=None)[source]

Sample from the multivariate normal distribution

Takes a draw from a multivariate distribution and returns an xarray.DataArray of parameter estimates.

Returns:drawDataArray of parameter estimates drawn from the multivariate normal
Return type:DataArray
impax.estimate.get_gammas(*args, **kwargs)[source]
impax.estimate.read_csvv(csvv_path)[source]

Returns the estimator object from a CSVV file

Parameters:path (str_or_buffer) – path to csvv file
Returns:estimatorGamma object with median and VCV matrix indexed by prednames, covarnames, and outcomes
Return type:MultivariateNormalEstimator

impax.impax module

class impax.impax.Impact[source]

Bases: object

Base class for computing an impact as specified by the Climate Impact Lab

compute(weather, betas, clip_flat_curve=True, t_star=None)[source]

Computes an impact for a unique set of gdp, climate, weather and gamma coefficient inputs. For each set of these, we take the analytic minimum value between two points, save t_star to disk and compute analytical min for function m_star for a given covariate set.

This operation is called for every adaptation scenario specified in the run script.

Parameters:
  • weather (DataArray) – weather DataArray
  • betas (DataArray) – covarname by outcome DataArray
  • clip_flat_curve (bool) – flag indicating that flat-curve clipping should be performed on the result
  • t_star (DataArray) – xarray.DataArray with minimum temperatures used for clipping
Returns:

Return type:

py:class ~xarray.Dataset of impacts by hierid by outcome group

compute_t_star(betas, bounds=None)[source]
get_t_star(betas, bounds, t_star_path=None)[source]

Read precomputed t_star

Parameters:
  • betas (DataArray) – DataArray of betas as prednames by hierid
  • bounds (list) – values between which to evaluate function
  • path (str) – place to load t-star from
impact_function(betas, weather)[source]

computes the dot product of betas and annual weather by outcome group

Parameters:
  • betas (DataArray) – DataArray of hierid by predname by outcome
  • weather (DataArray) – DataArray of hierid by predname by outcome
Returns:

  • DataArrayDataArray of impact by outcome by hierid
  • .. note:: – overrides impact_function method in Impact base class

min_function

alias of exceptions.NotImplementedError

postprocess_annual(impact)[source]
postprocess_daily(impact)[source]
class impax.impax.PolynomialImpact[source]

Bases: impax.impax.Impact

Polynomial-specific Impact spec, with ln(gdppc) and climtas for covariates

static min_function(**kwargs)[source]

helper function to call minimization function for given mortality polynomial spec mortality_polynomial implements findpolymin through np.apply_along_axis

Parameters:
  • betas (DataArray) – DataArray of hierid by predname by outcome
  • dim (str) – dimension to apply minimization to
  • bounds (list) – values between which to search for t_star
Returns:

Return type:

DataArray of hierid by predname by outcome

Note

overides min_function in Impact base class

impax.impax.construct_covars(add_constant=True, **covars)[source]

Helper function to construct the covariates dataarray

Parameters:
  • add_constant (bool) – flag indicating whether a constant term should be added. The constant term will have the same shape as the other covariate DataArrays
  • covars (dict) – dictionary of covariate name, covariate (str path or xarray.DataArray) pairs
Returns:

combined – Combined DataArray of covariate variables, with variables concatenated along the new covarnames dimension

Return type:

DataArray

impax.impax.construct_weather(**weather)[source]

Helper function to build out weather dataarray

Parameters:weather (dict) – dictionary of prednames and weather (either str file paths or xarray.DataArray objects) for each predname
Returns:combined – Combined DataArray of weather variables, with variables concatenated along the new prednames dimension
Return type:DataArray

impax.mins module

impax.mins.minimize_polynomial(da, dim='prednames', bounds=(-inf, inf))[source]

Finds the minimizing values of polynomials given an array of coefficients

Note

The coefficients along the dimension dim must be in _ascending_ power order and must not contain the zeroth-order term.

Parameters:
  • da (DataArray) – DataArray of coefficients of a (da.size[dim])-order polynomial in ascending power order along the dimension dim. The coefficients must not contain the zeroth-order term.
  • dim (str, optional) – dimension along which to evaluate the coefficients (default prednames)
  • bounds (list, optional) – domain on the polynomial within which to search for the minimum value, default (-inf, inf)
Returns:

DataArray in the same shape as da, with the minimizing value of the polynomial raised to the appropriate power in place of each coefficient

Return type:

DataArray

Examples

Create an array with two functions:

..math:

egin{array}{rcl}
    f_1 & = & x^2 \
    f_2 & = & -x^2 + 2x
\end{array}

This is specified as a 2-dimensional xarray.DataArray:

>>> da = xr.DataArray(
...     [[0, 1],   # x^2
...      [2, -1]], # -x^2 + 2x
...     dims=('spec', 'x'),
...     coords={'spec': ['f1', 'f2'], 'x': ['x1', 'x2']})
...

These functions can be minimized using impax.mins.minimize_polynomial():

>>> minimize_polynomial(
...     da, dim='x') 
...
<xarray.DataArray (spec: 2, x: 2)>
array([[  0.,   0.],
       [-inf,  inf]])
Coordinates:
  * x        (x) ... 'x1' 'x2'
  * spec     (spec) ... 'f1' 'f2'

Use the same function, but impose the domain limit \([2, 4]\):

>>> minimize_polynomial(
...     da, dim='x', bounds=[2, 4])
...     
<xarray.DataArray (spec: 2, x: 2)>
array([[  2.,   4.],
       [  4.,  16.]])
Coordinates:
  * x        (x) ... 'x1' 'x2'
  * spec     (spec) ... 'f1' 'f2'

Module contents

impax.minimize_polynomial(da, dim='prednames', bounds=(-inf, inf))[source]

Finds the minimizing values of polynomials given an array of coefficients

Note

The coefficients along the dimension dim must be in _ascending_ power order and must not contain the zeroth-order term.

Parameters:
  • da (DataArray) – DataArray of coefficients of a (da.size[dim])-order polynomial in ascending power order along the dimension dim. The coefficients must not contain the zeroth-order term.
  • dim (str, optional) – dimension along which to evaluate the coefficients (default prednames)
  • bounds (list, optional) – domain on the polynomial within which to search for the minimum value, default (-inf, inf)
Returns:

DataArray in the same shape as da, with the minimizing value of the polynomial raised to the appropriate power in place of each coefficient

Return type:

DataArray

Examples

Create an array with two functions:

..math:

egin{array}{rcl}
    f_1 & = & x^2 \
    f_2 & = & -x^2 + 2x
\end{array}

This is specified as a 2-dimensional xarray.DataArray:

>>> da = xr.DataArray(
...     [[0, 1],   # x^2
...      [2, -1]], # -x^2 + 2x
...     dims=('spec', 'x'),
...     coords={'spec': ['f1', 'f2'], 'x': ['x1', 'x2']})
...

These functions can be minimized using impax.mins.minimize_polynomial():

>>> minimize_polynomial(
...     da, dim='x') 
...
<xarray.DataArray (spec: 2, x: 2)>
array([[  0.,   0.],
       [-inf,  inf]])
Coordinates:
  * x        (x) ... 'x1' 'x2'
  * spec     (spec) ... 'f1' 'f2'

Use the same function, but impose the domain limit \([2, 4]\):

>>> minimize_polynomial(
...     da, dim='x', bounds=[2, 4])
...     
<xarray.DataArray (spec: 2, x: 2)>
array([[  2.,   4.],
       [  4.,  16.]])
Coordinates:
  * x        (x) ... 'x1' 'x2'
  * spec     (spec) ... 'f1' 'f2'
impax.construct_covars(add_constant=True, **covars)[source]

Helper function to construct the covariates dataarray

Parameters:
  • add_constant (bool) – flag indicating whether a constant term should be added. The constant term will have the same shape as the other covariate DataArrays
  • covars (dict) – dictionary of covariate name, covariate (str path or xarray.DataArray) pairs
Returns:

combined – Combined DataArray of covariate variables, with variables concatenated along the new covarnames dimension

Return type:

DataArray

impax.construct_weather(**weather)[source]

Helper function to build out weather dataarray

Parameters:weather (dict) – dictionary of prednames and weather (either str file paths or xarray.DataArray objects) for each predname
Returns:combined – Combined DataArray of weather variables, with variables concatenated along the new prednames dimension
Return type:DataArray
impax.read_csvv(csvv_path)[source]

Returns the estimator object from a CSVV file

Parameters:path (str_or_buffer) – path to csvv file
Returns:estimatorGamma object with median and VCV matrix indexed by prednames, covarnames, and outcomes
Return type:MultivariateNormalEstimator
class impax.MultivariateNormalEstimator(coefficients, vcv, index)[source]

Bases: object

Stores a median and residual VCV matrix for multidimensional variables with named indices and provides multivariate sampling and statistical analysis functions

Parameters:
  • coefficients (array) – length \((m_1*m_2*\cdots*m_n)\) 1-d numpy.ndarray with regression coefficients
  • vcv (array) – \((m_1*m_2*\cdots*m_n) x (m_1*m_2*\cdots*m_n)\) numpy.ndarray with variance-covariance matrix for multivariate distribution
  • index (Index) – Index or \((m_1*m_2*\cdots*m_n)\) 1-d MultiIndex describing the multivariate space
median()[source]

Returns the median values (regression coefficients)

Returns:medianDataArray of coefficients
Return type:DataArray
sample(seed=None)[source]

Sample from the multivariate normal distribution

Takes a draw from a multivariate distribution and returns an xarray.DataArray of parameter estimates.

Returns:drawDataArray of parameter estimates drawn from the multivariate normal
Return type:DataArray