How to use case2 method in yandex-tank

Best Python code snippet using yandex-tank

CompareMonitoring2SimusNachos12.py

Source:CompareMonitoring2SimusNachos12.py Github

copy

Full Screen

1#!/usr/bin/env python2#3"""4This script is making some plots from annual means of NACHSO12 outputs using cartopy5"""6## imports7import sys8import numpy as np9import numpy.ma as ma10import xarray as xr11import matplotlib.pyplot as plt12import cartopy.crs as ccrs13import cartopy.feature as cfeature14def all_plots(case1,case2,year,**kwargs):15 dirmean1='/scratch/cnt0024/hmg2840/albert7a/NACHOS12.L75/NACHOS12.L75-'+case1+'-MEAN/1d/'+year+'/'16 dirmean2='/scratch/cnt0024/hmg2840/albert7a/NACHOS12.L75/NACHOS12.L75-'+case2+'-MEAN/1d/'+year+'/'17 dirplot='/scratch/cnt0024/hmg2840/albert7a/NACHOS12.L75/PLOTS/NACHOS12.L75-'+case1+'-'+case2+'/python/'18 title="NACHOS12.L75 "+case1+"-"+case2+" "+year19 file1flxT=dirmean1+'NACHOS12.L75-'+case1+'_y'+year+'.1d_flxT.nc'20 file1T=dirmean1+'NACHOS12.L75-'+case1+'_y'+year+'.1d_gridT.nc'21 file1EKE=dirmean1+'NACHOS12.L75-'+case1+'_y'+year+'.1d_EKE.nc'22 file1MXL03=dirmean1+'NACHOS12.L75-'+case1+'_y'+year+'m03.1d_MXL.nc'23 file1MXL09=dirmean1+'NACHOS12.L75-'+case1+'_y'+year+'m09.1d_MXL.nc'24 file1ICE03=dirmean1+'NACHOS12.L75-'+case1+'_y'+year+'m03.1d_icemod3.nc'25 file1ICE09=dirmean1+'NACHOS12.L75-'+case1+'_y'+year+'m09.1d_icemod3.nc'26 file1PSI=dirmean1+'NACHOS12.L75-'+case1+'_y'+year+'.1d_PSI.nc'27 file2flxT=dirmean2+'NACHOS12.L75-'+case2+'_y'+year+'.1d_flxT.nc'28 file2T=dirmean2+'NACHOS12.L75-'+case2+'_y'+year+'.1d_gridT.nc'29 file2EKE=dirmean2+'NACHOS12.L75-'+case2+'_y'+year+'.1d_EKE.nc'30 file2MXL03=dirmean2+'NACHOS12.L75-'+case2+'_y'+year+'m03.1d_MXL.nc'31 file2MXL09=dirmean2+'NACHOS12.L75-'+case2+'_y'+year+'m09.1d_MXL.nc'32 file2ICE03=dirmean2+'NACHOS12.L75-'+case2+'_y'+year+'m03.1d_icemod3.nc'33 file2ICE09=dirmean2+'NACHOS12.L75-'+case2+'_y'+year+'m09.1d_icemod3.nc'34 file2PSI=dirmean2+'NACHOS12.L75-'+case2+'_y'+year+'.1d_PSI.nc'35 ds1T=xr.open_dataset(file1T)36 tem1=ds1T.votemper[0]37 sal1=ds1T.vosaline[0]38 ssh1=ds1T.sossheig[0]39 lat=ds1T.nav_lat40 lon=ds1T.nav_lon41 ds2T=xr.open_dataset(file2T)42 tem2=ds2T.votemper[0]43 sal2=ds2T.vosaline[0]44 ssh2=ds2T.sossheig[0]45 lat2=ds2T.nav_lat46 lon2=ds2T.nav_lon47 48 ds1MXL03=xr.open_dataset(file1MXL03)49 mxl103_rho010=ds1MXL03.somxl010[0]50 mxl103_rho030=ds1MXL03.somxl030[0]51 mxl103_t02=ds1MXL03.somxlt02[0]52 ds1MXL09=xr.open_dataset(file1MXL09)53 mxl109_rho010=ds1MXL09.somxl010[0]54 mxl109_rho030=ds1MXL09.somxl030[0]55 mxl109_t02=ds1MXL09.somxlt02[0]56 57 ds2MXL03=xr.open_dataset(file2MXL03)58 mxl203_rho010=ds2MXL03.somxl010[0]59 mxl203_rho030=ds2MXL03.somxl030[0]60 mxl203_t02=ds2MXL03.somxlt02[0]61 ds2MXL09=xr.open_dataset(file2MXL09)62 mxl209_rho010=ds2MXL09.somxl010[0]63 mxl209_rho030=ds2MXL09.somxl030[0]64 mxl209_t02=ds2MXL09.somxlt02[0]65 66 ds1EKE=xr.open_dataset(file1EKE)67 eke1=ds1EKE.voeke[0,0]68 69 ds2EKE=xr.open_dataset(file2EKE)70 eke2=ds2EKE.voeke[0,0]71 72 ds1PSI=xr.open_dataset(file1PSI)73 psi1=ds1PSI.sobarstf[0]74 75 ds2PSI=xr.open_dataset(file2PSI)76 psi2=ds2PSI.sobarstf[0]77 78 ds1flxT=xr.open_dataset(file1flxT)79 Heat1=ds1flxT.sohefldo[0]80 WaterFlx1=ds1flxT.sowaflup[0]81 WaterDmp1=ds1flxT.sowafld[0]82 83 ds2flxT=xr.open_dataset(file2flxT)84 Heat2=ds2flxT.sohefldo[0]85 WaterFlx2=ds2flxT.sowaflup[0]86 WaterDmp2=ds2flxT.sowafld[0]87 ds1ICE03=xr.open_dataset(file1ICE03)88 iconc103=ds1ICE03.siconc[0]89 ivolu103=ds1ICE03.sivolu[0]90 ds1ICE09=xr.open_dataset(file1ICE09)91 iconc109=ds1ICE09.siconc[0]92 ivolu109=ds1ICE09.sivolu[0]93 ds2ICE03=xr.open_dataset(file2ICE03)94 iconc203=ds2ICE03.siconc[0]95 ivolu203=ds2ICE03.sivolu[0]96 ds2ICE09=xr.open_dataset(file2ICE09)97 iconc209=ds2ICE09.siconc[0]98 ivolu209=ds2ICE09.sivolu[0]99 100 101 def plot_glob(fig,sub,var,vmin,vmax,unit,name,pal):102 ax = fig.add_subplot(sub,projection=ccrs.Orthographic(central_longitude=-30,103 central_latitude=35))104 cmap = plt.get_cmap(pal)105 cmap.set_under(color='grey')106 pcolor=ax.pcolormesh(lon,lat,ma.masked_invalid(var),transform=ccrs.PlateCarree(),cmap=cmap,vmin=vmin,vmax=vmax)107 ax.set_global()108 ax.add_feature(cfeature.LAND,facecolor='grey')109 ax.coastlines()110 cbar=plt.colorbar(pcolor,orientation='vertical',fraction=0.026,pad=0.1)111 cbar.ax.tick_params(labelsize=20)112 ax.set_title(name+' '+unit,size=17)113 114 def plot_glob_diff(fig,sub,var1,var2,vmin,vmax,unit,name,pal):115 ax = fig.add_subplot(sub,projection=ccrs.Orthographic(central_longitude=-30,116 central_latitude=35))117 cmap = plt.get_cmap(pal)118 cmap.set_under(color='grey')119 pcolor=ax.pcolormesh(lon,lat,ma.masked_invalid(var1-var2),transform=ccrs.PlateCarree(),cmap=cmap,vmin=vmin,vmax=vmax)120 ax.set_global()121 ax.add_feature(cfeature.LAND,facecolor='grey')122 ax.coastlines()123 cbar=plt.colorbar(pcolor,orientation='vertical',fraction=0.026,pad=0.1)124 cbar.ax.tick_params(labelsize=20)125 ax.set_title(name+' '+unit,size=17)126 def plot_atl(fig,sub,var,vmin,vmax,unit,name,pal):127 ax = fig.add_subplot(sub,projection=ccrs.PlateCarree(central_longitude=-30))128 cmap = plt.get_cmap(pal)129 ax.set_extent([-100, 50, 0, 70])130 cmap.set_under(color='grey')131 pcolor=ax.pcolormesh(lon,lat,ma.masked_invalid(var),transform=ccrs.PlateCarree(),cmap=cmap,vmin=vmin,vmax=vmax)132 ax.add_feature(cfeature.LAND,facecolor='grey')133 ax.coastlines()134 ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,135 linewidth=2, color='gray', alpha=0.5, linestyle='--')136 fig.subplots_adjust(right=0.8)137 ax.text(-0.07, 0.55, 'Latitude (in degree)', va='bottom', ha='center',138 rotation='vertical', rotation_mode='anchor',139 transform=ax.transAxes)140 ax.text(0.5, -0.2, 'Longitude (in degree)', va='bottom', ha='center',141 rotation='horizontal', rotation_mode='anchor',142 transform=ax.transAxes)143 cbar = plt.colorbar(pcolor,orientation='horizontal',shrink=0.75)144 ax.set_title(name+' '+unit,size=17,y=1.08)145 146 def plot_atl_cont(fig,sub,var,unit,name,vmin,vmax,pal):147 ax = fig.add_subplot(sub,projection=ccrs.PlateCarree(central_longitude=-30))148 ax.set_extent([-100, 50, 0, 70])149 cmap = plt.get_cmap(pal)150 cmap.set_under(color='grey')151 pcolor=ax.pcolormesh(lon,lat,ma.masked_invalid(var),transform=ccrs.PlateCarree(),cmap=cmap,vmin=vmin,vmax=vmax)152 pcont=ax.contour(lon,lat,ma.masked_invalid(var),10,colors='k',transform=ccrs.PlateCarree())153 ax.add_feature(cfeature.LAND,facecolor='black')154 ax.coastlines()155 ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,156 linewidth=2, color='grey', alpha=0.5, linestyle='--')157 fig.subplots_adjust(right=0.8)158 ax.text(-0.07, 0.55, 'Latitude (in degree)', va='bottom', ha='center',159 rotation='vertical', rotation_mode='anchor',160 transform=ax.transAxes)161 ax.text(0.5, -0.2, 'Longitude (in degree)', va='bottom', ha='center',162 rotation='horizontal', rotation_mode='anchor',163 transform=ax.transAxes)164 cbar = plt.colorbar(pcolor,orientation='horizontal',shrink=0.75)165 166 ax.set_title(name+' '+unit,size=17,y=1.08)167 168 def plot_natl(fig,sub,var,vmin,vmax,unit,name,pal):169 ax = fig.add_subplot(sub,projection=ccrs.PlateCarree(central_longitude=-30))170 ax.set_extent([-100, 50, 50, 70])171 cmap = plt.get_cmap(pal)172 cmap.set_under(color='grey')173 pcolor=ax.pcolormesh(lon,lat,ma.masked_invalid(var),transform=ccrs.PlateCarree(),cmap=cmap,vmin=vmin,vmax=vmax)174 ax.add_feature(cfeature.LAND,facecolor='grey')175 ax.coastlines()176 ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,177 linewidth=2, color='gray', alpha=0.5, linestyle='--')178 fig.subplots_adjust(right=0.8)179 ax.text(-0.07, 0.55, 'Latitude (in degree)', va='bottom', ha='center',180 rotation='vertical', rotation_mode='anchor',181 transform=ax.transAxes)182 ax.text(0.5, -0.4, 'Longitude (in degree)', va='bottom', ha='center',183 rotation='horizontal', rotation_mode='anchor',184 transform=ax.transAxes)185 cbar = plt.colorbar(pcolor,orientation='horizontal',shrink=0.75)186 ax.set_title(name+' '+unit,size=17,y=1.19)187 188 print dirplot189# Tous les plots190# Tous les plots glob191# Eke, SSH,T et S192 fig = plt.figure(figsize=(22,7))193 plot_glob(fig,131,10000*eke1,0,2500,'',case1,'jet')194 plot_glob(fig,132,10000*eke2,0,2500,'',case2,'jet')195 plot_glob(fig,133,10000*eke1-10000*eke2,-500,500,'',case1+'-'+case2,'bwr')196 fig.suptitle('NACHOS12.L75 Surf EKE 1e4m2s '+year, fontsize=25)197 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_glob_eke0_'+year+'.png')198 plt.close()199 fig = plt.figure(figsize=(22,7))200 plot_glob(fig,131,ssh1,-2.5,-0.7,'',case1,'tab20b')201 plot_glob(fig,132,ssh2,-2.5,-0.7,'',case2,'tab20b')202 plot_glob(fig,133,ssh1-ssh2,-0.2,0.2,'',case1+'-'+case2,'bwr')203 fig.suptitle('NACHOS12.L75 SSH m '+year, fontsize=25)204 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_glob_ssh_'+year+'.png')205 plt.close()206 fig = plt.figure(figsize=(22,7))207 plot_glob(fig,131,tem1[0],-2,30,'',case1,'jet')208 plot_glob(fig,132,tem2[0],-2,30,'',case2,'jet')209 plot_glob(fig,133,tem1[0]-tem2[0],-2,2,'',case1+'-'+case2,'bwr')210 fig.suptitle('NACHOS12.L75 Surf Temperature deg C '+year, fontsize=25)211 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_glob_t0_'+year+'.png')212 plt.close()213 fig = plt.figure(figsize=(22,7))214 plot_glob(fig,131,sal1[0],30,40,'',case1,'jet')215 plot_glob(fig,132,sal2[0],30,40,'',case2,'jet')216 plot_glob(fig,133,sal1[0]-sal2[0],-1,1,'',case1+'-'+case2,'bwr')217 fig.suptitle('NACHOS12.L75 Surf Salinity PSU '+year, fontsize=25)218 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_glob_s0_'+year+'.png')219 plt.close()220#MXL 221 fig = plt.figure(figsize=(22,7))222 plot_glob(fig,131,mxl103_rho010,0,1500,'',case1,'jet')223 plot_glob(fig,132,mxl203_rho010,0,1500,'',case2,'jet')224 plot_glob(fig,133,mxl103_rho010-mxl203_rho010,-100,100,'',case1+'-'+case2,'bwr')225 fig.suptitle('NACHOS12.L75 March MXL rho010 m '+year, fontsize=25)226 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_glob_mxl03_rho010_'+year+'.png')227 plt.close()228 fig = plt.figure(figsize=(22,7))229 plot_glob(fig,131,mxl109_rho010,0,200,'',case1,'jet')230 plot_glob(fig,132,mxl209_rho010,0,200,'',case2,'jet')231 plot_glob(fig,133,mxl109_rho010-mxl209_rho010,-50,50,'',case1+'-'+case2,'bwr')232 fig.suptitle('NACHOS12.L75 Sept MXL rho010 m '+year, fontsize=25)233 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_glob_mxl09_rho010_'+year+'.png')234 plt.close()235 fig = plt.figure(figsize=(22,7))236 plot_glob(fig,131,mxl103_rho030,0,1500,'',case1,'jet')237 plot_glob(fig,132,mxl203_rho030,0,1500,'',case2,'jet')238 plot_glob(fig,133,mxl103_rho030-mxl203_rho030,-100,100,'',case1+'-'+case2,'bwr')239 fig.suptitle('NACHOS12.L75 March MXL rho030 m '+year, fontsize=25)240 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_glob_mxl03_rho030_'+year+'.png')241 plt.close()242 fig = plt.figure(figsize=(22,7))243 plot_glob(fig,131,mxl109_rho030,0,200,'',case1,'jet')244 plot_glob(fig,132,mxl209_rho030,0,200,'',case2,'jet')245 plot_glob(fig,133,mxl109_rho030-mxl209_rho030,-50,50,'',case1+'-'+case2,'bwr')246 fig.suptitle('NACHOS12.L75 Sept MXL rho030 m '+year, fontsize=25)247 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_glob_mxl09_rho030_'+year+'.png')248 plt.close()249 fig = plt.figure(figsize=(22,7))250 plot_glob(fig,131,mxl103_t02,0,1500,'',case1,'jet')251 plot_glob(fig,132,mxl203_t02,0,1500,'',case2,'jet')252 plot_glob(fig,133,mxl103_t02-mxl203_t02,-100,100,'',case1+'-'+case2,'bwr')253 fig.suptitle('NACHOS12.L75 March MXL t02 m '+year, fontsize=25)254 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_glob_mxl03_t02_'+year+'.png')255 plt.close()256 fig = plt.figure(figsize=(22,7))257 plot_glob(fig,131,mxl109_t02,0,200,'',case1,'jet')258 plot_glob(fig,132,mxl209_t02,0,200,'',case2,'jet')259 plot_glob(fig,133,mxl109_t02-mxl209_t02,-50,50,'',case1+'-'+case2,'bwr')260 fig.suptitle('NACHOS12.L75 Sept MXL t02 m '+year, fontsize=25)261 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_glob_mxl09_t02_'+year+'.png')262 plt.close()263 264#flx 265 fig = plt.figure(figsize=(22,7))266 plot_glob(fig,131,Heat1,-400,400,'',case1,'jet')267 plot_glob(fig,132,Heat2,-400,400,'',case2,'jet')268 plot_glob(fig,133,Heat1-Heat2,-100,100,'',case1+'-'+case2,'bwr')269 fig.suptitle('NACHOS12.L75 Net Heat Flux '+year, fontsize=25)270 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_glob_heat_'+year+'.png')271 plt.close()272 fig = plt.figure(figsize=(22,7))273 plot_glob(fig,131,86400*WaterFlx1,-9,7,'',case1,'jet')274 plot_glob(fig,132,86400*WaterFlx2,-9,7,'',case2,'jet')275 plot_glob(fig,133,86400*WaterFlx1-86400*WaterFlx2,-2,2,'',case1+'-'+case2,'bwr')276 fig.suptitle('NACHOS12.L75 Water Flux '+year, fontsize=25)277 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_glob_wflx_'+year+'.png')278 plt.close()279 fig = plt.figure(figsize=(22,7))280 plot_glob(fig,131,86400*WaterDmp1,-7,7,'',case1,'jet')281 plot_glob(fig,132,86400*WaterDmp2,-7,7,'',case2,'jet')282 plot_glob(fig,133,86400*WaterDmp1-86400*WaterDmp2,-2,2,'',case1+'-'+case2,'bwr')283 fig.suptitle('NACHOS12.L75 Water Damping '+year, fontsize=25)284 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_glob_wdmp_'+year+'.png')285 plt.close()286 287#ice288 fig = plt.figure(figsize=(22,7))289 plot_glob(fig,131,iconc103,0,1,'',case1,'jet')290 plot_glob(fig,132,iconc203,0,1,'',case2,'jet')291 plot_glob(fig,133,iconc103-iconc203,-0.5,0.5,'',case1+'-'+case2,'bwr')292 fig.suptitle('NACHOS12.L75 March Ice concentration % '+year, fontsize=25)293 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_glob_iceconc03_'+year+'.png')294 plt.close()295 fig = plt.figure(figsize=(22,7))296 plot_glob(fig,131,ivolu103,0,4,'',case1,'jet')297 plot_glob(fig,132,ivolu203,0,4,'',case2,'jet')298 plot_glob(fig,133,ivolu103-ivolu203,-0.5,0.5,'',case1+'-'+case2,'bwr')299 fig.suptitle('NACHOS12.L75 March Ice Volume m '+year, fontsize=25)300 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_glob_icevolu03_'+year+'.png')301 plt.close()302 fig = plt.figure(figsize=(22,7))303 plot_glob(fig,131,iconc109,0,1,'',case1,'jet')304 plot_glob(fig,132,iconc209,0,1,'',case2,'jet')305 plot_glob(fig,133,iconc109-iconc209,-0.2,0.2,'',case1+'-'+case2,'bwr')306 fig.suptitle('NACHOS12.L75 Sept Ice concentration % '+year, fontsize=25)307 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_glob_iceconc09_'+year+'.png')308 plt.close()309 fig = plt.figure(figsize=(22,7))310 plot_glob(fig,131,ivolu109,0,4,'',case1,'jet')311 plot_glob(fig,132,ivolu209,0,4,'',case2,'jet')312 plot_glob(fig,133,ivolu109-ivolu209,-0.5,0.5,'',case1+'-'+case2,'bwr')313 fig.suptitle('NACHOS12.L75 Sept Ice Volume m '+year, fontsize=25)314 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_glob_icevolu09_'+year+'.png')315 plt.close()316 317# Tous les plots Atlantique318# T & S319 fig = plt.figure(figsize=(22,7))320 plot_atl(fig,131,tem1[0],-2,30,'',case1,'jet')321 plot_atl(fig,132,tem2[0],-2,30,'',case2,'jet')322 plot_atl(fig,133,tem1[0]-tem2[0],-2,2,'',case1+'-'+case2,'bwr')323 fig.suptitle('NACHOS12.L75 Surf Temperature deg C '+year, fontsize=25)324 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_atl_t0_'+year+'.png')325 plt.close()326 fig = plt.figure(figsize=(22,7))327 plot_atl(fig,131,sal1[0],30,40,'',case1,'jet')328 plot_atl(fig,132,sal2[0],30,40,'',case2,'jet')329 plot_atl(fig,133,sal1[0]-sal2[0],-1,1,'',case1+'-'+case2,'bwr')330 fig.suptitle('NACHOS12.L75 Surf Salinity PSU '+year, fontsize=25)331 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_atl_s0_'+year+'.png')332 plt.close()333 fig = plt.figure(figsize=(22,7))334 plot_atl(fig,131,tem1[30],-2,30,'',case1,'jet')335 plot_atl(fig,132,tem2[30],-2,30,'',case2,'jet')336 plot_atl(fig,133,tem1[30]-tem2[30],-2,2,'',case1+'-'+case2,'bwr')337 fig.suptitle('NACHOS12.L75 200m Temperature deg C '+year, fontsize=25)338 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_atl_t200_'+year+'.png')339 plt.close()340 fig = plt.figure(figsize=(22,7))341 plot_atl(fig,131,sal1[30],30,40,'',case1,'jet')342 plot_atl(fig,132,sal2[30],30,40,'',case2,'jet')343 plot_atl(fig,133,sal1[30]-sal2[30],-2,2,'',case1+'-'+case2,'bwr')344 fig.suptitle('NACHOS12.L75 200m Salinity PSU '+year, fontsize=25)345 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_atl_s200_'+year+'.png')346 plt.close()347 fig = plt.figure(figsize=(22,7))348 plot_atl(fig,131,tem1[46],-2,30,'',case1,'jet')349 plot_atl(fig,132,tem2[46],-2,30,'',case2,'jet')350 plot_atl(fig,133,tem1[46]-tem2[46],-2,2,'',case1+'-'+case2,'bwr')351 fig.suptitle('NACHOS12.L75 1000m Temperature deg C '+year, fontsize=25)352 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_atl_t1000_'+year+'.png')353 plt.close()354 fig = plt.figure(figsize=(22,7))355 plot_atl(fig,131,sal1[46],30,40,'',case1,'jet')356 plot_atl(fig,132,sal2[46],30,40,'',case2,'jet')357 plot_atl(fig,133,sal1[46]-sal2[46],-1,1,'',case1+'-'+case2,'bwr')358 fig.suptitle('NACHOS12.L75 1000m Salinity PSU '+year, fontsize=25)359 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_atl_s1000_'+year+'.png')360 plt.close()361#PSI 362 fig = plt.figure(figsize=(22,7))363 plot_atl_cont(fig,131,1e-7*psi1,'',case1,-4,4,'Blues')364 plot_atl_cont(fig,132,1e-7*psi2,'',case2,-4,4,'Blues')365 plot_atl_cont(fig,133,1e-7*psi1-1e-7*psi2,'',case1+'-'+case2,-1,1,'bwr')366 fig.suptitle('NACHOS12.L75 Stream function '+year, fontsize=25)367 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_atl_psi_'+year+'.png')368 plt.close()369#flx 370 fig = plt.figure(figsize=(22,7))371 plot_atl(fig,131,Heat1,-400,400,'',case1,'jet')372 plot_atl(fig,132,Heat2,-400,400,'',case2,'jet')373 plot_atl(fig,133,Heat1-Heat2,-100,100,'',case1+'-'+case2,'bwr')374 fig.suptitle('NACHOS12.L75 Net Heat Flux '+year, fontsize=25)375 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_atl_heat_'+year+'.png')376 plt.close()377 fig = plt.figure(figsize=(22,7))378 plot_atl(fig,131,86400*WaterFlx1,-9,7,'',case1,'jet')379 plot_atl(fig,132,86400*WaterFlx2,-9,7,'',case2,'jet')380 plot_atl(fig,133,86400*WaterFlx1-86400*WaterFlx2,-2,2,'',case1+'-'+case2,'bwr')381 fig.suptitle('NACHOS12.L75 Water Flux '+year, fontsize=25)382 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_atl_wflx_'+year+'.png')383 plt.close()384 fig = plt.figure(figsize=(22,7))385 plot_atl(fig,131,86400*WaterDmp1,-7,7,'',case1,'jet')386 plot_atl(fig,132,86400*WaterDmp2,-7,7,'',case2,'jet')387 plot_atl(fig,133,86400*WaterDmp1-86400*WaterDmp2,-2,2,'',case1+'-'+case2,'bwr')388 fig.suptitle('NACHOS12.L75 Water Damping '+year, fontsize=25)389 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_atl_wdmp_'+year+'.png')390 plt.close()391 392#MXL393 fig = plt.figure(figsize=(22,7))394 plot_atl(fig,131,mxl103_rho010,0,1500,'',case1,'jet')395 plot_atl(fig,132,mxl203_rho010,0,1500,'',case2,'jet')396 plot_atl(fig,133,mxl103_rho010-mxl203_rho010,-100,100,'',case1+'-'+case2,'bwr')397 fig.suptitle('NACHOS12.L75 March MXL rho010 m '+year, fontsize=25)398 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_atl_mxl03_rho010_'+year+'.png')399 plt.close()400 fig = plt.figure(figsize=(22,7))401 plot_atl(fig,131,mxl109_rho010,0,200,'',case1,'jet')402 plot_atl(fig,132,mxl209_rho010,0,200,'',case2,'jet')403 plot_atl(fig,133,mxl109_rho010-mxl209_rho010,-50,50,'',case1+'-'+case2,'bwr')404 fig.suptitle('NACHOS12.L75 Sept MXL rho010 m '+year, fontsize=25)405 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_atl_mxl09_rho010_'+year+'.png')406 plt.close()407 408#Tous les plots N Atlantique409 410 fig = plt.figure(figsize=(22,7))411 plot_natl(fig,131,iconc103,0,1,'',case1,'jet')412 plot_natl(fig,132,iconc203,0,1,'',case2,'jet')413 plot_natl(fig,133,iconc103-iconc203,-0.5,0.5,'',case1+'-'+case2,'bwr')414 fig.suptitle('NACHOS12.L75 March Ice concentration % '+year, fontsize=25)415 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_natl_iceconc03_'+year+'.png')416 plt.close()417 fig = plt.figure(figsize=(22,7))418 plot_natl(fig,131,ivolu103,0,4,'',case1,'jet')419 plot_natl(fig,132,ivolu203,0,4,'',case2,'jet')420 plot_natl(fig,133,ivolu103-ivolu203,-0.5,0.5,'',case1+'-'+case2,'bwr')421 fig.suptitle('NACHOS12.L75 March Ice Volume m '+year, fontsize=25)422 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_natl_icevolu03_'+year+'.png')423 plt.close()424 fig = plt.figure(figsize=(22,7))425 plot_natl(fig,131,iconc109,0,1,'',case1,'jet')426 plot_natl(fig,132,iconc209,0,1,'',case2,'jet')427 plot_natl(fig,133,iconc109-iconc209,-0.5,0.5,'',case1+'-'+case2,'bwr')428 fig.suptitle('NACHOS12.L75 Sept Ice concentration % '+case1+'-'+case2+' '+year, fontsize=25)429 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_natl_iceconc09_'+year+'.png')430 plt.close()431 fig = plt.figure(figsize=(22,7))432 plot_natl(fig,131,ivolu109,0,4,'',case1,'jet')433 plot_natl(fig,132,ivolu209,0,4,'',case2,'jet')434 plot_natl(fig,133,ivolu109-ivolu209,-0.5,0.5,'',case1+'-'+case2,'bwr')435 fig.suptitle('NACHOS12.L75 Sept Ice Volume m '+year, fontsize=25)436 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_natl_icevolu09_'+year+'.png')437 plt.close()438 439#MXL440 fig = plt.figure(figsize=(22,7))441 plot_natl(fig,131,mxl103_rho010,0,1500,'',case1,'jet')442 plot_natl(fig,132,mxl203_rho010,0,1500,'',case2,'jet')443 plot_natl(fig,133,mxl103_rho010-mxl203_rho010,-100,100,'',case1+'-'+case2,'bwr')444 fig.suptitle('NACHOS12.L75 March MXL rho010 m '+year, fontsize=25)445 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_natl_mxl03_rho010_'+year+'.png')446 plt.close()447 fig = plt.figure(figsize=(22,7))448 plot_natl(fig,131,mxl109_rho010,0,200,'',case1,'jet')449 plot_natl(fig,132,mxl209_rho010,0,200,'',case2,'jet')450 plot_natl(fig,133,mxl109_rho010-mxl209_rho010,-50,50,'',case1+'-'+case2,'bwr')451 fig.suptitle('NACHOS12.L75 Sept MXL rho010 m '+year, fontsize=25)452 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_natl_mxl09_rho010_'+year+'.png')453 plt.close()454 fig = plt.figure(figsize=(22,7))455 plot_natl(fig,131,mxl103_rho030,0,1500,'',case1,'jet')456 plot_natl(fig,132,mxl203_rho030,0,1500,'',case2,'jet')457 plot_natl(fig,133,mxl103_rho030-mxl203_rho030,-100,100,'',case1+'-'+case2,'bwr')458 fig.suptitle('NACHOS12.L75 March MXL rho030 m '+year, fontsize=25)459 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_natl_mxl03_rho030_'+year+'.png')460 plt.close()461 fig = plt.figure(figsize=(22,7))462 plot_natl(fig,131,mxl109_rho030,0,200,'',case1,'jet')463 plot_natl(fig,132,mxl209_rho030,0,200,'',case2,'jet')464 plot_natl(fig,133,mxl109_rho030-mxl209_rho030,-50,50,'',case1+'-'+case2,'bwr')465 fig.suptitle('NACHOS12.L75 Sept MXL rho030 m '+year, fontsize=25)466 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_natl_mxl09_rho030_'+year+'.png')467 plt.close()468 fig = plt.figure(figsize=(22,7))469 plot_natl(fig,131,mxl103_t02,0,1500,'',case1,'jet')470 plot_natl(fig,132,mxl203_t02,0,1500,'',case2,'jet')471 plot_natl(fig,133,mxl103_t02-mxl203_t02,-100,100,'',case1+'-'+case2,'bwr')472 fig.suptitle('NACHOS12.L75 March MXL t02 m '+year, fontsize=25)473 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_natl_mxl03_t02_'+year+'.png')474 plt.close()475 fig = plt.figure(figsize=(22,7))476 plot_natl(fig,131,mxl109_t02,0,200,'',case1,'jet')477 plot_natl(fig,132,mxl209_t02,0,200,'',case2,'jet')478 plot_natl(fig,133,mxl109_t02-mxl209_t02,-50,50,'',case1+'-'+case2,'bwr')479 fig.suptitle('NACHOS12.L75 Sept MXL t02 m '+year, fontsize=25)480 plt.savefig(dirplot+'NACHOS12.L75-'+case1+'-'+case2+'_natl_mxl09_t02_'+year+'.png')481 plt.close()482def script_parser():483 """Customized parser.484 """485 from optparse import OptionParser486 usage = "usage: %prog CASE1 CASE2 year"487 parser = OptionParser(usage=usage)488 return parser489def main():490 parser = script_parser()491 (options, args) = parser.parse_args()492 if len(args) < 3: # print the help message if number of args is not 2.493 parser.print_help()494 sys.exit()495 optdic = vars(options)496 if len(args) == 3:497 case1 = args[0]498 case2 = args[1]499 year = args[2]500 all_plots(case1,case2,year,**optdic)501if __name__ == '__main__':...

