NREL / OpenOA

This library provides a framework for assessing wind plant performance using operational assessment (OA) methodologies that consume time series data from wind plants. The goal of the project is to provide an open source implementation of common data structures, analysis methods, and utility functions relevant to wind plant OA.
https://openoa.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
194 stars 63 forks source link

Attach analysis classes to `PlantData` #221

Closed RHammond2 closed 1 year ago

RHammond2 commented 1 year ago

This PR attaches the analysis classes to PlantData at the time of import, maintaining the same behavior as a standalone analysis class import. For example, the following two import patters produce the same results when used in an analysis.

from openoa import PlantData
from openoa.analysis import WakeLosses

project = PlantData(<kwargs>)

# Original pattern
wake_classic = WakeLosses(project)

# New, equivalent pattern
wake_new = project.WakeLosses()

This PR also closes #216. @charlie9578 does the proposed solution seem to align with the expectations from our conversation?

@jordanperr, let me know if the implemented pattern works for you. It turns out it was a little more tricky than I originally showed you, but I think it still works nicely because the openoa namespace stays highly limited now as well

This should be a fairly straightforward review with the demonstrated pattern implemented in the updated 05 example notebook

charlie9578 commented 1 year ago

Hi Rob, yes. I've just made a pull request for the Cubico Projects, which uses a "quick fix," but I think what you've done will work for me. Thanks, Charlie

codecov-commenter commented 1 year ago

Codecov Report

Patch coverage: 85.10% and project coverage change: +0.43 :tada:

Comparison is base (91fe859) 65.02% compared to head (4aa2dd2) 65.46%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop_v3 #221 +/- ## ============================================== + Coverage 65.02% 65.46% +0.43% ============================================== Files 24 24 Lines 3500 3573 +73 ============================================== + Hits 2276 2339 +63 - Misses 1224 1234 +10 ``` | [Impacted Files](https://codecov.io/gh/NREL/OpenOA/pull/221?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NREL) | Coverage Δ | | |---|---|---| | [openoa/plant.py](https://codecov.io/gh/NREL/OpenOA/pull/221?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NREL#diff-b3Blbm9hL3BsYW50LnB5) | `84.78% <ø> (ø)` | | | [openoa/analysis/electrical\_losses.py](https://codecov.io/gh/NREL/OpenOA/pull/221?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NREL#diff-b3Blbm9hL2FuYWx5c2lzL2VsZWN0cmljYWxfbG9zc2VzLnB5) | `79.54% <76.92%> (-0.30%)` | :arrow_down: | | [openoa/analysis/turbine\_long\_term\_gross\_energy.py](https://codecov.io/gh/NREL/OpenOA/pull/221?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NREL#diff-b3Blbm9hL2FuYWx5c2lzL3R1cmJpbmVfbG9uZ190ZXJtX2dyb3NzX2VuZXJneS5weQ==) | `77.53% <78.57%> (+0.01%)` | :arrow_up: | | [openoa/analysis/eya\_gap\_analysis.py](https://codecov.io/gh/NREL/OpenOA/pull/221?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NREL#diff-b3Blbm9hL2FuYWx5c2lzL2V5YV9nYXBfYW5hbHlzaXMucHk=) | `93.44% <83.33%> (-1.21%)` | :arrow_down: | | [openoa/analysis/wake\_losses.py](https://codecov.io/gh/NREL/OpenOA/pull/221?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NREL#diff-b3Blbm9hL2FuYWx5c2lzL3dha2VfbG9zc2VzLnB5) | `86.80% <84.21%> (-0.01%)` | :arrow_down: | | [openoa/analysis/aep.py](https://codecov.io/gh/NREL/OpenOA/pull/221?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NREL#diff-b3Blbm9hL2FuYWx5c2lzL2FlcC5weQ==) | `85.87% <86.20%> (+0.09%)` | :arrow_up: | | [openoa/\_\_init\_\_.py](https://codecov.io/gh/NREL/OpenOA/pull/221?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NREL#diff-b3Blbm9hL19faW5pdF9fLnB5) | `100.00% <100.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

jordanperr commented 1 year ago

This pull request implements custom constructors for the analysis classes MonteCarloAEP, EYAGapAnalysis, ElectricalLosses, TurbineLongTermGrossEnergy, and WakeLosses and attaches them as attributes of the PlantData class dynamically using setattr in the init script of the OpenOA module.

I found that the correct docstrings and function signatures can be accessed for a PlantData object in Jupyter Nobteook through the Shift-Tab shortcut. The Control-Space shortcut doesn't work in VSCode's Jupyter Notebook extension. Additionally, the docs are not visible when developing code statically (e.g., in a script, outside of Jupyter).

I think this pull request can be merged as-is, but we must be aware of these limitations.

In Jupyter:

Screenshot 2023-02-20 at 9 28 22 AM

In VSCode:

VSCode_nodocs

Statically, Validate() method supports auto-complete:

Screenshot 2023-02-20 at 9 33 54 AM

... but MonteCarloAEP does not:

Screenshot 2023-02-20 at 9 33 08 AM