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

CICE grid generation from MOM supergrid #6

Closed
wants to merge 13 commits into from
24 changes: 9 additions & 15 deletions grid_generation/Gen_CICE_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,27 @@ def generate_cice_grid(in_superGridPath, output_file):
TLAT = np.deg2rad(in_superGridFile['y'][1::2, 1::2])
TLON = np.deg2rad(in_superGridFile['x'][1::2, 1::2])

# MPI
HTN = in_superGridFile['dx'] * 100.0 # convert to cm
HTN = HTN[1::2, ::2] + HTN[1::2, 1::2]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2024-03-07 at 4 15 14 pm

In the mom_grid, dx has units ('nyp','nx'). These correspond to the edges in y and the middle in x. So, the y coordinate (i.e. rows) should be 2::2

HTE = in_superGridFile['dy'] * 100.0 # convert to cm
HTE = HTE[::2, 1::2] + HTE[1::2, 1::2]

# The angle of rotation is a corner cell centres and applies to both t and u cells.
ANGLE = np.deg2rad(in_superGridFile['angle_dx'][2::2, 2::2])
ANGLET= np.deg2rad(in_superGridFile['angle_dx'][1::2, 1::2])

# Area
AREA = (in_superGridFile['area'])
TAREA = AREA[::2,::2] + AREA[1::2,1::2] + AREA[::2,1::2] + AREA[1::2,::2]

array_to_roll = AREA[2::2,2::2]

# Roll the array along axis 0 and concatenate the last row as the first row
rolled_array_axis0 = np.concatenate((
np.roll(array_to_roll, -1, axis=0),
array_to_roll[-1:, :]), axis=0)

# Roll the rolled array along axis 1 and concatenate the last column as the first column
rolled_array = np.concatenate((
np.roll(rolled_array_axis0, -1, axis=1),
rolled_array_axis0[:, -1:]), axis=1)

UAREA = AREA[1::2,1::2] + np.concatenate((np.roll(AREA[1::2, 2::2], -1, axis=1), AREA[1::2, 2::2][:, :1]), axis=1) + np.concatenate((np.roll(AREA[2::2, 1::2], -1, axis=0), AREA[2::2, 1::2][:1, :]), axis=0) + rolled_array
# UAREA need to wrap around the globe. Copy ocn_area and
# add an extra column at the end. Also u-cells cross the
# tri-polar fold so add an extra row at the top.
area_ext = np.append(AREA[:], AREA[:, 0:1], axis=1)
area_ext = np.append(area_ext[:], area_ext[-1:, :], axis=0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line only works because the top row is symmetrical? It doesn't actual seem to fold it... ?


UAREA = area_ext[1::2, 1::2] + area_ext[2::2, 1::2] + \
area_ext[2::2, 2::2] + area_ext[1::2, 2::2]

# Close input files
in_superGridFile.close()
Expand Down Expand Up @@ -156,7 +151,6 @@ def generate_cice_grid(in_superGridPath, output_file):
angleT[:] = ANGLET
tarea[:] = TAREA
uarea[:] = UAREA

# Close the file
nc.close()

Expand Down