From 91b979a0adfc8b65bb2c12889114bac3c30c509d Mon Sep 17 00:00:00 2001 From: Nikhar Abbas Date: Wed, 6 Nov 2019 12:06:54 -0700 Subject: [PATCH] Plot OpenFAST outputs --- Examples/example_10.py | 27 +++++++++++++++++ ROSCO_toolbox/utilities.py | 59 ++++++++++++++++++++++++++++++++++---- 2 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 Examples/example_10.py diff --git a/Examples/example_10.py b/Examples/example_10.py new file mode 100644 index 000000000..3306fb88f --- /dev/null +++ b/Examples/example_10.py @@ -0,0 +1,27 @@ +# example_10.py +# Plot OpenFAST output data + +import numpy as np +import matplotlib.pyplot as plt +import os +from ROSCO_toolbox import utilities as wtc_utilities + +# Instantiate fast_IO +FAST_IO = wtc_utilities.FAST_IO() + +# Define openfast output filenames +filenames = ["/Users/nabbas/Documents/TurbineModels/IEA-15-240-RWT/OpenFAST/IEA-15-240-RWT.out", + "/Users/nabbas/Documents/TurbineModels/DTU_10MW/DTU10MWRWT/Baseline/DTU_10MW_RWT.out"] + # "/Users/nabbas/Documents/TurbineModels/IEA-15-240-RWT/OpenFAST/IEA-15-240-RWT.outb"] + +# Load output info and data +allinfo, alldata = FAST_IO.load_output(filenames) + +# Define Plot cases +# - Comment,uncomment, create, and change these as desired... +cases = {} +cases['Baseline'] = ['Wind1VelX', 'BldPitch1', 'GenTq', 'RotSpeed', 'GenPwr'] +cases['RotPerf'] = ['RtTSR', 'RtAeroCp'] + +# Plot, woohoo! +FAST_IO.plot_fast_out(cases, allinfo, alldata) \ No newline at end of file diff --git a/ROSCO_toolbox/utilities.py b/ROSCO_toolbox/utilities.py index 27694ef36..7dadd2965 100644 --- a/ROSCO_toolbox/utilities.py +++ b/ROSCO_toolbox/utilities.py @@ -12,6 +12,9 @@ import datetime import os import numpy as np +import matplotlib.pyplot as plt +from itertools import takewhile +import struct # Some useful constants now = datetime.datetime.now() @@ -21,7 +24,7 @@ rpm2RadSec = 2.0*(np.pi)/60.0 RadSec2rpm = 60/(2.0 * np.pi) -class UseOpenFAST(): +class FAST_IO(): ''' A collection of utilities that may be useful for using the tools made accessbile in this toolbox with OpenFAST @@ -33,6 +36,7 @@ class UseOpenFAST(): plot_fast_out load_output load_ascii_output + ''' def __init__(self): pass @@ -61,17 +65,62 @@ def run_openfast(self,fast_dir,fastcall='OpenFAST',fastfile=None,): # save starting file path -- note: This is an artifact of needing to call OpenFAST from the same directory as DISCON.IN original_path = os.getcwd() - # change path, run sim + # change path, run OpenFAST os.chdir(fast_dir) os.system('{} {}'.format(fastcall, os.path.join(fast_dir,'*.fst'))) # return to original path os.chdir(original_path) - def plot_fast_out(self): + def plot_fast_out(self, cases, allinfo, alldata): ''' - Plot OpenFAST outputs - - NJA: this is a good place to emulate Post_LoadFastOut.m + Plots OpenFAST outputs for desired channels + + Parameters: + ----------- + cases : dict + Dictionary of lists containing desired outputs + allinfo : list + List of OpenFAST output information, output from load_output + alldata: list + List of OpenFAST output data, output from load_output ''' + # Plot cases + for case in cases.keys(): + # channels to plot + plot_list = cases[case] + # instantiate plot and legend + fig, axes = plt.subplots(len(plot_list),1, sharex=True) + myleg = [] + for info, data in zip(allinfo, alldata): + # Load desired attribute names for simplicity + channels = info['channels'] + # Define time + Time = np.ndarray.flatten(data[:,channels.index('Time')]) + # write legend + myleg.append(info['name']) + if len(plot_list) > 1: # Multiple channels + for axj, plot_case in zip(axes, plot_list): + try: + # plot + axj.plot(Time, (data[:,channels.index(plot_case)])) + # label + axj.set(ylabel = plot_case) + axj.grid(True) + except: + print('{} is not available as an output channel.'.format(plot_case)) + else: # Single channel + try: + # plot + axes.plot(Time, (data[:,channels.index(plot_list[0])])) + # label + axes.set(ylabel = plot_list[0]) + axes.grid(True) + plt.show(block=False) + except: + print('{} is not available as an output channel.'.format(plot_list[0])) + plt.legend(myleg,loc='upper center',bbox_to_anchor=(0.5, 0.0), borderaxespad=2, ncol=len(alldata)) + + plt.show() def load_output(self, filenames):