-
Notifications
You must be signed in to change notification settings - Fork 8
Update variables for v3 ELM #334
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
Changes from 6 commits
a7527e9
a00d1aa
900b83f
0c889d4
9017c66
ef9ec17
ae495be
2d3fc95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -802,19 +802,26 @@ def _compute_moc_time_series( | |
| ).sum(dim="nCells") | ||
| mocSlices.append(mocTop) | ||
|
|
||
| moc = xarray.concat(mocSlices, dim="lat") # type: ignore | ||
| moc = moc.transpose("Time", "nVertLevelsP1", "lat") # type: ignore | ||
| 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 | ||
|
Comment on lines
+805
to
+818
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| mocs = xarray.concat(mocs.values(), dim="basin") # type: ignore | ||
| mocs = mocs.transpose("Time", "basin", "depth", "lat") # type: ignore | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -323,7 +323,7 @@ def _get_e3sm_vars(self, input_path: str) -> list[str]: | |
|
|
||
| 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()] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| e3sm_vars = e3sm_vars + data_vars | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Conda Environment | ||
| # ----------------- | ||
| #conda activate e3sm_to_cmip_dev | ||
|
|
||
| # ----------------- | ||
| # PATHS | ||
| # ----------------- | ||
| e2c_path=/lcrc/group/e3sm/public_html/diagnostics/e3sm_to_cmip_data | ||
| model_data=/gpfs/fs0/globalscratch/ac.zhang40/e2c_tests/model_data | ||
| scratch=/gpfs/fs0/globalscratch/ac.zhang40 | ||
|
|
||
| # TODO: Update result_dir | ||
| result_dir=${scratch}/e2c_tests | ||
|
|
||
chengzhuzhang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| rgr_dir=${result_dir}/rgr | ||
| rgr_dir_vert=${result_dir}/rgr_vert | ||
| rgr_dir_vert_plev=${result_dir}/rgr_vert_plev | ||
| native_dir=${result_dir}/native | ||
|
|
||
| map_file=${e2c_path}/maps/map_r05_to_cmip6_180x360_traave.20231110.nc | ||
| tables_path=${e2c_path}/cmip6-cmor-tables/Tables/ | ||
| metadata_path=${e2c_path}/default_metadata.json | ||
|
|
||
| start=1850 | ||
| end=1850 | ||
| ypf=1 | ||
| caseid=v3.LR.historical_0101 | ||
|
|
||
| ## ------------------------------------------------------ | ||
| ## TEST CASE - land monthly h0 | ||
| ## ------------------------------------------------------ | ||
| #input_path=${model_data}/ | ||
| input_path=/lcrc/group/e3sm2/ac.wlin/E3SMv3/v3.LR.historical_0101/archive/lnd/hist | ||
| flags='-7 --dfl_lvl=1 --no_cll_msr' | ||
| #raw_var_list="LAISHA,LAISUN,QINTR,QOVER,QRUNOFF,QSOIL,QVEGE,QVEGT,SOILICE,SOILLIQ,SOILWATER_10CM,TSA,TSOI,H2OSNO" | ||
| #cmip_var_list="mrsos, mrso, mrfso, mrros, mrro, prveg, evspsblveg, evspsblsoi, tran, tsl, lai" | ||
| raw_var_list="LEAFC,FROOTC,LIVECROOTC,DEADCROOTC,CWDC,AR,MR,QVEGT,LEAFC_ALLOC,FROOTC_ALLOC,WOODC_ALLOC,FAREA_BURNED,LAND_USE_FLUX,FSNO,SNOWDP,SNOWLIQ,H2OSNO_TOP,QSNOMELT,FGR,SNOBCMSL,SNODSTMSL,SNOOCMSL" | ||
| cmip_var_list="burntFractionAll, cCwd, cLeaf, cRoot, nppLeaf, nppRoot, nppWood, rGrowth, rMaint, tran, hfdsn, lwsnl, snc, snd, snm, snw, sootsn" | ||
|
|
||
| rgr_dir=${result_dir}/rgr_lnd | ||
| native_dir=${result_dir}/native_lnd | ||
| mkdir -p $rgr_dir | ||
| mkdir -p $native_dir | ||
|
|
||
| # Note either include the extra variable landfrac or specify the file that has landfrac for subgrid scale mode to work. | ||
| #ncclimo -P elm -j 1 --var_xtr=landfrac --map=${map_file} --start=$start --end=$end --ypf=$ypf --split -c $caseid -o ${native_dir} -O ${rgr_dir} -v ${raw_var_list} -i ${input_path} ${flags} | ||
| # Alternative ncclimo invocation | ||
| #ncclimo -P elm -j 1 --map=${map_file} --start=$start --end=$end --ypf=$ypf --split -c $caseid -o ${native_dir} -O ${rgr_dir} -v ${raw_var_list} -i ${input_path} ${flags} --sgs_frc=${input_path}/v2.LR.historical_0101.elm.h0.1850-01.nc/landfrac | ||
|
|
||
| #raw_var_list_elm_bgc="TOTLITC,CWDC,TOTPRODC,SOIL1C,SOIL2C,SOIL3C,^SOIL4C$,COL_FIRE_CLOSS,WOOD_HARVESTC,TOTVEGC,NBP,GPP,AR,HR" | ||
| # CMORIZE Land Monthly variables | ||
| e3sm_to_cmip -i ${rgr_dir} -o $result_dir -v ${cmip_var_list} -t ${tables_path} -u ${metadata_path} --realm lnd --serial | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -382,21 +382,19 @@ def test_rtmt(): | |
|
|
||
| # Test when required variable keys are NOT in the data dictionary. | ||
| with pytest.raises(KeyError): | ||
| rsuscs(xr.Dataset()) | ||
| rtmt(xr.Dataset()) | ||
|
Comment on lines
407
to
+408
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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]]), | ||
|
Comment on lines
411
to
+417
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
| ) | ||
| xr.testing.assert_allclose(result, expected) | ||
|
|
||
| # Test when required variable keys are NOT in the data dictionary. | ||
| with pytest.raises(KeyError): | ||
| rsuscs(xr.Dataset()) | ||
| tran(xr.Dataset()) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed incorrect function reference in test. |
||
Uh oh!
There was an error while loading. Please reload this page.