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

Convert the Surface Water Mass Transformation example to be model-agnostic #402

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

Conversation

willaguiar
Copy link
Collaborator

@willaguiar willaguiar commented Jul 2, 2024

Closes #277
Closes #341

This is an attempt to make the surface water mass transformation partially model agnostic. I used cf-xarray to deal with operations along dimensions. To deal with the different diagnostics required by each model I added an embedded dictionary to the save_SWMT function. The function also spits the specific dictionary for that model so it can be used later for shelf masking.

Shelf masking requires the input isobath file. Currently we have these isobath files only for OM2 and Panans. Panan isobath is on @schmidt-christina disk. Perhaps we can move them to ik11 to avoid permission issues?
For mom5 I also changed the diag to use pme_net instead of pme_river, according to issue #341

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@navidcy
Copy link
Collaborator

navidcy commented Jul 7, 2024

Panan isobath is on @schmidt-christina disk. Perhaps we can move them to ik11 to avoid permission issues?

We definitely don't want our examples to be dependent on data that lives on user's personal home or g/data directories

Copy link

review-notebook-app bot commented Jul 7, 2024

View / edit / reply to this conversation on ReviewNB

navidcy commented on 2024-07-07T04:22:42Z
----------------------------------------------------------------

Line #1.    def save_SWMT(expt, session, start_time, end_time, outpath,model='mom6', lat_north = -59, n = None):

space after commas


Copy link

review-notebook-app bot commented Jul 7, 2024

View / edit / reply to this conversation on ReviewNB

navidcy commented on 2024-07-07T04:22:42Z
----------------------------------------------------------------

Line #215.        ds[SST.cf['latitude'].name].attrs= {'standard_name':'latitude'}

space after colons


Copy link

review-notebook-app bot commented Jul 7, 2024

View / edit / reply to this conversation on ReviewNB

navidcy commented on 2024-07-07T04:22:43Z
----------------------------------------------------------------

Line #228.        resolution = str(0.01/(pme_net.cf['longitude'].size/3600))[2:]

what is this here doing? reads strange to me


willaguiar commented on 2024-07-07T06:37:56Z
----------------------------------------------------------------

This is an attempt to automatically get the resolution of the model, assuming a global square-cell grid. This is necessary so we can identify the correct name of the isobath file for panan (contains 3 resolutions) . So this lines calculates there resolution and convert it to string to use it on...

contour_dir = "/home/142/cs6673/work/mom6_comparison/Antarctic_slope_contours/Antarctic_slope_contour_1000m_MOM6_" + resolution + "deg.nc"

Happy to improve if you have a suggestion

adele-morrison commented on 2024-07-07T06:49:58Z
----------------------------------------------------------------

Maybe a dictionary with experiment names mapped to resolution is best? This wouldn't work for a regional model right?

willaguiar commented on 2024-07-07T07:01:10Z
----------------------------------------------------------------

True, it wouldn't if the regional model is not circumpolar. How would we map the dict to the experiment name? something like...

if expt='panant-01-zstar-ACCESSyr2': resolution='01'

? Or maybe only extracting the 01 string from the name for experiments starting with 'panant'?

schmidt-christina commented on 2024-07-08T00:54:08Z
----------------------------------------------------------------

I extract the resolution from the experiment name, but that assumes we keep the naming convention:

resolution = expt.split('-')[1]

Copy link

review-notebook-app bot commented Jul 7, 2024

View / edit / reply to this conversation on ReviewNB

navidcy commented on 2024-07-07T04:22:44Z
----------------------------------------------------------------

what are all these 0.3.0?


willaguiar commented on 2024-07-07T06:41:09Z
----------------------------------------------------------------

This is a print that only appears when I run ...

cc.querying.getvar 

...through VScode ssh system. It doesn't appear when I run it on ARE as it is usually done. Not sure why tho ( but other then the 0.3.0 print itself, no other difference). The new edits/submission will be run on ARE so this will not appear

Copy link

review-notebook-app bot commented Jul 7, 2024

View / edit / reply to this conversation on ReviewNB

navidcy commented on 2024-07-07T04:22:44Z
----------------------------------------------------------------

Line #1.    def shelf_mask_isobath(var,model_dict):

space after comma


Copy link

review-notebook-app bot commented Jul 7, 2024

View / edit / reply to this conversation on ReviewNB

navidcy commented on 2024-07-07T04:22:45Z
----------------------------------------------------------------

space after commas


Copy link
Collaborator

@navidcy navidcy left a comment

Choose a reason for hiding this comment

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

Great job! Thanks @willaguiar!

Made a few minor comments.

My major comment is that you claim that it works with MOM6 output now. Let's make an example calculation and a figure using MOM6 output though to make sure! Unless it was there and I missed it?

@navidcy
Copy link
Collaborator

navidcy commented Jul 7, 2024

@willaguiar could you rename the PR to something more descriptive? E.g., "Convert the ..... example to be model agnostic"? Don't use SWMT... Personally I'm not 100% sure I know what that is? Is it another acronym similar to CDW, AABW, NADW, etc?

Copy link

review-notebook-app bot commented Jul 7, 2024

View / edit / reply to this conversation on ReviewNB

navidcy commented on 2024-07-07T04:29:28Z
----------------------------------------------------------------

