-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Final scripts for first draft of thesis
- Loading branch information
Kaitlin Naughten
committed
Dec 18, 2017
1 parent
0fbbda3
commit 1f8875e
Showing
11 changed files
with
702 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
from netCDF4 import Dataset, num2date | ||
from numpy import * | ||
from matplotlib.pyplot import * | ||
from calc_z import * | ||
from interp_lon_roms import * | ||
|
||
def bugs_convection_slices (): | ||
|
||
# Files and timesteps to plot | ||
file_beg = '/short/m68/kaa561/metroms_iceshelf/tmproms/run/bug_chapter/no_restoring/ocean_avg_0003.nc' | ||
tstep_beg = 18 | ||
file_end = '/short/m68/kaa561/metroms_iceshelf/tmproms/run/bug_chapter/no_restoring/ocean_avg_0012.nc' | ||
tstep_end = 2 | ||
# Longitude to interpolate to | ||
lon0 = -13 | ||
# Deepest depth to plot | ||
depth_min = -250 | ||
depth_ticks = arange(depth_min, 0+50, 50) | ||
depth_labels = [] | ||
for depth in depth_ticks: | ||
depth_labels.append(str(int(-depth))) | ||
# Latitudes to plot | ||
lat_min = -74 | ||
lat_max = -55 | ||
lat_ticks = arange(lat_min+4, lat_max+5, 5) | ||
lat_labels = [] | ||
for lat in lat_ticks: | ||
lat_labels.append(str(int(-lat)) + r'$^{\circ}$S') | ||
# Bounds on colour scales | ||
var_min = [-2, 33.9] | ||
var_max = [2, 34.7] | ||
var_tick = [1, 0.2] | ||
lev1 = linspace(var_min[0], var_max[0], num=50) | ||
lev2 = linspace(var_min[1], var_max[1], num=50) | ||
# Grid parameters | ||
theta_s = 7.0 | ||
theta_b = 2.0 | ||
hc = 250 | ||
N = 31 | ||
# Month names for titles | ||
month_names = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] | ||
|
||
# Get longitude for the title | ||
if lon0 < 0: | ||
lon_string = str(int(round(-lon0))) + r'$^{\circ}$W' | ||
else: | ||
lon_string = str(int(round(lon0))) + r'$^{\circ}$E' | ||
# Make sure we are in the range 0-360 | ||
if lon0 < 0: | ||
lon0 += 360 | ||
|
||
# Set up figure | ||
fig = figure(figsize=(18,12)) | ||
gs = GridSpec(2,2) | ||
gs.update(left=0.13, right=0.9, bottom=0.05, top=0.9, wspace=0.05, hspace=0.28) | ||
|
||
# Read 3D temperature, salinity, and grid variables at the beginning | ||
id = Dataset(file_beg, 'r') | ||
temp_3d_beg = id.variables['temp'][tstep_beg-1,:,:,:] | ||
salt_3d_beg = id.variables['salt'][tstep_beg-1,:,:,:] | ||
zeta_beg = id.variables['zeta'][tstep_beg-1,:,:] | ||
h = id.variables['h'][:,:] | ||
zice = id.variables['zice'][:,:] | ||
lon_2d = id.variables['lon_rho'][:,:] | ||
lat_2d = id.variables['lat_rho'][:,:] | ||
# Read time axis and convert to Date objects | ||
time_id = id.variables['ocean_time'] | ||
time_beg = num2date(time_id[tstep_beg-1], units=time_id.units, calendar=time_id.calendar.lower()) | ||
id.close() | ||
# Get a 3D array of z-coordinates | ||
z_3d, sc_r, Cs_r = calc_z(h, zice, theta_s, theta_b, hc, N, zeta_beg) | ||
# Get the date for the title | ||
date_string_beg = str(time_beg.day) + ' ' + month_names[time_beg.month-1] + ' ' + str(time_beg.year) | ||
# Interpolate to lon0 | ||
temp_beg, z, lat = interp_lon_roms(temp_3d_beg, z_3d, lat_2d, lon_2d, lon0) | ||
salt_beg, z, lat = interp_lon_roms(salt_3d_beg, z_3d, lat_2d, lon_2d, lon0) | ||
# Plot temperature | ||
ax = subplot(gs[0,0]) | ||
img = contourf(lat, z, temp_beg, lev1, extend='both', cmap='jet') | ||
title(r'Temperature ($^{\circ}$C)', fontsize=24) | ||
ax.set_xlim([lat_min, lat_max]) | ||
ax.set_xticks(lat_ticks) | ||
ax.set_xticklabels([]) | ||
ax.set_ylim([depth_min, 0]) | ||
ax.set_yticks(depth_ticks) | ||
ax.set_yticklabels(depth_labels, fontsize=16) | ||
ylabel('Depth (m)', fontsize=18) | ||
# Plot salinity | ||
ax = subplot(gs[0,1]) | ||
img = contourf(lat, z, salt_beg, lev2, extend='both', cmap='jet') | ||
title('Salinity (psu)', fontsize=24) | ||
ax.set_xlim([lat_min, lat_max]) | ||
ax.set_xticks(lat_ticks) | ||
ax.set_xticklabels([]) | ||
ax.set_ylim([depth_min, 0]) | ||
ax.set_yticks(depth_ticks) | ||
ax.set_yticklabels([]) | ||
# Label the timestep | ||
text(0.5, 0.95, date_string_beg + ', ' + lon_string, ha='center', transform=fig.transFigure, fontsize=28) | ||
|
||
# Read 3D temperature, salinity, and sea surface height at the end | ||
id = Dataset(file_end, 'r') | ||
temp_3d_end = id.variables['temp'][tstep_end-1,:,:,:] | ||
salt_3d_end = id.variables['salt'][tstep_end-1,:,:,:] | ||
zeta_end = id.variables['zeta'][tstep_end-1,:,:] | ||
# Read time axis and convert to Date objects | ||
time_id = id.variables['ocean_time'] | ||
time_end = num2date(time_id[tstep_end-1], units=time_id.units, calendar=time_id.calendar.lower()) | ||
id.close() | ||
# Get a 3D array of z-coordinates | ||
z_3d, sc_r, Cs_r = calc_z(h, zice, theta_s, theta_b, hc, N, zeta_end) | ||
# Get the date for the title | ||
date_string_end = str(time_end.day) + ' ' + month_names[time_end.month-1] + ' ' + str(time_end.year) | ||
# Interpolate to lon0 | ||
temp_end, z, lat = interp_lon_roms(temp_3d_end, z_3d, lat_2d, lon_2d, lon0) | ||
salt_end, z, lat = interp_lon_roms(salt_3d_end, z_3d, lat_2d, lon_2d, lon0) | ||
# Plot temperature | ||
ax = subplot(gs[1,0]) | ||
img = contourf(lat, z, temp_end, lev1, extend='both', cmap='jet') | ||
title(r'Temperature $^{\circ}$C)', fontsize=24) | ||
ax.set_xlim([lat_min, lat_max]) | ||
ax.set_xticks(lat_ticks) | ||
ax.set_xticklabels(lat_labels, fontsize=16) | ||
xlabel('Latitude', fontsize=18) | ||
ax.set_ylim([depth_min, 0]) | ||
ax.set_yticks(depth_ticks) | ||
ax.set_yticklabels(depth_labels, fontsize=16) | ||
ylabel('Depth (m)', fontsize=18) | ||
# Colourbar | ||
cbaxes = fig.add_axes([0.03, 0.3, 0.02, 0.4]) | ||
cbar = colorbar(img, cax=cbaxes, ticks=arange(var_min[0], var_max[0]+var_tick[0], var_tick[0])) | ||
cbar.ax.tick_params(labelsize=16) | ||
# Plot salinity | ||
ax = subplot(gs[1,1]) | ||
img = contourf(lat, z, salt_end, lev2, extend='both', cmap='jet') | ||
title('Salinity (psu)', fontsize=24) | ||
ax.set_xlim([lat_min, lat_max]) | ||
ax.set_xticks(lat_ticks) | ||
ax.set_xticklabels(lat_labels, fontsize=16) | ||
xlabel('Latitude', fontsize=18) | ||
ax.set_ylim([depth_min, 0]) | ||
ax.set_yticks(depth_ticks) | ||
ax.set_yticklabels([]) | ||
# Colourbar | ||
cbaxes = fig.add_axes([0.93, 0.3, 0.02, 0.4]) | ||
cbar = colorbar(img, cax=cbaxes, ticks=arange(var_min[1], var_max[1]+var_tick[1], var_tick[1])) | ||
cbar.ax.tick_params(labelsize=16) | ||
# Label the timestep | ||
text(0.5, 0.47, date_string_end + ', ' + lon_string, ha='center', transform=fig.transFigure, fontsize=28) | ||
fig.show() | ||
fig.savefig('bugs_convection_slices.png') | ||
|
||
|
||
# Command-line interface | ||
if __name__ == "__main__": | ||
|
||
bugs_convection_slices() | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
from netCDF4 import Dataset, num2date | ||
from numpy import * | ||
from matplotlib.pyplot import * | ||
|
||
def bugs_mld_polynya (): | ||
|
||
# Files and timesteps to read | ||
file_ocn = '/short/m68/kaa561/metroms_iceshelf/tmproms/run/bug_chapter/no_restoring/ocean_avg_0012.nc' | ||
tstep_ocn = 2 | ||
file_ice = '/short/m68/kaa561/metroms_iceshelf/tmproms/run/bug_chapter/no_restoring/cice/rundir/history/iceh.1994-09-26.nc' | ||
tstep_ice = 1 | ||
# Degrees to radians conversion factor | ||
deg2rad = pi/180 | ||
# Month names for titles | ||
month_names = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] | ||
# Maximum latitude to plot | ||
nbdry = -52+90 | ||
|
||
# Set up figure | ||
fig = figure(figsize=(16,8)) | ||
gs = GridSpec(1,2) | ||
gs.update(left=0.1, right=0.9, bottom=0.05, top=0.9, wspace=0.05) | ||
|
||
# Read mixed layer depth (actually surface boundary layer depth) | ||
# and ROMS grid | ||
id = Dataset(file_ocn, 'r') | ||
lon = id.variables['lon_rho'][:,:-1] | ||
lat = id.variables['lat_rho'][:,:-1] | ||
zice = id.variables['zice'][:,:-1] | ||
hsbl = id.variables['Hsbl'][tstep_ocn-1,:,:-1] | ||
# Also read time axis and convert to Date objects | ||
time_id = id.variables['ocean_time'] | ||
time = num2date(time_id[tstep_ocn-1], units=time_id.units, calendar=time_id.calendar.lower()) | ||
id.close() | ||
# Mask out the ice shelves and change the sign | ||
mld = ma.masked_where(zice!=0, -hsbl) | ||
# Polar coordinate transformation | ||
x = -(lat+90)*cos(lon*deg2rad+pi/2) | ||
y = (lat+90)*sin(lon*deg2rad+pi/2) | ||
# Get the date for the title | ||
date_string = str(time.day) + ' ' + month_names[time.month-1] + ' ' + str(time.year) | ||
# Plot | ||
ax = subplot(gs[0,0], aspect='equal') | ||
lev = linspace(0, amax(mld), num=50) | ||
contourf(x, y, mld, lev, cmap='jet') | ||
xlim([-nbdry, nbdry]) | ||
ylim([-nbdry, nbdry]) | ||
ax.set_xticks([]) | ||
ax.set_yticks([]) | ||
title('a) Surface boundary layer depth (m)', fontsize=24) | ||
# Colourbar | ||
cbaxes = fig.add_axes([0.03, 0.3, 0.02, 0.4]) | ||
cbar = colorbar(cax=cbaxes, ticks=arange(0,2000+500,500)) | ||
cbar.ax.tick_params(labelsize=16) | ||
|
||
# Read sea ice concentration and CICE grid | ||
id = Dataset(file_ice, 'r') | ||
lon_tmp = id.variables['TLON'][:,:] | ||
lat_tmp = id.variables['TLAT'][:,:] | ||
aice_tmp = id.variables['aice'][tstep_ice-1,:,:] | ||
id.close() | ||
# Wrap the periodic boundray by 1 cell | ||
lon = ma.empty([size(lon_tmp,0), size(lon_tmp,1)+1]) | ||
lat = ma.empty([size(lat_tmp,0), size(lat_tmp,1)+1]) | ||
aice = ma.empty([size(aice_tmp,0), size(aice_tmp,1)+1]) | ||
lon[:,:-1] = lon_tmp | ||
lon[:,-1] = lon_tmp[:,0] | ||
lat[:,:-1] = lat_tmp | ||
lat[:,-1] = lat_tmp[:,0] | ||
aice[:,:-1] = aice_tmp | ||
aice[:,-1] = aice_tmp[:,0] | ||
# Convert to spherical coordinates | ||
x = -(lat+90)*cos(lon*deg2rad+pi/2) | ||
y = (lat+90)*sin(lon*deg2rad+pi/2) | ||
# Plot | ||
ax = subplot(gs[0,1], aspect='equal') | ||
lev = linspace(0, 1, num=50) | ||
contourf(x, y, aice, lev, cmap='jet') | ||
xlim([-nbdry, nbdry]) | ||
ylim([-nbdry, nbdry]) | ||
ax.set_xticks([]) | ||
ax.set_yticks([]) | ||
title('b) Sea ice concentration', fontsize=24) | ||
# Colourbar | ||
cbaxes = fig.add_axes([0.92, 0.3, 0.02, 0.4]) | ||
cbar = colorbar(cax=cbaxes, ticks=arange(0,1+0.25,0.25)) | ||
cbar.ax.tick_params(labelsize=16) | ||
# Label the timestep | ||
text(0.5, 0.94, date_string, ha='center', transform=fig.transFigure, fontsize=28) | ||
fig.show() | ||
fig.savefig('bugs_mld_polynya.png') | ||
|
||
|
||
# Command-line interface | ||
if __name__ == "__main__": | ||
|
||
bugs_mld_polynya() | ||
|
||
|
Oops, something went wrong.