foxes.core.farm_controller.FarmController

class foxes.core.farm_controller.FarmController[source]

Bases: FarmDataModel

Analyses selected turbine models and handles their call.

Parameters:

pars (dict) – Parameters for the turbine models, stored under their respective name

turbine_types

The turbine type of each turbine

Type:

list of foxes.core.TurbineType

turbine_model_names

Names of all turbine models found in the farm

Type:

list of str

turbine_model_sels

Selection flags for all turbine models, shape: (n_states, n_turbines, n_models)

Type:

numpy.ndarray of bool

pre_rotor_models

The turbine models with pre-rotor flag

Type:

foxes.core.FarmDataModelList

post_rotor_models

The turbine models without pre-rotor flag

Type:

foxes.core.FarmDataModelList

pars

Parameters for the turbine models, stored under their respecitve name

Type:

dict

__init__(pars={})[source]

Methods

__init__([pars])

calculate(algo, mdata, fdata, pre_rotor[, ...])

"

collect_models(algo)

Analyze and gather turbine models, based on the turbines of the wind farm.

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.

output_farm_vars(algo)

The variables which are being modified by the model.

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

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

set_pars(model_name, init_pars, calc_pars, ...)

Set parameters for a turbine model

var(v)

Creates a model specific variable name.

Attributes

initialized

Initialization flag.

model_id

Unique id based on the model type.

__init__(pars={})[source]
calculate(algo, mdata, fdata, pre_rotor, st_sel=None)[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

  • mdata (foxes.core.Data) – The model data

  • fdata (foxes.core.Data) – The farm data

  • pre_rotor (bool) – Flag for running pre-rotor or post-rotor models

  • st_sel (numpy.ndarray of bool, optional) – Selection of states and turbines, shape: (n_states, n_turbines). None for all.

Returns:

results – The resulting data, keys: output variable str. Values: numpy.ndarray with shape (n_states, n_turbines)

Return type:

dict

collect_models(algo)[source]

Analyze and gather turbine models, based on the turbines of the wind farm.

Parameters:

algo (foxes.core.Algorithm) – The calculation algorithm

finalize(algo, verbosity=0)[source]

Finalizes the model.

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

  • verbosity (int) – The verbosity level, 0 means 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)[source]

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

output_farm_vars(algo)[source]

The variables which are being modified by the model.

Parameters:

algo (foxes.core.Algorithm) – The calculation algorithm

Returns:

output_vars – The output variable names

Return type:

list of str

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

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

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

Returns:

results – The calculation results

Return type:

xarray.Dataset

set_pars(model_name, init_pars, calc_pars, final_pars)[source]

Set parameters for a turbine model

Parameters:
  • model_name (str) – Name of the model

  • init_pars (dict) – Parameters for initialization

  • calc_pars (dict) – Parameters for calculation

  • final_pars (dict) – Parameters for finalization

var(v)

Creates a model specific variable name.

Parameters:

v (str) – The variable name

Returns:

Model specific variable name

Return type:

str