Postprocess OpenFAST results

# Add any possible locations of amr-wind-frontend here
amrwindfedirs = ['/projects/wind_uq/lcheung/amrwind-frontend/',
                 '/ccs/proj/cfd162/lcheung/amrwind-frontend/']
import sys, os, shutil, io
for x in amrwindfedirs: sys.path.insert(1, x)

import postproamrwindsample_xarray as ppsample
import postproengine as ppeng
import numpy as np
import pandas as pd

import matplotlib.pyplot as plt
%matplotlib inline
/ascldap/users/lcheung/.local/lib/python3.9/site-packages/pandas/core/computation/expressions.py:21: UserWarning: Pandas requires version '2.8.4' or newer of 'numexpr' (version '2.8.1' currently installed).
  from pandas.core.computation.check import NUMEXPR_INSTALLED
/ascldap/users/lcheung/.local/lib/python3.9/site-packages/pandas/core/arrays/masked.py:60: UserWarning: Pandas requires version '1.3.6' or newer of 'bottleneck' (version '1.3.4' currently installed).
  from pandas.core import (
# Load ruamel or pyyaml as needed
try:
    import ruamel.yaml as yaml
    print("# Loaded ruamel.yaml")
    useruamel=True
    loaderkwargs = {'Loader':yaml.RoundTripLoader}
    dumperkwargs = {'Dumper':yaml.RoundTripDumper, 'indent':4, 'default_flow_style':False} 
except:
    import yaml as yaml
    print("# Loaded yaml")
    useruamel=False
    loaderkwargs = {}
    dumperkwargs = {'default_flow_style':False }
    
if useruamel: Loader=yaml.load
else:         Loader=yaml.safe_load
# Loaded ruamel.yaml
def stringReplaceDict(s, dreplace):
    outstr = str(s)
    for k, g in dreplace.items():
        outstr=outstr.replace(k, g)
    return outstr
#rundir='/gpfs/lcheung/HFM/exawind-benchmarks/NREL5MW_ALM_BD_OFv400'
#RESULTSDIR='../results/OpenFAST_v40_out'

replacedict={'RUNDIR':'/pscratch/lcheung/HFM/exawind-benchmarks/NREL5MW_ALM_BD_OFv402_ROSCO.redo',
             'RESULTSDIR':'../results/OpenFAST_v402_out',
             'RESULTSOLDDIR':'../results/OpenFAST_out'
            }
yamlstring="""
globalattributes:
  verbose: False
  udfmodules: []
  executeorder:
  - openfast
  - plotcsv
  
trange: &trange [300, 900]   # Note: add 15,000 sec to get AMR-Wind time

openfast:
# For FSI case
- name: NREL5MW
  filename: RUNDIR/T0_NREL5MW_v402_ROSCO/openfast-cpp/5MW_Land_DLL_WTurb_cpp/5MW_Land_DLL_WTurb_cpp.out
  #filename: /nscratch/gyalla/HFM/exawind-benchmarks/amr-wind/NREL5MW_ALM_BD/runs/T0_NREL5MW_v402/openfast-cpp/5MW_Land_DLL_WTurb_cpp/5MW_Land_DLL_WTurb_cpp.out
  vars:
  - Time
  - GenPwr
  - RotThrust
  - RotTorq
  - RotSpeed
  - BldPitch1
  output_dir: RESULTSDIR
  csv:  # Store information to CSV files
    individual_files: False
  operate:
    operations: 
    - mean
    trange: *trange

plotcsv:
  - name: Power
    xlabel: 'Time [s]'
    ylabel: 'Power [kW]'
    title: 'Turbine power'
    figsize: [10,4]
    legendopts: {'loc':'upper right'}
    savefile: ../results/images/OpenFAST_T0_GenPwr.png
    csvfiles:
    - {'file':'RESULTSDIR/NREL5MW.csv', 'xcol':'Time', 'ycol':'GenPwr', 'lineopts':{'color':'b', 'lw':1, 'linestyle':'-', 'label':'NREL5MW ALM v4.0.2'}}    
    #- {'file':'RESULTSOLDDIR/NREL5MW.csv', 'xcol':'Time', 'ycol':'GenPwr', 'lineopts':{'color':'r', 'lw':1, 'linestyle':'--', 'label':'NREL5MW ALM v3.5.5'}}    
    
  - name: Thrust
    xlabel: 'Time [s]'
    ylabel: 'RotThrust [kN]'
    title: 'Turbine thrust'
    figsize: [10,4]
    legendopts: {'loc':'upper right'}
    savefile: ../results/images/OpenFAST_T0_RotThrust.png
    csvfiles:
    - {'file':'RESULTSDIR/NREL5MW.csv', 'xcol':'Time', 'ycol':'RotThrust', 'lineopts':{'color':'b', 'lw':1, 'linestyle':'-', 'label':'NREL5MW ALM v4.0.2'}}    
    #- {'file':'RESULTSOLDDIR/NREL5MW.csv', 'xcol':'Time', 'ycol':'RotThrust', 'lineopts':{'color':'r', 'lw':1, 'linestyle':'--', 'label':'NREL5MW ALM v3.5.5'}}    

  - name: RPM
    xlabel: 'Time [s]'
    ylabel: 'RPM [rpm]'
    title: 'Rotor speed'
    figsize: [10,4]
    legendopts: {'loc':'upper right'}
    savefile: ../results/images/OpenFAST_T0_RotSpeed.png
    csvfiles:
    - {'file':'RESULTSDIR/NREL5MW.csv', 'xcol':'Time', 'ycol':'RotSpeed', 'lineopts':{'color':'b', 'lw':1, 'linestyle':'-', 'label':'NREL5MW ALM v4.0.2'}}    
    #- {'file':'RESULTSOLDDIR/NREL5MW.csv', 'xcol':'Time', 'ycol':'RotSpeed', 'lineopts':{'color':'r', 'lw':1, 'linestyle':'--', 'label':'NREL5MW ALM v3.5.5'}}    

  - name: Pitch
    xlabel: 'Time [s]'
    ylabel: 'Pitch [deg]'
    title: 'Blade pitch'
    figsize: [10,4]
    legendopts: {'loc':'upper right'}
    savefile: ../results/images/OpenFAST_T0_BldPitch1.png
    csvfiles:
    - {'file':'RESULTSDIR/NREL5MW.csv', 'xcol':'Time', 'ycol':'BldPitch1', 'lineopts':{'color':'b', 'lw':1, 'linestyle':'-', 'label':'NREL5MW ALM v4.0.2'}}    
    #- {'file':'RESULTSOLDDIR/NREL5MW.csv', 'xcol':'Time', 'ycol':'BldPitch1', 'lineopts':{'color':'r', 'lw':1, 'linestyle':'--', 'label':'NREL5MW ALM v3.5.5'}}    

  - name: RotTorque
    xlabel: 'Time [s]'
    ylabel: 'Torque [kN-m]'
    title: 'Rotor Torque'
    figsize: [10,4]
    legendopts: {'loc':'upper right'}
    savefile: ../results/images/OpenFAST_T0_RotTorq.png
    csvfiles:
    - {'file':'RESULTSDIR/NREL5MW.csv', 'xcol':'Time', 'ycol':'RotTorq', 'lineopts':{'color':'b', 'lw':1, 'linestyle':'-', 'label':'NREL5MW ALM v4.0.2'}}    
    #- {'file':'RESULTSOLDDIR/NREL5MW.csv', 'xcol':'Time', 'ycol':'RotTorq', 'lineopts':{'color':'r', 'lw':1, 'linestyle':'--', 'label':'NREL5MW ALM v3.5.5'}}        

"""
f = io.StringIO(stringReplaceDict(yamlstring, replacedict))
yamldict = Loader(f, **loaderkwargs)
# Run the driver
ppeng.driver(yamldict, verbose=True)
Initialized openfast
Running openfast
NREL5MW /pscratch/lcheung/HFM/exawind-benchmarks/NREL5MW_ALM_BD_OFv402_ROSCO.redo/T0_NREL5MW_v402_ROSCO/openfast-cpp/5MW_Land_DLL_WTurb_cpp/5MW_Land_DLL_WTurb_cpp.out
Initialized csv inside NREL5MW
Executing csv
Initialized operate inside NREL5MW
Executing operate
Initialized plotcsv
Running plotcsv
Saving ../results/images/OpenFAST_T0_GenPwr.png
Saving ../results/images/OpenFAST_T0_RotThrust.png
Saving ../results/images/OpenFAST_T0_RotSpeed.png
Saving ../results/images/OpenFAST_T0_BldPitch1.png
Saving ../results/images/OpenFAST_T0_RotTorq.png
../../../../_images/98824342ecf70c886d47af8bb2229d52fc1bd33b4c5389dffe3ef5e1a7bcc853.png ../../../../_images/91aecae4ecf57a625cf3b0b05cc50b35882e6bee62a49a306e300c0d9fd298cc.png ../../../../_images/8030197dbfeeba55e2a117da415ec29c32c7fd56c124effd83023101db3be4f1.png ../../../../_images/da8adbd2a14b3a6aaf6d7ee24da106e910f453db88532136a709d57686ff9aeb.png ../../../../_images/b11e95af812c0233883e1610c44c44658e92b49ec7015b5ec47dad1125f916d4.png
# Write out the notebook to a python script
!jupyter nbconvert --to script OpenFAST_v40_Results.ipynb
with open('OpenFAST_v40_Results.py', 'r') as f:
    lines = f.readlines()
with open('OpenFAST_v40_Results.py', 'w') as f:
    for line in lines:
        if "'matplotlib', 'inline'" in line: line = 'plt.show(block=False)'
        if 'nbconvert --to script' in line:
            break
        else:
            f.write(line)
[NbConvertApp] Converting notebook OpenFAST_v40_Results.ipynb to script
[NbConvertApp] Writing 5669 bytes to OpenFAST_v40_Results.py