Postpro Module
Plotting and post-pro functions.
TODO: Needs refactor
- farmnet.postpro.attention_weights(attention_tuple: tuple, dataset)[source]
Visualize attention weights from a graph neural network using a directed graph and a heatmap.
This function draws a directed network graph showing turbine nodes and edges, with edge labels representing attention weights. It also creates a heatmap of the attention matrix. Two plots are saved to the experiment_plots directory: - graph.png: A network diagram with labeled edge weights. - heatmap.png: A matrix heatmap of attention values.
- Parameters:
attention_tuple (tuple) – A tuple containing: - edge_index: A 2xE tensor of edge indices, - attention_weights: A Ex1 tensor of attention scores for each edge.
dataset (list) – A list of graph data objects. Only the first element is used, and its .pos attribute provides turbine coordinates.
- Returns:
None
- Return type:
None
- farmnet.postpro.get_wind_direction(u: float, v: float)[source]
Calculate the wind direction angle based on the wind’s u and v components.
The function rotates the wind vector by -270 degrees to align with a standard reference frame and computes the angle between the rotated vector and the north (0, 1) direction. The returned angle is in degrees, with an adjustment depending on the sign of the v component.
- Parameters:
u (float) – The u-component (east-west) of the wind vector.
v (float) – The v-component (north-south) of the wind vector.
- Returns:
Wind direction in degrees.
- Return type:
float
Example
>>> round(get_wind_direction(1.0, 0.0), 2) np.float64(0.0) >>> round(get_wind_direction(0.0, 1.0), 2) np.float64(90.0) >>> round(get_wind_direction(-1.0, 0.0), 2) np.float64(180.0) >>> round(get_wind_direction(0.0, -1.0), 2) np.float64(270.0) >>> round(get_wind_direction(0.0, 0.0), 2) np.float64(nan)
- farmnet.postpro.plot_power_curves(model, dataset, meas: bool = False, prefix: str | None = None)[source]
Plot predicted and optionally measured power curves for each turbine in the dataset.
This function generates a scatter plot of wind speed versus predicted power output for each turbine. If meas is True, it also plots the measured power output for comparison. The plots are saved as PNG files.
- Parameters:
model (torch.nn.Module) – The trained model used to predict power output. It should take (x, edge_index, edge_attr) as input.
dataset (list) – A list of data objects, each containing node features x, edge information, and optionally labels y.
meas (bool, optional) – If True, measured values are also plotted. Default is False.
prefix (str or None, optional) – A prefix for the output filenames. If None, no prefix is used.
- Returns:
None
- Return type:
None
- farmnet.postpro.plot_power_diff(model, dataset, wtg_1: int, wtg_2: int, meas: bool = False, prefix: str | None = None)[source]
Plot the power output difference between two wind turbines as a function of wind direction.
This function considers wtg_1 as the upstream turbine and wtg_2 as the downstream turbine. It computes and plots the difference in power output predicted by the model and optionally the measured difference if meas=True. Smoothed rolling averages are also plotted to show trends.
The resulting plot is saved as a PNG file.
- Parameters:
model (torch.nn.Module) – A trained model used to predict power output. The model should accept (x, edge_index, edge_attr) as input.
dataset (list) – A list of data objects, each containing wind turbine features, edge connections, and possibly labels.
wtg_1 (int) – Index of the upstream wind turbine.
wtg_2 (int) – Index of the downstream wind turbine.
meas (bool, optional) – If True, measured power output differences are included in the plot. Default is False.
prefix (str or None, optional) – Optional prefix for the output filename. If None, no prefix is used.
- Returns:
None
- Return type:
None