-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #933 from FlorianDeconinck/pyMoist_setup
`pyMoist` setup & stub code
- Loading branch information
Showing
12 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSmoist_GridComp/pyMoist/.gitignore
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,6 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
.pytest_cache | ||
*.egg-info/ |
65 changes: 65 additions & 0 deletions
65
GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSmoist_GridComp/pyMoist/.pre-commit-config.yaml
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,65 @@ | ||
default_language_version: | ||
python: python3 | ||
|
||
files: pyMoist | ||
|
||
repos: | ||
- repo: https://github.com/psf/black | ||
rev: 20.8b1 | ||
hooks: | ||
- id: black | ||
additional_dependencies: ["click==8.0.4"] | ||
|
||
- repo: https://github.com/pre-commit/mirrors-isort | ||
rev: v5.4.2 | ||
hooks: | ||
- id: isort | ||
args: ["--profile", "black"] | ||
|
||
- repo: https://github.com/pre-commit/mirrors-mypy | ||
rev: v1.4.1 | ||
hooks: | ||
- id: mypy | ||
name: mypy-pyMoist | ||
args: [ | ||
--ignore-missing-imports, | ||
"--follow-imports=normal", | ||
--namespace-packages, | ||
--no-strict-optional, | ||
--warn-unreachable, | ||
--explicit-package-bases, | ||
] | ||
additional_dependencies: [types-PyYAML] | ||
files: pyMoist | ||
|
||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v2.3.0 | ||
hooks: | ||
- id: check-toml | ||
- id: check-yaml | ||
- id: end-of-file-fixer | ||
- id: trailing-whitespace | ||
|
||
- repo: https://github.com/pycqa/flake8 | ||
rev: 3.9.2 | ||
hooks: | ||
- id: flake8 | ||
name: flake8 | ||
language_version: python3 | ||
args: [ | ||
"--exclude=docs", | ||
"--ignore=W503,E302,E203,F841", | ||
"--max-line-length=88" | ||
] | ||
exclude: | | ||
(?x)^( | ||
.*/__init__.py | | ||
)$ | ||
- id: flake8 | ||
name: flake8 __init__.py files | ||
files: "__init__.py" | ||
# ignore unused import error in __init__.py files | ||
args: [ | ||
"--exclude=docs", | ||
"--ignore=W503,E302,E203,F841,F401", | ||
"--max-line-length=88",] |
17 changes: 17 additions & 0 deletions
17
GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSmoist_GridComp/pyMoist/README.md
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,17 @@ | ||
# pyMoist | ||
|
||
`pyMoist` is the [NDSL](https://github.com/NOAA-GFDL/NDSL) version of the NASA GMAO's GEOS Moist physics and it's required interface to GEOS. | ||
|
||
## Testing | ||
|
||
The `tests/savepoint` folder contains the numerical regression testing that served to port the code from the original Fortran. It tests that the difference from original Fortran is minimal. | ||
|
||
Note: bit to bit equivalence is not possible considering the targeted hardware and the change of compiled language (NDSL uses C). | ||
|
||
## Interface | ||
|
||
The `interface` sub-directory contain the three-way bridge to and from GEOS. | ||
|
||
## Develop | ||
|
||
- Run `pre-commit run --all-files` before comitting for code guidelines coherency. |
3 changes: 3 additions & 0 deletions
3
...cm_GridComp/GEOSphysics_GridComp/GEOSmoist_GridComp/pyMoist/interface/README.md
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,3 @@ | ||
# Interface between GEOS and pyMoist | ||
|
||
This is the `cffi` based interface between the GEOS Moist grid component and the `pyMoist` NDSL numerical code. |
32 changes: 32 additions & 0 deletions
32
...cm_GridComp/GEOSphysics_GridComp/GEOSmoist_GridComp/pyMoist/pyMoist/radiation_coupling.py
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,32 @@ | ||
from ndsl import QuantityFactory, StencilFactory | ||
from ndsl.constants import X_DIM, Y_DIM, Z_DIM | ||
|
||
|
||
def _fix_up_clouds_stencil(): | ||
pass | ||
|
||
|
||
def _radcouple_stencil(): | ||
pass | ||
|
||
|
||
class RadiationCoupling: | ||
def __init__( | ||
self, | ||
stencil_factory: StencilFactory, | ||
quantity_factory: QuantityFactory, | ||
do_qa: bool, | ||
) -> None: | ||
self._fix_up_clouds = stencil_factory.from_dims_halo( | ||
func=_fix_up_clouds_stencil, compute_dims=[X_DIM, Y_DIM, Z_DIM] | ||
) | ||
self._radcouple = stencil_factory.from_dims_halo( | ||
func=_radcouple_stencil, compute_dims=[X_DIM, Y_DIM, Z_DIM] | ||
) | ||
self.do_qa = do_qa | ||
|
||
def __call__(self) -> None: | ||
self._fix_up_clouds() | ||
self._radcouple() | ||
if self.do_qa: | ||
pass |
3 changes: 3 additions & 0 deletions
3
GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSmoist_GridComp/pyMoist/pyMoist/wrapper.py
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,3 @@ | ||
""" | ||
Wraps pyMoist for GEOS interface use. | ||
""" |
43 changes: 43 additions & 0 deletions
43
GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSmoist_GridComp/pyMoist/setup.cfg
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,43 @@ | ||
[bumpversion] | ||
current_version = 0.2.0 | ||
commit = True | ||
|
||
[bdist_wheel] | ||
universal = 1 | ||
|
||
[flake8] # WARNING: This configuration is duplicated in pre-commit-config.yaml due to pre-config lack of working dir | ||
exclude = docs | ||
ignore = W503,E302,E203,F841 | ||
max-line-length = 88 | ||
|
||
[aliases] | ||
|
||
[tool:isort] | ||
line_length = 88 | ||
force_grid_wrap = 0 | ||
include_trailing_comma = true | ||
multi_line_output = 3 | ||
use_parentheses = true | ||
lines_after_imports = 2 | ||
default_section = THIRDPARTY | ||
sections = FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER | ||
known_first_party = pyMoist,ndsl | ||
known_third_party = f90nml,pytest,xarray,numpy,mpi4py,gt4py | ||
|
||
[mypy] # WARNING: This configuration is duplicated in pre-commit-config.yaml due to pre-config lack of working dir | ||
ignore_missing_imports = True | ||
follow_imports = normal | ||
namespace_packages = True | ||
strict_optional = False | ||
warn_unreachable = True | ||
explicit_package_bases = True | ||
|
||
[coverage:run] | ||
parallel = true | ||
branch = true | ||
omit = | ||
tests/* | ||
*gt_cache* | ||
.dacecache* | ||
__init__.py | ||
source_pkgs = pyMoist |
46 changes: 46 additions & 0 deletions
46
GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSmoist_GridComp/pyMoist/setup.py
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,46 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
"""pyMoist is the NDSL version of GEOS Moist physics.""" | ||
|
||
from setuptools import find_namespace_packages, setup | ||
|
||
|
||
with open("README.md", encoding="utf-8") as readme_file: | ||
readme = readme_file.read() | ||
|
||
test_requirements = ["pytest", "pytest-subtests", "serialbox", "coverage"] | ||
ndsl_requirements = ["ndsl @ git+https://github.com/NOAA-GFDL/NDSL.git@2024.04.00"] | ||
develop_requirements = test_requirements + ndsl_requirements + ["pre-commit"] | ||
|
||
extras_requires = { | ||
"test": test_requirements, | ||
"ndsl": ndsl_requirements, | ||
"develop": develop_requirements, | ||
} | ||
|
||
setup( | ||
author="NASA", | ||
author_email="florian.g.deconinck@nasa.gov", | ||
python_requires=">=3.11", | ||
classifiers=[ | ||
"Development Status :: 2 - Pre-Alpha", | ||
"Intended Audience :: Developers", | ||
"License :: OSI Approved :: Apache 2 License", | ||
"Natural Language :: English", | ||
"Programming Language :: Python :: 3.11", | ||
], | ||
description=("pyMoist is the NDSL version of NASA GMAO's GEOS Moist physics."), | ||
install_requires=[], | ||
extras_require=extras_requires, | ||
license="BSD license", | ||
long_description=readme, | ||
include_package_data=True, | ||
name="pyMoist", | ||
packages=find_namespace_packages(include=["pyMoist", "pyMoist.*"]), | ||
setup_requires=[], | ||
test_suite="tests", | ||
url="https://github.com/NOAA-GFDL/pyFV3", | ||
version="0.0.0", | ||
zip_safe=False, | ||
) |
8 changes: 8 additions & 0 deletions
8
GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSmoist_GridComp/pyMoist/tests/conftest.py
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,8 @@ | ||
import savepoint | ||
|
||
import ndsl.stencils.testing.conftest | ||
from ndsl.stencils.testing.conftest import * # noqa: F403,F401 | ||
|
||
|
||
# Point to an __init__.py where all the TestX are improted | ||
ndsl.stencils.testing.conftest.translate = savepoint # type: ignore |
1 change: 1 addition & 0 deletions
1
...agcm_GridComp/GEOSphysics_GridComp/GEOSmoist_GridComp/pyMoist/tests/savepoint/__init__.py
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 @@ | ||
from .translate_radiation_coupling import TranslateRadiationCoupling |
36 changes: 36 additions & 0 deletions
36
...ysics_GridComp/GEOSmoist_GridComp/pyMoist/tests/savepoint/translate_radiation_coupling.py
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,36 @@ | ||
from ndsl import Namelist, StencilFactory | ||
from ndsl.stencils.testing.translate import TranslateFortranData2Py | ||
from pyMoist.radiation_coupling import RadiationCoupling | ||
|
||
|
||
class TranslateRadiationCoupling(TranslateFortranData2Py): | ||
def __init__( | ||
self, | ||
grid, | ||
namelist: Namelist, | ||
stencil_factory: StencilFactory, | ||
): | ||
super().__init__(grid, stencil_factory) | ||
self.compute_func = RadiationCoupling( # type: ignore | ||
self.stencil_factory, | ||
self.grid.quantity_factory, | ||
do_qa=namelist.do_qa, | ||
) | ||
|
||
# ADAPT BELOW TO INPUTS | ||
# | ||
# fillq_info = self.grid.compute_dict() | ||
# fillq_info["serialname"] = "fq" | ||
# self.in_vars["data_vars"] = { | ||
# "mass": self.grid.compute_dict(), | ||
# "q": self.grid.compute_dict(), | ||
# "fillq": fillq_info, | ||
# } | ||
# self.out_vars = { | ||
# "fillq": fillq_info, | ||
# "q": self.grid.compute_dict(), | ||
# } | ||
|
||
def compute_from_storage(self, inputs): | ||
self.compute_func(**inputs) | ||
return inputs |
1 change: 1 addition & 0 deletions
1
GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSmoist_GridComp/pyMoist/tests/test_translate.py
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 @@ | ||
from ndsl.stencils.testing.test_translate import * # noqa: F403,F401 |