elphick.geomet.interval_sample.IntervalSample

class elphick.geomet.interval_sample.IntervalSample(data=None, name=None, moisture_in_scope=True, mass_wet_var=None, mass_dry_var=None, moisture_var=None, component_vars=None, composition_units='%', components_as_symbols=True, ranges=None, config_file=None)[source]

A class to represent a sample of data with an interval index. This exposes methods to split the sample by a partition definition.

__init__(data=None, name=None, moisture_in_scope=True, mass_wet_var=None, mass_dry_var=None, moisture_var=None, component_vars=None, composition_units='%', components_as_symbols=True, ranges=None, config_file=None)[source]
Parameters:
  • data (Optional[DataFrame]) – The input data

  • name (Optional[str]) – The name of the sample

  • moisture_in_scope (bool) – Whether the moisture is in scope. If False, only dry mass is processed.

  • mass_wet_var (Optional[str]) – The name of the wet mass column

  • mass_dry_var (Optional[str]) – The name of the dry mass column

  • moisture_var (Optional[str]) – The name of the moisture column

  • component_vars (Optional[list[str]]) – The names of the chemical columns

  • components_as_symbols (bool) – If True, convert the composition variables to symbols, e.g. Fe

  • ranges (Optional[dict[str, list]]) – The range of valid data for each column in the data

  • config_file (Optional[Path]) – The configuration file

Methods

__init__([data, name, moisture_in_scope, ...])

add(other[, name, include_supplementary_data])

Add two objects together

balance_composition()

Balance the composition data

calculate_partition(preferred)

Calculate the partition number (K) [0, 1] of the preferred stream relative to self :rtype: DataFrame

clip_composition([ranges])

Clip the components

clip_recovery(other[, recovery_bounds, ...])

Clip the recovery to the specified bounds and recalculate the estimate.

create_congruent_object(name[, ...])

Create an object with the same attributes

div(other[, name, include_supplementary_data])

Divide two objects

filter_by_index(index)

Update the data by index

from_mass_dataframe(mass_df[, mass_wet, ...])

Class method to create a MassComposition object from a mass dataframe.

get_mass_data([include_moisture])

Get the mass data

ideal_incremental_composition([discard_from])

Incrementally separate a fractionated sample.

ideal_incremental_recovery([discard_from, ...])

Incrementally separate a fractionated sample.

ideal_incremental_separation([discard_from])

Incrementally separate a fractionated sample.

is_2d_grid()

Check if the sample is a 2d grid.

plot_amenability(target_analyte[, ...])

The yield-recovery plot.

plot_comparison(other[, color, ...])

Create an interactive parallel plot

plot_grade_recovery(target_analyte[, ...])

The grade-recovery plot.

plot_heatmap(components, **kwargs)

Plot the sample as a heatmap.

plot_intervals(variables[, cumulative, ...])

Plot "The Grade-Tonnage" curve.

plot_parallel([color, vars_include, ...])

Create an interactive parallel plot

plot_ternary(variables[, color, title])

Plot a ternary diagram

query(expr[, name])

Reduce the data by a query expression

resample_1d(interval_edges[, precision, ...])

Resample a 1D fractional dim/index

reset_index(index_name)

set_moisture(moisture[, mass_to_adjust])

Set the moisture to the specified value

split(fraction[, name_1, name_2, ...])

Split the object by mass

split_by_partition(partition_definition[, ...])

Split the sample into two samples based on the partition definition.

sub(other[, name, include_supplementary_data])

Subtract other from self

to_stream()

update_mass_data(value)

weight_average([group_by])

Attributes

aggregate

composition_columns

data

data_columns

is_rectilinear_grid

If rectilinear we can plot with a simple heatmap

mass_columns

mass_data

moisture_column

supplementary_columns

variable_map

A map from lower case standard names to the actual column names

calculate_partition(preferred)[source]

Calculate the partition number (K) [0, 1] of the preferred stream relative to self :rtype: DataFrame

\[K = \frac{{m_{preferred}}}{{m_{feed}}}\]
ideal_incremental_composition(discard_from='lowest')[source]

Incrementally separate a fractionated sample.

This method sorts by the provided direction prior to incrementally removing and discarding the first fraction

(of the remaining fractions) and recalculating the mass-composition of the portion remaining. This is equivalent to incrementally applying a perfect separation (partition) at every interval edge.

This method is only applicable to a 1D object where the single dimension is a pd.Interval type.

See also: ideal_incremental_separation, ideal_incremental_recovery.

Parameters:

discard_from (Literal['lowest', 'highest']) – Defines the discarded direction. discard_from = “lowest” will discard the lowest value first, then the next lowest, etc.

Return type:

DataFrame

Returns:

A pandas DataFrame

ideal_incremental_recovery(discard_from='lowest', apply_closure=True)[source]

Incrementally separate a fractionated sample.

This method sorts by the provided direction prior to incrementally removing and discarding the first fraction

