API#

Top-level API#

Not(value)

Inverted selector value.

ProcessingStepDescription(*, time, function, ...)

Structured description of a processing step done on a timeseries.

TimeseriesProcessingDescription(steps)

Structured description of all processing steps done on a timeseries.

accessors

xarray extension accessors providing an API under the 'pr' namespace.

open_dataset(filename_or_obj[, group, ...])

Open and decode a dataset from a file or file-like object.

ureg

Unit registry class.

Submodules#

primap2.pm2io#

Data reading module of the PRIMAP2 climate policy analysis package.

pm2io.convert_long_dataframe_if(data_long, ...)

Convert a DataFrame in long (tidy) format into the PRIMAP2 interchange format.

pm2io.convert_wide_dataframe_if(data_wide, ...)

Convert a DataFrame in wide format into the PRIMAP2 interchange format.

pm2io.from_interchange_format(data[, attrs, ...])

Convert dataset from the interchange format to the standard PRIMAP2 format.

pm2io.nir_add_unit_information(df_nir, *, ...)

Add unit information to a National Inventory Report (NIR) style DataFrame.

pm2io.nir_convert_df_to_long(df_nir, year[, ...])

Convert an entity-wide NIR table for a single year to a long format DataFrame.

pm2io.read_interchange_format(filepath)

Read a dataset in the interchange format from disk into memory.

pm2io.read_long_csv_file_if(...[, ...])

Read a CSV file in long (tidy) format into the PRIMAP2 interchange format.

pm2io.read_wide_csv_file_if(...[, ...])

Read a CSV file in wide format into the PRIMAP2 interchange format.

pm2io.write_interchange_format(filepath, data)

Write dataset in interchange format to disk.

primap2.csg#

Composite Source Generator

Generate a composite harmonized dataset from multiple sources according to defined source priorities and matching algorithms.

csg.GlobalLSStrategy([allow_shift, ...])

Fill missing data by global least square matching.

csg.PriorityDefinition(*, ...[, ...])

Defines source priorities for composing a full dataset or a single timeseries.

csg.StrategyDefinition(strategies)

Defines filling strategies for a single timeseries.

csg.StrategyUnableToProcess(reason)

The filling strategy is unable to process the given timeseries, possibly due to missing data.

csg.SubstitutionStrategy()

Fill missing data in the result dataset by copying.

csg.compose(*, input_data, ...[, progress_bar])

Compose a harmonized dataset from multiple input datasets.

DataArray#

Attributes#

DataArray.pr.dim_alias_translations

Translate a shortened dimension alias to a full dimension name.

DataArray.pr.gwp_context

The pint conversion context for this DataArray, directly usable for conversions.

DataArray.pr.loc

Location-based indexing like xr.DataArray.loc with added features.

Methods#

DataArray.pr.__getitem__(item)

Like da[], but translates short aliases like "area" into the long names including the corresponding category-set.

DataArray.pr.add_aggregates_coordinates(agg_info)

Manually aggregate data for coordinates

DataArray.pr.any([dim, keep_attrs])

Reduce this DataArray's data by applying any along some dimension(s).

DataArray.pr.combine_first(da_combine)

Combine data from multiple arrays.

DataArray.pr.convert_to_gwp(gwp_context, units)

Convert to a global warming potential

DataArray.pr.convert_to_gwp_like(like)

Convert to a global warming potential in the units of a reference array.

DataArray.pr.convert_to_mass([gwp_context, ...])

Convert a global warming potential of a greenhouse gas to a mass.

DataArray.pr.count([dim, reduce_to_dim, ...])

Reduce this array by counting along some dimension(s).

DataArray.pr.coverage(*dims)

Summarize how many data points exist for a dimension combination.

DataArray.pr.dequantify()

Removes units from the DataArray and its coordinates.

DataArray.pr.downscale_timeseries(*, dim, ...)

Downscale timeseries along a dimension using a basket defined on a broader timeseries.

DataArray.pr.fill_all_na(dim[, value])

Fill NA values only where all values along the specified dimension(s) are NA.

