forked from knaughten/roms_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
h_circumpolar.py
52 lines (42 loc) · 1.41 KB
/
h_circumpolar.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
from netCDF4 import Dataset
from numpy import *
from matplotlib.pyplot import *
from matplotlib.colors import ListedColormap
# Creates a circumpolar Antarctic plot of bathymetry.
# Follows the same process as circumpolar_plot.py, but since h is not
# time-dependent, it requires a special case.
# Input:
# grid_path = path to ROMS grid file
# fig_name = filename for figure
def h_circumpolar (grid_path, fig_name):
deg2rad = pi/180
nbdry = -60 + 90
# Read data
id = Dataset(grid_path, 'r')
data = id.variables['h'][:-15,:-1]
lon = id.variables['lon_rho'][:-15,:-1]
lat = id.variables['lat_rho'][:-15,:-1]
mask = id.variables['mask_rho'][:-15,:-1]
id.close()
# Mask with land mask
data = ma.masked_where(mask==0, data)
# Convert to spherical coordinates
x = -(lat+90)*cos(lon*deg2rad+pi/2)
y = (lat+90)*sin(lon*deg2rad+pi/2)
# Plot
fig = figure(figsize=(128,96))
fig.add_subplot(1,1,1, aspect='equal')
img = pcolor(x, y, data, vmin=0, vmax=2800)
xlim([-nbdry, nbdry])
ylim([-nbdry, nbdry])
cbar = colorbar(img, extend='max')
cbar.ax.tick_params(labelsize=160)
title('Bathymetry (m)', fontsize=240)
axis('off')
show()
savefig(fig_name)
# Command-line interface
if __name__ == "__main__":
grid_path = raw_input("Path to ROMS grid file: ")
fig_name = raw_input("Filename for figure: ")
h_circumpolar(grid_path, fig_name)