(of the remaining fractions) and recalculating the recovery of the portion remaining. This is equivalent to incrementally applying a perfect separation (partition) at every interval edge.

This method is only applicable to a 1D object where the single dimension is a pd.Interval type.

See also: ideal_incremental_separation, ideal_incremental_composition.

Parameters:
  • discard_from (Literal['lowest', 'highest']) – Defines the discarded direction. discard_from = “lowest” will discard the lowest value first, then the next lowest, etc.

  • apply_closure (bool) – If True, Add the missing record (zero recovery) that closes the recovery envelope.

Return type:

DataFrame

Returns:

A pandas DataFrame

ideal_incremental_separation(discard_from='lowest')[source]

Incrementally separate a fractionated sample.

This method sorts by the provided direction prior to incrementally removing and discarding the first fraction

(of the remaining fractions) and recalculating the mass-composition and recovery of the portion remaining. This is equivalent to incrementally applying a perfect separation (partition) at every interval edge.

This method is only applicable to a 1D object where the single dimension is a pd.Interval type.

See also: ideal_incremental_composition, ideal_incremental_recovery.

Parameters:

discard_from (Literal['lowest', 'highest']) – Defines the discarded direction. discard_from = “lowest” will discard the lowest value first, then the next lowest, etc.

Return type:

DataFrame

Returns:

A pandas DataFrame

is_2d_grid()[source]

Check if the sample is a 2d grid. :return: True if the sample has 2 levels of intervals, False otherwise.

property is_rectilinear_grid

If rectilinear we can plot with a simple heatmap

plot_amenability(target_analyte, discard_from='lowest', gangue_analytes=None, title=None)[source]

The yield-recovery plot.

The yield recovery curve provides an understanding of the amenability of a sample.

This method is only applicable to a 1D object where the single dimension is a pd.Interval type.

Parameters:
  • target_analyte (str) – The analyte of value.

  • discard_from (Literal['lowest', 'highest']) – Defines the discarded direction. discard_from = “lowest” will discard the lowest value first, then the next lowest, etc.

  • gangue_analytes (Optional[str]) – The analytes to be rejected

  • title (Optional[str]) – Optional plot title

Return type:

Figure

Returns:

A plotly.GraphObjects figure

plot_grade_recovery(target_analyte, discard_from='lowest', title=None)[source]

The grade-recovery plot.

The grade recovery curve is generated by assuming an ideal separation (for the chosen property, or dimension) at each fractional interval. It defines the theoretical maximum performance, which can only be improved if liberation is improved by comminution.

This method is only applicable to a 1D object where the single dimension is a pd.Interval type.

Parameters:
  • target_analyte – The analyte of value.

  • discard_from (Literal['lowest', 'highest']) – Defines the discarded direction. discard_from = “lowest” will discard the lowest value first, then the next lowest, etc.

  • title (Optional[str]) – Optional plot title

Return type:

Figure

Returns:

A plotly.GraphObjects figure

plot_heatmap(components, **kwargs)[source]

Plot the sample as a heatmap. :type components: list[str] :param components: The list of components to plot. :type kwargs: :param kwargs: Additional keyword arguments to pass to the plot method. :return: The axis with the plot.

plot_intervals(variables, cumulative=True, direction='descending', show_edges=True, min_x=None)[source]

Plot “The Grade-Tonnage” curve.

Mass and grade by bins for a cut-off variable.

Parameters:
  • variables (list[str]) – List of variables to include in the plot

  • cumulative (bool) – If True, the results are cumulative weight averaged.

  • direction (str) – ‘ascending’|’descending’, if cumulative is True, the direction of accumulation

  • show_edges (bool) – If True, show the edges on the plot. Applicable to cumulative plots only.

  • min_x (Optional[float]) – Optional minimum value for the x-axis, useful to set reasonable visual range with a log

  • data (scaled x-axis when plotting size)

Return type:

Figure

resample_1d(interval_edges, precision=None, include_original_edges=False)[source]

Resample a 1D fractional dim/index

Parameters:
  • interval_edges (Union[Iterable, int]) – The values of the new grid (interval edges). If an int, will up-sample by that factor, for example the value of 10 will automatically define edges that create 10 x the resolution (up-sampled).

  • precision (Optional[int]) – Optional integer for the number of decimal places to round the grid values to.

  • include_original_edges (bool) – If True include the original edges in the grid.

Return type:

IntervalSample

Returns:

A new IntervalSample object interpolated onto the new grid

split_by_partition(partition_definition, name_1='preferred', name_2='complement')[source]

Split the sample into two samples based on the partition definition.

\[K = \frac{{m_{preferred}}}{{m_{feed}}}\]
Parameters:
  • partition_definition – A function that takes a data frame and returns a boolean series with a range [0, 1]. A 1D function must have an argument that matches the dimension of the interval index. A 2D function must have two arguments that match the dimensions of the interval index.

  • name_1 (str) – The name of the first sample.

  • name_2 (str) – The name of the second sample.

Returns:

A tuple of two IntervalSamples.