-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_fv3lam_icbc.py
executable file
·574 lines (472 loc) · 19.6 KB
/
plot_fv3lam_icbc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
###################################################################### CHJ #####
## Name : plot_fv3sar_icbc.py
## Language : Python 3.7
## Usage : Plot time-dependent IC/LBC fields for fv3 regional modeling
## Input files : gfs_bndy.tile7.XXX.nc and gfs_data.tile7.nc
## NOAA/NWS/NCEP/EMC
## History ===============================
## V000: 2020/03/06: Chan-Hoo Jeon : Preliminary version
## V001: 2020/03/10: Chan-Hoo Jeon : Add velocities to plot options
## V002: 2020/04/03: Chan-Hoo Jeon : Read GFS data and index once
## V003: 2020/04/07: Chan-Hoo Jeon : Add refine ratio to output titles
## V004: 2020/04/21: Chan-Hoo Jeon : Print out max/min every time step
## V005: 2020/05/26: Chan-Hoo Jeon : Modified to include blending layers
## V006: 2020/06/22: Chan-Hoo Jeon : Add opt. for machine-specific arguments
## V007: 2021/03/04: Chan-Hoo Jeon : Simplify the script
###################################################################### CHJ #####
import os, sys
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import matplotlib.lines as mlines
import numpy as np
import xarray as xr
from mpl_toolkits.axes_grid1 import make_axes_locatable
# HPC machine ('hera','orion')
machine='hera'
print(' You are on', machine)
#### Machine-specific input data ==================================== CHJ =====
# out_fig_dir: directory where the output files are created
# mfdt_kwargs: mfdataset argument
if machine=='hera':
out_fig_dir="/scratch2/NCEPDEV/fv3-cam/Chan-hoo.Jeon/tools/fv3sar_pre_plot/Fig/"
mfdt_kwargs={'parallel':False}
elif machine=='orion':
out_fig_dir="/work/noaa/fv3-cam/chjeon/tools/Fig/"
mfdt_kwargs={'parallel':False,'combine':'by_coords'}
else:
sys.exit('ERROR: Required input data are NOT set !!!')
# Case-dependent input =============================================== CHJ =====
# Path to the directory where the input NetCDF files are located.
dnm_data="/scratch2/NCEPDEV/stmp1/Chan-hoo.Jeon/run_C96/INPUT_blend10/"
# File names of initial and boundary conditions
fnm_in_bndr_base='gfs_bndy.tile7.'
# Time steps of input netcdf files (3 digits): ex ["000","003","006","009","012"]
bndr_step=["000"]
# Variables
#vars_bc=["ps","w","zh","t","sphum","liq_wat","o3mr","ice_wat",
# "rainwat","snowwat","graupel","u_w","v_w","u_s","v_s"]
vars_bc=["t","u_s"]
# number of the target vertical level (only for 3-D fields)
ilvl=1
# Color-map range option flag ('symmetry','round','real','fixed')
cmap_range='round'
# basic forms of title and file name
out_title_base='FV3LAM::IC/LBC'
out_fname_base='fv3lam_icbc_'
# Number of additional boundary arrays (halo)
n_halo=4
# Number of blending layers (nrows_blend)
n_blend=10
# Total number of halos
n_halo_all=n_halo+n_blend
bc_lvl=format(ilvl,'03d')
sblend=format(n_blend,'02d')
# Main part (will be called at the end) ============================== CHJ =====
def main():
# ==================================================================== CHJ =====
print(' ===== Read GFS DATA ================================================')
# Initial GFS Data of the main domain
fnm_input_var='gfs_data.tile7.nc'
fname=os.path.join(dnm_data,fnm_input_var)
try: tvar=xr.open_mfdataset(fname,**mfdt_kwargs)
except: raise Exception('Could NOT find the file',fname)
print(tvar)
print(' ===== IC/BC :: i,j indexes =========================================')
fnm_input_var=fnm_in_bndr_base+'000.nc'
# open the data file
fname=os.path.join(dnm_data,fnm_input_var)
try: ibcf=xr.open_mfdataset(fname,**mfdt_kwargs)
except: raise Exception('Could NOT find the file',fname)
print(ibcf)
# variables
for svar in vars_bc: # variables
bndr_index(svar,ibcf)
# Plot initial gfs data inside the regular domain for comparison
plot_gfs(tvar,svar)
for ibc in bndr_step: # time steps
# main plot
plot_bc(svar,ibc)
# Read index of boundary fields ====================================== CHJ =====
def bndr_index(svar,ibcf):
# ==================================================================== CHJ =====
global i_bottom,j_bottom,i_top,j_top,i_left,j_left,i_right,j_right
global i_b,i_b_sym,i_bx_sym,j_l_sym
global i_b_xtk,i_b_xlb,j_b_ytk,j_t_ytk,j_l_ytk,j_l_ylb
global nd_xj,nd_yi,i_bx_xtk,i_bx_xlb
print(' ===== BC Field Index :: '+svar+' ==================================')
if svar=='u_w' or svar=='v_w':
# top & bottom: (halo,domain i+2*halo+1) : i(x-direction), j(y-direction)
i_bottom=np.ma.masked_invalid(ibcf['i_w_bottom'].data)
j_bottom=np.ma.masked_invalid(ibcf['j_w_bottom'].data)
i_top=np.ma.masked_invalid(ibcf['i_w_top'].data)
j_top=np.ma.masked_invalid(ibcf['j_w_top'].data)
# left & right: (domain j,halo)
i_left=np.ma.masked_invalid(ibcf['i_w_left'].data)
j_left=np.ma.masked_invalid(ibcf['j_w_left'].data)
i_right=np.ma.masked_invalid(ibcf['i_w_right'].data)
j_right=np.ma.masked_invalid(ibcf['j_w_right'].data)
n_jb=j_bottom.shape[0]
if n_jb!=n_halo_all:
sys.exit('ERROR: n_halo+n_blend is not the same as BC files !!!')
elif svar=='u_s' or svar=='v_s':
# top & bottom: (halo,domain i+2*halo) : i(x-direction), j(y-direction)
i_bottom=np.ma.masked_invalid(ibcf['i_s_bottom'].data)
j_bottom=np.ma.masked_invalid(ibcf['j_s_bottom'].data)
i_top=np.ma.masked_invalid(ibcf['i_s_top'].data)
j_top=np.ma.masked_invalid(ibcf['j_s_top'].data)
# left & right: (domain j,halo+1)
i_left=np.ma.masked_invalid(ibcf['i_s_left'].data)
j_left=np.ma.masked_invalid(ibcf['j_s_left'].data)
i_right=np.ma.masked_invalid(ibcf['i_s_right'].data)
j_right=np.ma.masked_invalid(ibcf['j_s_right'].data)
n_jb=i_right.shape[0]
if n_jb!=n_halo_all:
sys.exit('ERROR: n_halo+n_blend is not the same as BC files !!!')
else:
# top & bottom: (halo,domain i+2*halo) : i(x-direction), j(y-direction)
i_bottom=np.ma.masked_invalid(ibcf['i_bottom'].data)
j_bottom=np.ma.masked_invalid(ibcf['j_bottom'].data)
i_top=np.ma.masked_invalid(ibcf['i_top'].data)
j_top=np.ma.masked_invalid(ibcf['j_top'].data)
# left & right: (domain j,halo)
i_left=np.ma.masked_invalid(ibcf['i_left'].data)
j_left=np.ma.masked_invalid(ibcf['j_left'].data)
i_right=np.ma.masked_invalid(ibcf['i_right'].data)
j_right=np.ma.masked_invalid(ibcf['j_right'].data)
n_jb=j_bottom.shape[0]
if n_jb!=n_halo_all:
sys.exit('ERROR: n_halo+n_blend is not the same as BC files !!!')
# new coordinates for expanding axis-scales from mid
# nd_xj: x-dimensional length of the real domain
nd_xj=len(i_bottom)-2*n_halo
nd_yi=len(j_left)
print(' Domain size (nlat,nlon)=(',nd_yi,',',nd_xj,')')
# bottom
i_b_sym=axis_contract(i_bottom)
nib=len(i_b_sym)
i_b_xtk,i_b_xlb=tick_label(nib,i_b_sym,i_bottom)
nskp=int(len(j_bottom)/4)
if nskp<1:
nskp=1
j_b_ytk=j_bottom[::nskp]
# top
nskp=int(len(j_top)/4)
if nskp<1:
nskp=1
j_t_ytk=j_top[::nskp]
# left
j_l_sym=axis_contract(j_left)
nib=len(j_l_sym)
j_l_ytk,j_l_ylb=tick_label(nib,j_l_sym,j_left)
# x-axis only for domain
i_b=i_bottom[n_halo:-n_halo]
# print(i_b)
i_bx_sym=axis_contract(i_b)
nib=len(i_b)
i_bx_xtk,i_bx_xlb=tick_label(nib,i_bx_sym,i_b)
# print('i_bottom::',i_bottom)
# print('j_bottom::',j_bottom)
# print('i_top::',i_top)
# print('j_top::',j_top)
# print('i_left::',i_left)
# print('j_left::',j_left)
# print('i_right::',i_right)
# print('j_right::',j_right)
# Plot each variable ================================================= CHJ =====
def plot_bc(svar,ibc):
# ==================================================================== CHJ =====
print(' ===== BC Field:: '+svar+' :: ==== at '+ibc+' ==============')
fnm_input_var=fnm_in_bndr_base+ibc+'.nc'
# open the data file
fname=os.path.join(dnm_data,fnm_input_var)
print(fname)
try: ibcf=xr.open_mfdataset(fname,**mfdt_kwargs)
except: raise Exception('Could NOT find the file',fname)
# Extract data of svar at ibcf
bc_bottom=np.ma.masked_invalid(ibcf[svar+'_bottom'].data)
bc_top=np.ma.masked_invalid(ibcf[svar+'_top'].data)
bc_right=np.ma.masked_invalid(ibcf[svar+'_right'].data)
bc_left=np.ma.masked_invalid(ibcf[svar+'_left'].data)
bc1d_bottom=bc_bottom.ravel()
bc1d_top=bc_top.ravel()
bc1d_right=bc_right.ravel()
bc1d_left=bc_left.ravel()
bc1d_all=np.concatenate([bc1d_bottom,bc1d_top,bc1d_right,bc1d_left])
ndim_bc=bc_bottom.ndim
if ndim_bc==2: # 2d array
bc2d_bottom=bc_bottom
bc2d_top=bc_top
bc2d_right=bc_right
bc2d_left=bc_left
out_bc_fname=out_fname_base+svar+'_t'+ibc+'_B'+sblend
elif ndim_bc==3: # 3d array (vertical level,:,:)
bc2d_bottom=bc_bottom[ilvl-1,:,:]
bc2d_top=bc_top[ilvl-1,:,:]
bc2d_right=bc_right[ilvl-1,:,:]
bc2d_left=bc_left[ilvl-1,:,:]
out_bc_fname=out_fname_base+svar+'_L'+bc_lvl+'_t'+ibc+'_B'+sblend
var_min=[]
var_max=[]
# Max/min: overall
var_min.append(np.min(bc2d_bottom))
var_min.append(np.min(bc2d_top))
var_min.append(np.min(bc2d_left))
var_min.append(np.min(bc2d_right))
var_min_all=np.min(var_min)
var_max.append(np.max(bc2d_bottom))
var_max.append(np.max(bc2d_top))
var_max.append(np.max(bc2d_left))
var_max.append(np.max(bc2d_right))
var_max_all=np.max(var_max)
print("MIN=",var_min_all)
print("MAX=",var_max_all)
# Plot field
fig=plt.figure(figsize=(3,3))
grid=plt.GridSpec(4,4,wspace=0.1,hspace=0.1)
# center
ax_c=fig.add_subplot(grid[1:-1,1:-1])
# left
ax_l=fig.add_subplot(grid[1:-1,0])
# right
ax_r=fig.add_subplot(grid[1:-1,3])
# top
ax_t=fig.add_subplot(grid[0,:])
# bottom
ax_b=fig.add_subplot(grid[3,:])
tick_ln=1.5
tick_wd=0.45
tlb_sz=2.5
# bottom
xj_b,yi_b=np.meshgrid(i_b_sym,j_bottom)
ax_b.pcolormesh(xj_b,yi_b,bc2d_bottom,cmap=cs_cmap,vmin=cs_min,vmax=cs_max)
ax_b.tick_params(direction='out',length=tick_ln,width=tick_wd,labelsize=tlb_sz)
ax_b.set_xticks(i_b_xtk)
ax_b.set_xticklabels(i_b_xlb)
ax_b.set_yticks(j_bottom)
ax_b.set_yticklabels(j_bottom)
if n_blend>0:
x1=(i_b_sym[n_halo-1]+i_b_sym[n_halo])*0.5
x2=(i_b_sym[-n_halo-1]+i_b_sym[-n_halo])*0.5
y1=0.5
ln1=mlines.Line2D([x1,x2],[y1,y1],color='w',lw=0.7,ls='--')
ax_b.add_artist(ln1)
x1=(i_b_sym[n_halo-1]+i_b_sym[n_halo])*0.5
y1=(j_bottom[n_halo-1]+j_bottom[n_halo])*0.5
y2=j_bottom[-1]
ln1=mlines.Line2D([x1,x1],[y1,y2],color='w',lw=0.7,ls='--')
ax_b.add_artist(ln1)
x1=(i_b_sym[-n_halo-1]+i_b_sym[-n_halo])*0.5
y1=(j_bottom[n_halo-1]+j_bottom[n_halo])*0.5
y2=j_bottom[-1]
ln1=mlines.Line2D([x1,x1],[y1,y2],color='w',lw=0.7,ls='--')
ax_b.add_artist(ln1)
# top
xj_t,yi_t=np.meshgrid(i_b_sym,j_top)
ax_t.pcolormesh(xj_t,yi_t,bc2d_top,cmap=cs_cmap,vmin=cs_min,vmax=cs_max)
ax_t.tick_params(direction='out',length=tick_ln,width=tick_wd,labelsize=tlb_sz,
bottom=False,labelbottom=False,top=True,labeltop=False)
ax_t.set_xticks(i_b_xtk)
ax_t.set_xticklabels(i_b_xlb)
ax_t.set_yticks(j_top)
ax_t.set_yticklabels(j_top)
if n_blend>0:
x1=(i_b_sym[n_halo-1]+i_b_sym[n_halo])*0.5
x2=(i_b_sym[-n_halo-1]+i_b_sym[-n_halo])*0.5
y1=j_top[-n_halo-1]+0.5
ln1=mlines.Line2D([x1,x2],[y1,y1],color='w',lw=0.7,ls='--')
ax_t.add_artist(ln1)
x1=(i_b_sym[n_halo-1]+i_b_sym[n_halo])*0.5
y2=(j_top[-n_halo-1]+j_top[-n_halo])*0.5
y1=j_top[0]
ln1=mlines.Line2D([x1,x1],[y1,y2],color='w',lw=0.7,ls='--')
ax_t.add_artist(ln1)
x1=(i_b_sym[-n_halo-1]+i_b_sym[-n_halo])*0.5
y2=(j_top[-n_halo-1]+j_top[-n_halo])*0.5
y1=j_top[0]
ln1=mlines.Line2D([x1,x1],[y1,y2],color='w',lw=0.7,ls='--')
ax_t.add_artist(ln1)
# left
xj_l,yi_l=np.meshgrid(i_left,j_l_sym)
ax_l.pcolormesh(xj_l,yi_l,bc2d_left,cmap=cs_cmap,vmin=cs_min,vmax=cs_max)
ax_l.tick_params(direction='out',length=tick_ln,width=tick_wd,labelsize=tlb_sz,
labelbottom=False)
ax_l.set_yticks(j_l_ytk)
ax_l.set_yticklabels(j_l_ylb)
ax_l.set_xticks(i_left)
if n_blend>0:
x1=i_left[n_halo-1]+0.5
y1=j_l_sym[0]
y2=j_l_sym[-1]
ln1=mlines.Line2D([x1,x1],[y1,y2],color='w',lw=0.7,ls='--')
ax_l.add_artist(ln1)
# right
xj_r,yi_r=np.meshgrid(i_right,j_l_sym)
ax_r.pcolormesh(xj_r,yi_r,bc2d_right,cmap=cs_cmap,vmin=cs_min,vmax=cs_max)
ax_r.tick_params(direction='out',length=tick_ln,width=tick_wd,
left=False,labelleft=False,labelbottom=False,right=True)
ax_r.set_yticks(j_l_ytk)
ax_r.set_yticklabels(j_l_ylb)
ax_r.set_xticks(i_right)
if n_blend>0:
x1=i_right[-n_halo]-0.5
y1=j_l_sym[0]
y2=j_l_sym[-1]
ln1=mlines.Line2D([x1,x1],[y1,y2],color='w',lw=0.7,ls='--')
ax_r.add_artist(ln1)
# center
ax_c.axis([0,10,0,10])
ax_c.axis('off')
ax_c.text(5,7,out_title_base,fontsize=5,color='black',
horizontalalignment='center',verticalalignment='center')
ax_c.text(5,6,'Variable='+svar,fontsize=5,color='black',
horizontalalignment='center',verticalalignment='center')
ax_c.text(5,5,'Layer #='+bc_lvl,fontsize=5,color='black',
horizontalalignment='center',verticalalignment='center')
ax_c.text(5,4,'Time='+ibc,fontsize=5,color='black',
horizontalalignment='center',verticalalignment='center')
ax_c.text(5,2,'N_blend='+str(n_blend),fontsize=4,color='black',
horizontalalignment='center',verticalalignment='center')
ax_c.text(5,9.95,'Top',fontsize=tlb_sz,horizontalalignment='center',
verticalalignment='center')
ax_c.text(5,0.05,'Bottom',fontsize=tlb_sz,horizontalalignment='center',
verticalalignment='center')
ax_c.text(0.05,5,'Left',fontsize=tlb_sz,horizontalalignment='center',
verticalalignment='center',rotation='vertical')
ax_c.text(9.95,5,'Right',fontsize=tlb_sz,horizontalalignment='center',
verticalalignment='center',rotation='vertical')
# Output figure
out_file(out_bc_fname)
# Plot gfs data ====================================================== CHJ =====
def plot_gfs(tvar,svar):
# ==================================================================== CHJ =====
global cs_cmap,cs_min,cs_max
print(' ===== GFS Data::'+svar+' ===============================')
sgfs=np.ma.masked_invalid(tvar[svar].data)
ndim_sgfs=sgfs.ndim
if ndim_sgfs==2: # 2D array
nlvl=1
nyi,nxj=sgfs.shape
sgfs2d=sgfs
out_gfs_fname=out_fname_base+svar+'_gfs'
out_title_gfs_o=out_title_base+'::GFS::'+svar+'t000::Regular'
out_title_gfs_n=out_title_base+'::GFS::'+svar+'t000::Contracted'
elif ndim_sgfs==3: # 3D array
nlvl,nyi,nxj=sgfs.shape
sgfs2d=sgfs[ilvl-1,:,:]
out_gfs_fname=out_fname_base+svar+'_L'+bc_lvl+'_gfs'
out_title_gfs_o=out_title_base+'::GFS::'+svar+'::L'+bc_lvl+'t000::Regular'
out_title_gfs_n=out_title_base+'::GFS::'+svar+'::L'+bc_lvl+'t000::Contracted'
else:
sys.exit('ERROR: Wrong dimension of GFS !!!')
fmin=np.min(sgfs2d)
fmax=np.max(sgfs2d)
# cmap_range='round'
n_rnd=2
print(' cmap range=',cmap_range)
if cmap_range=='symmetry':
tmp_cmp=max(abs(fmax),abs(fmin))
cs_min=round(-tmp_cmp,n_rnd)
cs_max=round(tmp_cmp,n_rnd)
elif cmap_range=='round':
cs_min=round(fmin,n_rnd)
cs_max=round(fmax,n_rnd)
elif cmap_range=='real':
cs_min=fmin
cs_max=fmax
elif cmap_range=='fixed':
cs_min=-10.0
cs_max=10.0
else:
sys.exit('ERROR: wrong colormap-range flag !!!')
print(' cs_min=',cs_min)
print(' cs_max=',cs_max)
# Automate a range of color bars
cs_cmap='jet'
tick_ln=1.5
tick_wd=0.45
tlb_sz=3
# Plot field
if svar=='u_s' or svar=='v_s':
jlext_len=len(j_left)+2
j_l_ext=np.arange(1,jlext_len+1,1)
j_l_ext_sym=axis_contract(j_l_ext)
j_l_axs=j_l_ext
j_l_axs_sym=j_l_ext_sym
else:
j_l_axs=j_left
j_l_axs_sym=j_l_sym
fig,(ax1,ax2)=plt.subplots(2,1,figsize=(3.5,2.85))
# Plot 1: regular coordinate
ax1.set_title(out_title_gfs_o,fontsize=tlb_sz+1)
xj_o,yi_o=np.meshgrid(i_b,j_l_axs)
cs=ax1.pcolormesh(xj_o,yi_o,sgfs2d,cmap=cs_cmap,rasterized=True,vmin=cs_min,vmax=cs_max)
ax1.tick_params(direction='out',length=tick_ln,width=tick_wd,labelsize=tlb_sz)
# ax1.set_xticks(i_b_xtk)
# ax1.set_yticks(j_l_ytk)
# extend(pointed end): 'neither'|'both'|'min'|'max'
divider=make_axes_locatable(ax1)
ax_cb=divider.new_horizontal(size="3%",pad=0.1,axes_class=plt.Axes)
fig.add_axes(ax_cb)
cbar=plt.colorbar(cs,cax=ax_cb,extend='both')
cbar.ax.tick_params(labelsize=tlb_sz)
cbar.set_label(svar,fontsize=tlb_sz)
# Plot 2: Contracted coordinate
ax2.set_title(out_title_gfs_n,fontsize=tlb_sz+1)
xj_n,yi_n=np.meshgrid(i_bx_sym,j_l_axs_sym)
cs=ax2.pcolormesh(xj_n,yi_n,sgfs2d,cmap=cs_cmap,rasterized=True,vmin=cs_min,vmax=cs_max)
ax2.tick_params(direction='out',length=tick_ln,width=tick_wd,labelsize=tlb_sz)
ax2.set_xticks(i_bx_xtk)
ax2.set_xticklabels(i_bx_xlb)
ax2.set_yticks(j_l_ytk)
ax2.set_yticklabels(j_l_ylb)
# extend(pointed end): 'neither'|'both'|'min'|'max'
divider=make_axes_locatable(ax2)
ax_cb=divider.new_horizontal(size="3%",pad=0.1,axes_class=plt.Axes)
fig.add_axes(ax_cb)
cbar=plt.colorbar(cs,cax=ax_cb,extend='both')
cbar.ax.tick_params(labelsize=tlb_sz)
cbar.set_label(svar,fontsize=tlb_sz)
fig.tight_layout()
# Output figure
out_file(out_gfs_fname)
# Contracted coordinate ============================================== CHJ =====
def axis_contract(ij_xy):
# ==================================================================== CHJ =====
imid=(np.min(ij_xy)+np.max(ij_xy))/2.0 # find mid. pt.
itmp=np.absolute(ij_xy-imid)
# print(np.min(ij_xy),np.max(ij_xy),imid,itmp)
if n_blend==10:
iexp=3
elif n_blend==6:
iexp=5
elif n_blend==0:
iexp=10
else:
iexp=16
itmp2=np.power(itmp,iexp) # expand array from mid
itmp=itmp2/np.max(itmp2) # normalize
ix_xy_cont=np.cumsum(itmp) # new coord.
return ix_xy_cont
# Ticks and lables for a contracted coordinate ======================= CHJ =====
def tick_label(n_ary,n_crd,o_crd):
# ==================================================================== CHJ =====
# tick loc.
# tck_lbl=[2,5,10,19,36,n_ary-39,n_ary-22,n_ary-13,n_ary-8,n_ary-5]
# tck_lbl=[0,4,12,28,n_ary-29,n_ary-13,n_ary-5,n_ary-1]
tck_lbl=[0,3,9,13,50,n_ary-51,n_ary-14,n_ary-10,n_ary-4,n_ary-1]
# new ticks
n_xtk=[n_crd[ir] for ir in tck_lbl]
# new labels
n_xlb=[o_crd[ir] for ir in tck_lbl]
return n_xtk,n_xlb
# Output file ======================================================== CHJ =====
def out_file(out_file):
# ==================================================================== CHJ =====
# Output figure
plt.savefig(out_fig_dir+out_file+'.png',dpi=300,bbox_inches='tight')
plt.close('all')
# Main call ========================================================== CHJ =====
if __name__=='__main__':
main()