DataArray.pr.fillna(da_fill)

Fill missing information from other array.

DataArray.pr.merge(da_merge[, tolerance, ...])

Merge with da_merge with a tolerance for discrepancies in values found in both.

DataArray.pr.quantify(**kwargs)

Attaches units to the DataArray.

DataArray.pr.set(dim, key, value, *[, ...])

Set values, optionally expanding the given dimension as necessary.

DataArray.pr.sum([dim, reduce_to_dim, ...])

Reduce this DataArray's data by applying sum along some dimension(s).

DataArray.pr.to_df([name])

Convert this array into an unstacked (i.e. non-tidy) pandas.DataFrame.

Dataset#

Attributes#

Dataset.pr.comment

Longer form description

Dataset.pr.contact

Who can answer questions about the data

Dataset.pr.dim_alias_translations

Translate a shortened dimension alias to a full dimension name.

Dataset.pr.entity_terminology

The terminology of the entity attributes in this dataset's data variables

Dataset.pr.institution

Where the data originates

Dataset.pr.loc

Location-based indexing like xr.DataArray.loc with added features.

Dataset.pr.publication_date

The original date of publication of the dataset, if published.

Dataset.pr.references

Citable reference(s) describing the data

Dataset.pr.rights

License or other usage restrictions of the data

Dataset.pr.title

A succinct description

Methods#

Dataset.pr.__getitem__(item)

Like ds[], but translates short aliases like "area" into the long names including the corresponding category-set.

Dataset.pr.add_aggregates_coordinates(agg_info)

Manually aggregate data for coordinates

Dataset.pr.add_aggregates_variables(gas_baskets)

Creates or fills gas baskets

Dataset.pr.any([dim, keep_attrs])

Reduce this Dataset's data by applying any along some dimension(s).

Dataset.pr.combine_first(ds_combine)

Combine with data from other dataset or array.

Dataset.pr.count([dim, reduce_to_dim, ...])

Reduce this Dataset by counting along some dimension(s).

Dataset.pr.coverage(*dims)

Summarize how many data points exist for a dimension combination.

Dataset.pr.dequantify()

Removes units from the Dataset and its coordinates.

Dataset.pr.downscale_gas_timeseries(*, ...)

Downscale a gas basket defined on a broader timeseries to its contents known on fewer time points.

Dataset.pr.downscale_timeseries(*, dim, ...)

Downscale timeseries along a dimension using a basket defined on a broader timeseries.

Dataset.pr.ensure_valid()

Ensure this is a valid primap2 data set.

Dataset.pr.expand_dims(dim, coord_value[, ...])

Add a dimension and coordinate to dataset.

Dataset.pr.fill_all_na(dim[, value])

Fill NA values only where all values along the specified dimension(s) are NA.

Dataset.pr.fill_na_gas_basket_from_contents(*, ...)

Fill NA values in a gas basket using the sum of its contents.

Dataset.pr.fillna(ds_fill)

Fill missing information from other dataset.

Dataset.pr.gas_basket_contents_sum(*, ...[, ...])

The sum of gas basket contents converted using the global warming potential of the gas basket.

Dataset.pr.has_processing_info()

True if the dataset has processing information for at least one entity.

Dataset.pr.merge(ds_merge[, tolerance, ...])

Merge two Datasets with a tolerance for discrepancies in values present in both Datasets.

Dataset.pr.quantify([units])

Attaches units to each variable in the Dataset.

Dataset.pr.remove_processing_info()

Return dataset with all variables with processing information removed.

Dataset.pr.set(dim, key, value, *[, ...])

Set values, optionally expanding the given dimension as necessary.

Dataset.pr.sum([dim, reduce_to_dim, skipna, ...])

Reduce this Dataset's data by applying sum along some dimension(s).

Dataset.pr.to_df([name])

Convert this dataset into a pandas.DataFrame.

Dataset.pr.to_interchange_format([time_format])

Convert dataset to the interchange format.

Dataset.pr.to_netcdf(path[, mode, group, ...])

Write dataset contents to a netCDF file.