Пример #1
0
 while a <= nexp:
    ax = plt.subplot(gs[a-1])
    ax.contourf(xxv, yyv, np.ones_like(xxv)*np.nan) #contour valid dates and a forecast hour ranges
    if a == 1:
       yy,xx = np.meshgrid(models_dates_array[a-1,:], fcsthrs)
       C0 = ax.contourf(xx, yy, model_stat_array[a-1,:,:], cmap=plt.cm.winter_r, extend='both')
       C = ax.contour(xx, yy, model_stat_array[a-1,:,:], levels=C0.levels, colors='k', linewidths=1.0)
       ax.clabel(C,C0.levels, fmt='%1.2f', inline=True, fontsize=12.5)
       ax.set_title(str(model_fcst[a-1]), loc='left')
    elif a == 2:
       yy,xx = np.meshgrid(models_dates_array[a-1,:], fcsthrs)
       print(np.min(model_stat_array[a-1,:,:]-model_stat_array[0,:,:]))
       print(np.max(model_stat_array[a-1,:,:]-model_stat_array[0,:,:]))
       print(np.nanmin(model_stat_array[a-1,:,:]-model_stat_array[0,:,:]))
       print(np.nanmax(model_stat_array[a-1,:,:]-model_stat_array[0,:,:])) 
       c1levels = pd.get_clevels(model_stat_array[a-1,:,:]-model_stat_array[0,:,:])
       C1 = ax.contourf(xx, yy, model_stat_array[a-1,:,:]-model_stat_array[0,:,:], levels=c1levels, cmap=plt.cm.coolwarm, locator=matplotlib.ticker.MaxNLocator(symmetric='True'), extend='both')
       C = ax.contour(xx, yy, model_stat_array[a-1,:,:]-model_stat_array[0,:,:], levels=C1.levels, colors='k', linewidths=1.0)
       ax.clabel(C,C1.levels, fmt='%1.2f', inline=True, fontsize=12.5)
       ax.set_title(str(model_fcst[a-1])+'-'+str(model_fcst[0]), loc='left')
    elif a > 2:
       ax.contourf(xx, yy, model_stat_array[a-1,:,:]-model_stat_array[0,:,:], levels=C1.levels, cmap=plt.cm.coolwarm, extend='both')
       C = ax.contour(xx, yy, model_stat_array[a-1,:,:]-model_stat_array[0,:,:], levels=C1.levels, colors='k', linewidths=1.0)
       ax.clabel(C,C1.levels, fmt='%1.2f', inline=True, fontsize=12.5)
       ax.set_title(str(model_fcst[a-1])+'-'+str(model_fcst[0]), loc='left')
    ax.grid(True)
    ax.set_ylabel('Verification Date')
    if len(dates) <= 31:
       ax.yaxis.set_major_locator(md.DayLocator(interval=7))
       ax.yaxis.set_major_formatter(md.DateFormatter('%d%b\n%Y'))
       ax.yaxis.set_minor_locator(md.DayLocator())
     float)
 model_now_stat_now_means_array = np.ma.masked_array(
     model_now_stat_now_means_array,
     mask=model_now_stat_now_means_array == np.nan)
 #create image directory if does not exist
 if not os.path.exists(
         os.path.join(plotting_out_dir, "imgs", cycle + "Z")):
     os.makedirs(os.path.join(plotting_out_dir, "imgs", cycle + "Z"))
 #make plot
 ax = plt.subplot(gs[m - 1])
 yy, xx = np.meshgrid(fcst_var_levels_num, leads)
 if m == 1:
     logger.debug("Plotting " + stat_now + " leads - pressure for " +
                  model_now)
     if stat_now == 'bias':
         c0levels = pd.get_clevels(model_now_stat_now_means_array)
         C0 = ax.contourf(
             xx,
             yy,
             model_now_stat_now_means_array,
             levels=c0levels,
             cmap=cmap_bias,
             locator=matplotlib.ticker.MaxNLocator(symmetric=True),
             extend='both')
     else:
         C0 = ax.contourf(xx,
                          yy,
                          model_now_stat_now_means_array,
                          cmap=cmap,
                          extend='both')
         model_1_stat_now_dates_array = model_now_stat_now_means_array
    gs = gridspec.GridSpec(2,2)
    gs.update(wspace=0.3, hspace=0.25)
 elif nexp > 4 and nexp <= 6:
    fig = plt.figure(figsize=(19,12))
    gs = gridspec.GridSpec(2,3)
    gs.update(wspace=0.3, hspace=0.25)
 elif nexp > 6:
    fig = plt.figure(figsize=(21,17))
    gs = gridspec.GridSpec(3,3)
    gs.update(wspace=0.35, hspace=0.25)
 while a <= nexp:
    ax = plt.subplot(gs[a-1])
    #ax.contourf(xxv, yyv, np.ones_like(xxv)*np.nan)
    if a == 1:
       if stat_now_name == 'bias':
           c0levels = pd.get_clevels(models_tp_stat_array[a-1,:,:])
           C0 = ax.contourf(xx, yy, models_tp_stat_array[a-1,:,:], levels=c0levels, cmap=plt.cm.RdYlGn_r, locator=matplotlib.ticker.MaxNLocator(symmetric=True), extend='both')
       else:
          C0 = ax.contourf(xx, yy, models_tp_stat_array[a-1,:,:], cmap=plt.cm.BuPu_r, extend='both')
       C = ax.contour(xx, yy, models_tp_stat_array[a-1,:,:], levels=C0.levels, colors='k', linewidths=1.0)
       ax.clabel(C,C0.levels, fmt='%1.2f', inline=True, fontsize=12.5)
       ax.set_title(str(model_fcst[a-1]), loc='left')
    elif a == 2:
       if stat_now_name == 'bias':
          C1 = ax.contourf(xx, yy, models_tp_stat_array[a-1,:,:], levels=C0.levels, cmap=plt.cm.RdYlGn_r, extend='both')
          C = ax.contour(xx, yy, models_tp_stat_array[a-1,:,:], levels=C0.levels, colors='k', linewidths=1.0)
          ax.clabel(C,C0.levels, fmt='%1.2f', inline=True, fontsize=12.5)
          ax.set_title(str(model_fcst[a-1]), loc='left')
       else:
          c1levels = pf.get_clevels( models_tp_stat_array[a-1,:,:]-models_tp_stat_array[0,:,:])
          C1 = ax.contourf(xx, yy, models_tp_stat_array[a-1,:,:]-models_tp_stat_array[0,:,:], levels=c1levels, cmap=plt.cm.coolwarm, locator=matplotlib.ticker.MaxNLocator(symmetric=True), extend='both')