Full Screen

Full Screen

normalize_cases

Source:normalize_cases Github

copy

Full Screen

1#!/usr/bin/env python2"""3Remove uninteresting diffs between cases by changing the4first to be more like the second.5This is for debugging purposes and meant to assist the user6when they want to run case_diff.7"""8from standard_script_setup import *9from CIME.utils import expect, run_cmd_no_fail10import argparse, sys, os, glob11###############################################################################12def parse_command_line(args, description):13###############################################################################14 parser = argparse.ArgumentParser(15 usage="""\n{0} case1 case216OR17{0} --help18\033[1mEXAMPLES:\033[0m19 > {0} case1 case220""".format(os.path.basename(args[0])),21description=description,22formatter_class=argparse.ArgumentDefaultsHelpFormatter23)24 CIME.utils.setup_standard_logging_options(parser)25 parser.add_argument("case1", help="First case. This one will be changed")26 parser.add_argument("case2", help="Second case. This one will not be changed")27 args = CIME.utils.parse_args_and_handle_standard_logging_options(args, parser)28 return args.case1, args.case229###############################################################################30def normalize_cases(case1, case2):31###############################################################################32 # gunzip all logs33 for case_dir in [case1, case2]:34 for log_dir in ["bld", "run"]:35 gzips = glob.glob(os.path.join(case_dir, log_dir, "*.gz"))36 if (gzips):37 run_cmd_no_fail("gunzip -f {}".format(" ".join(gzips)))38 # Change case1 to be as if it had same test-id as case239 test_id1 = run_cmd_no_fail("./xmlquery --value TEST_TESTID", from_dir=case1)40 test_id2 = run_cmd_no_fail("./xmlquery --value TEST_TESTID", from_dir=case2)41 run_cmd_no_fail("for item in $(find -type f); do sed -i 's/{}/{}/g' $item; done".format(test_id1, test_id2),42 from_dir=case1)43 # Change case1 to look as if it is was built/run at exact same time as case244 for log_dir in ["bld", "run"]:45 case1_lids = set()46 for logfile in glob.glob("{}/{}/*.bldlog.*".format(case1, log_dir)):47 case1_lids.add(logfile.split(".")[-1])48 case2_lids = set()49 for logfile in glob.glob("{}/{}/*.bldlog.*".format(case2, log_dir)):50 case2_lids.add(logfile.split(".")[-1])51 case1_lids = list(sorted(case1_lids))52 case2_lids = list(sorted(case2_lids))53 for case1_lid, case2_lid in zip(case1_lids, case2_lids):54 run_cmd_no_fail("for item in $(find -type f); do sed -i 's/{}/{}/g' $item; done".format(case1_lid, case2_lid),55 from_dir=case1)56 for case1_lid, case2_lid in zip(case1_lids, case2_lids):57 files_needing_rename = run_cmd_no_fail('find -depth -name "*.{}"'.format(case1_lid), from_dir=case1).splitlines()58 for file_needing_rename in files_needing_rename:59 expect(file_needing_rename.endswith(case1_lid), "broken")60 new_name = file_needing_rename.rstrip(case1_lid) + case2_lid61 os.rename(os.path.join(case1, file_needing_rename), os.path.join(case1, new_name))62 # Normalize CIMEROOT63 case1_root = run_cmd_no_fail("./xmlquery --value CIMEROOT", from_dir=case1)64 case2_root = run_cmd_no_fail("./xmlquery --value CIMEROOT", from_dir=case2)65 if (case1_root != case2_root):66 run_cmd_no_fail("for item in $(find -type f); do sed -i 's:{}:{}:g' $item; done".format(case1_root, case2_root),67 from_dir=case1)68###############################################################################69def _main_func(description):70###############################################################################71 case1, case2 = parse_command_line(sys.argv, description)72 normalize_cases(case1, case2)73###############################################################################74if (__name__ == "__main__"):...

