Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix coordinates #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import copy
import subprocess as sp
import netCDF4 as nc
from scipy import interp
from numpy import interp
from scipy import ndimage as nd

from .mom_grid import MomGrid
Expand Down Expand Up @@ -189,8 +189,6 @@ def extend_src_data(src_data, src_grid, global_src_grid, temp_or_salt):

return global_src_data


@numba.jit
def apply_weights(src, dest_shape, n_s, n_b, row, col, s):
"""
Apply ESMF regirdding weights.
Expand Down
34 changes: 17 additions & 17 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ def create_mom_output(ocean_grid, filename, start_date, history):

f = nc.Dataset(filename, 'w')

f.createDimension('GRID_X_T', ocean_grid.num_lon_points)
f.createDimension('GRID_Y_T', ocean_grid.num_lat_points)
f.createDimension('ZT', ocean_grid.num_levels)
f.createDimension('time')
f.createDimension('lon', ocean_grid.num_lon_points)
f.createDimension('lat', ocean_grid.num_lat_points)
f.createDimension('depth', ocean_grid.num_levels)
f.createDimension('time', 1)

lons = f.createVariable('GRID_X_T', 'f8', ('GRID_X_T'))
lons = f.createVariable('lon', 'f8', ('lon'))
lons.long_name = 'Nominal Longitude of T-cell center'
lons.units = 'degree_east'
lons.modulo = 360.
Expand All @@ -99,7 +99,7 @@ def create_mom_output(ocean_grid, filename, start_date, history):
# MOM needs this to be a single dimension
lons[:] = ocean_grid.x_t[ocean_grid.x_t.shape[0] // 2, :]

lats = f.createVariable('GRID_Y_T', 'f8', ('GRID_Y_T'))
lats = f.createVariable('lat', 'f8', ('lat'))
lats.long_name = 'Nominal Latitude of T-cell center'
lats.units = 'degree_north'
lats.point_spacing = 'uneven'
Expand All @@ -108,22 +108,22 @@ def create_mom_output(ocean_grid, filename, start_date, history):
col = col_idx_largest_lat(ocean_grid.y_t[:])
lats[:] = ocean_grid.y_t[:, col]

zt = f.createVariable('ZT', 'f8', ('ZT'))
zt.long_name = 'zt'
zt.units = 'meters'
zt.positive = 'down'
zt.point_spacing = 'uneven'
zt.axis = 'Z'
zt[:] = ocean_grid.z[:]
depth = f.createVariable('depth', 'f8', ('depth'))
depth.long_name = 'depth'
depth.units = 'meters'
depth.positive = 'down'
depth.point_spacing = 'uneven'
depth.axis = 'Z'
depth[:] = ocean_grid.z[:]

time = f.createVariable('time', 'f8', ('time'))
time.long_name = 'time'
time.units = "days since {}-{}-{} 00:00:00".format(str(start_date.year).zfill(4),
time.units = "months since {}-{}-{} 00:00:00".format(str(start_date.year).zfill(4),
str(start_date.month).zfill(2),
str(start_date.day).zfill(2))
time.cartesian_axis = "T"
time.calendar_type = "GREGORIAN"
time.calendar = "GREGORIAN"
time.calendar_type = "noleap"
time.calendar = "noleap"

f.close()

Expand All @@ -133,7 +133,7 @@ def write_mom_output_at_time(filename, var_name, var_longname, var_units,
with nc.Dataset(filename, 'r+') as f:
if not var_name in f.variables:
var = f.createVariable(var_name, 'f8',
('time', 'ZT', 'GRID_Y_T', 'GRID_X_T'),
('time', 'depth', 'lat', 'lon'),
fill_value=-1.e+34, zlib=True, complevel=5, shuffle=True)
var.missing_value = -1.e+34
var.long_name = var_longname
Expand Down