[14644] | 1 | #!/usr/bin/env python |
---|
| 2 | # -*- coding: utf-8 -*- |
---|
| 3 | |
---|
| 4 | """ Draw a plot (or and animation) |
---|
| 5 | of passive tracer at the bottom |
---|
| 6 | in the DOME experiment |
---|
| 7 | """ |
---|
| 8 | |
---|
| 9 | from netCDF4 import Dataset |
---|
| 10 | import matplotlib.pyplot as plt |
---|
| 11 | import numpy as np |
---|
| 12 | from matplotlib.animation import FuncAnimation |
---|
| 13 | # from mpl_toolkits.axes_grid1.inset_locator import inset_axes |
---|
| 14 | # |
---|
| 15 | # Parent grid data: |
---|
| 16 | ncid = Dataset('DOME_grid_T.nc') |
---|
| 17 | lon0 = ncid.variables['nav_lon'][:, :] |
---|
| 18 | lat0 = ncid.variables['nav_lat'][:, :] |
---|
| 19 | work = ncid.variables['btra'][:, :, :] |
---|
| 20 | zos = ncid.variables['zos'][:, :, :] |
---|
| 21 | ncid.close() |
---|
| 22 | # |
---|
| 23 | (jpt0, jpj0, jpi0) = np.shape(work) |
---|
| 24 | mask = np.where((zos == 0.), True, False) |
---|
| 25 | tra0 = np.ma.array(work, mask=mask, hard_mask=True) |
---|
| 26 | |
---|
| 27 | # |
---|
| 28 | # Child grid data: |
---|
| 29 | ncid = Dataset('1_DOME_grid_T.nc') |
---|
| 30 | lon1 = ncid.variables['nav_lon'][:, :] |
---|
| 31 | lat1 = ncid.variables['nav_lat'][:, :] |
---|
| 32 | work = ncid.variables['btra'][:, :, :] |
---|
| 33 | zos = ncid.variables['zos'][:, :, :] |
---|
| 34 | sp = ncid.variables['Agrif_sponge'][:, :, :] |
---|
| 35 | ncid.close() |
---|
| 36 | # |
---|
| 37 | (jpt1, jpj1, jpi1) = np.shape(work) |
---|
| 38 | mask = np.where((zos == 0.), True, False) |
---|
| 39 | tra1 = np.ma.array(work, mask=mask, hard_mask=True) |
---|
| 40 | |
---|
| 41 | # Get resolution in km: |
---|
| 42 | res0 = np.abs(lon0[0, 1] - lon0[1, 0]) |
---|
| 43 | res1 = np.abs(lon1[0, 1] - lon1[0, 0]) |
---|
| 44 | |
---|
| 45 | # Shift lon, lat in order to have a pixel centred around the right location: |
---|
| 46 | lon0 = lon0 - res0/2. |
---|
| 47 | lat0 = lat0 - res0/2. |
---|
| 48 | lon1 = lon1 - res1/2. |
---|
| 49 | lat1 = lat1 - res1/2. |
---|
| 50 | |
---|
| 51 | # Indexes to skip ghost zone: |
---|
| 52 | nghost = 3 # + int(res0/res1)*2 - 1 |
---|
| 53 | imin = nghost + 1 |
---|
| 54 | jmin = nghost + 1 |
---|
| 55 | imax = jpi1 - nghost - 1 |
---|
| 56 | jmax = jpj1 - nghost - 1 |
---|
| 57 | # |
---|
| 58 | fig, ax = plt.subplots() |
---|
| 59 | fig.set_tight_layout(True) |
---|
| 60 | mycmap = plt.cm.nipy_spectral |
---|
| 61 | plt.set_cmap(mycmap) |
---|
| 62 | i = 0 |
---|
| 63 | label = ' Bottom tracer concentration day: {00}'.format(i+1) |
---|
| 64 | pcol = plt.pcolor(lon0, lat0, np.squeeze(tra0[i, :, :]), |
---|
| 65 | vmin=0.01, vmax=1., edgecolor='0.9', cmap=mycmap) |
---|
| 66 | pcol = plt.pcolor(lon1[jmin:jmax, imin:imax], lat1[jmin:jmax, imin:imax], np.squeeze(tra1[i, jmin:jmax, imin:imax]), |
---|
| 67 | vmin=0.01, vmax=1., edgecolor='0.4', cmap=mycmap) |
---|
| 68 | # plt.contour(lon1[jmin:jmax, imin:imax], lat1[jmin:jmax, imin:imax], np.squeeze(sp[i, jmin:jmax, imin:imax])) |
---|
| 69 | |
---|
| 70 | plt.axis('scaled') |
---|
| 71 | # plt.xlim((-800., 250.)) |
---|
| 72 | # plt.ylim((-500., 50.)) |
---|
| 73 | plt.xlim((-1400., 200.)) |
---|
| 74 | plt.ylim((-300., 50.)) |
---|
| 75 | plt.gcf().set_size_inches(6, 3) |
---|
| 76 | |
---|
| 77 | plt.ylabel('Y (km)', fontsize=14) |
---|
| 78 | plt.xlabel('X (km)', fontsize=14) |
---|
| 79 | cbar = plt.colorbar(pcol, shrink=0.5) |
---|
| 80 | cbar.ax.tick_params(labelsize=14) |
---|
| 81 | |
---|
| 82 | plt.title(label) |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | def update(t): |
---|
| 86 | txt = ' Bottom tracer concentration day: {00}'.format(t+1) |
---|
| 87 | print('Process day', t+1) |
---|
| 88 | pcol = plt.pcolor(lon0, lat0, np.squeeze(tra0[t, :, :]), |
---|
| 89 | vmin=0.01, vmax=1., edgecolor='0.9', cmap=mycmap) |
---|
| 90 | pcol = plt.pcolor(lon1[jmin:jmax, imin:imax], lat1[jmin:jmax, imin:imax], np.squeeze(tra1[t, jmin:jmax, imin:imax]), |
---|
| 91 | vmin=0.01, vmax=1., edgecolor='0.4', cmap=mycmap) |
---|
| 92 | plt.title(txt) |
---|
| 93 | return pcol |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | anim = FuncAnimation(fig, update, frames=np.arange(1, 39), interval=150) |
---|
| 97 | anim.save('DOME_anim_btra.gif', dpi=80, writer='imagemagick') |
---|
| 98 | # plt.savefig('DOME_bottom_tracer.png') |
---|
| 99 | # plt.show() |
---|