gcubed.base

This module contains the Base class.

class Base:

Overview

Provides convenience methods for all classes.

All G-Cubed classes inherit from this base class.

Base()

Constructor

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

These currently just set up numpy array print options.

def zeros(self, rows=1, cols=1) -> pandas.core.frame.DataFrame:

Overview

Create a dataframe filled with zeros.

Arguments

rows: the number of dataframe rows

cols: the number of dataframe columns

Returns

A dataframe containing zeros with the given number of rows and the given number of columns.

def load_data(self, filename: str, name_column: int = 1) -> tuple:

Overview

Loads data from a CSV file, splitting it into two parts, the data selected as the columns with a 4 digit column name, and the non-data, selected as all other columns.

This is used to load a variety of different CSV data sources.

Arguments

filename: the name of the CSV file, including the path relative to the model root directory.

name_column: the column of the CSV file that contains the variable names, indexed from zero for the first column and defaulting to 1.

Returns

A tuple is returned. The first element in the tuple is the dataframe consisting of all columns that were loaded and that did not have a year label for the column. The second element in the tuple is the dataframe consisting of all columns that were loaded and that did have a year label for the column.

Exceptions

Raises an exception if the file has no contents.

def get_year_labels(self, labels: list[str]) -> list[str]:

Overview

Extracts the subset of elements in the input list of labels that have a YYYY format.

Arguments

labels: A list of strings, some of which contain years in YYYY format.

Returns

all strings in the list that match the YYYY year format.

def log_calling_stack(self):