Conversation
|
@tomvothecoder Somethow I got inconsistent @acme-y9s The proposed new v3 variables are supported by this PR. (I removed several variables only present in CMIP5 but not in CMIP6, e.g. cMisc, cWood, fLuc. burntArea is renamed to burnAreaFractionAll from CMIP5 to CMIP6. I have a example script to process and cmorize these variables as well. Could you please inspect the sample CMIP files at LCRC under: /gpfs/fs0/globalscratch/ac.zhang40/e2c_tests/CMIP6/CMIP/E3SM-Project/E3SM-1-0/piControl/r1i1p1f1/ |
tomvothecoder
left a comment
There was a problem hiding this comment.
Review of my latest commits. Should be good to go now.
| moc = xarray.concat(mocSlices, dim="lat") # type: ignore[arg-type] | ||
| moc = moc.transpose("Time", "nVertLevelsP1", "lat") | ||
|
|
||
| # average to bin and level centers | ||
| moc = 0.25 * ( | ||
| moc[:, 0:-1, 0:-1] + moc[:, 0:-1, 1:] + moc[:, 1:, 0:-1] + moc[:, 1:, 1:] | ||
| moc_avg = ( | ||
| 0.25 | ||
| * ( | ||
| moc[:, 0:-1, 0:-1] # type: ignore[index] | ||
| + moc[:, 0:-1, 1:] # type: ignore[index] | ||
| + moc[:, 1:, 0:-1] # type: ignore[index] | ||
| + moc[:, 1:, 1:] # type: ignore[index] | ||
| ) | ||
| ) | ||
| moc = moc.rename({"nVertLevelsP1": "depth"}) # type: ignore | ||
| binCounts = xarray.DataArray(binCounts, dims=("lat")) # type: ignore | ||
| moc = moc.where(binCounts > 0) # type: ignore | ||
| moc_avg = moc_avg.rename({"nVertLevelsP1": "depth"}) | ||
| binCounts = xarray.DataArray(binCounts, dims=("lat")) # type: ignore[assignment] | ||
| moc_masked = moc_avg.where(binCounts > 0) # type: ignore[operator] | ||
|
|
||
| _compute_dask(moc, showProgress, "Computing {} MOC".format(regionName)) | ||
| _compute_dask(moc_masked, showProgress, "Computing {} MOC".format(regionName)) | ||
|
|
||
| mocs[regionName] = moc | ||
| mocs[regionName] = moc_masked |
There was a problem hiding this comment.
mpas.py changes to make mypy happy
| for path in paths: | ||
| ds = xr.open_dataset(path, decode_timedelta=True) | ||
| data_vars = list(ds.data_vars.keys()) | ||
| data_vars = [str(var) for var in ds.data_vars.keys()] |
There was a problem hiding this comment.
mpas.py changes to make mypy happy
| with pytest.raises(KeyError): | ||
| rsuscs(xr.Dataset()) | ||
| rtmt(xr.Dataset()) |
There was a problem hiding this comment.
Fixed incorrect function reference in test.
| # Test when required variable keys are NOT in the data dictionary. | ||
| with pytest.raises(KeyError): | ||
| rsuscs(xr.Dataset()) | ||
| tran(xr.Dataset()) |
There was a problem hiding this comment.
Fixed incorrect function reference in test.
| def test_tran(): | ||
| ds = xr.Dataset( | ||
| data_vars={"QSOIL": _dummy_dataarray(), "QVEGT": _dummy_dataarray()} | ||
| ) | ||
| ds = xr.Dataset(data_vars={"QVEGT": _dummy_dataarray()}) | ||
|
|
||
| result = tran(ds) | ||
| expected = xr.DataArray( | ||
| dims=["lat", "lon"], | ||
| data=np.array([[0, 2, 4], [0, 2, 4], [0, 2, 4]]), | ||
| data=np.array([[0, 1, 2], [0, 1, 2], [0, 1, 2]]), |
There was a problem hiding this comment.
Updated test_tran() to get it passing for v3 formula code change.
There was a problem hiding this comment.
Pull request overview
This PR updates E3SM-to-CMIP CMOR handlers and formulas to support additional ELM v3 land (Lmon) and land-ice (LImon) variables, including adjusting the definition of tran to exclude soil evaporation.
Changes:
- Add new CMIP6 land and land-ice variable handler entries (and corresponding formula functions where needed).
- Update
tranhandler/formula and align unit tests with the new definition. - Minor robustness/type-related adjustments in the runner and MPAS MOC computation, plus a new debug run script.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
e3sm_to_cmip/cmor_handlers/handlers.yaml |
Adds new Lmon/LImon handlers and updates tran mapping/formula. |
e3sm_to_cmip/cmor_handlers/_formulas.py |
Updates tran formula and adds new formula functions for newly introduced handlers. |
tests/cmor_handlers/test__formulas.py |
Fixes/updates unit tests for rtmt KeyError behavior and tran output/inputs. |
e3sm_to_cmip/runner.py |
Ensures discovered dataset variable names are collected as str. |
e3sm_to_cmip/mpas.py |
Refactors MOC time series computation variables for clearer typing/flow and computes the masked/averaged result. |
scripts/debug/334-new_v3_land_handlers/run_v3_land.sh |
Adds a debug script for running v3 land handler CMORization. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Description
● Brief Summary of Changes
Variables Added/Modified in handlers.yaml
Land Variables (CMIP6_Lmon.json) - 12 variables
Land Ice Variables (CMIP6_LImon.json) - 7 variables
hfdsn - Heat flux into snow
lwsnl - Liquid water in snow
snc/snd/snm/snw - Snow coverage, depth, melt, and amount
sootsn - Snow impurities (BC + dust + OC)
Closes [Feature]: add land variables for v3 #292
Checklist
If applicable: