reskit#

Submodules#

Attributes#

Classes#

OffshoreParameters

This class holds all offshore-wind specific techno-economic base parameter

OnshoreParameters

This class holds all onshore-wind specific techno-economic base parameter

WorkflowManager

The WorkflowManager class assists with the construction of more specialized WorkflowManagers,

WorkflowQueue

The WorkflowQueue object allows for the queueing of multiple RESKit workflow simulations

Functions#

distribute_workflow(workflow_function, placements[, ...])

Distributes a RESKit simulation workflow across multiple CPUs

execute_workflow_iteratively(workflow, ...[, zoom])

The function executes the indicated workflow iteratively, iterating over weather tiles. The appropriate weather

load_workflow_result(datasets[, loader, sortby])

Package Contents#

reskit.TEST_DATA#
class reskit.OffshoreParameters(fp=None, year=2050, constant_rotor_diam=True, **kwargs)#

Bases: Parameters

This class holds all offshore-wind specific techno-economic base parameter assumptions as static attributes as well as specific methods to manipulate offshore parameters.

distance_to_busnumeric or array-like, optional

Distance from the wind farm’s bus in km from the turbine’s location.

foundationstr or array-like of strings, optional

Turbine’s foundation type. Accepted types are: “monopile”, “jacket”, “semisubmersible” or “spar”, by default “monopile”

mooring_countnumeric, optional

Refers to the number of mooring lines are there attaching a turbine only applicable for floating foundation types. By default 3 assuming a triangular attachment to the seafloor.

anchorstr, optional

Turbine’s anchor type only applicable for floating foundation types, by default as recommended by [1]. Arguments accepted are “dea” (drag embedment anchor) or “spa” (suction pile anchor).

turbine_countnumeric, optional

Number of turbines in the offshore windpark. CSM valid for the range [3-200], by default 80

turbine_spacingnumeric, optional

Spacing distance in a row of turbines (turbines that share the electrical connection) to the bus. The value must be a multiplier of rotor diameter. CSM valid for the range [4-9], by default 5

turbine_row_spacingnumeric, optional

Spacing distance between rows of turbines. The value must be a multiplier of rotor diameter. CSM valid for the range [4-10], by default 9

Initializes an instance of the OffshoreParameters class.

