Instantaneous planes from NREL5MW ALM case

# 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
import numpy as np
for x in amrwindfedirs: sys.path.insert(1, x)

from functools import partial
import matplotlib.pyplot as plt

# Make all plots inline 
%matplotlib inline

import postproengine as ppeng
/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
    yaml = ruamel.yaml.YAML(typ='unsafe', pure=True)
    useruamel=True
    loaderkwargs = {'Loader':yaml.RoundTripLoader}
    dumperkwargs = {'Dumper':yaml.RoundTripDumper, 'indent':4, 'default_flow_style':False}
    Loader=yaml.load
except:
    import yaml as yaml
    useruamel=False
    loaderkwargs = {}
    dumperkwargs = {'default_flow_style':False }
    Loader=yaml.safe_load
    
def stringReplaceDict(s, dreplace):
    outstr = str(s)
    for k, g in dreplace.items():
        outstr=outstr.replace(k, str(g))
    return outstr

def formatplot(fig, ax):
    #ax.set_xlim([-2, 10])
    #ax.set_ylim([-1.5,1.5])
    return

ppeng.formatplot = formatplot
replacedict={'RUNDIR':'/pscratch/lcheung/HFM/exawind-benchmarks/NREL5MW_ALM_BD_OFv402_ROSCO.redo',
            }
yamlstring="""

trange: &trange [15300, 15900]

globalattributes:
  verbose: False
#  udfmodules:
#  - testinterp.py  
  executeorder:
  - avgworkflow
  - instantaneousplanes
  

avgworkflow:
  avgplanes:
  - name: XYdomain
    ncfile:
    - RUNDIR/post_processing/XYdomain_090_30000.nc
    tavg: *trange
    #savepklfile:  avg_fixed_hhdomain.pkl         # Name of pickle file to save results (Optional, Default: '')
    #loadpklfile:  avg_fixed_hhdomain.pkl
    #group: T0_YZ_wake2              # Which group to pull from netcdf file (Optional, Default: None)
    contourplot:
      plotfunc: "lambda db: np.sqrt(db['velocityx_avg']**2 + db['velocityy_avg']**2)"
      title: 'NREL5MW ALM AVG horizontal velocity'
      xaxis: x           # Which axis to use on the abscissa 
      yaxis: y           # Which axis to use on the ordinate 
      iplane: [0]
      clevels: np.linspace(0, 14, 141)
      cbar_nticks: 15
      savefile: '../results/images/XYdomain_AVG_15300_15900.png'
      
instantaneousplanes:
  - name: DomainXY
    ncfile: RUNDIR/post_processing/XYdomain_090_30000.nc
    iters:  []
    times: [15300, 15900]
    iplane: 0
    xaxis: x
    yaxis: y
    # --- optional stuff here ---
    plot:
      title: 'NREL5MW ALM $U_h$ T={time:0.2f}'
      plotfunc: "lambda db,i: np.sqrt(db['velocityx'][i]**2 + db['velocityy'][i]**2)"
      clevels: 'np.linspace(0, 14, 141)'
      xlabel: 'X [m]'
      ylabel: 'Y [m]'
      cbar_nticks: 15
      fontsize: 12
      figsize: [6,6]
      dpi: 125
      savefile: '../results/images/XYdomain_INST_{time:05.0f}.png'
      
  - name: Turb HH
    ncfile: RUNDIR/post_processing/turbhh_30000.nc
    iters:  []
    times: [15300, 15900]
    iplane: 0
    xaxis: a1
    yaxis: a2
    # --- optional stuff here ---
    plot:
      title: 'NREL5MW ALM $U_h$ T={time:0.2f}'
      plotfunc: "lambda db,i: np.sqrt(db['velocityx'][i]**2 + db['velocityy'][i]**2)"
      clevels: 'np.linspace(0, 14, 141)'
      xlabel: 'X/D'
      ylabel: 'Y/D'
      figsize: [12,4]
      cbar_nticks: 15
      fontsize: 12   
      xscalefunc: 'lambda x: (x-126*4)/126.0'
      yscalefunc: 'lambda y: (y-126*2)/126.0'
      savefile: '../results/images/turbineHH_INST_{time:05.0f}.png'

  - name: Turb SW
    ncfile: RUNDIR/post_processing/turbsw_30000.nc
    iters:  []
    times: [15300, 15900]
    iplane: 0
    xaxis: a1
    yaxis: a2
    # --- optional stuff here ---
    plot:
      title: 'NREL5MW ALM $U_h$ T={time:0.2f}'
      plotfunc: "lambda db,i: np.sqrt(db['velocityx'][i]**2 + db['velocityy'][i]**2)"
      #plotfunc: "lambda db,i: db['velocityz'][i]"
      clevels: 'np.linspace(0, 14, 141)'
      #clevels: 'np.linspace(-2, 2, 21)'
      xlabel: 'X/D'
      ylabel: 'Z/D'
      figsize: [12,3]
      cbar_nticks: 11
      fontsize: 12   
      xscalefunc: 'lambda x: (x-126*4)/126.0'
      yscalefunc: 'lambda z: (z-90)/126.0'
      savefile: '../results/images/turbineSW_INST_{time:05.0f}.png'
"""
f = io.StringIO(stringReplaceDict(yamlstring, replacedict))
yamldict = Loader(f, **loaderkwargs)
# Run the driver
ppeng.driver(yamldict, verbose=True)
Initialized avgplanes
Running avgplanes
/pscratch/lcheung/HFM/exawind-benchmarks/NREL5MW_ALM_BD_OFv402_ROSCO.redo/post_processing/XYdomain_090_30000.nc 697
Getting data from ncfile:  /pscratch/lcheung/HFM/exawind-benchmarks/NREL5MW_ALM_BD_OFv402_ROSCO.redo/post_processing/XYdomain_090_30000.nc
[============================================================] 100.0% 
Ncount = 697

