-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
grid_generation/Gen_CICE_grid.py
Outdated
|
||
# Constants | ||
ULAT = np.deg2rad(in_superGridFile['y'][2::2, 1::2]) | ||
ULON = np.deg2rad(in_superGridFile['x'][1::2, 2::2]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be
ULAT = np.deg2rad(in_superGridFile['y'][2::2, 2::2])
ULON = np.deg2rad(in_superGridFile['x'][2::2, 2::2])
?
it might be clearer to write:
np.deg2rad(in_superGridFile.y.sel(x=slice(start=2,step=2), y=slice(start=2, step=2)))
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, but with isel
, not sel
I'll mostly defer to Andrew review but we'll want some versioning information added to the output of both the source mom file and the script version used |
Yes, versioning info would be good too, e.g. https://github.com/COSIMA/om3-scripts/blob/main/mesh_generation/generate_mesh.py#L397-L413 |
It would be a good idea to compare the new There might be something in here that could be useful: |
This is missing the following from
|
Those three quantities are computer internally in CICE: We might want to think a little bit about whether computing the areas in a projection aware way improves accuracy. I guess the first check would be whether the old |
I wonder whether it would be better to make CICE read the MOM supergrid directly? |
It looks like code was added to cice5 to read tarea, tlat and tlon from the cice grid file rather than calculate them:
|
There is something similar in the cmeps driver for CICE:
Which looks like it will get the area from the mesh file. |
Co-authored-by: Andrew Kiss <[email protected]>
Co-authored-by: Andrew Kiss <[email protected]>
@ezhilsabareesh8 Thanks for the changes! I think |
@ezhilsabareesh8 - Can you test the new grid with OM2? I think you will need to add:
for it to work in OM2. Should we have two versions of this grid? One for OM2 and one for OM3 (with less variables?)
Shall we split this into a different issue? Current OM3 implementation has CICE calculating area internally, which is problematic. |
@anton-seaice I can test OM2 with the new The newly generated
|
Oh yes - I was just thinking of two versions because its confusing if we have a grid.nc file loaded by OM3 that is then only using some of the variables. |
@aekiss, I've incorporated the TAREA and UAREA variables in the latest commit (09be9fb). However, I've noticed a discrepancy between the output of the newly generated
|
re. the differences at the fold - not sure if this helps, but FYI we are using |
Sec 9.4.3 of Elements of MOM describes the special treatment of grid cell areas long the fold. |
Re. the area mismatch, I guess the original 1deg areas in the supergrid were calculated using |
Sorry to intrude in the discussion, somehow I get notifications for this. The area of a quadrilateral on the sphere is uniquely defined given the lon-lat coords of its four vertices. It doesn’t need to be approximated. So, regardless how it was done in the past, it’s a good idea to drop any unnecessary approximations. The sum of all grid areas should be precisely 4πR^2 (up to machine precision). |
There a way to avoid needing to ensure you give the vertices in counter-clockwise order. I can put more details when I am in front of a computer. |
Thanks. We are trying to calculate the area of each cice grid cell by using the mom supergrid file. The areas in the mom supergrid seem to be calculated consistently with the way you are saying (https://github.com/ESMG/gridtools/blob/de0a18c1ce0807748aa70023300dfc415277bd4c/gridtools/spherical.py#L36). This is a good thing for us to try though, if the areas calculated based on the lat/lons only are the same as the ones derived from the mom supergrid, that would be a good validation of the method. |
All we are doing is summing the area of the four relevant cells from the supergrid to make the cice grid, I can't see anything inconsistent with the update_cell_area in that? This is similar to what Navid is saving I think - we could use this method to calculate area based on lat/lon only, and not from the supergrid. |
Does this mean the coordinates move away from regular 1 degree spacing? p.s. Its also odd that the patterning below 65N is there in the uarea calc and not the tarea calc. |
The patterning found above in t-area seems to only be there in the 1-degree grid, so it might be an artifact of the Meridional refinement and the grids getting out of sync at some point. Its not there in the 0.25 degree grid, so maybe we can ignore it. The difference in u-area, is still strange. In our current grid at the join: and in the calculating from the mom supergrid at the join: I think the second one is correct. (Amusingly the files in '/g/data/ik11/grids/' also have one of each option) This figure kind of demonstrates it (viewed straight down on the north pole): u-area is the sum of the areas of a quarter of each grid cell which surrounds each u-point (i.e. NE corner point). The areas north of the join (The thick line) are smaller than those south of the join with a notable change. So the u-areas at the join are the average of the smaller and larger cell areas which exist either side of the join, and therefore create the 'step' shown in the second figure. As an aside, I stumbled across this code which Nic wrote and does what we want: |
yes, the meridional (y) spacing is refined to 1/3° near the equator on the 1° grid. Note that the y spacing is not regular at most latitudes at 0.25° or 0.1° either, because a Mercator grid is used between 65S and 65N to keep the cell aspect ratio equal to 1. See https://github.com/COSIMA/ACCESS-OM2-1-025-010deg-report/blob/master/figures/grid/grid.ipynb
yes, indeed |
I think I agree with your analysis @anton-seaice, so long as the 65°N junction between the Mercator and tripolar grids falls on U points - is that the case? |
Good point - I checked - all three resolutions have the join at u-points |
The angle ANGLET in the current implementation is calculated directly from the super grid as Refer here
which is consistent with the OM2 Should we consider adapting the angleT calculation method to utilize the weighted average approach used in CICE6? |
grid_generation/Gen_CICE_grid.py
Outdated
TLON = np.deg2rad(in_superGridFile['x'][1::2, 1::2]) | ||
|
||
HTN = in_superGridFile['dx'] * 100.0 # convert to cm | ||
HTN = HTN[1::2, ::2] + HTN[1::2, 1::2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…t edge respectively. Therefore for cice we want the index to start from 2.
# 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) |
There was a problem hiding this comment.
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... ?
I did a plot with every var and every resolution (left to right: 1deg, 0.25deg, 0.1deg). I masked difference which were less than 2e-6
I think we should merge this PR soon. We still have to add CF metadata and test with OM2, but these could be new issues to stop this PR totally blowing out? We also need to decide if we are sticking with np syntax (e.g. [2::2,1::2] or moving to written xarray style (e.g. |
I turned on compression: Before
After:
I left chunking at the default sizes, which gives 0.1 deg chunks of 900, 1200 (y,x) but the other resolutions are full size |
else: | ||
nc.inputfile = f"{in_superGridPath}" | ||
nc.timeGenerated = f"{datetime.now()}" | ||
nc.created_by = f"{os.environ.get('USER')}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nc.inputfile = f"{in_superGridPath}"
nc.timeGenerated = f"{datetime.now()}"
nc.created_by = f"{os.environ.get('USER')}"
These three lines can go outside the if/else as they are the same in both cases.
Can we add a hash for the input file? Similar to the payu manifests md5 hash?
I compared every resolution & every var between the version from this script, and the version in '/g/data/ik11/inputs/access-om2/input_20200530/'
|
I suggest - to remove duplication in code and make the result more extendable we close this PR and re-write this using https://github.com/COSIMA/esmgrids. The script can be based on https://github.com/COSIMA/access-om2/blob/master/tools/make_cice_grid.py but we need add version control, fix AngleT in esmgrids and add CF metadata. Using esmgrids makes this easier to extend in the future (e.g. to make the ocean_grid file for analysis). |
@aekiss thoughts ? |
Thanks for all your work on this Ezhil. I've taken our lessons and re-worked using esmgrids in a new PR :) |
This pull request addresses issues COSIMA/access-om3#101 and COSIMA/access-om2#280 by adding a Python script to generate the CICE6 grid from the MOM6 supergrid.
The script facilitates the creation of a CICE grid, resolving a previously encountered longitude mismatch issue by correctly positioning the U points in the NE corner.