impactlab_tools.acp package¶
Submodules¶
impactlab_tools.acp.aggregate module¶
- impactlab_tools.acp.aggregate.population_weighted_mean(ds, level='state', dim='fips', year=2012, pop=None)[source]¶
Find the population-weighted mean of a county-level xarray DataArray
- Parameters:
ds (array) –
DataArrayto be aggregated. May contain any number of dimensions >= 1.level (str (optional)) – Level of resolution to aggregate to. May be one of
'fips','state','state_names','state_abbrevs','census', or'national'(default'state')dim (str (optional)) – dimension to aggregate along (default
'fips')year (int (optional)) – population year (or column in the
popdataset) to use for the weights. If not provided, 2012 population is used.pop (array (optional)) –
DataArrayto use for weights. If not provided, US Census Bureau 2014 vintage CO-EST2014-alldata.csv estimates from the ACP are used
- Returns:
mean – weighted average aggregated
DataArray- Return type:
array
impactlab_tools.acp.dist module¶
- impactlab_tools.acp.dist.acp_quantiles(data, rcp, quantiles=[0.05, 0.17, 0.5, 0.83, 0.95], values_sorted=False, dim='model')[source]¶
Compute quantiles of an xarray distribution using ACP weights
Note
This function does not control for the number of samples of each model. If they are not constant across models provide a correctly weighted weights array to
utils.weighting.weighted_quantile_xr(). We would like to fix this. If you have a good fix we’d love a PR :)- Parameters:
data (DataArray or Dataset) –
xarray.DataArrayorxarray.Datasetwith data indexed by ACP model along the dimensiondim. If a Dataset is passed,acp_quantilescomputes the weighted quantile for each variable in theDatasetthat is indexed bydim.rcp (str) – RCP weights/models to use (‘rcp45’, ‘rcp85’)
quantiles (list-like, optional) – quantiles of distribution to return. quantiles should be in [0, 1]. Default [0.05, 0.17, 0.5, 0.83, 0.95].
values_sorted (bool, optional) – if True, then will avoid sorting of initial array. default False.
dim (str, optional) – dimension along which to retrieve quantiles. The indices of this dimension should be valid (case insensitive) ACP climate models. Default: ‘model’.
- Returns:
returns a new
DataArrayorDatasetwith quantiles computed from weighted distribution along a new dimensionquantileand dimensiondimdropped.- Return type:
DataArray or Dataset
See also
gcp.dist.acp_quantiles()numpy.percentile()xarray.Dataset.quantile()xarray.DataArray.quantile()pandas.DataFrame.quantile()pandas.Series.quantile()