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

Add example of regional configuration using regional-mom6 package forced with ACCESS-OM2-01 #338

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

Conversation

navidcy
Copy link
Collaborator

@navidcy navidcy commented Apr 23, 2024

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@navidcy
Copy link
Collaborator Author

navidcy commented Apr 23, 2024

We need to ensure the example runs.

Also we need to modify so that it uses the cosima-cookbook to load ACCESS-OM2 data; see COSIMA/regional-mom6#131

@navidcy
Copy link
Collaborator Author

navidcy commented Apr 25, 2024

@ashjbarnes I tried to run this and it errors on initial condition. See the output of Step 5 cell at https://app.reviewnb.com/COSIMA/cosima-recipes/pull/338/

@navidcy
Copy link
Collaborator Author

navidcy commented May 3, 2024

@ashjbarnes is this error related to the bug in COSIMA/regional-mom6#170? If so, it means that https://github.com/COSIMA/regional-mom6/releases/tag/v0.5.1 would be required.

cc @luweiyang

@navidcy
Copy link
Collaborator Author

navidcy commented May 6, 2024

I tried to see if regional-mom6 v0.5.2 healed the issues I was having. It didn't... :(

@luweiyang
Copy link
Collaborator

@ashjbarnes I tried to run the ACCESS-OM2 forced case and realised that the west and east unprocessed boundary files west_unprocessed.nc and east_unprocessed.nc are missing dimensions xu_ocean and xt_ocean (north_unprocessed.nc and south_unprocessed.nc have these two dimensions and can be processed by expt.rectangular_boundary )
xu_ocean = UNLIMITED ; // (0 currently)

@luweiyang
Copy link
Collaborator

luweiyang commented May 10, 2024

@ashjbarnes @navidcy

I've fixed the west and east boundary condition issues. I changed cell 6 in step 2 (changes in bold):
rmom6.longitude_slicer(om2_input, [longitude_extent[1]-0.2, longitude_extent[1]+0.2], ["xu_ocean", "xt_ocean"]).to_netcdf(tmp_dir + "/east_unprocessed.nc")

The notebook is running fine now and I've pushed the working version to the ncc/regional-mom6-v2 branch.

However, I couldn't run the experiment as I keep getting warning & error messages about initialization and extreme surface state. So somehow the date of ocean forcing and atmospheric forcing do not match? Since we use repeated year forcing, I didn't think that would be a problem... Any thoughts? And it turns out that the temperature unit is K (instead of C) in init_tracers.nc.

 Entering coupler_init at 20240510 154506.457
 Starting initializing ensemble_manager at 20240510 154506.458
 Finished initializing ensemble_manager at 20240510 154506.458
 Starting to initialize diag_manager at 20240510 154506.489

WARNING from PE     0: diag_manager_mod::diag_manager_init: DIAG_MANAGER_NML not found in input nml file.  Using defaults.

 Finished initializing diag_manager at 20240510 154506.493
 Starting to initialize tracer_manager at 20240510 154506.502
 Finished initializing tracer_manager at 20240510 154506.512
 Beginning to initialize component models at 20240510 154506.512
 Starting to initialize atmospheric model at 20240510 154506.534
 Finished initializing atmospheric model at 20240510 154506.581
 Starting to initialize land model at 20240510 154506.595
 Finished initializing land model at 20240510 154506.607
 Starting to initialize ice model at 20240510 154506.636
 Finished initializing ice model at 20240510 154506.731
 Starting to initialize ocean model at 20240510 154506.739
WARNING from PE    54: Extreme surface sfc_state detected: i=  57 j= 128 lon= 145.825 lat= -43.366 x= 145.825 y= -43.366 D= 8.3479E+01 SSH= 5.6639E-02 SST= 2.8748E+02 SSS= 3.4988E+01 U-= 2.0583E-02 U+= 2.0757E-02 V-=-6.1662E-03 V+= 4.9824E-03

WARNING from PE    54: There were more unreported extreme events!

FATAL from PE    39: There were a total of     29869 locations detected with extreme surface values!

@navidcy
Copy link
Collaborator Author

navidcy commented May 10, 2024

