foxes.input.states.scan

Classes

ScanStates

Scan over selected variables

Module Contents

class foxes.input.states.scan.ScanStates(scans: dict[str, numpy.typing.ArrayLike], fixed_vars: dict[str, float] | None = None, **kwargs: object)[source]

Bases: foxes.core.States

Scan over selected variables

Parameters

scans

The scans, key: variable name, value: scan values

fixed_vars

A dictionary containing the fixed variables, with variable names as keys and corresponding float values as values.

Parameters:
scans

The scans, key: variable name, value: scan values

fixed_vars

A dictionary containing the fixed variables, with variable names as keys and corresponding float values as values.

kwargs

Parameters for the base class

calculate(algo: foxes.core.Algorithm, mdata: foxes.core.MData, fdata: foxes.core.FData, tdata: foxes.core.TData) dict[str, numpy.ndarray][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

The calculation algorithm

mdata

The model data

fdata

The farm data

tdata

The target point data

Returns:
results

The resulting data, keys: output variable str. Values (n_states, n_targets, n_tpoints)

ensure_output_vars(algo: foxes.core.algorithm.Algorithm, tdata: foxes.core.data.TData) None

Ensures that the output variables are present in the target data.

Parameters:
algo

The calculation algorithm

tdata

The target point data

finalize(algo: foxes.core.algorithm.Algorithm, verbosity: int = 0) None

Finalize the model.

Parameters:
algo

The calculation algorithm.

verbosity

The verbosity level; 0 is silent.

gen_states_split_size() Generator[int | None, None, None]

Generator for suggested states split sizes for output writing.

Yields:
split_size

The suggested split size, or None for no splitting

get_data(variable: str, target: str, lookup: str = 'smfp', mdata: foxes.core.data.MData | None = None, fdata: foxes.core.data.FData | None = None, tdata: foxes.core.data.TData | None = None, downwind_index: int | None = None, accept_none: False = False, accept_nan: bool = True, algo: foxes.core.algorithm.Algorithm | None = None, upcast: bool = False, selection: numpy.ndarray[Any, Any] | tuple[Any, ...] | list[Any] | None = None) numpy.ndarray[Any, Any]
get_data(variable: str, target: str, lookup: str = 'smfp', mdata: foxes.core.data.MData | None = None, fdata: foxes.core.data.FData | None = None, tdata: foxes.core.data.TData | None = None, downwind_index: int | None = None, accept_none: True = True, accept_nan: bool = True, algo: foxes.core.algorithm.Algorithm | None = None, upcast: bool = False, selection: numpy.ndarray[Any, Any] | tuple[Any, ...] | list[Any] | None = None) numpy.ndarray[Any, Any] | None

Getter for a data entry in the model object or provided data sources

Parameters:
variable

The variable name used as the data key.

target

The dimensions identifier for the output: FC.STATE_TURBINE, FC.STATE_TARGET, or FC.STATE_TARGET_TPOINT.

lookup

The order of data sources. Combination of: 's' for self, 'm' for mdata, 'f' for fdata, 't' for tdata, and 'w' for wake-modeling data.

mdata

The model data.

fdata

The farm data.

tdata

The target point data.

downwind_index

The index in the downwind order.

accept_none

Do not raise an error if the data entry is None.

accept_nan

Do not raise an error if the data entry is np.nan.

algo

The algorithm, needed for data from previous iterations.

upcast

Ensure the target dimensions are present. If expansion is needed, the result is a read-only broadcasted view.

selection

Apply this selection to the result, for state-turbine, state-target, or state-target-tpoint outputs.

index() list[int]

The index list

Returns:
indices

The index labels of states, or None for default integers

initialize(algo: foxes.core.algorithm.Algorithm, loaded_data: LoadedData | None = None, force: bool = False, verbosity: int = 0) LoadedData

Initialize the model.

Parameters:
algo

The calculation algorithm.

loaded_data

Data that has already been loaded, to be extended by this function. Keys are “coords”, a dict with entries dim_name_str -> dim_array; “data_vars”, a dict with entries name_str -> (dim_tuple, data_ndarray); and “extra_data”, a dict with non-array additional data.

force

Overwrite existing data.

verbosity

The verbosity level, where 0 is silent.

Returns:
loaded_data

The loaded data, containing the keys “coords”, “data_vars”, and “extra_data”.

load_chunk_data(algo: foxes.core.algorithm.Algorithm, *data: foxes.core.data.Data) None

Load chunk data according to the configured load mode.

This function adds data to the model data container.

Parameters:
algo

The calculation algorithm.

data

Input data, typically either (mdata, fdata) for farm calculations or (mdata, fdata, tdata) for point data calculations.

load_data(algo: foxes.core.Algorithm, loaded_data: foxes.core.LoadedData, force: bool = False, verbosity: int = 0) None[source]

Load and/or create all model data that is subject to chunking.

Such data should not be stored under self, for memory reasons. The data returned here will automatically be chunked and then provided as part of the mdata object during calculations.

Parameters:
algo

The calculation algorithm

loaded_data

Data that has already been loaded, to be extended by this function. It contains coordinate data, model variables, and additional data.

force

Overwrite existing data

verbosity

The verbosity level, 0 = silent

classmethod new(states_type: str, *args: Any, **kwargs: Any) States

Create a states instance at runtime.

Parameters:
states_type

The selected derived class name.

args

Additional positional arguments for the constructor.

kwargs

Additional keyword arguments for the constructor.

output_coords() tuple[str, ...]

Gets the coordinates of all output arrays

Returns:
dims

The coordinates of all output arrays

output_point_vars(algo: foxes.core.Algorithm) list[str][source]

The variables which are being modified by the model.

Parameters:
algo

The calculation algorithm

Returns:
output_vars

The output variable names

abstract reset(algo: foxes.core.algorithm.Algorithm | None = None, states_sel: slice | range | list[int] | None = None, states_loc: list[int] | None = None, verbosity: int = 0) None

Reset the states, optionally selecting a subset.

Parameters:
states_sel

State subset selection.

states_loc

State index selection via the pandas loc function.

verbosity

The verbosity level, where 0 is silent.

run_calculation(algo: foxes.core.algorithm.Algorithm, *data: tuple[Any, ...], out_vars: list[str], **calc_pars: Any) Any

Starts the model calculation in parallel.

Typically this function is called by algorithms.

Parameters:
algo

The calculation algorithm

*data

The input data

out_vars

The calculation output variables

**calc_pars

Additional arguments for the calculate function

Returns:
results

The calculation results

set_running(algo: foxes.core.Algorithm, data_stash: dict[str, dict[str, object]] | None, sel: dict[str, object] | None = None, isel: dict[str, object] | None = None, verbosity: int = 0) None[source]

Sets this model status to running, and moves all large data to stash.

The stashed data will be returned by the unset_running() function after running calculations.

Parameters:
algo

The calculation algorithm.

data_stash

Large data stash. This function adds data here if given.

sel

The subset selection dictionary.

isel

The index subset selection dictionary.

verbosity

The verbosity level, 0 = silent.

size() int[source]

The total number of states.

Returns:
int:

The total number of states

sub_models() list[Model]

Return the list of all sub-models.

Returns:
smdls

All sub-models.

unset_running(algo: foxes.core.Algorithm, data_stash: dict[str, dict[str, object]] | None, sel: dict[str, object] | None = None, isel: dict[str, object] | None = None, verbosity: int = 0) None[source]

Sets this model status to not running, recovering large data from stash

Parameters:
algo

The calculation algorithm.

data_stash

Reconstruct model data from this stash if given.

sel

The subset selection dictionary.

isel

The index subset selection dictionary.

verbosity

The verbosity level, 0 = silent.

unvar(vnm: str) str | None

Translate a model-specific variable name to the original variable name.

Parameters:
vnm

The model-specific variable name.

Returns:
v

The original variable name.

var(v: str) str

Create a model-specific variable name.

Parameters:
v

The variable name.

Returns:
vnm

The model-specific variable name.

fixed_vars
property initialized : bool

Initialization flag.

Returns:
initialized

True if the model has been initialized.

load_mode = 'preload'
property model_id : int

Unique id based on the model type.

Returns:
int

Unique id of the model object

name = 'Model'
property running : bool

Flag for currently running models

Returns:
running

True if currently running

scans
property shp : tuple[int, ...]

Shape of the scan states.

Returns:
shp

The shape of the scan states, i.e., the lengths of the scan arrays for each variable.