mand_args = ['base_capacity', 'base_hub_height', 'base_rotor_diam', 'reference_wind_speed',...#
opt_args#
constant_rotor_diam = True#
class reskit.OnshoreParameters(fp=None, year=2050, constant_rotor_diam=True, **kwargs)#

Bases: Parameters

This class holds all onshore-wind specific techno-economic base parameter assumptions as static attributes as well as specific methods to manipulate onshore parameters.

constant_rotor_diambool, optional

Whether the rotor diameter is maintained constant or not, by default True

base_capacitynumeric or array_like, optional

Baseline turbine capacity in kW, by default 4200.

base_hub_heightnumeric or array_like, optional

Baseline turbine hub height in m, by default 120.

base_rotor_diamnumeric or array_like, optional

Baseline turbine rotor diameter in m, by default 136.

reference_wind_speednumeric, optional

Average wind speed corresponding to the baseline turbine design, by default 6.7.

min_tip_heightnumeric, optional.

Minimum distance in m between the lower tip of the blades and the ground, by default 20.

min_specific_powernumeric, optional

Minimum specific power allowed in kw/m2, by default 180.

base_capexnumeric, optional

The baseline turbine’s capital costs in €, by default 1100*4200 [€/kW * kW] #TODO change to

tcc_sharefloat, optional

The baseline turbine’s TCC percentage contribution in the total cost, by default 0.673

bos_sharefloat, optional

The baseline turbine’s BOS percentage contribution in the total cost, by default 0.229

Initializes an instance of the OnshoreParameters class.

mand_args = ['base_capacity', 'base_hub_height', 'base_rotor_diam', 'reference_wind_speed',...#
opt_args#
constant_rotor_diam = True#
base_capex#
class reskit.WorkflowManager(placements)#

The WorkflowManager class assists with the construction of more specialized WorkflowManagers, such as the WindWorkflowManager or the SolarWorkflowManager. In addition to providing the general structure for simulation workflow management, the WorkflowManager also defines functionalities which should be common across all WorkflowManagers.

This includes:
  • Basic initialization

  • Time domain management

  • Reading weather data

  • Adjusting variables by a long-run-average value

  • Applying simple loss factors

  • Saving the state of WorkflowManagers to XArray datasets, either in memory or on disc

Initialization:#

WorkflowManager( placements )

placements#
locs = None#
ext#
sim_data#
time_index = None#
workflow_parameters#
set_time_index(times)#

Sets the time index of the WorkflowManager

Parameters:

times (pd.DatetimeIndex) – The timesteps to use throughout the WorkflowManager’s life cycle. The length of this dataset must match the shape of data which is loaded into the WorkflorManager.sim_data member.

_set_sim_shape()#
extract_raster_values_at_placements(raster, **kwargs)#

Extracts pixel values at each of the configured placements from the specified raster file

read(variables, source_type, source, set_time_index=False, spatial_interpolation_mode='bilinear', temporal_reindex_method='nearest', time_index_from=None, **kwargs)#

Reads the specified variables from the NetCDF4-style weather dataset, and then extracts those variables for each of the coordinates configured in .placements. The resulting data is then available in .sim_data.

Parameters:
  • variables (str or list of strings) – The variables (or variables) to be read from the specified source - If a path to a weather source is given, then only the ‘standard’ variables configured for that source type are available (see the doc string for the weather source you are interested in) - If either ‘elevated_wind_speed’ or ‘surface_wind_speed’ is included in the variable list, then the members .elevated_wind_speed_height and .surface_wind_speed_height, respectfully, are also added. These are constants which specify what the ‘native’ wind speed height is, which depends on the source - A pre-loaded NCSource can also be given, thus allowing for any variable in the source to be specified in the variables list. But the user needs to take care of initializing the NCSource and loading the data they want

  • source_type (str) – The type of weather datasource which is to be loaded. Can be one of: “ERA5”, “SARAH”, “MERRA”, or ‘user’ - If a pre-loaded NCSource is given for the source object, then the source_type should be “user”

  • source (str or rk.weather.NCSource) – The source to read weather variables from

  • set_time_index (bool, optional) – If True, instructs the workflow manager to set the time index to that which is read from the weather source - By default False

  • spatial_interpolation_mode (str, optional) – The spatial interpolation mode to use while reading data from the weather source at each of the placement coordinates - By default “bilinear”

  • temporal_reindex_method (str, optional) – In the event of missing data, this algorithm is used to fill in the missing data. - Can be, for example, “nearest”, “ffill”, “bfill”, “interpolate” - By default “nearest”

Returns:

Returns the invoking WorkflowManager (for chaining)

Return type:

WorkflowManager

Raises:
  • RuntimeError – If set_time_index is False but no .time_index exists

  • RuntimeError – If source_type is unknown

get_scalar_values_from_raster(fp, spatial_interpolation, points=None)#

Auxiliary function to extract raster values with NaN fallback options.

adjust_variable_to_long_run_average(variable, source_long_run_average, real_long_run_average, real_lra_scaling=1, spatial_interpolation='linear-spline', nodata_fallback='nan', nodata_fallback_scaling=1, allow_nans=True)#

Adjusts the average mean of the specified variable to a known long-run-average

Note:#

uses the equation: variable[t] = variable[t] * real_long_run_average / source_long_run_average

param variable:

The variable to be adjusted

type variable:

str

param source_long_run_average:

The variable’s native long run average (the average in the weather file) - If a string is given, it is expected to be a path to a raster file which can be used to look up the average values from using the coordinates in .placements - If a numpy ndarray (or derivative) is given, the shape must be one of (time, placements) or at least (placements)

type source_long_run_average:

Union[str, float, np.ndarray]

param real_long_run_average:

The variables ‘true’ long run average - If a string is given, it is expected to be a path to a raster file which can be used to look up the average values from using the coordinates in .placements - If a numpy ndarray (or derivative) is given, the shape must be one of (time, placements) or at least (placements)

type real_long_run_average:

Union[str, float, np.ndarray]

param real_lra_scaling:

An optional scaling factor to apply to the values derived from real_long_run_average. - This is primarily useful when real_long_run_average is a path to a raster file - By default 1

type real_lra_scaling:

float, optional

param spatial_interpolation:

When either source_long_run_average or real_long_run_average are a path to a raster file, this input specifies which interpolation algorithm should be used - Options are: “near”, “linear-spline”, “cubic-spline”, “average” - By default “linear-spline” - See for more info: geokit.raster.interpolateValues

type spatial_interpolation:

str, optional

param nodata_fallback:

When real_long_run_average has no data, one can decide between different fallback options, by default np.nan: - np.nan or None : return np.nan for missing values in real_long_run_average - float : Apply this float value as a scaling factor for all no-data locations only: source_long_run_average * nodata_fallback. NOTE: A value of 1.0 will return the source lra value in case of missing real lra values (no additional nodata_fallback_scaling applied). - str : Will be interpreted as a filepath to a raster with alternative real_long_run_average values, scaled by nodata_fallback_scaling. - callable : any callable method taking the arguments (all iterables): ‘locs’ and ‘source_long_run_average_value’ (the locations as gk.geom.point objects and original value from source data). The output values will be considered as the new real_long_run_average for missing locations only (absolute data, no additional nodata_fallback_scaling applied).

NOTE: np.nan will also be returned in case that the nodata fallback does not yield values either.

type nodata_fallback:

float, str, callable, optional

param nodata_fallback_scaling:

An optional scaling factor to apply to the values derived from nodata_fallback. - This is primarily useful when nodata_fallback is a path to a raster file - By default 1

type nodata_fallback_scaling:

float

param allow_nans:

If True, NaN values may remain after scaling, else an error will raised. By default True.

type allow_nans:

boolean, optional

returns:

Returns the invoking WorkflowManager (for chaining)

rtype:

WorkflowManager

Parameters:
  • variable (str)

  • source_long_run_average (Union[str, float, numpy.ndarray])

  • real_long_run_average (Union[str, float, numpy.ndarray])

  • real_lra_scaling (float)

  • spatial_interpolation (str)

  • nodata_fallback (str)

  • nodata_fallback_scaling (float)

  • allow_nans (bool)

spatial_disaggregation(variable, source_high_resolution, source_low_resolution, real_lra_scaling=1, spatial_interpolation='linear-spline')#

[summary]

Parameters:
  • variable (str) – [description]

  • source_long_run_average (Union[str, float, np.ndarray]) – [description]

  • real_long_run_average (Union[str, float, np.ndarray]) – [description]

  • real_lra_scaling (float, optional) – [description], by default 1

  • spatial_interpolation (str, optional) – [description], by default “linear-spline”

  • source_high_resolution (Union[str, float, numpy.ndarray])

  • source_low_resolution (Union[str, float, numpy.ndarray])

apply_loss_factor(loss, variables=['capacity_factor'])#

Applies a loss factor onto a specified variable

Parameters:
  • loss (Union[float, np.ndarray, FunctionType]) – The loss factor(s) to be applied - If a float or a numpy ndarray is given, then the following operation is performed: > variable = variable * (1 - loss) - If a function is given, then the following operation is performed: > variable = variable * (1 - loss(variable) ) - If a numpy ndarray is given, it must be broadcastable to the variable’s shape in .sim_data

  • variables (Union[str, List[str]], optional) – The variable or variables to apply the loss factor to - By default [“capacity_factor”]

Returns:

Returns the invoking WorkflowManager (for chaining)

Return type:

WorkflowManager

register_workflow_parameter(key, value)#

Add a parameter to the WorkflowManager which will be included in the output XArray dataset

Parameters:
  • key (str) – The workflow parameter’s access key

  • value (Union[str,float]) – The workflow parameter’s value. Only strings and floats are allowed

to_xarray(output_netcdf_path=None, output_variables=None, custom_attributes=None, _intermediate_dict=False)#

Generates an XArray dataset from the data currently contained in the WorkflowManager

Note: - The .placements data is automatically added to the XArray dataset along the ‘locations’ dimension - The workflow_parameters data is automatically added as dimensionless variables - The .sim_data is automatically added along the dimensions (time, locations) - The .time_index is automatically added along the dimension ‘time’

Parameters:
  • output_netcdf_path (str, optional) – If given, the XArray dataset will be written to disc at the specified path - By default None

  • output_variables (List[str], optional) – If given, specifies the variables which should be included in the resulting dataset. Otherwise all suitable variables found in .placements, .workflow_parameters, .sim_data, and .time_index will be included - Only variables of numeric or string type are suitable due to NetCDF4 limitations - By default None

  • custom_attributes (dict, optional) – If given, adds the key-value pairs as attributes to the XArray dataset - These will be added in addition to the workflow_parameters - By default None

Returns:

The resulting XArray dataset

Return type:

xarray.Dataset

to_netcdf(xds, output_netcdf_path=None, output_variables=None, custom_attributes=None, _intermediate_dict=False)#

Saves an XArray dataset to netCDF4 format

Note: - The .placements data is automatically added to the XArray dataset along the ‘locations’ dimension - The workflow_parameters data is automatically added as dimensionless variables - The .sim_data is automatically added along the dimensions (time, locations) - The .time_index is automatically added along the dimension ‘time’

Parameters:
  • xds (xarray.Dataset) – The XArray dataset to save

  • output_netcdf_path (str) – If given, the XArray dataset will be written to disc at the specified path - By default None

  • output_variables (List[str], optional) – If given, specifies the variables which should be included in the resulting dataset. Otherwise all suitable variables found in .placements, .workflow_parameters, .sim_data, and .time_index will be included - Only variables of numeric or string type are suitable due to NetCDF4 limitations - By default None

  • custom_attributes (dict, optional) – If given, adds the key-value pairs as attributes to the XArray dataset before saving - These will be added in addition to existing attributes - By default None

Returns:

The resulting output_netcdf_path

Return type:

output_netcdf_path

Parameters:

placements (pandas.DataFrame)

class reskit.WorkflowQueue(workflow, **kwargs)#

The WorkflowQueue object allows for the queueing of multiple RESKit workflow simulations which are then executed in parallel

Initialize:#

WorkflowFunction( workflow:FunctionType, **kwargs )

param workflow:

type workflow:

FunctionType

param The workflow function to be parallelized:

param - All RESKit workflow functions should be suitable here:

param - Don’t forget that that all inputs required for the workflow function are still required:

:param : :param and are passed on either as constants through kwargs specified in the initializer: :param or: :param else in the subsequent ‘’.append(…)’’ calls: :param **kwargs: All key word arguments are passed on as constants to each simulation

Use these to set the required arguments for the given workflow

workflow#
constants#
queue#
append(key, **kwargs)#

Appends a simulation set the current queue

Parameters:
  • key (str) – The access key to use for this simulation set

  • **kwargs – All other keyword arguments are passed on to the simulation for only this simulation

execute(jobs=1)#

Executes all of the simulation sets that are currently in the queue

Parameters:

jobs (int, optional) – The number of parallel jobs, by default 1

Returns:

The results of each simulation set, accessible via their access keys

Return type:

OrderedDict[xarray.Dataset]

Parameters:

workflow (types.FunctionType)

reskit.distribute_workflow(workflow_function, placements, jobs=2, max_batch_size=None, intermediate_output_dir=None, **kwargs)#

Distributes a RESKit simulation workflow across multiple CPUs

Parallelism is achieved by breaking up the placements dataframe into placement groups via

KMeans grouping

Parameters:
  • workflow_function (FunctionType) – The workflow function to be parallelized - All RESKit workflow functions should be suitable here - If you want to make your own function, the only requirement is that its first argument should be a pandas DataFrame in the form of a placements table (i.e. has a ‘lat’ and ‘lon’ column) - Don’t forget that that all inputs required for the workflow function are still required, and are passed on as constants through any specified kwargs

  • placements (pandas.DataFrame) – A DataFrame describing the placements to be simulated For example, if you are simulating wind turbines, the following columns are likely required: [‘lon’,’lat’,’capacity’,’hub_height’,’rotor_diam’,]

  • jobs (int, optional) – The number of parallel jobs - By default 2

  • max_batch_size (int, optional) – If given, limits the maximum number of total placements which are simulated in parallel - Use this to reduce the memory requirements of the simulations (in turn increasing overall simulation time) - By default None

  • intermediate_output_dir (str, optional) – In case of very large outputs (which are too large to be joined into a singular XArray dataset), use this to write the individual simulation results to the specified directory - By default None

  • **kwargs – All all key word arguments are passed on as constants to each simulation - Use these to set the required arguments for the given workflow_function

Returns:

An XArray Dataset which contains the combined results of the distributed simulations

Return type:

xarray.Dataset

reskit.execute_workflow_iteratively(workflow, weather_path_varname, zoom=None, **workflow_args)#

The function executes the indicated workflow iteratively, iterating over weather tiles. The appropriate weather tile per placement is extracted automatically and placements are batched together based on weather tile.

workflowRESkit workflow

Callable workflow function, e.g. reskit.wind.wind_era5_2023

weather_path_varnamestr

Str formatted name of the weather path variable in this workflow, e.g. ‘era5_path’ for reskit.wind.wind_era5_2023. Must must be a key of workflow_args.

zoomint, optional

The zoom level of the weather tiles, required only if <X-TILE> or <Y-TILE> in weather path.

**workflow_args

Passed on to the workflow specified above. Must contain ‘’placements’’ and the above weather_path_varname as keys.

reskit.load_workflow_result(datasets, loader=xarray.load_dataset, sortby='location')#