nargs = len(args)

if (nargs == 0):
    index_first, index_last = nfiles - 101, nfiles - 1
    # By default average over the last 100 files
else:
    index_first, index_last = get_desired_range(int_file_list, args)

# Set the timeavg savename by the directory, what we are saving, and first and last
# iteration files for the average
savename = dirname_stripped + '_enstrophy_from_mer_' +\
        file_list[index_first] + '_' + file_list[index_last] + '.pkl'
savefile = datadir + savename

# Get grid info from first mer slice file
mer0 = Meridional_Slices(radatadir + file_list[index_first], '')
rr = mer0.radius
ri, ro = np.min(rr), np.max(rr)
d = ro - ri
rr_depth = (ro - rr) / d
rr_height = (rr - ri) / d
sint = mer0.sintheta
cost = mer0.costheta
tt = np.arccos(cost)
tt_lat = (np.pi / 2 - tt) * 180 / np.pi
nr = mer0.nr
nt = mer0.ntheta
phivals = mer0.phi
# phiinds = mer0.phi_indices
# This attribute of Meridional_Slices does not actually seem to be there!
nphi = mer0.nphi
def main():

    helicity_type = 1

    saveplot = True
    tindex = -1
    phi_index = 0

    if (helicity_type == 1):  # full
        vr_index = 1
        vt_index = 2
        vp_index = 3
        wr_index = 301
        wt_index = 302
        wp_index = 303
        hr_index = 324
        ht_index = 325
        hp_index = 326
        helicity = 339
        print("full helicity check")
    elif (helicity_type == 2):  # u-prime, w-mean
        vr_index = 4
        vt_index = 5
        vp_index = 6
        wr_index = 307
        wt_index = 308
        wp_index = 309
        hr_index = 336
        ht_index = 337
        hp_index = 338
        helicity = 343
        print("prime-mean helicity check")
    elif (helicity_type == 3):  # u-mean, w-prime
        vr_index = 7
        vt_index = 8
        vp_index = 9
        wr_index = 304
        wt_index = 305
        wp_index = 306
        hr_index = 333
        ht_index = 334
        hp_index = 335
        helicity = 342
        print("mean-prime helicity check")
    elif (helicity_type == 4):  # u-mean, w-mean
        vr_index = 7
        vt_index = 8
        vp_index = 9
        wr_index = 307
        wt_index = 308
        wp_index = 309
        hr_index = 330
        ht_index = 331
        hp_index = 332
        helicity = 341
        print("mean-mean helicity check")
    elif (helicity_type == 5):  # u-prime, w-prime
        vr_index = 4
        vt_index = 5
        vp_index = 6
        wr_index = 304
        wt_index = 305
        wp_index = 306
        hr_index = 327
        ht_index = 328
        hp_index = 329
        helicity = 340
        print("prime-prime helicity check")

    # build file list and get data
    files = build_file_list(0, 10000000, path="./Meridional_Slices/")
    F = Meridional_Slices(filename=files[-1], path='')

    radius = F.radius
    costh = F.costheta
    sinth = F.sintheta

    # extract data
    vr = F.vals[phi_index, :, :, F.lut[vr_index], tindex]
    vt = F.vals[phi_index, :, :, F.lut[vt_index], tindex]
    vp = F.vals[phi_index, :, :, F.lut[vp_index], tindex]
    wr = F.vals[phi_index, :, :, F.lut[wr_index], tindex]
    wt = F.vals[phi_index, :, :, F.lut[wt_index], tindex]
    wp = F.vals[phi_index, :, :, F.lut[wp_index], tindex]
    hr = F.vals[phi_index, :, :, F.lut[hr_index], tindex]
    ht = F.vals[phi_index, :, :, F.lut[ht_index], tindex]
    hp = F.vals[phi_index, :, :, F.lut[hp_index], tindex]
    hel = F.vals[phi_index, :, :, F.lut[helicity], tindex]

    # True value
    hr_T = vr * wr
    ht_T = vt * wt
    hp_T = vp * wp
    hel_T = hr_T + ht_T + hp_T

    # setup grid
    fig = plt.figure(1, dpi=100, figsize=(9, 9))
    Grid = gridspec.GridSpec(ncols=3, nrows=4)

    ax = fig.add_subplot(Grid[0, 0])
    plot_azav(fig,
              ax,
              hr_T,
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Radial True")

    ax = fig.add_subplot(Grid[1, 0])
    plot_azav(fig,
              ax,
              ht_T,
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Theta True")

    ax = fig.add_subplot(Grid[2, 0])
    plot_azav(fig,
              ax,
              hp_T,
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Phi True")

    ax = fig.add_subplot(Grid[3, 0])
    plot_azav(fig,
              ax,
              hel_T,
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Total True")

    ax = fig.add_subplot(Grid[0, 1])
    plot_azav(fig,
              ax,
              hr,
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Radial Diag")

    ax = fig.add_subplot(Grid[1, 1])
    plot_azav(fig,
              ax,
              ht,
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Theta Diag")

    ax = fig.add_subplot(Grid[2, 1])
    plot_azav(fig,
              ax,
              hp,
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Phi Diag")

    ax = fig.add_subplot(Grid[3, 1])
    plot_azav(fig,
              ax,
              hel,
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Total Diag")

    ax = fig.add_subplot(Grid[0, 2])
    plot_azav(fig,
              ax,
              np.abs(hr_T - hr),
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Radial Error")
    print("Max error, radial", np.amax(np.abs(hr_T - hr)))

    ax = fig.add_subplot(Grid[1, 2])
    plot_azav(fig,
              ax,
              np.abs(ht_T - ht),
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Theta Error")
    print("Max error, theta", np.amax(np.abs(ht_T - ht)))

    ax = fig.add_subplot(Grid[2, 2])
    plot_azav(fig,
              ax,
              np.abs(hp_T - hp),
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Phi Error")
    print("Max error, phi", np.amax(np.abs(hp_T - hp)))

    ax = fig.add_subplot(Grid[3, 2])
    plot_azav(fig,
              ax,
              np.abs(hel_T - hel),
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Total Error")
    print("Max error, total", np.amax(np.abs(hel_T - hel)))

    fig.tight_layout()

    if (saveplot):
        output = "test_helicity_{}.png".format(helicity_type)
        plt.savefig(output, bbox_inches='tight', dpi=300)
    else:
        plt.show()
Example #3
0
#
#
# We begin with the usual preamble and import the *plot_azav* helper function.  Examining the data structure, we see that it is similar to the AZ_Avgs data structure.  The *vals* array possesses an extra dimension relative to its AZ_Avgs counterpart to account for the multiple longitudes that may be output, we see attributes *phi* and *phi_indices* have been added to reference the longitudinal grid.

# In[19]:

#####################################
#  Meridional Slice
from rayleigh_diagnostics import Meridional_Slices, plot_azav
import numpy
import matplotlib.pyplot as plt
from matplotlib import ticker, font_manager
# Read the data

istring = '00040000'
ms = Meridional_Slices(istring)
tindex = 1  # All example quantities were output with same cadence.  Grab second time-index from all.

# In[20]:

radius = ms.radius
costheta = ms.costheta
sintheta = ms.sintheta
phi_index = 0  # We only output one Meridional Slice
vr_ms = ms.vals[phi_index, :, :, ms.lut[1], tindex]
units = 'nondimensional'

# Plot
sizetuple = (8, 5)
fig, ax = plt.subplots(figsize=(8, 8))
tsize = 20  # title font size
Example #4
0
    az = None

if use_sh and 'prime_sph' in varname:
    try:
        sh = Shell_Avgs(dirname + '/Shell_Avgs/' + fname, '')
        print("read Shell_Avgs/" + fname)
    except:
        print("No file Shell_Avgs/" + fname)
        print("setting sh = None")
        sh = None
else:
    sh = None

# Read in desired meridional slice
print("read Meridional_Slices/" + fname)
mer = Meridional_Slices(radatadir + fname, '')
vals = get_merslice(mer, varname, dirname=dirname, sh=sh, az=az)

# Get local time (in seconds)
t_loc = mer.time[0]

field = vals[iphi, :, :]
lonval = mer.phi[iphi] * 180. / np.pi

# Display at terminal what we are plotting
print('Plotting mer: ' + varname + (', lon = %.1f deg (iphi = %02i), '\
        %(lonval, iphi)) + 'iter ' + fname)

# Figure dimensions
subplot_width_inches = 2.5
subplot_height_inches = 5.