Skip to content

Conversation

@Bartdoekemeijer
Copy link
Collaborator

This PR is ready to be merged.

Feature or improvement description
Split interpolation into 2D and 3D grid, and general pandas improvements to replace manually adding rows with pd.concat() function. Significant speed-ups achieved.

Related issue, if one exists
N/A

Impacted areas of the software
floris_tools

Additional supporting information
Found a significant speed-up with in-house work. Found it hard to reproduce, but see code below:

Test results, if applicable
Here's a minimal example to reproduce:

import os
import numpy as np
import pandas as pd
from time import perf_counter as timerpc

from flasc.floris_tools import interpolate_floris_from_df_approx
from flasc.utilities_examples import load_floris_artificial as load_floris


if __name__ == "__main__":
    # Create fake df_fi_approx table
    wd_mesh, ws_mesh = np.meshgrid(
        np.arange(0.0, 360.0, 1.0),
        np.arange(1.0, 30.0, 1.0)
    )
    N = len(wd_mesh.flatten())
    fake_power = 1500.0 + 30.0 * np.random.randn(N, 100)
    df_fi_approx = pd.concat([
        pd.DataFrame(
            {
                "wd": wd_mesh.flatten(),
                "ws": ws_mesh.flatten(),
                "ti": 0.08 * np.ones_like(ws_mesh.flatten())}
        ),
        pd.DataFrame(fake_power, columns=[f"pow_{ti}" for ti in range(100)])
    ], axis=1)
    
    # Now interpolate from table
    N = int(1e8)  # Number of measurements
    df = pd.DataFrame(
        {
            "wd": 360.0 * np.random.uniform(N),
            "ws": 1.01 + 28.0 * np.random.uniform(N),
            "ti": 0.08 * np.ones(N),
        }
    )
    
    # Perform interpolation
    t0 = timerpc()
    df = interpolate_floris_from_df_approx(df, df_fi_approx, mirror_nans=False)
    dt = timerpc() - t0
    print(f"Completed 'interpolate_floris_from_df_approx' call in {dt:.3f} seconds.")

This times at 41 seconds with the new code, and 50 seconds in the old code. So about a 20% improvement in this simplified example. Found a factor 3-4 speed-up in my in-house codes though.

…nts to replace manually adding rows with pd.concat() function. Significant speed-ups achieved.
@misi9170 misi9170 added the enhancement An improvement of an existing feature label Dec 1, 2023
@misi9170 misi9170 self-requested a review December 1, 2023 22:45
Copy link
Collaborator

@misi9170 misi9170 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me---I've run a couple of examples and seen no issues, and happy to take your word for speed ups for your internal process. @paulf81, any objections? Otherwise, I think we can merge.

Sorry that we've left this sitting a while---bit of a hectic couple of months...

@paulf81
Copy link
Collaborator

paulf81 commented Dec 1, 2023

Yes, ok for me too to merge. Thank you for checking @misi9170 and thanks for the submission @Bartdoekemeijer

@misi9170 misi9170 merged commit 929b94a into NatLabRockies:develop Dec 4, 2023
@misi9170 misi9170 mentioned this pull request Dec 21, 2023
@misi9170 misi9170 mentioned this pull request Apr 10, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement An improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants