foxes_opt.pipelines.layout_pipelines

Classes

LayoutPipeline

Pipeline for layout generation.

Module Contents

class foxes_opt.pipelines.layout_pipelines.LayoutPipeline(base_dir: str, algo_pars: dict[str, Any], n_turbines: int, turbine_models: list[str], farm_boundary: foxes.utils.geom2d.AreaGeometry | None, states: foxes.core.States | None = None, mbook: foxes.ModelBook | None = None, farm_pars: dict[str, Any] | None = None, reset_table: bool = False, name: str = 'layout_pipeline', **kwargs: Any)[source]

Bases: iwopy.core.Pipeline

Pipeline for layout generation.

Parameters:
base_dir

Base directory for the self.

algo_pars

The parameters for the foxes algorithm

n_turbines

The number of turbines in the wind farm

turbine_models

The turbine models

farm_boundary

The wind farm boundary

states

The states to optimize the layout for

mbook

The model book to be used

farm_pars

Additional parameters for the wind farm

reset_table

Whether to reset the table file if it exists

name

The name of the pipeline

kwargs

Additional keyword arguments for the self.

add_stage(stage: PipelineStage) → None

Add a stage to the pipeline

Parameters:
stage

The stage to add

add_to_table(stage: iwopy.core.PipelineStage | str, success: bool, algo: foxes.core.Algorithm, farm_results: xarray.Dataset) → int[source]

Add the results of a stage to the table.

Parameters:
stage

The stage or the name of the stage

success

Whether the stage was successful

algo

The foxes algorithm instance

farm_results

The results of the wind farm simulation

Returns:
i

The index of the new row in the table

finalize(verbosity: int = 0) → None

Finalize the object.

Parameters:
verbosity

The verbosity level, 0 = silent

find_stage(stage_name: str) → int

Find the index of a stage by name

Parameters:
stage_name

The stage name

Returns:
stage_index

The stage index, or -1 if not found

get_algo(layout_xy: numpy.ndarray | None = None, farm: foxes.WindFarm | None = None, states: foxes.core.States | None = None, initialize: bool = True, force: bool = False, verbosity: int = 0, **kwargs: Any) → foxes.core.Algorithm[source]

Create an algorithm instance

Parameters:
layout_xy

The layout coordinates of the turbines, shape (n_turbines, 2)

farm

The wind farm instance, if None a new one will be created

states

The states to optimize the layout for, if None the states of the pipeline will be used

initialize

Whether to initialize the algorithm after creation

force

Whether to force re-initialization of the algorithm

verbosity

The verbosity level, 0 = silent

kwargs

Additional keyword arguments for the algorithm creation

Returns:
algo

The algorithm instance

get_stage(stage_index: int) → PipelineStage

Get a stage by index

Parameters:
stage_index

The stage index

Returns:
stage

The stage at the given index

initialize(verbosity: int = 0) → None

Initialize the object.

Parameters:
verbosity

The verbosity level, 0 = silent

read_layout(results: Any) → numpy.ndarray[source]

Read the layout coordinates from the results.

Parameters:
results

The results of the pipeline

Returns:
layout_xy

The layout coordinates of the turbines, shape (n_turbines, 2)

read_layout_index(layout_index: int, layout_dir: str | pathlib.Path = 'layouts') → numpy.ndarray[source]

Read a persisted pipeline layout by its numeric file suffix.

Files are matched as layout_<index>.csv by numeric suffix, so zero padding does not affect the match. The CSV must contain finite x and y columns and may contain an index column equal to 0, ..., n_turbines - 1.

Parameters:
layout_index

Non-negative numeric suffix of the layout file.

layout_dir

Existing layout directory. Relative paths are resolved below the pipeline base_dir; absolute paths are used unchanged.

Returns:
layout_xy

Turbine x/y coordinates in metres with shape (n_turbines, 2).

Raises:
TypeError

If layout_index is not an integer.

ValueError

If the index is negative, multiple files have the requested numeric suffix, or the CSV coordinates, columns, turbine indices, or shape are invalid.

FileNotFoundError

If no matching layout file exists.

run(start_stage: int = 0, end_stage: int | None = None, initial_layout: numpy.ndarray | None = None, restart_layout_index: int | None = None, restart_layout_dir: str | pathlib.Path = 'layouts', finalize: bool = True, layout_plot_pars: dict[str, Any] | None = None, layout_plot_pars_final: dict[str, Any] | None = None, verbosity: int = 1) → tuple[bool, tuple[Any, Any]][source]

Run selected layout stages from an optional initial layout.

