Skip to content

Commit

Permalink
Merge pull request #933 from FlorianDeconinck/pyMoist_setup
Browse files Browse the repository at this point in the history
`pyMoist` setup & stub code
  • Loading branch information
FlorianDeconinck authored May 21, 2024
2 parents 977cfcd + 0722e58 commit 39de4e7
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 0 deletions.
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/
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",]
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.
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.
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Wraps pyMoist for GEOS interface use.
"""
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
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,
)
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .translate_radiation_coupling import TranslateRadiationCoupling
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from ndsl.stencils.testing.test_translate import * # noqa: F403,F401

0 comments on commit 39de4e7

Please sign in to comment.