forked from knaughten/roms_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adv_u3_sss_anom.py
88 lines (74 loc) · 3 KB
/
adv_u3_sss_anom.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
from netCDF4 import Dataset
from numpy import *
from matplotlib.pyplot import *
# Plot the sea surface salinity anomaly between the U3 and U3_LIM simulations
# on 23 August (sea ice area maximum).
def adv_u3_sss_anom ():
# Paths to simulation directories
paths = ['/short/m68/kaa561/advection/u3_lim/', '/short/m68/kaa561/advection/u3/']
# File for 23 August daily average
file_tail = 'iceh.1992-08-23.nc'
# Bounds on colour scale
max_anom = 0.2
tick_anom = 0.1
# Degrees to radians conversion factor
deg2rad = pi/180.
# Centre of missing circle in grid
lon_c = 50
lat_c = -83
# Radius of missing circle
radius = 10.5
# Boundary of regular grid to embed circle in
circle_bdry = -70+90
# Read salinity data from U3_LIM simulation; also grid and mask variables
id = Dataset(paths[0]+file_tail, 'r')
data0_tmp = id.variables['sss'][0,:350,:]
lon_tmp = id.variables['TLON'][:350,:]
lat_tmp = id.variables['TLAT'][:350,:]
mask_tmp = id.variables['tmask'][:350,:]
id.close()
# Read salinity from U3 simulation
id = Dataset(paths[1]+file_tail, 'r')
data1_tmp = id.variables['sss'][0,:350,:]
id.close()
data_tmp = data1_tmp - data0_tmp
# Wrap periodic boundary so there isn't a gap in the plot
lon = ma.empty([size(lon_tmp,0), size(lon_tmp,1)+1])
lat = ma.empty([size(lat_tmp,0), size(lat_tmp,1)+1])
mask = ma.empty([size(mask_tmp,0), size(mask_tmp,1)+1])
data = ma.empty([size(data_tmp,0), size(data_tmp,1)+1])
lon[:,:-1] = lon_tmp
lon[:,-1] = lon_tmp[:,0]
lat[:,:-1] = lat_tmp
lat[:,-1] = lat_tmp[:,0]
mask[:,:-1] = mask_tmp
mask[:,-1] = mask_tmp[:,0]
data[:,:-1] = data_tmp
data[:,-1] = data_tmp[:,0]
# Land mask
land = ma.masked_where(mask==1, mask)
# Circumpolar x and y coordinates for plotting
x = -(lat+90)*cos(lon*deg2rad+pi/2)
y = (lat+90)*sin(lon*deg2rad+pi/2)
# Coordinates of centre of missing circle
x_c = -(lat_c+90)*cos(lon_c*deg2rad+pi/2)
y_c = (lat_c+90)*sin(lon_c*deg2rad+pi/2)
# Regular grid to embed missing circle in
x_reg, y_reg = meshgrid(linspace(-circle_bdry, circle_bdry, num=100), linspace(-circle_bdry, circle_bdry, num=100))
# Mask everything except the circle out of the regular grid
land_circle = zeros(shape(x_reg))
land_circle = ma.masked_where(sqrt((x_reg-x_c)**2 + (y_reg-y_c)**2) > radius, land_circle)
fig = figure(figsize=(16,12))
fig.add_subplot(1,1,1, aspect='equal')
contourf(x, y, land, 1, colors=(('0.6', '0.6', '0.6')))
contourf(x_reg, y_reg, land_circle, 1, colors=(('0.6', '0.6', '0.6')))
img = pcolor(x, y, data, vmin=-max_anom, vmax=max_anom, cmap='RdBu_r')
cbar = colorbar(img, ticks=arange(-max_anom, max_anom+tick_anom, tick_anom))
cbar.ax.tick_params(labelsize=20)
title('Sea surface salinity (psu)\nU3 - U3_LIM', fontsize=30)
axis('off')
#fig.show()
fig.savefig('sss_u3_anom.png')
# Command-line interface
if __name__ == "__main__":
adv_u3_sss_anom()