Skip to content
Snippets Groups Projects
Commit 1a33ce1e authored by Paul Gierz's avatar Paul Gierz
Browse files

plugin works

parent ebbbc1a5
No related branches found
No related tags found
No related merge requests found
...@@ -20,7 +20,8 @@ ...@@ -20,7 +20,8 @@
# #
import os import os
import sys import sys
sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath(".."))
import gfw_creator import gfw_creator
...@@ -32,22 +33,22 @@ import gfw_creator ...@@ -32,22 +33,22 @@ import gfw_creator
# Add any Sphinx extension module names here, as strings. They can be # Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode'] extensions = ["sphinx.ext.autodoc", "sphinx.ext.viewcode"]
# Add any paths that contain templates here, relative to this directory. # Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates'] templates_path = ["_templates"]
# The suffix(es) of source filenames. # The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string: # You can specify multiple suffix as a list of string:
# #
# source_suffix = ['.rst', '.md'] # source_suffix = ['.rst', '.md']
source_suffix = '.rst' source_suffix = ".rst"
# The master toctree document. # The master toctree document.
master_doc = 'index' master_doc = "index"
# General information about the project. # General information about the project.
project = u'GFW Creator' project = u"GFW Creator"
copyright = u"2020, Paul Gierz" copyright = u"2020, Paul Gierz"
author = u"Paul Gierz" author = u"Paul Gierz"
...@@ -70,10 +71,10 @@ language = None ...@@ -70,10 +71,10 @@ language = None
# List of patterns, relative to source directory, that match files and # List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files. # directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path # This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
# The name of the Pygments (syntax highlighting) style to use. # The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx' pygments_style = "sphinx"
# If true, `todo` and `todoList` produce output, else they produce nothing. # If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False todo_include_todos = False
...@@ -84,7 +85,7 @@ todo_include_todos = False ...@@ -84,7 +85,7 @@ todo_include_todos = False
# The theme to use for HTML and HTML Help pages. See the documentation for # The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes. # a list of builtin themes.
# #
html_theme = 'alabaster' html_theme = "alabaster"
# Theme options are theme-specific and customize the look and feel of a # Theme options are theme-specific and customize the look and feel of a
# theme further. For a list of options available for each theme, see the # theme further. For a list of options available for each theme, see the
...@@ -95,13 +96,13 @@ html_theme = 'alabaster' ...@@ -95,13 +96,13 @@ html_theme = 'alabaster'
# Add any paths that contain custom static files (such as style sheets) here, # Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files, # relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css". # so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static'] html_static_path = ["_static"]
# -- Options for HTMLHelp output --------------------------------------- # -- Options for HTMLHelp output ---------------------------------------
# Output file base name for HTML help builder. # Output file base name for HTML help builder.
htmlhelp_basename = 'gfw_creatordoc' htmlhelp_basename = "gfw_creatordoc"
# -- Options for LaTeX output ------------------------------------------ # -- Options for LaTeX output ------------------------------------------
...@@ -110,15 +111,12 @@ latex_elements = { ...@@ -110,15 +111,12 @@ latex_elements = {
# The paper size ('letterpaper' or 'a4paper'). # The paper size ('letterpaper' or 'a4paper').
# #
# 'papersize': 'letterpaper', # 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt'). # The font size ('10pt', '11pt' or '12pt').
# #
# 'pointsize': '10pt', # 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble. # Additional stuff for the LaTeX preamble.
# #
# 'preamble': '', # 'preamble': '',
# Latex figure (float) alignment # Latex figure (float) alignment
# #
# 'figure_align': 'htbp', # 'figure_align': 'htbp',
...@@ -128,9 +126,13 @@ latex_elements = { ...@@ -128,9 +126,13 @@ latex_elements = {
# (source start file, target name, title, author, documentclass # (source start file, target name, title, author, documentclass
# [howto, manual, or own class]). # [howto, manual, or own class]).
latex_documents = [ latex_documents = [
(master_doc, 'gfw_creator.tex', (
u'GFW Creator Documentation', master_doc,
u'Paul Gierz', 'manual'), "gfw_creator.tex",
u"GFW Creator Documentation",
u"Paul Gierz",
"manual",
),
] ]
...@@ -138,11 +140,7 @@ latex_documents = [ ...@@ -138,11 +140,7 @@ latex_documents = [
# One entry per manual page. List of tuples # One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section). # (source start file, name, description, authors, manual section).
man_pages = [ man_pages = [(master_doc, "gfw_creator", u"GFW Creator Documentation", [author], 1)]
(master_doc, 'gfw_creator',
u'GFW Creator Documentation',
[author], 1)
]
# -- Options for Texinfo output ---------------------------------------- # -- Options for Texinfo output ----------------------------------------
...@@ -151,13 +149,13 @@ man_pages = [ ...@@ -151,13 +149,13 @@ man_pages = [
# (source start file, target name, title, author, # (source start file, target name, title, author,
# dir menu entry, description, category) # dir menu entry, description, category)
texinfo_documents = [ texinfo_documents = [
(master_doc, 'gfw_creator', (
u'GFW Creator Documentation', master_doc,
author, "gfw_creator",
'gfw_creator', u"GFW Creator Documentation",
'One line description of project.', author,
'Miscellaneous'), "gfw_creator",
"One line description of project.",
"Miscellaneous",
),
] ]
...@@ -7,7 +7,7 @@ from loguru import logger ...@@ -7,7 +7,7 @@ from loguru import logger
def create_hosing_files(config): def create_hosing_files(config):
if config["general"]["setup_name"] == "awiesm": if config["general"]["setup_name"] == "awiesm":
if config["fesom"]["do_hosing"]: if config["fesom"].get("do_hosing"):
logger.info("Creating hosing files...") logger.info("Creating hosing files...")
hosing_type = config["fesom"].get("hosing_type") hosing_type = config["fesom"].get("hosing_type")
if hosing_type == "homogeneous": if hosing_type == "homogeneous":
...@@ -22,11 +22,23 @@ def create_hosing_files(config): ...@@ -22,11 +22,23 @@ def create_hosing_files(config):
gfw_atmo_file.to_netcdf( gfw_atmo_file.to_netcdf(
config["fesom"]["thisrun_forcing_dir"] + "/gfw_atmo.nc" config["fesom"]["thisrun_forcing_dir"] + "/gfw_atmo.nc"
) )
logger.info(f"Wrote {config['fesom']['thisrun_forcing_dir'] + '/gfw_atmo.nc'} for use in the simulation!") logger.info(
f"Wrote {config['fesom']['thisrun_forcing_dir'] + '/gfw_atmo.nc'} for use in the simulation!"
)
config["oasis3mct"].setdefault("coupling_input_fields", {}) config["oasis3mct"].setdefault("coupling_input_fields", {})
config["oasis3mct"]["coupling_input_fields"]["gfw_atmo"] = {"freq": 999, "field_filepath": "gfw_atmo.nc"} config["oasis3mct"]["coupling_input_fields"]["gfw_atmo"] = {
# TODO(PG): Add gfw_atmo.nc to forcing files dict in FESOM... "freq": 86400,
# TODO(PG): Or copy it directly into the work folder from here... "field_filepath": "gfw_atmo.nc",
}
config["fesom"].setdefault("forcing_files", {})
config["fesom"].setdefault("forcing_sources", {})
config["fesom"].setdefault("forcing_in_work", {})
config["fesom"]["forcing_files"]["gfw_atmo"] = "gfw_atmo"
config["fesom"]["forcing_sources"]["gfw_atmo"] = (
config["fesom"]["thisrun_forcing_dir"] + "/gfw_atmo.nc"
)
config["fesom"]["forcing_in_work"]["gfw_atmo"] = "gfw_atmo.nc"
return config return config
elif hosing_type == "from_file": elif hosing_type == "from_file":
logger.error("Sorry, hosing from a file has no yet been implemented!") logger.error("Sorry, hosing from a file has no yet been implemented!")
......
...@@ -7,10 +7,18 @@ import xarray as xr ...@@ -7,10 +7,18 @@ import xarray as xr
import os import os
import pkgutil import pkgutil
import subprocess
import sys
CDO = cdo.Cdo() def build_cdo_object():
try:
return cdo.Cdo()
except Exception as e:
print("Python exception:", e)
print("Unable to use CDO, this won't work, sorry...")
print("You may consider running >> module load cdo << and trying to run again")
sys.exit(1)
def _get_template_file(): def _get_template_file():
""" """
...@@ -49,6 +57,7 @@ def _lat_lon_area(lat_0, lat_1, lon_0, lon_1): ...@@ -49,6 +57,7 @@ def _lat_lon_area(lat_0, lat_1, lon_0, lon_1):
Figures out the area of a lat/lon box for distributing a flux across a Figures out the area of a lat/lon box for distributing a flux across a
total area total area
""" """
CDO = build_cdo_object()
ds = _get_template_file() ds = _get_template_file()
selected_ds = CDO.fldsum( selected_ds = CDO.fldsum(
input=f"-sellonlatbox,{lon_0},{lon_1},{lat_0},{lat_1} -selname,cell_area {ds}", input=f"-sellonlatbox,{lon_0},{lon_1},{lat_0},{lat_1} -selname,cell_area {ds}",
...@@ -61,6 +70,7 @@ def create_homogeneous_hosing(lat_0, lat_1, lon_0, lon_1, hosing_strength): ...@@ -61,6 +70,7 @@ def create_homogeneous_hosing(lat_0, lat_1, lon_0, lon_1, hosing_strength):
""" """
Creates a homogeneous hosing field Creates a homogeneous hosing field
""" """
CDO = build_cdo_object()
ds = _get_template_file() ds = _get_template_file()
# Notes: # Notes:
# ------ # ------
......
...@@ -5,45 +5,55 @@ ...@@ -5,45 +5,55 @@
from setuptools import setup, find_packages from setuptools import setup, find_packages
with open('README.rst') as readme_file: with open("README.rst") as readme_file:
readme = readme_file.read() readme = readme_file.read()
with open('HISTORY.rst') as history_file: with open("HISTORY.rst") as history_file:
history = history_file.read() history = history_file.read()
requirements = ['Click>=6.0', "xarray", "cdo", "netcdf4",] requirements = [
"Click>=6.0",
"xarray",
"cdo@git+https://github.com/Try2Code/cdo-bindings#egg=pkg&subdirectory=python",
"netcdf4",
]
setup_requirements = ['pytest-runner', ] setup_requirements = [
"pytest-runner",
]
test_requirements = ['pytest', ] test_requirements = [
"pytest",
]
setup( setup(
author="Paul Gierz", author="Paul Gierz",
author_email='pgierz@awi.de', author_email="pgierz@awi.de",
classifiers=[ classifiers=[
'Development Status :: 2 - Pre-Alpha', "Development Status :: 2 - Pre-Alpha",
'Intended Audience :: Developers', "Intended Audience :: Developers",
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', "License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
'Natural Language :: English', "Natural Language :: English",
'Programming Language :: Python :: 3.6', "Programming Language :: Python :: 3.6",
], ],
description="GFW Creator allows you to generate files for the gfw_atmo switch in ECHAM6/JSBACH of AWI-ESM", description="GFW Creator allows you to generate files for the gfw_atmo switch in ECHAM6/JSBACH of AWI-ESM",
entry_points={ entry_points={
'console_scripts': [ "console_scripts": ["gfw_creator=gfw_creator.cli:main",],
'gfw_creator=gfw_creator.cli:main', "esm_tools.plugins": [
"create_hosing_files=gfw_creator.esm_tools_plugin:create_hosing_files",
], ],
}, },
install_requires=requirements, install_requires=requirements,
license="GNU General Public License v3", license="GNU General Public License v3",
long_description=readme + '\n\n' + history, long_description=readme + "\n\n" + history,
include_package_data=True, include_package_data=True,
keywords='gfw_creator', keywords="gfw_creator",
name='gfw_creator', name="gfw_creator",
packages=find_packages(include=['gfw_creator']), packages=find_packages(include=["gfw_creator"]),
setup_requires=setup_requirements, setup_requires=setup_requirements,
test_suite='tests', test_suite="tests",
tests_require=test_requirements, tests_require=test_requirements,
url='https://github.com/pgierz/gfw_creator', url="https://github.com/pgierz/gfw_creator",
version='0.0.2', version="0.0.2",
zip_safe=False, zip_safe=False,
) )
...@@ -33,7 +33,7 @@ def test_command_line_interface(): ...@@ -33,7 +33,7 @@ def test_command_line_interface():
result = runner.invoke(cli.main) result = runner.invoke(cli.main)
# Running without arguments should give you an error: # Running without arguments should give you an error:
assert result.exit_code == 2 assert result.exit_code == 2
assert 'Usage: main [OPTIONS]' in result.output assert "Usage: main [OPTIONS]" in result.output
help_result = runner.invoke(cli.main, ['--help']) help_result = runner.invoke(cli.main, ["--help"])
assert help_result.exit_code == 0 assert help_result.exit_code == 0
assert '--help Show this message and exit.' in help_result.output assert "--help Show this message and exit." in help_result.output
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment