-
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.
Fixed vector rotation issue, fixed some grid issues, and a bunch of n…
…ew figure scripts.
- Loading branch information
Kaitlin Alexander
committed
Sep 15, 2016
1 parent
be2997d
commit dbf9882
Showing
34 changed files
with
1,386 additions
and
443 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,30 @@ | ||
from netCDF4 import Dataset | ||
from numpy import * | ||
|
||
# Given a ROMS tide file with tidal potential amplitude and phase angle | ||
# (created using Kate's potential tide scripts), add the tidal period in seconds | ||
# for each component. | ||
def add_tide_period (): | ||
|
||
# Tide file to add periods to | ||
# Order is q1, o1, p1, k1, n2, m2, s2, k2 | ||
tide_file = '../ROMS-CICE-MCT/data/pot_tides.nc' | ||
# Periods in seconds | ||
# Order is m2, s2, n2, k2, k1, o1, p1, q1, mf, mm | ||
period = array([44714.165191868, 43200.0012869521, 86164.0770050671, 92949.6357005365, 45570.0535117177, 86637.1997716528, 43082.0503185947, 96726.0857029666, 2380715.86358729, 1180295.54554976]) | ||
# Put them in the right order | ||
period_reorder = array([period[7], period[5], period[6], period[4], period[2], period[0], period[1], period[3]]) | ||
|
||
id = Dataset(tide_file, 'a') | ||
id.createVariable('tide_period', 'f8', ('tide_period')) | ||
id.variables['tide_period'].long_name = 'tide angular period' | ||
id.variables['tide_period'].units = 'seconds' | ||
id.variables['tide_period'][:] = period_reorder | ||
id.close() | ||
|
||
|
||
# Command-line interface | ||
if __name__ == "__main__": | ||
|
||
add_tide_period() | ||
|
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 | ||
from numpy import * | ||
from matplotlib.pyplot import * | ||
|
||
def bw_diff_plot (file_path, var_name, colour_bounds=None, save=False, fig_name=None): | ||
|
||
init_path = '../ROMS-CICE-MCT/data/woa_ini.nc' | ||
deg2rad = pi/180 | ||
lon_c = 50 | ||
lat_c = -83 | ||
radius = 10.1 | ||
|
||
id = Dataset(init_path, 'r') | ||
data1 = id.variables[var_name][0,0,:-15,:-2] | ||
id.close() | ||
|
||
id = Dataset(file_path, 'r') | ||
lon = id.variables['lon_rho'][:-15,:-2] | ||
lat = id.variables['lat_rho'][:-15,:-2] | ||
data2 = id.variables[var_name][-1,0,:-15,:-2] | ||
id.close() | ||
|
||
data_diff = data2 - data1 | ||
|
||
# Convert grid to spherical coordinates | ||
x = -(lat+90)*cos(lon*deg2rad+pi/2) | ||
y = (lat+90)*sin(lon*deg2rad+pi/2) | ||
# Find centre in spherical coordinates | ||
x_c = -(lat_c+90)*cos(lon_c*deg2rad+pi/2) | ||
y_c = (lat_c+90)*sin(lon_c*deg2rad+pi/2) | ||
# Build a regular x-y grid and select the missing circle | ||
x_reg, y_reg = meshgrid(linspace(amin(x), amax(x), num=1000), linspace(amin(y), amax(y), num=1000)) | ||
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) | ||
|
||
if colour_bounds is not None: | ||
# User has set bounds on colour scale | ||
lev = linspace(colour_bounds[0], colour_bounds[1], num=50) | ||
if colour_bounds[0] == -colour_bounds[1]: | ||
# Bounds are centered on zero, so choose a blue-to-red colourmap | ||
# centered on yellow | ||
colour_map = 'RdYlBu_r' | ||
else: | ||
colour_map = 'jet' | ||
else: | ||
max_val = amax(abs(data_diff)) | ||
lev = linspace(-max_val, max_val, num=50) | ||
colour_map = 'RdYlBu_r' | ||
|
||
# Plot | ||
fig = figure(figsize=(16,12)) | ||
ax = fig.add_subplot(1,1,1,aspect='equal') | ||
fig.patch.set_facecolor('white') | ||
# First shade everything in grey | ||
contourf(x, y, ones(shape(data_diff)), 1, colors=(('0.6', '0.6', '0.6'))) | ||
# Fill in the missing circle | ||
contourf(x_reg, y_reg, land_circle, 1, colors=(('0.6', '0.6', '0.6'))) | ||
# Now shade the temperature (land mask will remain grey) | ||
contourf(x, y, data_diff, lev, cmap=colour_map, extend='both') | ||
cbar = colorbar() | ||
cbar.ax.tick_params(labelsize=20) | ||
if var_name == 'temp': | ||
title(r'Difference in bottom water temperature since initialisation ($^{\circ}$C)', fontsize=30) | ||
elif var_name == 'salt': | ||
title(r'Difference in bottom water salinity since initialisation (psu)', fontsize=30) | ||
axis('off') | ||
|
||
# Finished | ||
if save: | ||
fig.savefig(fig_name) | ||
else: | ||
fig.show() | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
file_path = raw_input("Path to ocean history/averages file: ") | ||
tmp = raw_input("Temperature (t) or salinity (s)? ") | ||
if tmp == 't': | ||
var_name = 'temp' | ||
elif tmp == 's': | ||
var_name = 'salt' | ||
colour_bounds = None | ||
get_bounds = raw_input("Set bounds on colour scale (y/n)? ") | ||
if get_bounds == 'y': | ||
lower_bound = float(raw_input("Lower bound: ")) | ||
upper_bound = float(raw_input("Upper bound: ")) | ||
colour_bounds = [lower_bound, upper_bound] | ||
action = raw_input("Save figure (s) or display on screen (d)? ") | ||
if action == 's': | ||
save = True | ||
fig_name = raw_input("Filename for figure: ") | ||
else: | ||
save = False | ||
fig_name = None | ||
|
||
bw_diff_plot(file_path, var_name, colour_bounds, save, fig_name) | ||
|
||
|
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
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,74 @@ | ||
from netCDF4 import Dataset | ||
from numpy import * | ||
from matplotlib.pyplot import * | ||
from rotate_vector_cice import * | ||
|
||
def cice_strx (file_path, tstep, colour_bounds=None, save=False, fig_name=None): | ||
|
||
deg2rad = pi/180 | ||
|
||
id = Dataset(file_path, 'r') | ||
lon = id.variables['ULON'][:-15,:] | ||
lat = id.variables['ULAT'][:-15,:] | ||
angle = id.variables['ANGLET'][:-15,:] | ||
strx = id.variables['strairx'][tstep-1,:-15,:] + id.variables['strocnx'][tstep-1,:-15,:] + id.variables['strtltx'][tstep-1,:-15,:] + id.variables['strcorx'][tstep-1,:-15,:] + id.variables['strintx'][tstep-1,:-15,:] | ||
stry = id.variables['strairy'][tstep-1,:-15,:] + id.variables['strocny'][tstep-1,:-15,:] + id.variables['strtlty'][tstep-1,:-15,:] + id.variables['strcory'][tstep-1,:-15,:] + id.variables['strinty'][tstep-1,:-15,:] | ||
id.close() | ||
|
||
strx_lonlat, stry_lonlat = rotate_vector_cice(strx, stry, angle) | ||
|
||
x = -(lat+90)*cos(lon*deg2rad+pi/2) | ||
y = (lat+90)*sin(lon*deg2rad+pi/2) | ||
|
||
if colour_bounds is not None: | ||
# User has set bounds on colour scale | ||
lev = linspace(colour_bounds[0], colour_bounds[1], num=40) | ||
if colour_bounds[0] == -colour_bounds[1]: | ||
# Bounds are centered on zero, so choose a blue-to-red colourmap | ||
# centered on yellow | ||
colour_map = 'RdYlBu_r' | ||
else: | ||
colour_map = 'jet' | ||
else: | ||
max_val = amax(abs(stry_lonlat)) | ||
lev = linspace(-max_val, max_val, num=40) | ||
colour_map = 'RdYlBu_r' | ||
|
||
fig = figure(figsize=(16,12)) | ||
fig.add_subplot(1,1,1, aspect='equal') | ||
contourf(x, y, strx_lonlat, lev, cmap=colour_map, extend='both') | ||
cbar = colorbar() | ||
cbar.ax.tick_params(labelsize=20) | ||
title('Sum of eastward stresses N/m^2', fontsize=30) | ||
axis('off') | ||
|
||
if save: | ||
fig.savefig(fig_name) | ||
else: | ||
fig.show() | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
file_path = raw_input("Path to CICE history file: ") | ||
tstep = int(raw_input("Timestep number (starting at 1): ")) | ||
|
||
# Get colour bounds if necessary | ||
colour_bounds = None | ||
get_bounds = raw_input("Set bounds on colour scale (y/n)? ") | ||
if get_bounds == 'y': | ||
lower_bound = float(raw_input("Lower bound: ")) | ||
upper_bound = float(raw_input("Upper bound: ")) | ||
colour_bounds = [lower_bound, upper_bound] | ||
|
||
action = raw_input("Save figure (s) or display in window (d)? ") | ||
if action == 's': | ||
save = True | ||
fig_name = raw_input("File name for figure: ") | ||
elif action == 'd': | ||
save = False | ||
fig_name = None | ||
|
||
cice_strx(file_path, tstep, colour_bounds, save, fig_name) | ||
|
||
|
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,74 @@ | ||
from netCDF4 import Dataset | ||
from numpy import * | ||
from matplotlib.pyplot import * | ||
from rotate_vector_cice import * | ||
|
||
def cice_stry (file_path, tstep, colour_bounds=None, save=False, fig_name=None): | ||
|
||
deg2rad = pi/180 | ||
|
||
id = Dataset(file_path, 'r') | ||
lon = id.variables['ULON'][:-15,:] | ||
lat = id.variables['ULAT'][:-15,:] | ||
angle = id.variables['ANGLET'][:-15,:] | ||
strx = id.variables['strairx'][tstep-1,:-15,:] + id.variables['strocnx'][tstep-1,:-15,:] + id.variables['strtltx'][tstep-1,:-15,:] + id.variables['strcorx'][tstep-1,:-15,:] + id.variables['strintx'][tstep-1,:-15,:] | ||
stry = id.variables['strairy'][tstep-1,:-15,:] + id.variables['strocny'][tstep-1,:-15,:] + id.variables['strtlty'][tstep-1,:-15,:] + id.variables['strcory'][tstep-1,:-15,:] + id.variables['strinty'][tstep-1,:-15,:] | ||
id.close() | ||
|
||
strx_lonlat, stry_lonlat = rotate_vector_cice(strx, stry, angle) | ||
|
||
x = -(lat+90)*cos(lon*deg2rad+pi/2) | ||
y = (lat+90)*sin(lon*deg2rad+pi/2) | ||
|
||
if colour_bounds is not None: | ||
# User has set bounds on colour scale | ||
lev = linspace(colour_bounds[0], colour_bounds[1], num=40) | ||
if colour_bounds[0] == -colour_bounds[1]: | ||
# Bounds are centered on zero, so choose a blue-to-red colourmap | ||
# centered on yellow | ||
colour_map = 'RdYlBu_r' | ||
else: | ||
colour_map = 'jet' | ||
else: | ||
max_val = amax(abs(stry_lonlat)) | ||
lev = linspace(-max_val, max_val, num=40) | ||
colour_map = 'RdYlBu_r' | ||
|
||
fig = figure(figsize=(16,12)) | ||
fig.add_subplot(1,1,1, aspect='equal') | ||
contourf(x, y, stry_lonlat, lev, cmap=colour_map, extend='both') | ||
cbar = colorbar() | ||
cbar.ax.tick_params(labelsize=20) | ||
title('Sum of northward stresses N/m^2', fontsize=30) | ||
axis('off') | ||
|
||
if save: | ||
fig.savefig(fig_name) | ||
else: | ||
fig.show() | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
file_path = raw_input("Path to CICE history file: ") | ||
tstep = int(raw_input("Timestep number (starting at 1): ")) | ||
|
||
# Get colour bounds if necessary | ||
colour_bounds = None | ||
get_bounds = raw_input("Set bounds on colour scale (y/n)? ") | ||
if get_bounds == 'y': | ||
lower_bound = float(raw_input("Lower bound: ")) | ||
upper_bound = float(raw_input("Upper bound: ")) | ||
colour_bounds = [lower_bound, upper_bound] | ||
|
||
action = raw_input("Save figure (s) or display in window (d)? ") | ||
if action == 's': | ||
save = True | ||
fig_name = raw_input("File name for figure: ") | ||
elif action == 'd': | ||
save = False | ||
fig_name = None | ||
|
||
cice_stry(file_path, tstep, colour_bounds, save, fig_name) | ||
|
||
|
Oops, something went wrong.