Full Screen

Full Screen

test_cases.py

Source:test_cases.py Github

copy

Full Screen

1### Tests cases input, partial order, relevance, etc.2import pytest3from aacbr.cases import Case, different_outcomes, inconsistent_pair #, mostConcise, attacks, newcaseattacks, 4def test_create_case():5 empty_case = Case('empty', set())6 print(empty_case)7 pass8def test_specificity():9 case1 = Case('1', {'a'})10 case2 = Case('2', {'a','b'})11 assert case2 >= case112 assert case2 > case113 assert not case1 >= case214 assert case1 >= case115 assert not case1 > case116 assert case2 >= case217def test_different_outcomes():18 case1 = Case('1', {'a'}, outcome=0)19 case2 = Case('2', {'a','b'}, outcome=1)20 assert different_outcomes(case1, case2)21 assert different_outcomes(case2, case1)22 assert not different_outcomes(case1, case1)23 assert not different_outcomes(case2, case2)24 25# def test_conciseness():26# case1 = Case('1', {'a'})27# case2 = Case('2', {'a','b'})28# case3 = Case('3', {'a','b','c'})29# cases = [case1, case2, case3]30# assert mostConcise(cases, case2, case1)31# assert not mostConcise(cases, case3, case1)32# assert not mostConcise(cases, case1, case2)33# def test_newcaseattack():34# newcase = Case('new', {'a'})35# case1 = Case('1', {'a'}, outcome=0)36# case2 = Case('2', {'a','b'}, outcome=1)37# default = Case('default', set(), outcome=0)38# cases = (default, case1, case2, newcase)39# assert newcaseattacks(newcase, case2)40# assert not newcaseattacks(newcase, case1)41# assert not newcaseattacks(newcase, default)42 43def test_inconsistent_pair():44 case1 = Case('1', {'a','b'}, outcome=0)45 case2 = Case('2', {'a','b'}, outcome=1)46 assert inconsistent_pair(case1, case2)47def test_order_notation():48 default = Case('default', set(), outcome=0)49 case1 = Case('1', {'a'}, outcome=1)50 case2 = Case('2', {'a','b'}, outcome=0)51 case2b = Case('2b', {'a','b'}, outcome=1)52 case3 = Case('3', {'c'})53 case4 = Case('4', {'a','b', 'c'}, outcome=1)54 cases = [default, case1, case2, case2b, case3, case4]55 assert all([default <= case for case in cases])56 assert all([case <= case for case in cases])57 assert not any([case < case for case in cases])58 assert case1 < case259 assert not case1 < case360 assert not case3 < case161 assert all([case >= default for case in cases])62 assert all([case >= case for case in cases])63 assert case4 > case1 and case4 > case364 assert case4 > case2 and case4 > case2b65 assert case2 >= case2b and case2b >= case266 assert not case2 == case2b67 assert case2 != case2b68 69def test_alternative_partial_order(): 70 class OrderedPair:71 """Pair (a,b) where (a,b) are natural numbers.72 Partial order is defined by (a,b) <= (c,d) iff a<=c and b<=d."""73 74 def __init__(self, x, y):75 self.x: int = x76 self.y: int = y77 78 def __eq__(self, other):79 return self.x == other.x and self.y == other.y80 def __le__(self, other):81 return self.x <= other.x and self.y <= other.y82 def __lt__(self, other):83 """Not necessary for Cases, but recommended."""84 return self <= other and self != other85 default = Case('default', OrderedPair(0,0), outcome=0)86 case1 = Case('1', OrderedPair(1,0), outcome=1)87 case2 = Case('2', OrderedPair(0,1), outcome=0)88 case2b = Case('2b', OrderedPair(0,1), outcome=1)89 case3 = Case('3', OrderedPair(2,1), outcome=0)90 cb = (case1, case2, case2b, case3)91 assert default <= default92 assert not default < default93 for case in cb:94 assert default < case95 assert not case < default96 assert not case2 < case197 assert not case2 > case198 assert case2 >= case2b99 assert case2b >= case2100 assert not case2 > case2b101 assert not case2b > case2102 assert case3 > case1103 assert case2 < case3104 105def test_load_cases():106 # TODO: implement107 pass108def test_list_of_numbers_partial_order():109 # TODO: implement110 pass111def test_arbitrary_partial_order():112 # TODO: implement...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run yandex-tank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful