Var Class

class cascade_at.model.var.Var(ages, times, column_name='mean')[source]

A Var is a function of age and time, defined by values on a grid. It linearly interpolates over values defined at grid points in a rectangular grid of age and time.

This is a single age-time grid. It is usually found in cascade.model.DismodGroups object which is a set of age-time grids. The following are DismodGroups containing cascade.model.Var: the fit, initial guess, truth var, and scale var.

Parameters
  • ages (List[float]) – Points along the age axis.

  • times (List[float]) – Points in time.

  • column_name (str) – A var has an internal Pandas DataFrame representation, and this column name can be mean or meas_value, depending on which Var is needed.

__setitem__(at_slice, value)[source]

To set a value on a Var instance, set it on ranges of age and time or at specific ages and times.

>>> var = Var([0, 10, 20], [2000])
>>> var[:, :] = 0.001
>>> var[5:50, 2000] = 0.01
>>> var[10, :] = 0.02
Parameters
  • at_slice (slice, slice) – What to change, as integer offset into ages and times.

  • value (float) – A float or integer.

__getitem__(age_and_time)[source]

Gets the value of a Var at a single point. The point has to be one of the ages and times defined when the var was created.

>>> var = Var([0, 50, 100], [1990, 2000, 2010])
>>> var[:, :] = 1e-4
>>> assert var[50, 2000] == 1e-4

Trying to read from an age and time not in the ages and times of the grid will result in a KeyError.

An easy way to set values is to use the age_time iterator, which loops through the ages and times in the underlying grid.

>>> for age, time in var.age_time():
>>>    var[age, time] = 0.01 * age
Parameters

age_and_time (age, time) – A two-dimensional index of age and time.

Returns

The value at this age and time.

Return type

float

set_mulstd(kind, value)[source]

Set the value of the multiplier on the standard deviation. Kind must be one of “value”, “dage”, or “dtime”. The value should be convertible to a float.

>>> var = Var([50], [2000, 2001, 2002])
>>> var.set_mulstd("value", 0.4)
get_mulstd(kind)[source]

Get the value of a standard deviation multiplier for a Var.

>>> var = Var([50], [2000, 2001, 2002])
>>> var.set_mulstd("value", 0.4)
>>> assert var.get_mulstd("value") == 4

If the standard deviation multiplier wasn’t set, then this will return a nan.

>>> assert np.isnan(var.get_mulstd("dage"))
__call__(age, time)[source]

A Var is a function of age and time, and this is how to call it.

>>> var = Var([0, 100], [1990, 2000])
>>> var[0, 1990] = 0
>>> var[0, 2000] = 1
>>> var[100, 1990] = 2
>>> var[100, 2000] = 3
>>> for a, t in var.age_time():
>>>     print(f"At corner ({a}, {t}), {var(a, t)}")
>>> for a, ti in [[53, 1997], [-5, 2000], [120, 2000], [0, 1900], [0, 2010]]:
>>>     print(f"Anywhere ({a}, {t}), {var(a, t)}")
At corner (0.0, 1990.0), 0.0
At corner (0.0, 2000.0), 1.0
At corner (100.0, 1990.0), 2.0
At corner (100.0, 2000.0), 3.0
Anywhere (53, 2000.0), 2.06
Anywhere (-5, 2000.0), 1.0
Anywhere (120, 2000.0), 3.0
Anywhere (0, 2000.0), 1.0
Anywhere (0, 2000.0), 1.0

The grid points in a Var represent a continuous function, determined by bivariate interpolation. All points outside the grid are equal to the nearest point inside the grid.