Changeset 2079 in lmdz_wrf


Ignore:
Timestamp:
Aug 10, 2018, 9:25:59 PM (7 years ago)
Author:
lfita
Message:

Starting to add draw_WRFeta_levels

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing.py

    r2031 r2079  
    1029810298    return
    1029910299
     10300def draw_WRFeta_levels(filenames, values):
     10301    """ Function to plot vertical levels from WRF wrfinput_d[nn] file
     10302      filenames= ',' list of name of files to use
     10303      values = [labs]:[colors]:[markers]:[legvals]:[imgtit]:[imgkind]:[close]
     10304        [labs]= ',' list of labels for the plot (LaTeX like)
     10305        [colors]= ',' list of colors for the lines
     10306        [markers]= '@' list of markers for the lines
     10307        [legvals]=[loclegend]|[fonstsize] values for the legend
     10308          [locleg]: location of the legend (0, automatic)
     10309            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
     10310            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     10311            9: 'upper center', 10: 'center'
     10312          [fontsize]: font size for the legend ('auto' for 12)
     10313        [imgtit]= title of the image ('!' for spaces)
     10314        [imgkind]= kind of file output of the image (ps, pns, pdf, ...)
     10315        [close]= whether figure should be closed or not
     10316    """
     10317    fname = 'draw_WRFeta_levels'
     10318
     10319    if values == 'h':
     10320        print fname + '_____________________________________________________________'
     10321        print draw_WRFeta_levels.__doc__
     10322        quit()
     10323
     10324    expectargs = '[labs]:[colors]:[markers]:[legvals]:[imgtit]:[imgkind]:[close]'
     10325    drw.check_arguments(fname,values,expectargs,':')
     10326
     10327    labs = values.split(':')[0].split(',')
     10328    colors = gen.auto_val_list(values.split(':')[1], ',', colorsauto)
     10329    markers = gen.auto_val_list(values.split(':')[2], '@', pointkindsauto)
     10330    legvals = values.split(':')[3].split(',')
     10331    imgtit = values.split(':')[4].replace('!', ' ')
     10332    imgkind = values.split(':')[5]
     10333    close = gen.str_Bool(values.split(':')[6])
     10334   
     10335    files = filenames.split(',')
     10336    allhgtsea = []
     10337    allxhgt = []
     10338    allhgtxhgt = []
     10339    alldhgtsea = []
     10340    alldhgtxhgt = []
     10341    alletaw = []
     10342    alletau = []
     10343
     10344    for filen in files:
     10345        if not os.path.isfile(filen):
     10346            print errormsg
     10347            print '  ' + fname + ": file '" + filen + "' does not exist !!"
     10348            quit(-1)
     10349
     10350        onc = NetCDFFile(filen, 'r')
     10351        ophb = onc.variables['PHB']
     10352        olandseamask = onc.variables['LANDMASK']
     10353        ohgt = onc.variables['HGT']
     10354        oznw = onc.variables['ZNW']
     10355        oznu = onc.variables['ZNU']
     10356
     10357        dimx = ophb.shape[3]
     10358        dimy = ophb.shape[2]
     10359        dimz = ophb.shape[1]
     10360        dimt = ophb.shape[0]
     10361
     10362        for j in range(10,dimy):
     10363            for i in range(10,dimx):
     10364                if olandseamask[0,j,i] == 0:
     10365                    hgtssea = ophb[0,:,j,i]/9.8
     10366                    break
     10367
     10368        maxhgt = np.max(ohgt[0,:,:])
     10369        ijxhgt = gen.index_mat(ohgt[0,:,:], maxhgt)
     10370        hgtsxhgt = ophb[0,:, ijxhgt[0], ijxhgt[1]]/9.8
     10371
     10372        allhgtsea.append(hgtssea)
     10373        allxhgt.append(maxhgt)
     10374        allhgtxhgt.append(hgtsxhgt)
     10375        alldhgtsea.append(hgtssea[1:dimz]-hgtssea[0:dimz-1])
     10376        alldhgtxhgt.append(hgtsxhgt[1:dimz]-hgtsxhgt[0:dimz-1])
     10377        alletaw.append(oznw[0,:])
     10378        alletau.append(oznu[0,:])
     10379
     10380        onc.close()
     10381
     10382    # Legend
     10383    locleg, legfontsize = drw.legend_values(legvals,'|')
     10384
     10385    plt.plot_draw_WRFeta_levels(allhgtsea, allxhgt, allhgtxhgt, alldhgtsea,          \
     10386      alldhgtxhgt, alletaw, alletau, labs, colors, markers, [locleg, legfontsize],   \
     10387      imgtit, imgkind, close)
     10388
     10389    return
     10390
    1030010391#quit()
    1030110392
  • trunk/tools/drawing_tools.py

    r2031 r2079  
    1274212742    return
    1274312743
     12744def plot_draw_WRFeta_levels(ahgtsea, axhgt, ahgtxhgt, adhgtsea, adhgtxhgt, aetaw,    \
     12745     imgtit, labels, cols, marks, legvs, figtitle, kfig, close):
     12746    """ Function to plot different sets of WRF eta-levels
     12747      ahgtsea: all hegights of a point above sea
     12748      axhgt: all maximum hegights
     12749      ahgtxhgt: all hegights of the point above mximum height
     12750      adhgtsea: all relative heights of a point above sea
     12751      adhgtxhgt: all relative heights of the point above maximum topo
     12752      aetaw: all eta-full values
     12753      aetau: all eta-half values
     12754      labels: labels
     12755      cols: colors
     12756      marks: markers
     12757      legvs: [legloc, legfs] legend values
     12758      figtitle: title of figure
     12759      kfig: kind of file of graphical output
     12760      close: whether figure should be closed
     12761    """
     12762    fname = 'plot_draw_WRFeta_levels'
     12763
     12764
     12765    plt.rc('text', usetex=True)
     12766
     12767    fig = plt.subplots(2)
     12768
     12769    plt.subplot(1,1,2)
     12770    # Absolute heights
     12771    Nlabs = len(labels)
     12772    for ilab in range(Nlabs):
     12773        hgtsea = ahgtsea[ilab]
     12774        hgtxhgt = ahgtxhgt[ilab]
     12775        znw = aetaw[ilab]
     12776
     12777        plt.plot(znw, hgtssea, '-', marker=marks[ilab], linewidth=1.5, markersize=4, \
     12778          label='$hgt_{sea}^{'+labels[ilab]+'}$', color=cols[ilab])
     12779        if ilab == 0:
     12780            plt.plot(znw, hgtsxhgt,  '-.', marker=marks[ilab], linewidth=1.5,        \
     12781              markersize=4, label='$hgt_{hgtmax}^{'+labels[ilab]+'}$',               \
     12782              color=colors[ilab])
     12783        else:
     12784            plt.plot(znw, hgtsxhgt,  '-.', marker=marks[ilab], linewidth=1.5,        \
     12785              markersize=4, label=None, color=cols[ilab])
     12786
     12787    plt.xlabel('$\eta$-level', color='k')
     12788    plt.ylabel('absolute height ($m$)', color='black')
     12789    plt.yscale('log')
     12790
     12791    titleloc = (0.5,1.075)
     12792
     12793    plt.title('Absoulte Heights from sea \& highest grid point',position=titleloc)
     12794    plt.legend(loc=0, prop={'size':10})
     12795
     12796    plt.title(gen.latex_text(figtitle))
     12797
     12798    plt.subplot(2,1,2)
     12799    # Relative heights
     12800    Nlabs = len(labels)
     12801    for ilab in range(Nlabs):
     12802        hgtsea = adhgtsea[ilab]
     12803        hgtxhgt = adhgtxhgt[ilab]
     12804        znw = aetau[ilab]
     12805
     12806        plt.plot(znw, hgtssea, '-', marker=marks[ilab], linewidth=1.5, markersize=4, \
     12807          label='$\delta hgt_{sea}^{'+labels[ilab]+'}$', color=cols[ilab])
     12808        if ilab == 0:
     12809            plt.plot(znw, hgtsxhgt,  '-.', marker=marks[ilab], linewidth=1.5,        \
     12810              markersize=4, label='$\delta hgt_{hgtmax}^{'+labels[ilab]+'}$',        \
     12811              color=colors[ilab])
     12812        else:
     12813            plt.plot(znw, hgtsxhgt,  '-.', marker=marks[ilab], linewidth=1.5,        \
     12814              markersize=4, label=None, color=cols[ilab])
     12815
     12816    plt.xlabel('$\eta$-level', color='k')
     12817    plt.ylabel('$\delta height$ ($m$)', color='black')
     12818    plt.yscale('log')
     12819
     12820    titleloc = (0.5,1.075)
     12821
     12822    plt.title('Relative Heights from sea \& highest grid point',position=titleloc)
     12823    plt.legend(loc=0, prop={'size':10})
     12824
     12825    plt.title(gen.latex_text(figtitle))
     12826
     12827    fig.suptitle(imgtit)
     12828
     12829    figname = 'stations_map'
     12830    output_kind(kfig, figname, close)
     12831
     12832    return
     12833
Note: See TracChangeset for help on using the changeset viewer.