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

Include ILAMB output in notebook and provide link to full diagnostic package #165

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

Conversation

TeaganKing
Copy link
Collaborator

@TeaganKing TeaganKing commented Jan 16, 2025

Description of changes:

  • Wrote script to generate ILAMB model_setup.txt file based on config.yml
  • Included link to ILAMB notebook which includes a link to ILAMB full output as well as a few 'key metric' plots from ILAMB directly in the jupyterbook
  • Included config files for BGC & SP cases (without hardcoded glade paths) in a parallel location to ADF config file templates.

@TeaganKing TeaganKing self-assigned this Jan 16, 2025
@TeaganKing TeaganKing requested a review from mnlevy1981 January 17, 2025 19:15
@TeaganKing TeaganKing added the lnd label Jan 17, 2025
@TeaganKing TeaganKing linked an issue Jan 17, 2025 that may be closed by this pull request
@TeaganKing
Copy link
Collaborator Author

Note the linked issue also requires workflow updates to include ILAMB and choose BGC or SP.

@TeaganKing
Copy link
Collaborator Author

TeaganKing commented Jan 21, 2025

  • Note to self: need to remove some printed statements in link_to_ILAMB.ipynb that are currently there for development purposes once we get ILAMB working with CLM6

@TeaganKing
Copy link
Collaborator Author

TeaganKing commented Jan 22, 2025

Made some changes per discussion in CUPiD meeting today.

  • Added active layer thickness plot
  • A few other minor changes (eg, remove word 'link')

Still need to do the following:

  • Add overarching "score chart"
  • Remove glade filepaths, specify them in BGC cfg file, and add to helper script to generate these
  • Add into key metrics?

@TeaganKing
Copy link
Collaborator Author

The overarching score chart is not a static image-- rather an html page. Thus, I think it'd be difficult to reproduce as a static image within the CUPiD jupyterbook output. This will also be the first thing that appears when you click on the link to the full ILAMB output, so I'm going to suggest we don't implement this as one of the plots that shows up automatically within the jupyterbook after all.

Also, for single runs, this is not the most interesting score chart...
Screenshot 2025-01-24 at 9 28 19 AM

It's really only useful for comparisons against other runs:
Screenshot 2025-01-24 at 9 30 44 AM

@mnlevy1981
Copy link
Collaborator

mnlevy1981 commented Jan 24, 2025

For key_metrics, can we run ILAMB on both the new case and the baseline? And is that table useful if there are two columns? If so, I think you can imbed one HTML page into another with something like this:

display(
    HTML(
         '<iframe src="/path/to/table.html"></iframe>'
    )
)

But I agree that it's not very useful for the single run case. If the above code works, maybe we could include it in an if print_table: block where print_table defaults to False, just so it is available in the future. If the above code doesn't work, I don't think it's worth the time and agree with

I'm going to suggest we don't implement this as one of the plots that shows up automatically within the jupyterbook after all

@mnlevy1981
Copy link
Collaborator

mnlevy1981 commented Jan 24, 2025

(my first version of the above comment relied on javascript, but I think the HTML <iframe> option would work better)

@TeaganKing
Copy link
Collaborator Author

Removing mpiexec from command works! Updating helper script shortly to implement new script suggestion. For now, we are planning to bring this in to the external diagnostic packages example (and not key metrics until the mpiexec issue and the copying ADF output dir issue are both fixed since the latter will also apply to ILAMB).

@TeaganKing
Copy link
Collaborator Author

I'm still getting a VarNotInModel error from ILAMB-- also with the old configurations from the previous ILAMB example. Otherwise this full workflow is working.

@TeaganKing
Copy link
Collaborator Author

TeaganKing commented Jan 30, 2025

This worked with a different dataset: ilamb-run --config ../ilamb_aux/ilamb_nohoff_final_CLM.cfg --build_dir ILAMB_output/ --df_errs ../ilamb_aux/quantiles_Whittaker_cmip5v6.parquet --define_regions ../ilamb_aux/DATA/regions/LandRegions.nc ../ilamb_aux/DATA/regions/Whittaker.nc --regions global --model_setup ../examples/external_diag_packages/model_setup.txt --filter .clm2.h0.

