elphick.mass_composition.mc_xarray.MassCompositionAccessor

class elphick.mass_composition.mc_xarray.MassCompositionAccessor(xarray_obj)[source]
__init__(xarray_obj)[source]

MassComposition xarray Accessor

Parameters:

xarray_obj (Dataset) –

Methods

__init__(xarray_obj)

MassComposition xarray Accessor

add(other)

Add two objects

aggregate([group_var, group_bins, ...])

Calculate the weight average of this dataset.

column_map()

composition_to_mass()

Transform composition to mass

cumulate(direction)

Cumulate along the dims

data()

div(other)

Divide self by the supplied object

mass_to_composition()

Transform mass to composition.

mul(value)

Multiply self and retain attrs

rename(new_name)

split(fraction)

Split the object by mass

split_by_partition(partition_definition)

Partition the object along a given dimension.

sub(other)

Subtract the supplied object from self

to_dataframe([original_column_names, ds])

rtype:

DataFrame

Attributes

composition_context

name

add(other)[source]

Add two objects

Perform the addition with the mass-composition variables only and then append any attribute variables.

Parameters:

other (Dataset) – object to add to self

Return type:

Dataset

Returns:

aggregate(group_var=None, group_bins=None, as_dataframe=False, original_column_names=False, column_formats=None)[source]

Calculate the weight average of this dataset.

Parameters:
  • group_var (Optional[str]) – Optional grouping variable

  • group_bins (Union[int, Iterable, None]) – Optional bins to apply to the group_var

  • as_dataframe (bool) – If True return a pd.DataFrame

  • original_column_names (bool) – If True, and as_dataframe is True, will return with the original column names.

  • column_formats (Optional[Dict]) – If not None, and as_dataframe is True, will format the dataframe per the dict.

Return type:

Union[Dataset, DataFrame]

Returns:

composition_to_mass()[source]

Transform composition to mass

Return type:

Dataset

Returns:

cumulate(direction)[source]

Cumulate along the dims

Expected use case is only for Datasets that have been reduced to 1D.

Parameters:

direction (str) – ‘ascending’|’descending’

Return type:

Dataset

Returns:

div(other)[source]

Divide self by the supplied object

Perform the division with the mass-composition variables only and then append any attribute variables. :type other: Dataset :param other: denominator object, self will be divided by this object

Returns:

Return type:

Dataset

mass_to_composition()[source]

Transform mass to composition.

Return type:

Dataset

Returns:

mul(value)[source]

Multiply self and retain attrs

Multiply the mass-composition variables only by the value then append any attribute variables. NOTE: does not multiply two objects together. Used for separation (partition) operations.

Parameters:

value (Union[float, ndarray]) – the multiplier, a scalr or array of floats.

Return type:

Dataset

Returns:

split(fraction)[source]

Split the object by mass

A simple mass split maintaining the same composition

Parameters:

fraction (float) – A constant in the range [0.0, 1.0]

Return type:

Tuple[Dataset, Dataset]

Returns:

tuple of two datasets, the first with the mass fraction specified, the other the complement

split_by_partition(partition_definition)[source]

Partition the object along a given dimension.

This method applies the defined partition resulting in two new objects.

See also: split

Parameters:

partition_definition (Callable) – A partition function that defines the efficiency of separation along a dimension

Return type:

Tuple[Dataset, Dataset]

Returns:

tuple of two datasets, the first defined by the function, the other the complement

sub(other)[source]

Subtract the supplied object from self

Perform the subtraction with the mass-composition variables only and then append any attribute variables. :type other: Dataset :param other: object to subtract from self

Returns:

Return type:

Dataset