foxes.core.data_calc_model.DataCalcModel

class foxes.core.data_calc_model.DataCalcModel[source]

Bases: Model

Abstract base class for models with that run calculation on xarray Dataset data.

The calculations are run via xarray’s apply_ufunc function, i.e., they run in parallel depending on the dask settings.

For each individual data chunk the calculate function is called.

__init__()

Methods

__init__()

calculate(algo, *data, **parameters)

"

finalize(algo[, verbosity])

Finalizes the model.

get_data(variable, data[, st_sel, upcast, ...])

Getter for a data entry in either the given data source, or the model object.

initialize(algo[, verbosity])

Initializes the model.

run_calculation(algo, *data, out_vars, ...)

Starts the model calculation in parallel, via xarray's apply_ufunc.

var(v)

Creates a model specific variable name.

Attributes

initialized

Initialization flag.

model_id

Unique id based on the model type.

__init__()
abstract calculate(algo, *data, **parameters)[source]

” The main model calculation.

This function is executed on a single chunk of data, all computations should be based on numpy arrays.

Parameters:
  • algo (foxes.core.Algorithm) – The calculation algorithm

  • *data (foxes.core.Data) – The input data

  • **parameters (dict, optional) – The calculation parameters

Returns:

results – The resulting data, keys: output variable str. Values: numpy.ndarray

Return type:

dict

finalize(algo, verbosity=0)

Finalizes the model.

Parameters:
  • algo (foxes.core.Algorithm) – The calculation algorithm

  • verbosity (int) – The verbosity level, 0 = silent

get_data(variable, data, st_sel=None, upcast=None, data_prio=False, accept_none=False)

Getter for a data entry in either the given data source, or the model object.

Parameters:
  • variable (str) – The variable, serves as data key

  • data (dict) – The data source

  • st_sel (numpy.ndarray of bool, optional) – If given, get the specified state-turbine subset

  • upcast (str, optional) – Either ‘farm’ or ‘points’, broadcasts potential scalar data to numpy.ndarray with dimensions (n_states, n_turbines) or (n_states, n_points), respectively

  • data_prio (bool) – First search the data source, then the object

  • accept_none (bool) – Do not throw an error if data entry is None or np.nan

initialize(algo, verbosity=0)

Initializes the model.

This includes loading all required data from files. The model should return all array type data as part of the idata return dictionary (and not store it under self, for memory reasons). This data will then be chunked and provided as part of the mdata object during calculations.

Parameters:
  • algo (foxes.core.Algorithm) – The calculation algorithm

  • verbosity (int) – The verbosity level, 0 = silent

Returns:

idata – The dict has exactly two entries: data_vars, a dict with entries name_str -> (dim_tuple, data_ndarray); and coords, a dict with entries dim_name_str -> dim_array

Return type:

dict

property initialized

Initialization flag.

Returns:

True if the model has been initialized.

Return type:

bool

property model_id

Unique id based on the model type.

Returns:

Unique id of the model object

Return type:

int

run_calculation(algo, *data, out_vars, loop_dims, out_core_vars, **calc_pars)[source]

Starts the model calculation in parallel, via xarray’s apply_ufunc.

Typically this function is called by algorithms.

Parameters:
  • algo (foxes.core.Algorithm) – The calculation algorithm

  • *data (tuple of xarray.Dataset) – The input data

  • out_vars (list of str) – The calculation output variables

  • loop_dims (array_like of str) – List of the loop dimensions during xarray’s apply_ufunc calculations

  • out_core_vars (list of str) – The core dimensions of the output data, use FV.VARS for variables dimension (required)

  • **calc_pars (dict, optional) – Additional arguments for the calculate function

Returns:

results – The calculation results

Return type:

xarray.Dataset

var(v)

Creates a model specific variable name.

Parameters:

v (str) – The variable name

Returns:

Model specific variable name

Return type:

str