MISO2 Survival functions

Created on Tue Mar 1 11:13:21 2022

@author: jstreeck, bgrammer

class model.config.MISO2_survival_functions.MISO2SurvivalFunctions(miso_config=None, parametrization='LogNormal', cache=None, randomization=False, bias=None)

Contains the survival function array and helper methods for constructing and saving them to disk.

The parameters for constructing the SF_Array are taken from a MISO2Config object. As an object of this class is dependent on the correct parametrization, the UUID of the config is saved and both are cross-checked by the model to prevent running the model on non-matching MISO2Configs and MISO2SurvivalFunctions.

Parameters:
  • miso_config (MISOConfig) – The MISOConfig from which the survival arrays are constructed.

  • parametrization (str) – Lifetime distribution as expected by ODYM’s dynamic stock model. One of “MISO2LogNormal”, “LogNormal”, “Normal” (default), “Weibull”, “Fixed”, “FoldedNormal”.

  • cache (dict) – Dictionary to look up cached survival functions. This may be reused between survival functions to

  • computation. (speed up)

  • randomization (bool) – Randomise survival functions

  • bias (str) – Randomise survival functions into biased direction, e.g. always “higher” or “lower” than mean.

config_path

Default save path for pickling. Set to value found in MISO2Config.

Type:

str

miso_config_id

Unique ID of the MISO2Config used to create the array.

Type:

UUID

SF_Array
Type:

np.array

nr_start

Region start index for which SF were created.

Type:

int

nr_stop

Region stop index for which SF were created.

Type:

int

parametrization

Lifetime distribution

Type:

str

create_lifetime_functions(miso_config, cache=None, randomization=False, bias=None)

Create Survival Functions with the help of ODYMs Dynamic Stock Model.

Note that the SF Array will have the full size (over all regions) of the MISO2Config, but survival functions will only be calculated for the regions specified with nr_start and nr_stop.

Parametrization is dependent on the format of the MISO2_Lifetimes and MISO2_Lifetimes_deviation input parameters.

The function has an unbounded cached to speed up computation. Please note that when you supply a lot of different input arguments, the cache will grow without bound and add significant memory requirements to the call.

Parameters:
  • miso_config (MISO2Config) – Config object holding the relevant parameters.

  • cache (dict) – Already existing cache of survival functions. If None (default), cache is created.

  • randomization (bool) – Randomize survival functions. Defaults to false.

  • bias (str) – Return “higher” or “lower” biased survival functions.

Returns:

A (r,e,m,g,t,t)-shaped array of floats. Over the last two dimensions, this a lower triangular matrix with lifetime functions, ones in the diagonal, and zeros in the upper half.

Return type:

SF_Array(np.array)

get_sf_array(nr_start, nr_stop)

Returns subset of SF_Array.

Parameters:
  • nr_start (int) – Start region index.

  • nr_stop (int) – Stop region index.

Returns:

Sliced view of SF_Array

Return type:

SF_Array(np.array)

Raises:

ValueError – If region indexes not within range of SF_Array.

save_to_pickle(filename=None, folder=None)

Save the Survival functions to a pickle with the highest protocol.

Parameters:
  • filename (str) – Defaults to <UUID>_SF.pickle

  • folder (str) – Defaults to MISO2Configs config path.

model.config.MISO2_survival_functions.load_sfs_from_folder(sfs_path, key='id')

Tries to load all .pickle files in a directory as MISO2SurvivalFunctions and returns them as a list.

Parameters:
  • sfs_path (str) – A filepath

  • key (str) – One of “id” (default) or “filename”

Returns:

A list of MISO2Config objects.

Return type:

configs(dict)

model.config.MISO2_survival_functions.save_split_sfs_to_folder(path, sf_name, sf)

Splits a SF object into multiple objects, one per region, and saves them to a folder.

Individual files receive a running index. Note that a corresponding miso config id must be set manually.

Parameters:
  • path (str) – Folder path to save to

  • sf_name (str) – Filename of the config.

  • sf (MISO2SurvivalFunctions) – SF to split

model.config.MISO2_survival_functions.split_survival_functions(miso_survival_functions, index)

Returns a new MISOSurvivalFunctions object with a view of subset SF array.

Since SF_Array should never be modified in-place, it is okay to return a view here.

Parameters:
  • miso_survival_functions (MISOSurvivalFunctions) – Original object.

  • index (int) – Index to be subset, first dimension of sf array (region).

Returns:

New object split at index dimension.

Return type:

split_sf(MISOSurvivalFunctions)