From 56c7800c31f5a39e8319a4fb31abdf7f8f5c27b0 Mon Sep 17 00:00:00 2001 From: John Krasting Date: Wed, 6 Apr 2016 15:12:05 -0400 Subject: [PATCH 1/2] Added obs values and color coding --- tools/analysis/section_transports.py | 37 ++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/tools/analysis/section_transports.py b/tools/analysis/section_transports.py index 26ca06614c..0892be2b0b 100755 --- a/tools/analysis/section_transports.py +++ b/tools/analysis/section_transports.py @@ -18,8 +18,7 @@ def run(): parser.add_argument('-o','--outdir', type=str, default='.', help='''Directory in which to place plots.''') parser.add_argument('-t','--trange', type=str, default=None, help='''Tuple containing start and end years to plot''') cmdLineArgs = parser.parse_args() - A = main(cmdLineArgs) - return A + main(cmdLineArgs) def main(cmdLineArgs,stream=None): @@ -50,20 +49,41 @@ def __init__(self, cmdLineArgs, section, var, label=None, ylim=None, mks2Sv=True if cmdLineArgs.suptitle != '': self.suptitle = cmdLineArgs.suptitle + ' ' + cmdLineArgs.label else: self.suptitle = rootGroup.title + ' ' + cmdLineArgs.label - def plotPanel(section,n,autolim=True): + def plotPanel(section,n,observedFlows=None,autolim=True,colorCode=True): ax = plt.subplot(6,3,n) - plt.plot(section.time,section.data,color='#c3c3c3') + color = '#c3c3c3'; obsLabel = None + if section.label in observedFlows.keys(): + if isinstance(observedFlows[section.label],tuple): + if colorCode == True: + if min(observedFlows[section.label]) <= section.data.mean() <= max(observedFlows[section.label]): + color = '#90ee90' + else: color = '#f26161' + obsLabel = str(min(observedFlows[section.label])) + ' to ' + str(max(observedFlows[section.label])) + else: obsLabel = str(observedFlows[section.label]) + plt.plot(section.time,section.data,color=color) plt.title(section.label,fontsize=12) - plt.text(0.04,0.05,'Mean = '+'{0:.2f}'.format(section.data.mean()),transform=ax.transAxes,fontsize=10) + plt.text(0.04,0.11,'Mean = '+'{0:.2f}'.format(section.data.mean()),transform=ax.transAxes,fontsize=10) + if obsLabel != None: plt.text(0.04,0.04,'Obs. = '+obsLabel,transform=ax.transAxes,fontsize=10) if autolim == False: if section.ylim != None: plt.ylim(section.ylim) if n in [1,4,7,10,13,16]: plt.ylabel('Transport (Sv)') + reference = 'Griffies et al., 2016: Experimental and diagnostic protocol for the physical component of the\nCMIP6 Ocean Model Intercomparison Project (OMIP) Geosci. Model Dev., Submitted' + observedFlows = {'reference':reference,'Bering Strait':(0.7,1.1), + 'Barents Opening':2.0, 'Canadian Archipelago':(0.5,1.0), 'Denmark Strait':(-4.8,-2.0), + 'Drake Passage':(129.8,143.6), 'English Channel':(0.1,0.2), 'Faroe-Scotland':(0.8,1.0), 'Florida-Bahamas':(28.9,34.3), + 'Fram Strait':(6.2,7.0), 'Gibraltar Strait':0.11, 'Iceland-Faroe':(4.35,4.85), + 'Indonesian Throughflow':-13., 'Mozambique Channel':(-25.6,-7.8), 'Pacific Equatorial Undercurrent':(24.,36.), + 'Taiwan-Luzon Striat':(-3.0,-1.8), 'Windward Passage':(-15.,5.)} + plotSections = [] try: res = Transport(cmdLineArgs,'ocean_Agulhas_section','umo',label='Agulhas',ylim=(120,180)); plotSections.append(res) except: print('WARNING: unable to process ocean_Agulhas_section') + try: res = Transport(cmdLineArgs,'ocean_Bering_Strait','vmo',label='Bering Strait',ylim=(-2,8)); plotSections.append(res) + except: print('WARNING: unable to process ocean_Barents_opening') + try: res = Transport(cmdLineArgs,'ocean_Barents_opening','umo',label='Barents Opening',ylim=(-2,8)); plotSections.append(res) except: print('WARNING: unable to process ocean_Barents_opening') @@ -113,8 +133,9 @@ def plotPanel(section,n,autolim=True): except: print('WARNING: unable to process ocean_Windward_Passage') fig = plt.figure(figsize=(13,17)) - for n in range(0,len(plotSections)): plotPanel(plotSections[n],n) - fig.text(0.5,0.94,str(plotSections[n-1].suptitle),horizontalalignment='center',fontsize=14) + for n in range(0,len(plotSections)): plotPanel(plotSections[n],n,observedFlows=observedFlows) + fig.text(0.5,0.955,str(plotSections[n-1].suptitle),horizontalalignment='center',fontsize=14) + fig.text(0.5,0.925,'Observations summarized in '+observedFlows['reference'],horizontalalignment='center',fontsize=11) plt.subplots_adjust(hspace=0.3) if stream != None: fig.text(0.5,0.05,str('Generated by dora.gfdl.noaa.gov'),horizontalalignment='center',fontsize=12) plt.show(block=False) @@ -124,5 +145,5 @@ def plotPanel(section,n,autolim=True): plt.savefig(objOut) if __name__ == '__main__': - A = run() + run() From 4a6bf80ea6c46498fe20eb08d4328241fffe143e Mon Sep 17 00:00:00 2001 From: John Krasting Date: Wed, 6 Apr 2016 15:18:22 -0400 Subject: [PATCH 2/2] Typo with Taiwan-Luzon Strait --- tools/analysis/section_transports.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/analysis/section_transports.py b/tools/analysis/section_transports.py index 0892be2b0b..df9e667b96 100755 --- a/tools/analysis/section_transports.py +++ b/tools/analysis/section_transports.py @@ -74,7 +74,7 @@ def plotPanel(section,n,observedFlows=None,autolim=True,colorCode=True): 'Drake Passage':(129.8,143.6), 'English Channel':(0.1,0.2), 'Faroe-Scotland':(0.8,1.0), 'Florida-Bahamas':(28.9,34.3), 'Fram Strait':(6.2,7.0), 'Gibraltar Strait':0.11, 'Iceland-Faroe':(4.35,4.85), 'Indonesian Throughflow':-13., 'Mozambique Channel':(-25.6,-7.8), 'Pacific Equatorial Undercurrent':(24.,36.), - 'Taiwan-Luzon Striat':(-3.0,-1.8), 'Windward Passage':(-15.,5.)} + 'Taiwan-Luzon Strait':(-3.0,-1.8), 'Windward Passage':(-15.,5.)} plotSections = [] @@ -126,7 +126,7 @@ def plotPanel(section,n,observedFlows=None,autolim=True,colorCode=True): try: res = Transport(cmdLineArgs,'ocean_Pacific_undercurrent','umo',label='Pacific Equatorial Undercurrent',ylim=(-8,8)); plotSections.append(res) except: print('WARNING: unable to process ocean_Pacific_undercurrent') - try: res = Transport(cmdLineArgs,'ocean_Taiwan_Luzon','umo',label='Taiwan-Luzon Striat',ylim=(-15,10)); plotSections.append(res) + try: res = Transport(cmdLineArgs,'ocean_Taiwan_Luzon','umo',label='Taiwan-Luzon Strait',ylim=(-15,10)); plotSections.append(res) except: print('WARNING: unable to process ocean_Taiwan_Luzon') try: res = Transport(cmdLineArgs,'ocean_Windward_Passage','vmo',label='Windward Passage',ylim=(-15,15)); plotSections.append(res)