diagnostics(see this -> diagnostics (see this


Copy link

review-notebook-app bot commented Jul 7, 2024

View / edit / reply to this conversation on ReviewNB

navidcy commented on 2024-07-07T04:29:29Z
----------------------------------------------------------------

Line #19.    import cf_xarray as cfxr

this is under "plotting"!

let's remove the ## plotting comment? or put the import cf_xarray as cfxr before that comment.


Copy link

review-notebook-app bot commented Jul 7, 2024

View / edit / reply to this conversation on ReviewNB

navidcy commented on 2024-07-07T04:29:30Z
----------------------------------------------------------------

Rephrase to "We suggest..."

Always use plural because we want the users to feel that the community is guiding them, not a particular individual.


@navidcy
Copy link
Collaborator

navidcy commented Jul 7, 2024

Seems that the PR closes #341, right @willaguiar?
In that case can you edit your first comment in the PR to write closes #341 somewhere... this way the PR will be linked with the issue and the issue will be automatically closed upon merging this PR.

@navidcy
Copy link
Collaborator

navidcy commented Jul 7, 2024

Also the phrase Solves issue #277 is not recognized by GitHub to automatically link the issue. You should rephrase to Closes #277 or Resolves #277.

@willaguiar willaguiar changed the title partially model-agnostic SWMT partially model-agnostic Surface Water Mass Transformation Jul 7, 2024
@willaguiar willaguiar changed the title partially model-agnostic Surface Water Mass Transformation Convert the Surface Water Mass Transformation example to be model-agnostic Jul 7, 2024
Copy link
Collaborator Author

This is an attempt to automatically get the resolution of the model, assuming a global square-cell grid. This is necessary so we can identify the correct name of the isobath file for panan (contains 3 resolutions) . So this lines calculates there resolution and convert it to string to use it on...

contour_dir = "/home/142/cs6673/work/mom6_comparison/Antarctic_slope_contours/Antarctic_slope_contour_1000m_MOM6_" + resolution + "deg.nc"

Happy to improve if you have a suggestion


View entire conversation on ReviewNB

Copy link
Collaborator Author

This is a print that only appears when I run ...

cc.querying.getvar 

...through VScode ssh system. It doesn't appear when I run it on ARE as it is usually done. Not sure why tho ( but other then the 0.3.0 print itself, no other difference). The new edits/submission will be run on ARE so this will not appear


View entire conversation on ReviewNB

Copy link
Collaborator

Maybe a dictionary with experiment names mapped to resolution is best? This wouldn't work for a regional model right?


View entire conversation on ReviewNB

Copy link
Collaborator Author

True, it wouldn't if the regional model is not circumpolar. How would we map the dict to the experiment name? something like...

if expt='panant-01-zstar-ACCESSyr2': resolution='01'

? Or maybe only extracting the 01 string from the name for experiments starting with 'panant'?


View entire conversation on ReviewNB

Copy link
Collaborator

I extract the resolution from the experiment name, but that assumes we keep the naming convention:

resolution = expt.split('-')[1]


View entire conversation on ReviewNB

Copy link

review-notebook-app bot commented Jul 8, 2024

View / edit / reply to this conversation on ReviewNB

schmidt-christina commented on 2024-07-08T07:59:23Z
----------------------------------------------------------------

Line #132.        pressure = xr.DataArray(p_from_z(depth_tile, lat_t), coords = [yt_ocean, xt_ocean], dims = [SST.cf['latitude'].name, SST.cf['longitude'].name], name = 'pressure', attrs = {'units':'dbar'})

Here, and whenever you use the gsw functions: There is no need to explicitly convert it into xr.DataArray anymore as the result is already a DataArray.

pressure = p_from_z(depth_tile, lat_t)
pressure.attrs = {'units': 'dbar'}


Copy link
Collaborator

Some accidental newlines (e.g. th

e water mass transformation in each model simulation)


View entire conversation on ReviewNB

@navidcy navidcy added 🛸 updating An existing notebook needs to be updated MOM5+MOM6 ❤️ 🕹️ hackathon 4.0 labels Jul 12, 2024
@willaguiar willaguiar self-assigned this Jul 20, 2024
@julia-neme julia-neme self-requested a review July 22, 2024 05:20
@navidcy
Copy link
Collaborator

navidcy commented Jul 28, 2024

I admit this has always been an example that feels impenetrable for me to grasp... There is too much hardcoded code and in a dense matter that makes it hard for me. I tried to clean it up a bit. It's not there yet, somebody should run to check it actually runs. It takes too long for my patience so I gave up on running it -- sorry... :(

Thanks all for your efforts here!

@julia-neme
Copy link
Collaborator

I also find it a bit hard to follow, mostly because all the magic is happening within 1 function in a really long cell. Would maybe splitting the code into components/functions make it more understandable? For example, one function to load, one function to calculate the thermal component, one for the haline, one for isopycnal binning and so on?

I think that splitting code like this would make it way more digestible for the non-initiated in SWMT. I know it is probably a lot of work to do it... so apologies for the suggestion.

@adele-morrison
Copy link
Collaborator

It takes too long for my patience

If the slow part is the density binning, we could convert to using xhistogram or a faster binning method.

@navidcy
Copy link
Collaborator

navidcy commented Jul 29, 2024

I would like to see something in the spirit of what @julia-neme suggests!

But also that could happen in a future PR...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🕹️ hackathon 4.0 MOM5+MOM6 ❤️ 🛸 updating An existing notebook needs to be updated
Projects
None yet
5 participants