Initialized contourplot inside avgplanes
Executing contourplot
Initialized instantaneousplanes
Running instantaneousplanes
Extracting from ncfile:  /pscratch/lcheung/HFM/exawind-benchmarks/NREL5MW_ALM_BD_OFv402_ROSCO.redo/post_processing/XYdomain_090_30000.nc 0
extracting iter 348
extracting iter 1045
Initialized plot inside instantaneousplanes
Executing plot
Extracting from ncfile:  /pscratch/lcheung/HFM/exawind-benchmarks/NREL5MW_ALM_BD_OFv402_ROSCO.redo/post_processing/turbhh_30000.nc 0
extracting iter 348
extracting iter 1045
Initialized plot inside instantaneousplanes
Executing plot
Extracting from ncfile:  /pscratch/lcheung/HFM/exawind-benchmarks/NREL5MW_ALM_BD_OFv402_ROSCO.redo/post_processing/turbsw_30000.nc 0
extracting iter 348
extracting iter 1045
Initialized plot inside instantaneousplanes
Executing plot
../../../../_images/73899c1e3ded4d0490496e758fe0c7016da6d64548fe819b1aed272485548e9f.png ../../../../_images/155a26a27847dd9866609613257814b2ba9de97c554f533bd1cf28298a36b814.png ../../../../_images/ce01709fc91600190f6010bd26c0f39c37ea7ef38ec369a1db0ddc0dd98c8d41.png ../../../../_images/000eb4f0ef86b704887162e2c7e04acda9bbf5a813c9dcccad21f05593f9dc60.png ../../../../_images/4cd649f4e5c4042511056aa4275fa501da722abb21b7d8a8e1bd4b24872fbed9.png ../../../../_images/54f083ed10aad8d0c90aa4c3f63b28dab68362fe489a528dae1e70ab8ba74078.png ../../../../_images/a83acb0b2d1cfbe7b416078cf036fae73dd216516390589888f98e1b6aa0a6ce.png
# Write out the notebook to a python script
!jupyter nbconvert --to script InstantaneousAvgPlanes.ipynb
with open('InstantaneousAvgPlanes.py', 'r') as f:
    lines = f.readlines()
with open('InstantaneousAvgPlanes.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 InstantaneousAvgPlanes.ipynb to script
[NbConvertApp] Writing 5014 bytes to InstantaneousAvgPlanes.py