NREL / flasc

A rich floris-driven suite for SCADA analysis
https://nrel.github.io/flasc/
BSD 3-Clause "New" or "Revised" License
31 stars 18 forks source link

Bugfix: Add additional outputs to floris_tools.calc_floris_approx_table() #46

Closed Bartdoekemeijer closed 1 year ago

Bartdoekemeijer commented 1 year ago

This PR is ready to be merged.

Feature or improvement description Currently, on the main branch the example generate_demo_dataset.py fails on line 121 with:

Exception has occurred: KeyError
'wd_000'

The above exception was the direct cause of the following exception:

  File "/mnt/c/Users/Bart.Doekemeijer/OneDrive - Shell/Documents/python_scripts/flasc/examples/demo_dataset/generate_demo_dataset.py", line 121, in <module>
    df_fi["wd_{:03d}".format(ti)] += 3.0 * np.random.randn(df_fi.shape[0])

This is because of a modification that I think I made during the updates from FLORIS v2 to FLORIS v3.

Related issue, if one exists I haven't opened a separate issue, but see above.

Impacted areas of the software floris_tools

Additional supporting information I have expanded the function calc_floris_approx_table to also output the turbine inflow wind direction, wind speed and TI, if desired. This functionality was previously removed.

Test results, if applicable This is what the output of calc_floris_approx_table looks like after the update:

df_approx
          wd    ws    ti  pow_000     ws_000  wd_000  ti_000  pow_001     ws_001  wd_001  ti_001  pow_002     ws_002  wd_002  ti_002  ...     ws_003  wd_003  ti_003  pow_004     ws_004  wd_004  ti_004  pow_005     ws_005  wd_005  ti_005  pow_006     ws_006  wd_006  ti_006
0        0.0   0.0  0.03      NaN        NaN     0.0     NaN      NaN        NaN     0.0     NaN      NaN        NaN     0.0     NaN  ...        NaN     0.0     NaN      NaN        NaN     0.0     NaN      NaN        NaN     0.0     NaN      NaN        NaN     0.0     NaN
1        3.0   0.0  0.03      NaN        NaN     3.0     NaN      NaN        NaN     3.0     NaN      NaN        NaN     3.0     NaN  ...        NaN     3.0     NaN      NaN        NaN     3.0     NaN      NaN        NaN     3.0     NaN      NaN        NaN     3.0     NaN
2        6.0   0.0  0.03      NaN        NaN     6.0     NaN      NaN        NaN     6.0     NaN      NaN        NaN     6.0     NaN  ...        NaN     6.0     NaN      NaN        NaN     6.0     NaN      NaN        NaN     6.0     NaN      NaN        NaN     6.0     NaN
3        9.0   0.0  0.03      NaN        NaN     9.0     NaN      NaN        NaN     9.0     NaN      NaN        NaN     9.0     NaN  ...        NaN     9.0     NaN      NaN        NaN     9.0     NaN      NaN        NaN     9.0     NaN      NaN        NaN     9.0     NaN
4       12.0   0.0  0.03      NaN        NaN    12.0     NaN      NaN        NaN    12.0     NaN      NaN        NaN    12.0     NaN  ...        NaN    12.0     NaN      NaN        NaN    12.0     NaN      NaN        NaN    12.0     NaN      NaN        NaN    12.0     NaN
...      ...   ...   ...      ...        ...     ...     ...      ...        ...     ...     ...      ...        ...     ...     ...  ...        ...     ...     ...      ...        ...     ...     ...      ...        ...     ...     ...      ...        ...     ...     ...
32395  345.0  26.0  0.30      0.0  25.880843   345.0     0.3      0.0  25.880940   345.0     0.3      0.0  25.880813   345.0     0.3  ...  25.881165   345.0     0.3      0.0  25.881165   345.0     0.3      0.0  25.881165   345.0     0.3      0.0  25.881165   345.0     0.3
32396  348.0  26.0  0.30      0.0  25.880781   348.0     0.3      0.0  25.880850   348.0     0.3      0.0  25.880734   348.0     0.3  ...  25.881165   348.0     0.3      0.0  25.881165   348.0     0.3      0.0  25.881165   348.0     0.3      0.0  25.881165   348.0     0.3
32397  351.0  26.0  0.30      0.0  25.880755   351.0     0.3      0.0  25.880770   351.0     0.3      0.0  25.880690   351.0     0.3  ...  25.881165   351.0     0.3      0.0  25.881165   351.0     0.3      0.0  25.881165   351.0     0.3      0.0  25.881165   351.0     0.3
32398  354.0  26.0  0.30      0.0  25.880772   354.0     0.3      0.0  25.880721   354.0     0.3      0.0  25.880692   354.0     0.3  ...  25.881165   354.0     0.3      0.0  25.881165   354.0     0.3      0.0  25.881165   354.0     0.3      0.0  25.881165   354.0     0.3
32399  357.0  26.0  0.30      0.0  25.880829   357.0     0.3      0.0  25.880716   357.0     0.3      0.0  25.880740   357.0     0.3  ...  25.881165   357.0     0.3      0.0  25.881165   357.0     0.3      0.0  25.881165   357.0     0.3      0.0  25.881165   357.0     0.3

[32400 rows x 31 columns]

where clearly, we see the additional columns wd_000, ws_000, ti_000, and so on. This resolves the error.

paulf81 commented 1 year ago

hi @Bartdoekemeijer , I checked out this branch and the main example ran fine (thanks for fixing!) so I say merge, work for you @misi9170 ?

misi9170 commented 1 year ago

UPDATED:

Hi @Bartdoekemeijer, I can confirm recreation of the original issue on main and am happy that this fixes the problem. I think we can merge.

There are a number of pandas warnings that get spewed out when I run generate_demo_dataset.py, but that probably belongs in a separate issue.

Bartdoekemeijer commented 1 year ago

UPDATED:

Hi @Bartdoekemeijer, I can confirm recreation of the original issue on main and am happy that this fixes the problem. I think we can merge.

There are a number of pandas warnings that get spewed out when I run generate_demo_dataset.py, but that probably belongs in a separate issue.

Thanks for double checking! I think the other warnings you mention are related to similar issues as the df_downsample function. We could revise this at some point, but since it's just an example file perhaps less urgent. I'll merge it in now!

paulf81 commented 1 year ago

Thank you!