A supplied or persisted layout is validated before stage execution and passed to the first selected stage as prev_results. Successful layout coordinates are evaluated with FOXES and written to the pipeline table and final layout outputs.

Parameters:
start_stage

Index of the first stage to run.

end_stage

Exclusive end index, or None to run through the final stage.

initial_layout

Initial turbine x/y coordinates with shape (n_turbines, 2), or None to use normal stage propagation. Mutually exclusive with restart_layout_index.

restart_layout_index

Persisted layout index supplied to the first selected stage, or None to use initial_layout or normal stage propagation.

restart_layout_dir

Directory containing persisted layouts. Relative paths are resolved below base_dir.

finalize

Whether to finalize the pipeline after stage execution.

layout_plot_pars

Additional parameters for intermediate and final layout plots.

layout_plot_pars_final

Parameters that override layout_plot_pars for the final plot.

verbosity

Verbosity level, where zero is silent.

Returns:
success

Whether all selected stages succeeded.

results

FOXES algorithm and farm results when the resulting layout can be evaluated; otherwise the propagated stage results and None.

Raises:
TypeError

If restart_layout_index is not an integer.

ValueError

If both initial-layout options are supplied, or if either layout or the restart index is invalid.

FileNotFoundError

If the requested restart layout does not exist.

run_foxes(layout_xy: numpy.ndarray | None = None, algo: foxes.core.Algorithm | None = None, farm: foxes.WindFarm | None = None, states: foxes.core.States | None = None, algo_pars: dict[str, Any] | None = None, initialize: bool = False, force: bool = True, verbosity: int = 0, **kwargs: Any) → tuple[foxes.core.Algorithm, Any][source]

Run the foxes algorithm.

Parameters:
layout_xy

The layout coordinates of the turbines, shape (n_turbines, 2)

algo

The foxes algorithm instance, if None a new one will be created

farm

The wind farm instance, if None a new one will be created

states

The states to optimize the layout for, if None the states of the pipeline will be used

algo_pars

Additional parameters for the foxes algorithm

verbosity

The verbosity level, 0 = silent

force

Whether to force the initialization of the algorithm

initialize

Whether to initialize the algorithm after creation

kwargs

Additional keyword arguments for the calc_farm method of the foxes algorithm

Returns:
algo

The foxes algorithm instance

farm_results

The results of the wind farm simulation

write_layout_csv(algo: foxes.core.Algorithm, farm_results: xarray.Dataset, table_index: int | None = None, final: bool = False) → None[source]

Write the layout coordinates to a CSV file.

Parameters:
algo

The foxes algorithm instance

farm_results

The results of the wind farm simulation

table_index

The index of the row in the table to use for naming the CSV file

final

Whether this is the final layout CSV file

write_layout_plot(algo: foxes.core.Algorithm, farm_results: xarray.Dataset, title: str | None = None, table_index: int | None = None, figsize: tuple[float, float] = (12, 8), show_flow: bool = True, resolution: float = 50.0, alpha: float = 0.6, annotate: int = 0, final: bool = False, **kwargs: Any) → None[source]

Write a plot of the layout and the farm results.

Parameters:
algo

The foxes algorithm instance

farm_results

The results of the wind farm simulation

plot_path

The path to save the plot

title

The title of the plot

figsize

The size of the figure

show_flow

Whether to show the flow field in the plot

resolution

The resolution of the flow field plot

alpha

The alpha value for the flow field plot

annotate

The turbine annotation level

final

Whether this is the final layout plot

kwargs

Additional farm layout plot parameters. These override the default turbine style shared with the layout callback.

write_table() → None[source]

Write the table to the file.

algo_pars
property base_dir : pathlib.Path

Get the base directory

Returns:
base_dir

The base directory

end_stage : int | None = None
farm_boundary
farm_pars
property initialized : bool

Flag for finished initialization

Returns:
initialized

True if initialization has been done

mbook
property n_stages : int

Get the number of stages

Returns:
n_stages

The number of stages

n_turbines
name = 'Base'
reset_table = False
property running : bool

Get whether the pipeline is currently running

Returns:
running

Whether the pipeline is currently running

property stage_index : int

Get the current stage index

Returns:
stage_index

The current stage index

property stage_names : list[str]

Get the stage names

Returns:
stage_names

The stage names

start_stage : int = 0
states = None
property table : pandas.DataFrame

The table of the pipeline.

Returns:
table

The table of the pipeline.

property table_path : pathlib.Path

The path to the table file.

Returns:
table_path

The path to the table file.

turbine_models