Great!

something else we’d want to do is to use the cookbook to load the ACCESS-OM2 output

@@ -0,0 +1,699 @@
{
Copy link
Collaborator Author

@navidcy navidcy May 10, 2024

Choose a reason for hiding this comment

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

why there are 3 commented out lines of code @luweiyang?

if we need them, then uncomment,

if we don't need them then delete?


Reply via ReviewNB

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need them. L20 and L21 are the same as L6 and L7 for selecting data along the dims yu_ocean and yt_ocean. I will delete them.

Copy link
Collaborator Author

@navidcy navidcy May 10, 2024

Choose a reason for hiding this comment

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

Generally, commented code is bad practice...
Either we want the code or we delete it.
It's good to let go. :)

@@ -0,0 +1,699 @@
{
Copy link
Collaborator Author

@navidcy navidcy May 10, 2024

Choose a reason for hiding this comment

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

why was this cell commented out @luweiyang? is the dask client create issues?


Reply via ReviewNB

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, I commented them out when I was debugging because at some stage I did get some client-related errors. But it's no longer an issue. I will uncomment them.

@navidcy
Copy link
Collaborator Author

navidcy commented May 10, 2024

something else we’d want to do is to use the cookbook to load the ACCESS-OM2 output

this is related to loading from cookbook: COSIMA/regional-mom6#131

@luweiyang
Copy link
Collaborator

Yes, I checked the date as well and was confused.

As @angus-g pointed out, the data in this folder
/g/data/ik11/outputs/access-om2-01/01deg_jra55v13_ryf9091/output1077/
is for year 2170, it goes from 2170/ 4/ 1 0: 0: 0 to 2170/ 7/ 1 0: 0: 0 (you can see this info in access-om2.out). Looks like we're actually getting boundary conditions from April in year 2170 as our ocean forcing?

The info for the atmospheric forcing is provided in data_table:
"ATM", "u_bot", "uas_10m", "./INPUT/RYF.u_10.1990_1991.nc", "bicubic", 1.0
Maybe we should update the year in filename to 2003_2004 here? Or it wouldn't matter since it's repeated year forcing?

Does this mismatch in year explain the initialisation error?

@ashjbarnes
Copy link
Collaborator

ashjbarnes commented May 10, 2024

I've fixed the west and east boundary condition issues. I changed cell 6 in step 2 (changes in bold): rmom6.longitude_slicer(om2_input, [longitude_extent[1]-0.2, longitude_extent[1]+0.2], ["xu_ocean", "xt_ocean"]).to_netcdf(tmp_dir + "/east_unprocessed.nc")

The notebook is running fine now and I've pushed the working version to the ncc/regional-mom6-v2 branch.

However, I couldn't run the experiment as I keep getting warning & error messages about initialization and extreme surface state. So somehow the date of ocean forcing and atmospheric forcing do not match? Since we use repeated year forcing, I didn't think that would be a problem... Any thoughts? And it turns out that the temperature unit is K (instead of C) in init_tracers.nc.

Yes good find! It'll be crashing because of the temperatures being in Kelvin. This is strange - these lines of code check the minimum surface temperature value of the dataset and then assume that it's in Kelvin if this minimum is above 100. This used to work but apparently not any more! The code here hasn't been changed for a long time

This notebook worked fine a while ago but it was neglected whilst we made a lot of changes. Somewhere we've introduced a change that breaks it but I don't know where..

@navidcy
Copy link
Collaborator Author

navidcy commented May 10, 2024

This is good. It will force us to find whe K->C doesn’t work and implement a test to capture future similar failures.

Let’s not ruminate on the past. Sure it worked at some point. It doesn’t matter that much, unless it helps us find why it’s not working now. Let’s just make an example that works now. It doesn’t even have to resemble how it was in the past if we want to showcase something else.

@navidcy
Copy link
Collaborator Author

navidcy commented May 10, 2024

Yes, I checked the date as well and was confused.

As @angus-g pointed out, the data in this folder /g/data/ik11/outputs/access-om2-01/01deg_jra55v13_ryf9091/output1077/ is for year 2170, it goes from 2170/ 4/ 1 0: 0: 0 to 2170/ 7/ 1 0: 0: 0 (you can see this info in access-om2.out). Looks like we're actually getting boundary conditions from April in year 2170 as our ocean forcing?

The info for the atmospheric forcing is provided in data_table: "ATM", "u_bot", "uas_10m", "./INPUT/RYF.u_10.1990_1991.nc", "bicubic", 1.0 Maybe we should update the year in filename to 2003_2004 here? Or it wouldn't matter since it's repeated year forcing?

Does this mismatch in year explain the initialisation error?

If we are gonna load the RYF then there is no point referring to “year 2003” or anything. All years are the same! They are looped.

I do think it more intuitive if we force with IAF, some particular year that we load via the cookbook

@ashjbarnes
Copy link
Collaborator

This is good. It will force us to find whe K->C doesn’t work and implement a test to capture future similar failures.

Let’s not ruminate on the past. Sure it worked at some point. It doesn’t matter that much, unless it helps us find why it’s not working now. Let’s just make an example that works now. It doesn’t even have to resemble how it was in the past if we want to showcase something else.

Knowing that it worked in the past should help us troubleshoot though right? Nothing about the forcing dataset has changed, only our code. If our code used to correctly convert K to C and no longer does, that means something in the package (specifically something in the initial condition method) has changed that prevents it from doing this.

I've had a quick look in case there was a premature "fill nans with 0s" or something but that doesn't seem to be the case

@luweiyang
Copy link
Collaborator

Yes, same ocean forcing year and same atmos forcing did work in the past. I remember a while ago @ashjbarnes updated and recompiled MOM6, and with new exe file everything worked fine.

@navidcy
Copy link
Collaborator Author

navidcy commented May 11, 2024

I never doubted that it worked in the past.. But now it's not, so let's fix it.

There are seem to be at least 1 or more issues. One is that temperature is not converted to K->C despite there is a method that supposedly does that. Possibly:

  • the method is never called, or
  • the method does not do what we think it does

How does ERA5-forced example work? Is ERA5 in degrees C to begin with?

@navidcy
Copy link
Collaborator Author

navidcy commented May 11, 2024

I've had a quick look in case there was a premature "fill nans with 0s" or something but that doesn't seem to be the case

This statement is unclear to me. I don't get what you want to say here @ashjbarnes.
"Premature" implying that it shouldn't be there... and now it "doesn't seem to be the case" so that mean "now it's not there anyway" or does it mean that "the fill nans with 0s is not premature" anymore?

@luweiyang
Copy link
Collaborator

I've updated the notebook (uncomment client cell and delete the commented lines). I noticed that temperature in the unit of K in unprocessed initial and boundary conditions (*_unprocessed.nc) in the tmp_dir, and also in forcing_obc_segment_00?.nc (so both initial and forcing conditions). So none of these lines (-=273.15) worked for some reason? @ashjbarnes

It would be nice to make this version work (for output1077 and RYF) and then try to read a particular year of forcing using cookbook.

@navidcy
Copy link
Collaborator Author

navidcy commented May 13, 2024

Thanks @luweiyang.

OK, agreed, let's fix everything else and we convert to reading output via cookbook later.

What's the plan for finding out where the K->C conversion fail?

@luweiyang
Copy link
Collaborator

@navidcy @ashjbarnes
As far as I can tell, in this notebook, the unprocessed forcing files are obtained via longitude_slicer;
The temperature conversion is done in, for example, initial_condition (in regional_mom6.py);
But initial_condition is not called in longitude_slicer, which may be why the temperature data was not checked and corrected?

@navidcy
Copy link
Collaborator Author

navidcy commented May 13, 2024

@navidcy @ashjbarnes As far as I can tell, in this notebook, the unprocessed forcing files are obtained via longitude_slicer; The temperature conversion is done in, for example, initial_condition (in regional_mom6.py); But initial_condition is not called in longitude_slicer, which may be why the temperature data was not checked and corrected?

longitude_slicer just slices the fields in longitude. It would be very counterintuitive if it was expected to call initial_condition.

@luweiyang are you suggesting that the notebook never ends up calling the jnitial_condition method?

@luweiyang
Copy link
Collaborator

No sorry, initial_condition was called in step 5. So that's not the reason.

@ashjbarnes
Copy link
Collaborator

I've had a quick look in case there was a premature "fill nans with 0s" or something but that doesn't seem to be the case

This statement is unclear to me. I don't get what you want to say here @ashjbarnes. "Premature" implying that it shouldn't be there... and now it "doesn't seem to be the case" so that mean "now it's not there anyway" or does it mean that "the fill nans with 0s is not premature" anymore?

Sorry to clarify:

The line that tries to convert K to C checks whether the minimum is greater than 100. This means that if NaNs have been filled in with zeros before this step then the check would pass regardless of the data being C or K. I read through the code and didn't see that this was the case.

To debug we could print what the minimum of the temperature field actually returns, or copy the code into a notebook and return the temperature field at this step to see what it looks like.

Or, instead of fixing it, a quick fix could be to add a "units" flag for temperature to both IC and BC functions so the user just has to tell us when it needs to do the conversion rather than trying to do so automatically.

@navidcy
Copy link
Collaborator Author

navidcy commented May 13, 2024

Hi both, it's helpful to discuss and read the code but we are not compilers and often just by "reading the code" we (or at least I) fail to capture what is actually going on. So to be certain of what's happening here we need to properly debug. To do that we should modify the regional-mom6 source code and install the local copy of the regional-mom6 in the environment so that the notebook uses that. Only this way we (or at least I) would be able to pin-point the source of the matter and fix it. Thoughts?

Or, instead of fixing it, a quick fix could be to add a "units" flag for temperature to both IC and BC functions so the user just has to tell us when it needs to do the conversion rather than trying to do so automatically.

I suggest we "properly fix it" rather than doing a "quick fix". There must be some error in the logic and it's good to make this robust. Note that in addition, my personal experience suggests that a proper fix ends up saving everyone (developers and usrers) much more time compared to what a quick fix does.

@luweiyang
Copy link
Collaborator

I did a quick test and the if condition for checking the min temperature was not satisfied.

I used an old environment (analysis3-23.07) where the regional_mom6 package wasn't installed. I imported the package from my home directory. This way I can modify the code and see what it does.

I added a line print('xxxx') following the if statement to check this part of the code runs. I can confirm that the if condition was not satisfied for some reason so the temperature unit was not changed.

@navidcy
Copy link
Collaborator Author

navidcy commented May 14, 2024

Can you post here what you did? A minimal example of a notebook loading the temperature and trying to reproduce what the package does demonstrating that it fails?

@navidcy
Copy link
Collaborator Author

navidcy commented May 14, 2024

I used an old environment (analysis3-23.07) where the regional_mom6 package wasn't installed. I imported the package from my home directory. This way I can modify the code and see what it does.

You can always install a local copy of the package even if it’s already installed in the environment. You just need to ensure that you are using your local copy and not the version in the env. I’ll try to demonstrate that and post the code here

@navidcy
Copy link
Collaborator Author

navidcy commented May 14, 2024

Could this be the culprit?

>>> import numpy as np
>>> temp_K = np.array([270., 272., 287.])
>>> temp_K
array([270., 272., 287.])
>>> np.min(temp_K)
270.0
>>> np.min(temp_K) > 100
True

But if this was masked, then]

>>> import numpy as np
>>> temp_K_masked = np.array([270., float('nan'), 287.])
>>> temp_K_masked
array([270.,  nan, 287.])
>>> np.min(temp_K_masked)
nan
>>> np.min(temp_K_masked) > 100
False

?

If it is, then the solution would be to use numpy.nanmin:

>>> np.nanmin(temp_K_masked)
270.0
>>> np.nanmin(temp_K_masked) > 100
True

@ashjbarnes
Copy link
Collaborator

Nice that could be it!!

@navidcy
Copy link
Collaborator Author

navidcy commented May 14, 2024

@luweiyang could you check that with the change suggested in COSIMA/regional-mom6#176 the issue goes away?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert demo that uses ACCESS-OM2 output to cosima-recipes example
3 participants