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

Version 1.0: North Atlantic Update - Tides, Curved Boundaries, Config, and More!😀🤯🥳 #193

Open
wants to merge 253 commits into
base: main
Choose a base branch
from

Conversation

manishvenu
Copy link
Collaborator

@manishvenu manishvenu commented Oct 11, 2024

Authors: @ashjbarnes, @manishvenu, @helenmacdonald

Description:

Ashley and I worked together to add a few features to RM6. While we get the changes ready to merge with the main COSIMA branch, please check out this draft with a list of the changes below.

Major Features:

  1. Accepting curved boundary supergrids and bathymetry (Add angled grids to RMOM6 CROCODILE-CESM/regional-mom6#13)
  2. Implement Boundary Tides from OSU's TPXO using GFDL NWA25 Code (Merge various quality-of-life changes & tides boundary functions (From GFDL NWA25) into RMOM6 CROCODILE-CESM/regional-mom6#12)
  3. Import experiment configuration from a light config JSON (Merge various quality-of-life changes & tides boundary functions (From GFDL NWA25) into RMOM6 CROCODILE-CESM/regional-mom6#12)
  4. Major bathymetry fixes for land-sea mask (Various bathymetry improvements / bugfixes CROCODILE-CESM/regional-mom6#17)
  5. Moving experiment specific changes to MOM_override (All OBC, Tides, and other minor changes) and out of MOM_input
  6. New GLORYS downloader (that can account for curved boundaries) (Merge various quality-of-life changes & tides boundary functions (From GFDL NWA25) into RMOM6 CROCODILE-CESM/regional-mom6#12)
  7. Tests: Additional tests (tides. rotation, and regridding), Conftest.py, Add to Docker Image (MOM6 Angle Calculation CROCODILE-CESM/regional-mom6#34)
  8. Changing function names to verb beginnings (initial_condition -> setup_initial_condition) (Merge various quality-of-life changes & tides boundary functions (From GFDL NWA25) into RMOM6 CROCODILE-CESM/regional-mom6#12)
  9. Add properties (i.e. more functional object variables) and dataset plotting (Merge various quality-of-life changes & tides boundary functions (From GFDL NWA25) into RMOM6 CROCODILE-CESM/regional-mom6#12)
  10. Add Rotation: Add MOM6 angle calculation at t points (MOM6 doesn't use an input hgrid's angle_dx field. It calculate the angle internally at t-points) & two angle approximation methods for the boundary q/u/v points (MOM6 Angle Calculation CROCODILE-CESM/regional-mom6#34)
  11. Add Land Mask (Fix tides on angled boundaries, consolidate regridded of velocity and tracers, add proper body tide parameters, add MOM6's angle calculation. CROCODILE-CESM/regional-mom6#33)

Minor Features:

  1. Ability to code without greek letters
  2. Removed unintentional machine-specific code
  3. Increased print statements

Breaking Changes (for backwards compatibility):

  1. Functions changed names, so it's not compatible with older code. All that needs to be updated is the function name itself in previous code (like the demos). (Merge various quality-of-life changes & tides boundary functions (From GFDL NWA25) into RMOM6 CROCODILE-CESM/regional-mom6#12)

Documentation Changes:

  1. Update README and Docs (MOM6 Angle Calculation CROCODILE-CESM/regional-mom6#34, Fix tides on angled boundaries, consolidate regridded of velocity and tracers, add proper body tide parameters, add MOM6's angle calculation. CROCODILE-CESM/regional-mom6#33)

Co-authored-by: @ashjbarnes, @helenmacdonald

this PR closes #184 , #168 , and also #55 in a roundabout way since user now specifies which boundaries they want, and the MOM inputs are adjusted accordingly.

Before merging, need to resolve the following:

Outstanding Questions:

  1. (Solved!) Logging was implemented in the two new modules of RM6 (regridding.py and rotation.py). Do we want to switch over RM6 to use python logging instead of print statements? Currently, we would prefer that but open it up to opinions.
  2. (Solved!) A while back, we all briefly discussed that this should be version 0.8 instead of 1. Any opinions or insight?
  3. (Solved!) The docker image is currently CROCODILE's image, if we want to update RM6's image, it's a three step process by someone with write permissions & docker downloaded

ashjbarnes and others added 30 commits August 29, 2024 13:51
Changes to make compatible with CESM
having mask table and layout no longer required
Replace minimum layers with min depth
…nt num

After talking with Ashley, the find_MOM6_orientation will likely be removed
The function names for rectangular and sinmple boundaries were changed because the tides are a kind of boundary function, the old names now give a warning and call the correct function. GFDL had rough horizontal subsetting for the tpxo dataset (probably for efficiency?), implemented in setup_tides_rectangular_boundaries.
Collapsed the *_tidal_dims functions into the encode_tides function in segment, and add citing documentation to the docstrings for now.
@manishvenu
Copy link
Collaborator Author

I would also like to see the test run and pass before we merge. At the moment they don't do anything? I see this for every commit:

Yeah not sure what's going on! They all passed yesterday with my changes but are hanging today. Nothing structural has changed since they passed yesterday though

Which commit of yours yesterday had all the tests working? We may able to figure out why if that was the case. But as far as I understand, the last time I saw the test jobs starting and passing is 0523f1d. Perhaps I'm wrong.

These pending checks on this PR have been around the whole time for me. The tests have been running on CROCODILE's fork so not sure what's up here.

Thanks,
Manish V

@navidcy
Copy link
Contributor

navidcy commented Feb 11, 2025

They were running up to some point; last time I've seen them run was for commit 0523f1d.

@manishvenu
Copy link
Collaborator Author

Fixed!

@navidcy
Copy link
Contributor

navidcy commented Feb 11, 2025

G R E A T!

@navidcy
Copy link
Contributor

navidcy commented Feb 11, 2025

@manishvenu we can perhaps zoom on Fri and sort out the explanation of the steps at https://regional-mom6--193.org.readthedocs.build/en/193/angle_calculation.html#boundary-rotation-algorithm ?

I'm in California timezone until Fri but busy up to Thu...

We can also always continue chat via GitHub.

@manishvenu
Copy link
Collaborator Author

@manishvenu we can perhaps zoom on Fri and sort out the explanation of the steps at https://regional-mom6--193.org.readthedocs.build/en/193/angle_calculation.html#boundary-rotation-algorithm ?

I'm in California timezone until Fri but busy up to Thu...

We can also always continue chat via GitHub.

Yes, we can definitely zoom to wrap up this PR. Feel free to email me to coordinate! I'm happy to do Friday, though it may also be easier to do sometime next week if anyone in the Australian timezone wants to join.

@navidcy
Copy link
Contributor

navidcy commented Feb 11, 2025

@manishvenu we can perhaps zoom on Fri and sort out the explanation of the steps at https://regional-mom6--193.org.readthedocs.build/en/193/angle_calculation.html#boundary-rotation-algorithm ?
I'm in California timezone until Fri but busy up to Thu...
We can also always continue chat via GitHub.

Yes, we can definitely zoom to wrap up this PR. Feel free to email me to coordinate! I'm happy to do Friday, though it may also be easier to do sometime next week if anyone in the Australian timezone wants to join.

Let's play it by ear on Fri...
Next week is super busy for me :(

@manishvenu
Copy link
Collaborator Author

@manishvenu we can perhaps zoom on Fri and sort out the explanation of the steps at https://regional-mom6--193.org.readthedocs.build/en/193/angle_calculation.html#boundary-rotation-algorithm ?
I'm in California timezone until Fri but busy up to Thu...
We can also always continue chat via GitHub.

Yes, we can definitely zoom to wrap up this PR. Feel free to email me to coordinate! I'm happy to do Friday, though it may also be easier to do sometime next week if anyone in the Australian timezone wants to join.

Let's play it by ear on Fri... Next week is super busy for me :(

Sounds good.

@ashjbarnes
Copy link
Collaborator

I've fixed the MOM_layout not writing issue, and tried testing the example notebook again. However, it crashes with the 'eta has dropped below bathy' issue even with a really short timestep. It's suggesting a huge instability too, with the sea surface passing through the centre of the planet and making it all the way to Neptune. The instabilities are located at the boundaries too.

Could you confirm whether MOM6 runs the demo successfully out of the box on Derecho @manishvenu ? If not, then some of the changes since October might have caused this to break.

Last I'd checked in October, the rectangular Tasmania demo worked fine on the NCAR computers, but the curved boundary with tides on did not because of a bug I introduced but which you've subsequently fixed. If this is only an issue on our machine then that would make the diagnosis a lot easier!

@manishvenu
Copy link
Collaborator Author

I've fixed the MOM_layout not writing issue, and tried testing the example notebook again. However, it crashes with the 'eta has dropped below bathy' issue even with a really short timestep. It's suggesting a huge instability too, with the sea surface passing through the centre of the planet and making it all the way to Neptune. The instabilities are located at the boundaries too.

Could you confirm whether MOM6 runs the demo successfully out of the box on Derecho @manishvenu ? If not, then some of the changes since October might have caused this to break.

Last I'd checked in October, the rectangular Tasmania demo worked fine on the NCAR computers, but the curved boundary with tides on did not because of a bug I introduced but which you've subsequently fixed. If this is only an issue on our machine then that would make the diagnosis a lot easier!

Hey Ashley,

The tidal bug did have pretty much that error (I think). I can try to run the reanalysis_forced demo -> We've shifted away from using a few of the functions however, CrocoDash isn't using setup_run_directory and such, mostly just the forcing functions. That should still apply to this error (it's boundary related iirc??).

For the tidal bug, it's because the corners of the boundaries had NaNs in them, but that should be fixed now.

Did you try turning off the tides?

Thanks,
Manish V.

@ashjbarnes
Copy link
Collaborator

I've fixed the MOM_layout not writing issue, and tried testing the example notebook again. However, it crashes with the 'eta has dropped below bathy' issue even with a really short timestep. It's suggesting a huge instability too, with the sea surface passing through the centre of the planet and making it all the way to Neptune. The instabilities are located at the boundaries too.
Could you confirm whether MOM6 runs the demo successfully out of the box on Derecho @manishvenu ? If not, then some of the changes since October might have caused this to break.
Last I'd checked in October, the rectangular Tasmania demo worked fine on the NCAR computers, but the curved boundary with tides on did not because of a bug I introduced but which you've subsequently fixed. If this is only an issue on our machine then that would make the diagnosis a lot easier!

Hey Ashley,

The tidal bug did have pretty much that error (I think). I can try to run the reanalysis_forced demo -> We've shifted away from using a few of the functions however, CrocoDash isn't using setup_run_directory and such, mostly just the forcing functions. That should still apply to this error (it's boundary related iirc??).

For the tidal bug, it's because the corners of the boundaries had NaNs in them, but that should be fixed now.

Did you try turning off the tides?

Thanks, Manish V.

Thanks yeah if you can check whether it works on your setup we’ll know at least that it’s not the forcing and related to the differences to our setups. If there’s a problem for you though then the forcing files might still have an issue!

@ashjbarnes
Copy link
Collaborator

But the tidal but didn’t used to be an issue on the non rotated Tasmania example right? I remember first getting it on the curved NWA domain

so something else might have happened in the meantime which messed up the non rotated simple case. I’ll try without tides though

@manishvenu
Copy link
Collaborator Author

manishvenu commented Feb 13, 2025

But the tidal but didn’t used to be an issue on the non rotated Tasmania example right? I remember first getting it on the curved NWA domain

so something else might have happened in the meantime which messed up the non rotated simple case. I’ll try without tides though

Yeah, it shouldn't be an issue of the non rotated Tasmania because don't get NaNs there. I haven't tested this but it probably would fail if there were NaNs in the corner. Probably isn't that error tho! I'll see if it runs on our computer tmrw.

We got to figure out that way to share cases across computers at some point:)

@helenmacdonald
Copy link

Hi @ashjbarnes - I managed to get output from the curved domain to run at the point where I was doing my pull request to get the example notebook into the CROCODILE repository. I only ran it for a day though and didn't look at sea level output. How long before the crash appears? If it helps, I can dig a bit deeper to see if both of mine was running properly at that point in time.

# Compute angle
angle = np.arctan2(
lon_scale * ((lonB[0, 1] - lonB[1, 0]) + (lonB[1, 1] - lonB[0, 0])),
(bottom_left.y - top_right.y) + (top_left.y - bottom_right.y),
Copy link
Contributor

@navidcy navidcy Feb 14, 2025

Choose a reason for hiding this comment

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

if we look at

https://github.com/mom-ocean/MOM6/blob/05d8cc395c1c3c04dd04885bf8dd6df50a86b862/src/initialization/MOM_shared_initialization.F90#L581

it should be

Suggested change
(bottom_left.y - top_right.y) + (top_left.y - bottom_right.y),
(top_right.y - bottom_left.y) + (top_left.y - bottom_right.y),

right @manishvenu, @ashjbarnes? Am I missing something here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes it is, good catch, thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can do a little bit of testing next week for this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Getting weird results, let me look at this further

Copy link
Collaborator Author

@manishvenu manishvenu Feb 15, 2025

Choose a reason for hiding this comment

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

Ok I figured it out, this bug worked the first time because the numerator is also flipped the exact same way lonB is in indexing [y,x] so the complete fix should be :

angle = np.arctan2( lon_scale * (( lonB[1, 0] - lonB[0, 1]) + (lonB[1, 1] - lonB[0, 0])), (top_right.y - bottom_left.y) + (top_left.y - bottom_right.y) )

Basically, you always want the top points subtracting the bottom points on a diagonal.

We either do the suggestion here, or change the lonB matrix to be x,y instead of y, x. I can make this change.

Interesting note, because they were both flipped, thankfully, there were only differences in angles up to the 1e-5

Copy link
Contributor

Choose a reason for hiding this comment

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

how's the commit I pushed?

the difference in angles "only up to 1e-5" depends on the grid you are testing; coarser grid might have more difference!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great - Fixed it. Forgot to swap the other part of the numerator

Copy link
Collaborator Author

@manishvenu manishvenu Feb 15, 2025

Choose a reason for hiding this comment

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

I had a 90 degree transformation, didn't need that, which is good. Thanks for catching this Navid

Comment on lines +126 to +203
def test_mom6_angle_calculation_method(get_curvilinear_hgrid):
"""
Check no rotation, up tilt, down tilt.
"""

# Check no rotation
top_left = xr.Dataset(
{
"x": (("nyp", "nxp"), [[0]]),
"y": (("nyp", "nxp"), [[1]]),
}
)
top_right = xr.Dataset(
{
"x": (("nyp", "nxp"), [[1]]),
"y": (("nyp", "nxp"), [[1]]),
}
)
bottom_left = xr.Dataset(
{
"x": (("nyp", "nxp"), [[0]]),
"y": (("nyp", "nxp"), [[0]]),
}
)
bottom_right = xr.Dataset(
{
"x": (("nyp", "nxp"), [[1]]),
"y": (("nyp", "nxp"), [[0]]),
}
)
point = xr.Dataset(
{
"x": (("nyp", "nxp"), [[0.5]]),
"y": (("nyp", "nxp"), [[0.5]]),
}
)

assert (
rot.mom6_angle_calculation_method(
2, top_left, top_right, bottom_left, bottom_right, point
)
== 0
)

# Angled
hgrid = get_curvilinear_hgrid
ds_t = rgd.get_hgrid_arakawa_c_points(hgrid, "t")
ds_q = rgd.get_hgrid_arakawa_c_points(hgrid, "q")

# Reformat into x, y comps
t_points = xr.Dataset(
{
"x": (("nyp", "nxp"), ds_t.tlon.data),
"y": (("nyp", "nxp"), ds_t.tlat.data),
}
)
q_points = xr.Dataset(
{
"x": (("nyp", "nxp"), ds_q.qlon.data),
"y": (("nyp", "nxp"), ds_q.qlat.data),
}
)
assert (
(
rot.mom6_angle_calculation_method(
hgrid.x.max() - hgrid.x.min(),
q_points.isel(nyp=slice(1, None), nxp=slice(0, -1)),
q_points.isel(nyp=slice(1, None), nxp=slice(1, None)),
q_points.isel(nyp=slice(0, -1), nxp=slice(0, -1)),
q_points.isel(nyp=slice(0, -1), nxp=slice(1, None)),
t_points,
)
- hgrid["angle_dx"].isel(nyp=ds_t.t_points_y, nxp=ds_t.t_points_x).values
)
< 1
).all()

return
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain what this test tests?

I see "assert something, something < 1", that doesn't sound too strict. But I admit I don't quite understand what the test tries to test what's been tested so that may be clear if I did?

For a test of mom6_angle_calculation_method I'd expect we construct a grid at a particular angle and test to see if the mom6_angle_calculation_method computes that angle?

regional_mom6/rotation.py Outdated Show resolved Hide resolved
@manishvenu
Copy link
Collaborator Author

manishvenu commented Feb 15, 2025

I've fixed the MOM_layout not writing issue, and tried testing the example notebook again. However, it crashes with the 'eta has dropped below bathy' issue even with a really short timestep. It's suggesting a huge instability too, with the sea surface passing through the centre of the planet and making it all the way to Neptune. The instabilities are located at the boundaries too.
Could you confirm whether MOM6 runs the demo successfully out of the box on Derecho @manishvenu ? If not, then some of the changes since October might have caused this to break.
Last I'd checked in October, the rectangular Tasmania demo worked fine on the NCAR computers, but the curved boundary with tides on did not because of a bug I introduced but which you've subsequently fixed. If this is only an issue on our machine then that would make the diagnosis a lot easier!

Hey Ashley,
The tidal bug did have pretty much that error (I think). I can try to run the reanalysis_forced demo -> We've shifted away from using a few of the functions however, CrocoDash isn't using setup_run_directory and such, mostly just the forcing functions. That should still apply to this error (it's boundary related iirc??).
For the tidal bug, it's because the corners of the boundaries had NaNs in them, but that should be fixed now.
Did you try turning off the tides?
Thanks, Manish V.

Thanks yeah if you can check whether it works on your setup we’ll know at least that it’s not the forcing and related to the differences to our setups. If there’s a problem for you though then the forcing files might still have an issue!

Hey @ashjbarnes,

5 day run worked on the NCAR computer. I wonder what it is. Happy to send over the forcing files if that'll help

@navidcy
Copy link
Contributor

navidcy commented Feb 16, 2025

@ashjbarnes could you update the features-limitations in the Readme as well? Thanks!

@ashjbarnes
Copy link
Collaborator

Hi @ashjbarnes - I managed to get output from the curved domain to run at the point where I was doing my pull request to get the example notebook into the CROCODILE repository. I only ran it for a day though and didn't look at sea level output. How long before the crash appears? If it helps, I can dig a bit deeper to see if both of mine was running properly at that point in time.

Awesome thanks @helenmacdonald ! All I can say is that I took the Tassie example as it currently is, put in the same paths as I've done before (I have all the Tassie stuff saved for this purpose on Gadi), and it crashes before completing one day. Unfortunately I really need focus on my PhD after allowing myself a bit of rmom6 time last week (A wonderfully productive source of procrastination) so I won't get back around to troubleshooting further myself for another couple of weeks. If anyone on Gadi had the time to test it out that would be much appreciated!

Given that @manishvenu said it works in Casper, it's got to be something to do with the setup_rundir function, and in turn the text files in the run directory rather than the input files, as there's no reason that the inputs would be different between our cases. Unless the NCAR workflow now does further modifications to the input files that I'm not aware of

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Need to override MOM6 min depth based on value set in setup_bathymetry function
8 participants