foxes.core.algorithm.Algorithm

class foxes.core.algorithm.Algorithm[source]

Bases: Model

Abstract base class for algorithms.

Algorithms collect required objects for running calculations, and contain the calculation functions which are meant to be called from top level code.

Parameters:
  • mbook (foxes.ModelBook) – The model book

  • farm (foxes.WindFarm) – The wind farm

  • chunks (dict) – The chunks choice for running in parallel with dask, e.g. {“state”: 1000} for chunks of 1000 states

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

  • dbook (foxes.DataBook) – The data book, or None for default

  • keep_models (list of str) – Keep these models data in memory and do not finalize them

  • mbook – The model book

  • farm – The wind farm

  • chunks – The chunks choice for running in parallel with dask, e.g. {“state”: 1000} for chunks of 1000 states

  • verbosity – The verbosity level, 0 means silent

  • dbook – The data book, or None for default

  • keep_models – Keep these models data in memory and do not finalize them

__init__(mbook, farm, chunks, verbosity, dbook=None, keep_models=[])[source]

Methods

__init__(mbook, farm, chunks, verbosity[, ...])

finalize([clear_mem])

Finalizes the algorithm.

finalize_model(model[, verbosity])

Call the finalization routine of the model, if not to be kept.

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

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

get_models_data([idata])

Creates xarray from model input data.

initialize()

Initializes the algorithm.

new(algo_type, *args, **kwargs)

Run-time algorithm factory.

new_point_data(points[, states_indices])

Creates a point data xarray object, containing only points.

print(*args, **kwargs)

Print function, based on verbosity.

update_idata(models[, idata, verbosity])

Add to idata memory, optionally update and return idata object.

update_n_turbines()

Reset the number of turbines, according to self.farm

var(v)

Creates a model specific variable name.

Attributes

idata_mem

The current idata memory

initialized

Initialization flag.

model_id

Unique id based on the model type.

__init__(mbook, farm, chunks, verbosity, dbook=None, keep_models=[])[source]
finalize(clear_mem=False)[source]

Finalizes the algorithm.

Parameters:

clear_mem (bool) – Clear idata memory, including keep_models entries

finalize_model(model, verbosity=None)[source]

Call the finalization routine of the model, if not to be kept.

Parameters:
  • model (foxes.core.Model) – The model to be finalized, if not in the keep_models list

  • verbosity (int, optional) – 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

get_models_data(idata=None)[source]

Creates xarray from model input data.

Parameters:

idata (dict, optional) – 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. Take algorithm’s idata object by default.

Returns:

The model input data

Return type:

xarray.Dataset

property idata_mem

The current idata memory

Returns:

Keys: model name, value: idata dict

Return type:

dict

initialize()[source]

Initializes the algorithm.

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

classmethod new(algo_type, *args, **kwargs)[source]

Run-time algorithm factory.

Parameters:
  • algo_type (str) – The selected derived class name

  • args (tuple, optional) – Additional parameters for the constructor

  • kwargs (dict, optional) – Additional parameters for the constructor

new_point_data(points, states_indices=None)[source]

Creates a point data xarray object, containing only points.

Parameters:
  • points (numpy.ndarray) – The points, shape: (n_states, n_points, 3)

  • states_indices (array_like, optional) – The indices of the states dimension

Returns:

A dataset containing the points data

Return type:

xarray.Dataset

print(*args, **kwargs)[source]

Print function, based on verbosity.

update_idata(models, idata=None, verbosity=None)[source]

Add to idata memory, optionally update and return idata object.

Parameters:
  • models (foxes.core.Model or list of foxes.core.Model) – The models to initialize

  • idata (dict, optional) – The idata dictionary to be updated, else only add to idata memory

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

update_n_turbines()[source]

Reset the number of turbines, according to self.farm

var(v)

Creates a model specific variable name.

Parameters:

v (str) – The variable name

Returns:

Model specific variable name

Return type:

str