gcubed.projections.derivations

Provides capacity to augment charting projections with derived variable projections

class Derivations(gcubed.base.Base):

Overview

Provides convenience methods for all classes.

All G-Cubed classes inherit from this base class.

Derivations(sym_data: gcubed.sym_data.SymData)

Constructor

Does constructor operations required by all classes that inherit from this base class.

These currently just set up numpy array print options.

Returns

  • SymData: The sym_data object
derivation_definitions: dict[str, gcubed.projections.derivation.Derivation]

Returns

  • dict[str, Derivation]: The derivations that have been added to the projections object
def has_derivation_definition(self, prefix: str) -> bool:

Overview

Checks if a derivation object has been added to the projections object.

Arguments

  • prefix (str): The prefix of the derivation object

Returns

  • bool: Whether the derivation object has been added to the projections object
def add( self, derivation: gcubed.projections.derivation.Derivation, force: bool = False) -> None:

Overview

Adds a derived variable to the projections object

Arguments

  • derivation (Derivation): The derivation object that defines the derived variable

  • force (bool): Whether to add the derivation even if it already exists in this collection of derivations. Defaults to False in which case the derivation is only added if there is not an existing derivation definition that is already available.

def add_all( self, derivations: list[gcubed.projections.derivation.Derivation], force: bool = False) -> None:

Overview

Adds multiple derived variables to the projections object if they do not already have an existing derivation.

Arguments

  • derivations (list[Derivation]): The derivation objects that define the derived variables

  • force (bool): Whether to add the derivation even if it already exists in this collection of derivations. Defaults to False in which case the derivation is only added if there is not an existing derivation definition that is already available.

def get_derivation_definition(self, prefix: str) -> gcubed.projections.derivation.Derivation:

Overview

Gets a derivation object by its prefix.

Arguments

  • prefix (str): The prefix of the derivation object

Returns

  • Derivation: The derivation object
all_derivation_definitions: list[gcubed.projections.derivation.Derivation]

Overview

Gets all the derivation objects that have been added to the projections object.

Returns

  • list[Derivation]: The derivation objects
derivation_definition_details: pandas.core.frame.DataFrame

Returns

A dataframe with details about the derivation definitions that are available.

def generate_all_derived_projections( self, original_projections: pandas.core.frame.DataFrame) -> pandas.core.frame.DataFrame:

Overview

Derives all the projections for all the derived variables that have been added to the projections object.

Arguments

  • original_projections: The original projections. These MUST be level projections rather than deviations and they MUST be obtained using the charting_projections property of the relevant Projections object.

Returns

The derived variable projections.

Exceptions

  • ValueError: If the original projections do not include the column labels associated with charting projections.
def derive_projections( self, derivation: gcubed.projections.derivation.Derivation, projections: pandas.core.frame.DataFrame) -> pandas.core.frame.DataFrame:

Overview

Calculates the derived variable projections and adds them to the derived variable projections dataframe.

def generate_all_derived_deviations( self, new_projections: pandas.core.frame.DataFrame, original_projections: pandas.core.frame.DataFrame) -> pandas.core.frame.DataFrame:

Overview

Derives all the projected deviations for the derived variables.

The deviations are of the new projections from the original projections.

Arguments

  • new_projections: The new projections

  • original_projections: The original projections

Returns

The derived deviations of the new projections from the original projections.

def calculate_deviations( self, derivation: gcubed.projections.derivation.Derivation, new_projections: pandas.core.frame.DataFrame, original_projections: pandas.core.frame.DataFrame) -> pandas.core.frame.DataFrame:

Overview

Calculates the derived variable deviations and adds them to the derived variable deviations dataframe.

Arguments

  • derivation (Derivation): The derivation object that defines the derived variable

  • new_projections (pd.DataFrame): The new projections

  • original_projections (pd.DataFrame): The original projections

Returns

The derived variable deviations of the new projections from the original projections.