elphick.mass_composition.stream.Stream
- class elphick.mass_composition.stream.Stream(mc, **kwargs)[source]
- __init__(mc, **kwargs)[source]
- Parameters:
mc (
MassComposition
) – MassComposition object to be used as a stream.**kwargs – The key word arguments for the Mass Composition object
Methods
__init__
(mc, **kwargs)- type mc:
add
(other[, name])Adds the stream to another stream or a tuple of streams.
aggregate
([group_var, group_bins, ...])Calculate the weight average.
binned_mass_composition
(cutoff_var, bin_width)A.K.A "The Grade-Tonnage" curve.
calculate_partition
(ref)Calculate the partition of the ref stream relative to self
compare
(other[, comparisons, ...])- rtype:
Union
[DataFrame
,Dataset
]
constrain
([clip_mass, clip_composition, ...])Constrain the mass-composition
div
(other[, name])Divide two objects
from_mass_composition
(mc, **kwargs)from_xarray
(ds[, name])get_common_prefix
(columns)- rtype:
str
get_constraint_bounds
(constraints)- rtype:
Dict
[str
,List
]
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.
plot_amenability
(target_analyte[, ...])The yield-recovery plot.
plot_bins
(variables, cutoff_var, bin_width)Plot "The Grade-Tonnage" curve.
plot_comparison
(other[, color, ...])Create an interactive parallel plot
plot_grade_recovery
(target_analyte[, ...])The grade-recovery plot.
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
(queries)- rtype:
rename
(new_name)- rtype:
resample_1d
(interval_edges[, precision, ...])Resample a 1D fractional dim/index
set_child_node
(child)- rtype:
set_data
(data[, constraints])set_parent_node
(parent)- rtype:
set_stream_nodes
(nodes)- rtype:
split
(fraction[, name_1, name_2])Splits the stream into two streams.
split_by_estimator
(estimator[, name_1, ...])Split an object using a sklearn estimator.
split_by_function
(split_function[, name_1, ...])Split an object using a function.
split_by_partition
(partition_definition[, ...])Partition the object along a given dimension.
sub
(other[, name])Subtract two streams
to_xarray
()Returns the mc compliant xr.Dataset
update_data
(values)Attributes
data
destination_node
name
source_node
- split(fraction, name_1=None, name_2=None)[source]
Splits the stream into two streams.
- Parameters:
fraction (
float
) – The fraction of the stream to be assigned to the first stream.name_1 (
Optional
[str
]) – The name of the first stream.name_2 (
Optional
[str
]) – The name of the second stream.
- Return type:
tuple
[Stream, Stream]- Returns:
A tuple of two Stream objects.
- split_by_estimator(estimator, name_1=None, name_2=None, extra_features=None, allow_prefix_mismatch=False, mass_recovery_column=None, mass_recovery_max=1.0)[source]
Split an object using a sklearn estimator.
This method applies the function to self, resulting in two new objects. The object returned with name_1 is the result of the estimator.predict() method. The object returned with name_2 is the complement.
See also: split, split_by_function, split_by_partition
- Parameters:
estimator (sklearn.base.BaseEstimator) – Any sklearn estimator that transforms the dataframe from a MassComposition object into a new dataframe with values representing a new (output) stream using the predict method. The returned dataframe structure must be identical to the input dataframe.
name_1 (
Optional
[str
]) – The name of the stream created by the estimator.name_2 (
Optional
[str
]) – The name of the complement stream created by the split, which is calculated automatically. extra_features: Optional additional features to pass to the estimator as features.allow_prefix_mismatch (
bool
) – If True, allow feature names to be different and log an info message. If False, raise an error when feature names are different.mass_recovery_column (
Optional
[str
]) – If provided, this indicates that the model has estimated mass recovery, not mass explicitly. This will execute a transformation of the predicted dry mass recovery to dry mass.mass_recovery_max (
float
) – The maximum mass recovery value, used to scale the mass recovery to mass. Only applicable if mass_recovery_column is provided. Should be either 1.0 or 100.0.
- Return type:
tuple
[Stream, Stream]- Returns:
tuple of two Stream objects, the first the output of the estimator, the other the complement
- split_by_function(split_function, name_1=None, name_2=None)[source]
Split an object using a function.
This method applies the function to self, resulting in two new objects. The object returned with name_1 is the result of the function. The object returned with name_2 is the complement.
See also: split, split_by_estimator, split_by_partition
- Parameters:
split_function (
Callable
) – Any function that transforms the dataframe from a MassComposition object into a new dataframe with values representing a new (output) stream. The returned dataframe structure must be identical to the input dataframe.name_1 (
Optional
[str
]) – The name of the stream created by the functionname_2 (
Optional
[str
]) – The name of the complement stream created by the split, which is calculated automatically.
- Return type:
tuple
[Stream, Stream]- Returns:
A generator of two Streams,
- split_by_partition(partition_definition, name_1=None, name_2=None)[source]
Partition the object along a given dimension.
This method applies the defined separation resulting in two new objects.
See also: split, split_by_function
- Parameters:
partition_definition (
Callable
) – A partition function that defines the efficiency of separation along a dimensionname_1 (
Optional
[str
]) – The name of the reference stream created by the splitname_2 (
Optional
[str
]) – The name of the complement stream created by the split
- Return type:
tuple
[Stream, Stream]- Returns:
tuple of two datasets, the first with the mass fraction specified, the other the complement