impax package¶
Submodules¶
impax.cli module¶
Console script for impax.
impax.estimate module¶
-
class
impax.estimate.MultivariateNormalEstimator(coefficients, vcv, index)[source]¶ Bases:
objectStores 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.ndarraywith regression coefficients - vcv (array) – \((m_1*m_2*\cdots*m_n) x (m_1*m_2*\cdots*m_n)\)
numpy.ndarraywith variance-covariance matrix for multivariate distribution - index (Index) –
Indexor \((m_1*m_2*\cdots*m_n)\) 1-dMultiIndexdescribing the multivariate space
-
median()[source]¶ Returns the median values (regression coefficients)
Returns: median – DataArrayof coefficientsReturn type: DataArray
-
sample(seed=None)[source]¶ Sample from the multivariate normal distribution
Takes a draw from a multivariate distribution and returns an
xarray.DataArrayof parameter estimates.Returns: draw – DataArrayof parameter estimates drawn from the multivariate normalReturn type: DataArray
- coefficients (array) – length \((m_1*m_2*\cdots*m_n)\) 1-d
-
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: estimator – Gammaobject with median and VCV matrix indexed by prednames, covarnames, and outcomesReturn type: MultivariateNormalEstimator
impax.impax module¶
-
class
impax.impax.Impact[source]¶ Bases:
objectBase 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.DataArraywith minimum temperatures used for clipping
Returns: Return type: py:class ~xarray.Dataset of impacts by hierid by outcome group
- weather (DataArray) – weather
-
impact_function(betas, weather)[source]¶ computes the dot product of betas and annual weather by outcome group
Parameters: Returns: - DataArray –
DataArrayof impact by outcome by hierid - .. note:: – overrides impact_function method in Impact base class
- DataArray –
-
min_function¶ alias of
exceptions.NotImplementedError
-
-
class
impax.impax.PolynomialImpact[source]¶ Bases:
impax.impax.ImpactPolynomial-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: Returns: Return type: DataArrayof hierid by predname by outcomeNote
overides min_function in Impact base class
-
static
-
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 (
strpath orxarray.DataArray) pairs
Returns: combined – Combined
DataArrayof covariate variables, with variables concatenated along the new covarnames dimensionReturn type: DataArray
-
impax.impax.construct_weather(**weather)[source]¶ Helper function to build out weather dataarray
Parameters: weather (dict) – dictionary of prednames and weather (either strfile paths orxarray.DataArrayobjects) for each prednameReturns: combined – Combined DataArrayof weather variables, with variables concatenated along the new prednames dimensionReturn 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
dimmust be in _ascending_ power order and must not contain the zeroth-order term.Parameters: - da (DataArray) –
DataArrayof coefficients of a(da.size[dim])-order polynomial in ascending power order along the dimensiondim. 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: DataArrayin the same shape as da, with the minimizing value of the polynomial raised to the appropriate power in place of each coefficientReturn 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'
- da (DataArray) –
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
dimmust be in _ascending_ power order and must not contain the zeroth-order term.Parameters: - da (DataArray) –
DataArrayof coefficients of a(da.size[dim])-order polynomial in ascending power order along the dimensiondim. 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: DataArrayin the same shape as da, with the minimizing value of the polynomial raised to the appropriate power in place of each coefficientReturn 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'
- da (DataArray) –
-
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 (
strpath orxarray.DataArray) pairs
Returns: combined – Combined
DataArrayof covariate variables, with variables concatenated along the new covarnames dimensionReturn type: DataArray
-
impax.construct_weather(**weather)[source] Helper function to build out weather dataarray
Parameters: weather (dict) – dictionary of prednames and weather (either strfile paths orxarray.DataArrayobjects) for each prednameReturns: combined – Combined DataArrayof weather variables, with variables concatenated along the new prednames dimensionReturn 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: estimator – Gammaobject with median and VCV matrix indexed by prednames, covarnames, and outcomesReturn type: MultivariateNormalEstimator
-
class
impax.MultivariateNormalEstimator(coefficients, vcv, index)[source] Bases:
objectStores 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.ndarraywith regression coefficients - vcv (array) – \((m_1*m_2*\cdots*m_n) x (m_1*m_2*\cdots*m_n)\)
numpy.ndarraywith variance-covariance matrix for multivariate distribution - index (Index) –
Indexor \((m_1*m_2*\cdots*m_n)\) 1-dMultiIndexdescribing the multivariate space
-
median()[source] Returns the median values (regression coefficients)
Returns: median – DataArrayof coefficientsReturn type: DataArray
-
sample(seed=None)[source] Sample from the multivariate normal distribution
Takes a draw from a multivariate distribution and returns an
xarray.DataArrayof parameter estimates.Returns: draw – DataArrayof parameter estimates drawn from the multivariate normalReturn type: DataArray
- coefficients (array) – length \((m_1*m_2*\cdots*m_n)\) 1-d