When model_setup.txt used this filepath: /glade/campaign/cgd/tss/common/Land_Only_Simulations/CTSM52_DEV/ctsm51_ctsm51d166deadveg_1deg_CRUJRA_FLDS_ABsnoCDE_blk_A5BCD_hist/lnd/hist/
and ilamb_nohoff_final_CLM.cfg has filepaths such as /glade/campaign/cesm/community/lmwg/diag/ILAMB/DATA/biomass/Tropical/biomass_0.5x0.5.nc

The exact same setup did not work with clean directories and /glade/campaign/cesm/development/cross-wg/diagnostic_framework/CESM_output_for_testing/b.e30_beta02.BLT1850.ne30_t232.104/lnd/hist/regrid/(but did appear to run when directories were not cleaned). In this case, I get ValueError: Unable to convert from 'Unit('steradian')' to 'Unit('m2')'. and NameError: name 'logger' is not defined.

"# Model Name , Location of Files , Shift From, Shift To\n", # noqa: E501
)
ms.write(
f"CTSM51 , {base_case_output_dir}/lnd/hist/regrid/",
Copy link
Collaborator Author

@TeaganKing TeaganKing Jan 31, 2025

Choose a reason for hiding this comment

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

I should add some sort of "if regrid" then append the regrid directory here. Perhaps this would be useful to in the long term create the regridded files if they don't yet exist, and in the short term print out a "warning: please run regridding with command below"

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 added a note that regridded files are required

@TeaganKing
Copy link
Collaborator Author

TeaganKing commented Feb 3, 2025

We actually want to remap with this command to avoid steradian units and instead get km^2 for area: ncremap -m /glade/campaign/cesm/cesmdata/inputdata/cpl/gridmaps/ne30pg3/map_ne30pg3_TO_fv0.9x1.25_blin.240826.nc -P clm "$file" regrid/"$file" . Thanks @slevis-lmwg for the suggestion!

Copy link
Collaborator

@mnlevy1981 mnlevy1981 left a comment

Choose a reason for hiding this comment

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

I didn't try to run this, but read through the diffs and have a few comments. Overall, this looks really good and I'm excited about adding ILAMB to external_diag_packages!

Should we address #160 in this PR, since we'll have the same problem with ILAMB and users only running CUPiD on non-land components? Seeing your change to cupid/cupid_webpage.py brought that issue to mind, but I'd be happy to wait for a later PR to try to fix it.

@TeaganKing TeaganKing requested a review from mnlevy1981 February 7, 2025 19:54
@TeaganKing
Copy link
Collaborator Author

This is running smoothly now. I added a note to remove the ILAMB_output directory if it exists, as that potentially causes errors.

After talking with Keith, we also decided that using a BGC/SP flag specified by users is better than relying on an assumption that f cases are usually SP and b cases are usually BGC. If an SP case is run with a BGC flag, we may just have some additional variables that don't produce graphs, etc.
Also, ILAMB is best used with historical cases. If 1850 cases are used, one could technically specify an additional argument in the model_setup.txt file that includes a model year that corresponds with a real year. However, this is potentially misleading, so we're going to assume that people will be comparing reasonable cases if using ILAMB.

This is now ready for review.

Copy link
Collaborator

@mnlevy1981 mnlevy1981 left a comment

Choose a reason for hiding this comment

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

I had one comment about cleaning up some of the code in cupid_webpage.py, but I also have a general question about the functionality of the new generate_ilamb_config_files.py.

I was trying to see how this would fit in with the CESM workflow, so I went into a test case directory and used generate_cupid_config_for_cesm_case.py to create config.yml. Then I used the new script to generate the config files for ILAMB:

$ ../../../tools/CUPiD/helper_scripts/generate_ilamb_config_files.py --cesm-root /glade/work/mlevy/codes/CESM/cesm3_0_beta04_cupid --cupid-config-loc ${PWD} --run-type SP
{'cesm_root': '/glade/work/mlevy/codes/CESM/cesm3_0_beta04_cupid', 'cupid_config_loc': '/glade/work/mlevy/codes/CESM/cesm3_0_beta04_cupid/cases/test_cupid_30b04.005/cupid', 'run_type': 'SP'}
wrote /glade/work/mlevy/codes/CESM/cesm3_0_beta04_cupid/tools/CUPiD/ilamb_aux/ilamb_nohoff_final_CLM_SP.cfg
wrote /glade/work/mlevy/codes/CESM/cesm3_0_beta04_cupid/cases/test_cupid_30b04.005/cupid/model_setup.txt
WARNING: ILAMB requires regridded output to be in /glade/derecho/scratch/mlevy/archive/b.e23_alpha17f.BLT1850.ne30_t232.092/lnd/hist/regrid/ directory.
You can now run ILAMB with the following commands:
(Users on a super computer should make sure they are on a compute node rather than a login node)
---------
conda activate cupid-analysis
export ILAMB_ROOT=../ilamb_aux
ilamb-run --config /glade/work/mlevy/codes/CESM/cesm3_0_beta04_cupid/tools/CUPiD/ilamb_aux/ilamb_nohoff_final_CLM_SP.cfg --build_dir /glade/work/mlevy/codes/CESM/cesm3_0_beta04_cupid/cases/test_cupid_30b04.005/cupid/ILAMB_output/ --df_errs /glade/work/mlevy/codes/CESM/cesm3_0_beta04_cupid/tools/CUPiD/ilamb_aux/quantiles_Whittaker_cmip5v6.parquet --define_regions /glade/work/mlevy/codes/CESM/cesm3_0_beta04_cupid/tools/CUPiD/ilamb_aux/DATA/regions/LandRegions.nc /glade/work/mlevy/codes/CESM/cesm3_0_beta04_cupid/tools/CUPiD/ilamb_aux/DATA/regions/Whittaker.nc --regions global --model_setup /glade/work/mlevy/codes/CESM/cesm3_0_beta04_cupid/cases/test_cupid_30b04.005/cupid/model_setup.txt --filter .clm2.h0.
---------

The first thing that caught my eye is the location of the output files:

wrote /glade/work/mlevy/codes/CESM/cesm3_0_beta04_cupid/tools/CUPiD/ilamb_aux/ilamb_nohoff_final_CLM_SP.cfg
wrote /glade/work/mlevy/codes/CESM/cesm3_0_beta04_cupid/cases/test_cupid_30b04.005/cupid/model_setup.txt

model_setup.txt showed up in the directory where I ran the generate script, which is good. Shouldn't ilamb_nohoff_final_CLM_SP.cfg also be written locally? We may need to also copy the quantiles file locally, then we can change the recommendation from export ILAMB_ROOT=../ilamb_aux to set the current working directory to ILAMB_ROOT.

-print("export ILAMB_ROOT=../ilamb_aux")
+print(f"export ILAMB_ROOT={os.getcwd()}")

(which was actually the second thing I noticed -- as the script is written, we want print(f"export ILAMB_ROOT=os.path.join(cesm_root,'tools','CUPiD','ilamb_aux')")).

I think some of these suggestions for getting better output in the CESM workflow may break things for the CUPiD examples; it'll probably take a little back-and-forth to figure out how we want things to work in both use-cases.

@TeaganKing
Copy link
Collaborator Author

Hi @mnlevy1981 , Thanks for reviewing this-- I have addressed your comments!

RE "Shouldn't ilamb_nohoff_final_CLM_SP.cfg also be written locally?": I did update this per your suggestion. For context, my original thought was that these won't actually change with every configuration for running CUPiD; there's really just a general specification of ilamb_config_data_loc that gets added, and that's the only change, so I figured it could be used from the same place for any ILAMB runs using the same CESM root. That said, it's not a large file, so I think that it may be clearer to write it locally and keep everything together anyways.

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