-
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.
Modularised calculations of dx, dy, dz, z into 2D and 3D functions ra…
…ther than copying and pasting in many files
- Loading branch information
Kaitlin Alexander
committed
Apr 28, 2016
1 parent
54473e7
commit 668c600
Showing
11 changed files
with
202 additions
and
305 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
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,50 @@ | ||
from numpy import * | ||
|
||
# Given ROMS grid variables, calculate Cartesian integrands dx and dy. | ||
# Input: | ||
# lon, lat = 2D arrays containing values for latitude and longitude, with | ||
# dimension latitude x longitude | ||
# Output: | ||
# dx, dy = 2D arrays (dimension latitude x longitude) containing Cartesian | ||
# integrands | ||
def cartesian_grid_2d (lon, lat): | ||
|
||
# Radius of the Earth in metres | ||
r = 6.371e6 | ||
# Degrees to radians conversion factor | ||
deg2rad = pi/180.0 | ||
|
||
# Save horizontal dimensions | ||
num_lat = size(lon, 0) | ||
num_lon = size(lon, 1) | ||
|
||
# Add or subtract 360 from longitude values which wrap around so that | ||
# longitude increases monotonically from west to east | ||
i = tile(arange(1,num_lon+1), (num_lat,1)) | ||
index1 = nonzero((i > 1200)*(lon < 100)) | ||
lon[index1] = lon[index1] + 360 | ||
index2 = nonzero((i < 200)*(lon > 300)) | ||
lon[index2] = lon[index2] - 360 | ||
|
||
# Interpolate to get longitude at the edges of each cell | ||
w_bdry = 0.5*(lon[:,0] + lon[:,-1] - 360) | ||
middle_lon = 0.5*(lon[:,0:-1] + lon[:,1:]) | ||
e_bdry = 0.5*(lon[:,0] + 360 + lon[:,-1]) | ||
lon_edges = concatenate((w_bdry[:,None], middle_lon, e_bdry[:,None]), axis=1) | ||
# Subtract to get the change in longitude over each cell | ||
dlon = abs(lon_edges[:,1:] - lon_edges[:,0:-1]) | ||
|
||
# Similarly for latitude; linearly extrapolate for latitude at edges of | ||
# N/S boundary cells | ||
middle_lat = 0.5*(lat[0:-1,:] + lat[1:,:]) | ||
s_bdry = 2*lat[0,:] - middle_lat[0,:] | ||
n_bdry = 2*lat[-1,:] - middle_lat[-1,:] | ||
lat_edges = concatenate((s_bdry[None,:], middle_lat, n_bdry[None,:]), axis=0) | ||
dlat = lat_edges[1:,:] - lat_edges[0:-1,:] | ||
|
||
# dx = r*cos(lat)*dlon where lat and dlon are converted to radians | ||
dx = r*cos(lat*deg2rad)*dlon*deg2rad | ||
# dy = r*dlat where dlat is converted to radians | ||
dy = r*dlat*deg2rad | ||
|
||
return dx, dy |
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,40 @@ | ||
from numpy import * | ||
from cartesian_grid_2d import * | ||
from calc_z import * | ||
|
||
# Given ROMS grid variables, calculate Cartesian integrands (dx, dy, dz) as | ||
# well as z-coordinates. | ||
# Input: | ||
# lon, lat, h, zice = 2D arrays containing values for latitude, longitude, | ||
# bathymetry, and ice shelf draft. All have dimension | ||
# latitude x longitude. | ||
# theta_s, theta_b, hc, N = scalar parameters (check your grid file and roms.in) | ||
# zeta = optional 2D array containing values for sea surface height at the | ||
# desired timestep | ||
# Output: | ||
# dx, dy, dz, z = 3D arrays (dimension depth x latitude x longitude) containing | ||
# Cartesian integrands (dx, dy, dz) and z-coordinates (z). | ||
def cartesian_grid_3d (lon, lat, h, zice, theta_s, theta_b, hc, N, zeta=None): | ||
|
||
# Calculate 2D dx and dy in another script | ||
dx, dy = cartesian_grid_2d(lon, lat) | ||
# Copy into 3D arrays, same at each depth level | ||
dx = tile(dx, (N,1,1)) | ||
dy = tile(dy, (N,1,1)) | ||
# Save horizontal dimensions | ||
num_lat = size(lon, 0) | ||
num_lon = size(lon, 1) | ||
|
||
# Get a 3D array of z-coordinates; sc_r and Cs_r are unused | ||
z, sc_r, Cs_r = calc_z(h, zice, theta_s, theta_b, hc, N, zeta) | ||
# We have z at the midpoint of each cell, now find it on the top and | ||
# bottom edges of each cell | ||
z_edges = zeros((N+1, num_lat, num_lon)) | ||
z_edges[1:-1,:,:] = 0.5*(z[0:-1,:,:] + z[1:,:,:]) | ||
# At surface, z=zice; at bottom, extrapolate | ||
z_edges[-1,:,:] = zice[:,:] | ||
z_edges[0,:,:] = 2*z[0,:,:] - z_edges[1,:,:] | ||
# Now find dz | ||
dz = z_edges[1:,:,:] - z_edges[0:-1,:,:] | ||
|
||
return dx, dy, dz, z |
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
Oops, something went wrong.