Commit 33d3fb35 authored by Paul Gierz's avatar Paul Gierz

Various Updates

* Starts to use typed Python
* Some updates to the docs
* Functions for taking newest and oldest timesteps
parent fdd99166
...@@ -77,7 +77,7 @@ docs: ## generate Sphinx HTML documentation, including API docs ...@@ -77,7 +77,7 @@ docs: ## generate Sphinx HTML documentation, including API docs
$(BROWSER) docs/_build/html/index.html $(BROWSER) docs/_build/html/index.html
servedocs: docs ## compile the docs watching for changes servedocs: docs ## compile the docs watching for changes
watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D . watchmedo shell-command -p '*.rst; *py' -c '$(MAKE) -C docs html' -R -D .
release: dist ## package and upload a release release: dist ## package and upload a release
twine upload dist/* twine upload dist/*
......
...@@ -23,7 +23,12 @@ Earth System. It is written in Python and configured with YAML files. ...@@ -23,7 +23,12 @@ Earth System. It is written in Python and configured with YAML files.
Features Features
-------- --------
* TODO * Automatic remapping between various grids via the ``SCRIP`` library
* Ability to run other programs before and after each step
* Configuration via yaml files
* No modification of model source code necessary
Credits Credits
------- -------
......
...@@ -64,7 +64,7 @@ master_doc = "index" ...@@ -64,7 +64,7 @@ master_doc = "index"
# General information about the project. # General information about the project.
project = u"SCOPE" project = u"SCOPE"
copyright = u"2019, Paul Gierz" copyright = u"2020, Paul Gierz"
author = u"Paul Gierz" author = u"Paul Gierz"
# The version info for the project you're documenting, acts as replacement # The version info for the project you're documenting, acts as replacement
......
===== =============
Usage Library Usage
===== =============
An example configuration file is provided under ``examples/scope_config.yaml``: An example configuration file is provided under ``examples/scope_config.yaml``:
...@@ -8,6 +8,8 @@ An example configuration file is provided under ``examples/scope_config.yaml``: ...@@ -8,6 +8,8 @@ An example configuration file is provided under ``examples/scope_config.yaml``:
:language: yaml :language: yaml
:linenos: :linenos:
This section describes how to use ``scope`` from a Python program.
To use scope in a project:: To use scope in a project::
import scope import scope
template_replacements:
EXP_ID: "PI_1x10"
DATE_PATTERN: "[0-9]{6}"
scope:
couple_dir: "/work/ollie/pgierz/scope_tests/couple/"
number openMP processes: 8
pism:
type: ice
griddes: ice.griddes
recieve:
solid_earth:
some_variable_name:
interp: bil
some_other_variable_name:
interp: con
transformation:
- expr: "dBdt=...."
send:
solid_earth:
thk:
files:
pattern: "{{ EXP_ID }}_"
take:
what: timesteps
newest: 1
vilma:
type: solid_earth
griddes: n128
recieve:
solid_earth:
thk:
interp: con
send:
ice:
rsl:
files: "{{ EXP_ID }}_vilma_{{ DATE_PATTERN }}.nc"
take:
what: timesteps
newest: 1
...@@ -15,11 +15,20 @@ from scope import Regrid, Preprocess ...@@ -15,11 +15,20 @@ from scope import Regrid, Preprocess
YAML_AUTO_EXTENSIONS = ["", ".yml", ".yaml", ".YML", ".YAML"] YAML_AUTO_EXTENSIONS = ["", ".yml", ".yaml", ".YML", ".YAML"]
def yaml_file_to_dict(filepath): def yaml_file_to_dict(filepath: str) -> dict:
""" """
Given a yaml file, returns a corresponding dictionary. Given a scope configuration yaml file, returns a corresponding dictionary.
If you do not give an extension, tries again after appending one. If you do not give an extension, tries again after appending one:
+ ``.yml``
+ ``.yaml``
+ ``.YML``
+ ``.YAML``
Note that this function also uses `~jinja2` to replace any templated
variables found in the under the top-level key ``template_replacements``.
This key is then deleted from the remainder of the dictionary.
Parameters Parameters
---------- ----------
...@@ -30,6 +39,10 @@ def yaml_file_to_dict(filepath): ...@@ -30,6 +39,10 @@ def yaml_file_to_dict(filepath):
------- -------
dict dict
A dictionary representation of the yaml file. A dictionary representation of the yaml file.
Raises
------
``OSError`` if the file cannot be found.
""" """
for extension in YAML_AUTO_EXTENSIONS: for extension in YAML_AUTO_EXTENSIONS:
try: try:
...@@ -57,15 +70,18 @@ def yaml_file_to_dict(filepath): ...@@ -57,15 +70,18 @@ def yaml_file_to_dict(filepath):
@click.version_option() @click.version_option()
def main(args=None): def main(args=None):
"""Console script for scope.""" """Console script for scope."""
click.echo("Replace this message by putting your code into scope.cli.main") click.echo(
click.echo("See click documentation at http://click.pocoo.org/") "SCOPE a stand-alone coupler. Please use --help for available operations."
)
click.echo("See documentation at https://scope-coupler.readthedocs.io")
return 0 return 0
@main.command() @main.command()
@click.argument("config_path", type=click.Path(exists=True)) @click.argument("config_path", type=click.Path(exists=True))
@click.argument("whos_turn") @click.argument("whos_turn")
def regrid(config_path, whos_turn): def regrid(config_path: str, whos_turn: str) -> None:
"""Command line interface to regridding"""
config = yaml_file_to_dict(config_path) config = yaml_file_to_dict(config_path)
regridder = Regrid(config, whos_turn) regridder = Regrid(config, whos_turn)
regridder.regrid() regridder.regrid()
...@@ -74,7 +90,7 @@ def regrid(config_path, whos_turn): ...@@ -74,7 +90,7 @@ def regrid(config_path, whos_turn):
@main.command() @main.command()
@click.argument("config_path", type=click.Path(exists=True)) @click.argument("config_path", type=click.Path(exists=True))
@click.argument("whos_turn") @click.argument("whos_turn")
def preprocess(config_path, whos_turn): def preprocess(config_path: str, whos_turn: str) -> None:
config = yaml_file_to_dict(config_path) config = yaml_file_to_dict(config_path)
print(80 * "-") print(80 * "-")
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment