New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
anim_dome.py in NEMO/branches/2020/dev_r14116_HPC-04_mcastril_Mixed_Precision_implementation_final/tests/DOME/EXPREF – NEMO

source: NEMO/branches/2020/dev_r14116_HPC-04_mcastril_Mixed_Precision_implementation_final/tests/DOME/EXPREF/anim_dome.py @ 14644

Last change on this file since 14644 was 14644, checked in by sparonuz, 3 years ago

Merge trunk -r14642:HEAD

  • Property svn:executable set to *
File size: 3.0 KB
Line 
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
9from netCDF4 import Dataset
10import matplotlib.pyplot as plt
11import numpy as np
12from matplotlib.animation import FuncAnimation
13# from mpl_toolkits.axes_grid1.inset_locator import inset_axes
14#
15# Parent grid data:
16ncid = Dataset('DOME_grid_T.nc')
17lon0 = ncid.variables['nav_lon'][:, :]
18lat0 = ncid.variables['nav_lat'][:, :]
19work = ncid.variables['btra'][:, :, :]
20zos = ncid.variables['zos'][:, :, :]
21ncid.close()
22#
23(jpt0, jpj0, jpi0) = np.shape(work)
24mask = np.where((zos == 0.), True, False)
25tra0 = np.ma.array(work, mask=mask, hard_mask=True)
26
27#
28# Child grid data:
29ncid = Dataset('1_DOME_grid_T.nc')
30lon1 = ncid.variables['nav_lon'][:, :]
31lat1 = ncid.variables['nav_lat'][:, :]
32work = ncid.variables['btra'][:, :, :]
33zos = ncid.variables['zos'][:, :, :]
34sp = ncid.variables['Agrif_sponge'][:, :, :]
35ncid.close()
36#
37(jpt1, jpj1, jpi1) = np.shape(work)
38mask = np.where((zos == 0.), True, False)
39tra1 = np.ma.array(work, mask=mask, hard_mask=True)
40
41# Get resolution in km:
42res0 = np.abs(lon0[0, 1] - lon0[1, 0])
43res1 = np.abs(lon1[0, 1] - lon1[0, 0])
44
45# Shift lon, lat in order to have a pixel centred around the right location:
46lon0 = lon0 - res0/2.
47lat0 = lat0 - res0/2.
48lon1 = lon1 - res1/2.
49lat1 = lat1 - res1/2.
50
51# Indexes to skip ghost zone:
52nghost = 3 # + int(res0/res1)*2 - 1
53imin = nghost + 1
54jmin = nghost + 1
55imax = jpi1 - nghost - 1
56jmax = jpj1 - nghost - 1
57#
58fig, ax = plt.subplots()
59fig.set_tight_layout(True)
60mycmap = plt.cm.nipy_spectral
61plt.set_cmap(mycmap)
62i = 0 
63label = ' Bottom tracer concentration day: {00}'.format(i+1)
64pcol = plt.pcolor(lon0, lat0, np.squeeze(tra0[i, :, :]),
65                  vmin=0.01, vmax=1., edgecolor='0.9', cmap=mycmap)
66pcol = 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
70plt.axis('scaled')
71# plt.xlim((-800., 250.))
72# plt.ylim((-500.,  50.))
73plt.xlim((-1400., 200.))
74plt.ylim((-300.,  50.))
75plt.gcf().set_size_inches(6, 3)
76
77plt.ylabel('Y (km)', fontsize=14)
78plt.xlabel('X (km)', fontsize=14)
79cbar = plt.colorbar(pcol, shrink=0.5)
80cbar.ax.tick_params(labelsize=14)
81
82plt.title(label)
83
84
85def 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
96anim = FuncAnimation(fig, update, frames=np.arange(1, 39), interval=150)
97anim.save('DOME_anim_btra.gif', dpi=80, writer='imagemagick')
98# plt.savefig('DOME_bottom_tracer.png')
99# plt.show()
Note: See TracBrowser for help on using the repository browser.