-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Usage Example, Python Frontend, documentation updates (#17)
- Loading branch information
Showing
21 changed files
with
1,177 additions
and
87 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(low_level_interface)= | ||
# Low-Level Interface | ||
|
||
The `pyrte_rrtmgp.pyrte_rrtmgp` module provides a low-level interface to the RTE-RRTMGP and RRTMGP functions. It is generated by pybind11 from C headers of RTE-RRTMGP. | ||
|
||
See the [RTE-RRTMGP repository on GitHub](https://github.com/earth-system-radiation/pyRTE-RRTMGP) and the [RTE-RRTMGP documentation](https://earth-system-radiation.github.io/rte-rrtmgp/) for more information about these functions. | ||
|
||
The following RTE functions from [RTE-RRTMGP](https://github.com/earth-system-radiation/pyRTE-RRTMGP) are currently available in the `pyrte_rrtmgp.pyrte_rrtmgp` module: | ||
|
||
```{include} ../../../README.md | ||
:start-after: <!-- start-rte-functions-section --> | ||
:end-before: <!-- end-rte-functions-section --> | ||
``` | ||
|
||
The following RRTMGP functions from [RTE-RRTMGP](https://github.com/earth-system-radiation/pyRTE-RRTMGP) are currently available in the `pyrte_rrtmgp.pyrte_rrtmgp` module: | ||
|
||
```{include} ../../../README.md | ||
:start-after: <!-- start-rrtmgp-functions-section --> | ||
:end-before: <!-- end-rrtmgp-functions-section --> | ||
``` |
33 changes: 33 additions & 0 deletions
33
docs/source/reference_guide/pyrte_rrtmgp_python_modules.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
.. _module_ref: | ||
|
||
Python Modules | ||
============== | ||
|
||
The documentation below provides details for several of the high-level functions wrapping the underlying Fortran code. | ||
|
||
For more information about the low-level functions available in the ``pyrte_rrtmgp.pyrte_rrtmgp`` submodule, please go to :ref:`low_level_interface`. | ||
|
||
|
||
pyrte\_rrtmgp.rte module | ||
------------------------ | ||
|
||
.. automodule:: pyrte_rrtmgp.rte | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
pyrte\_rrtmgp.rrtmgp module | ||
--------------------------- | ||
|
||
.. automodule:: pyrte_rrtmgp.rrtmgp | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
pyrte\_rrtmgp.utils module | ||
-------------------------- | ||
|
||
.. automodule:: pyrte_rrtmgp.utils | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from pyrte_rrtmgp.gas_optics import GasOptics\n", | ||
"import xarray as xr\n", | ||
"import numpy as np\n", | ||
"from pyrte_rrtmgp.rte import lw_solver_noscat\n", | ||
"\n", | ||
"ERROR_TOLERANCE = 1e-4\n", | ||
"\n", | ||
"rte_rrtmgp_dir = \"../rrtmgp-data\"\n", | ||
"clear_sky_example_files = f\"{rte_rrtmgp_dir}/examples/rfmip-clear-sky/inputs\"\n", | ||
"\n", | ||
"rfmip = xr.load_dataset(\n", | ||
" f\"../tests/test_python_frontend/multiple_input4MIPs_radiation_RFMIP_UColorado-RFMIP-1-2_none.nc\"\n", | ||
")\n", | ||
"rfmip = rfmip.sel(expt=0) # only one experiment\n", | ||
"\n", | ||
"kdist = xr.load_dataset(f\"../tests/test_python_frontend/rrtmgp-gas-lw-g256.nc\")\n", | ||
"\n", | ||
"# RRTMGP won't run with pressure less than its minimum. so we add a small value to the minimum pressure\n", | ||
"# There was an issue replicating k_dist%get_press_min() + epsilon(k_dist%get_press_min()) in python, sys.epsilon is not the same\n", | ||
"min_index = rfmip[\"pres_level\"].argmin()\n", | ||
"rfmip[\"pres_level\"][:, min_index] = 1.0051835744630002\n", | ||
"\n", | ||
"gas_optics = GasOptics(kdist, rfmip)\n", | ||
"gas_optics.source_is_internal\n", | ||
"tau, layer_src, level_src, sfc_src, sfc_src_jac = gas_optics.gas_optics()\n", | ||
"\n", | ||
"# Expand the surface emissivity to ngpt\n", | ||
"sfc_emis = rfmip[\"surface_emissivity\"].values\n", | ||
"sfc_emis = np.stack([sfc_emis]*tau.shape[2]).T\n", | ||
"\n", | ||
"_, solver_flux_up, solver_flux_down, _, _ = lw_solver_noscat(\n", | ||
" tau=tau,\n", | ||
" lay_source=layer_src,\n", | ||
" lev_source=level_src,\n", | ||
" sfc_emis=sfc_emis,\n", | ||
" sfc_src=sfc_src,\n", | ||
" sfc_src_jac=sfc_src_jac\n", | ||
")\n", | ||
"\n", | ||
"rlu = xr.load_dataset(\"../tests/test_python_frontend/rlu_Efx_RTE-RRTMGP-181204_rad-irf_r1i1p1f1_gn.nc\")\n", | ||
"ref_flux_up = rlu.isel(expt=0)[\"rlu\"].values\n", | ||
"\n", | ||
"rld = xr.load_dataset(\"../tests/test_python_frontend/rld_Efx_RTE-RRTMGP-181204_rad-irf_r1i1p1f1_gn.nc\")\n", | ||
"ref_flux_down = rld.isel(expt=0)[\"rld\"].values\n", | ||
"\n", | ||
"assert np.isclose(solver_flux_up, ref_flux_up, atol=ERROR_TOLERANCE).all()\n", | ||
"assert np.isclose(solver_flux_down, ref_flux_down, atol=ERROR_TOLERANCE).all()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "venv", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.8" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.