Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recipe parametrisation #337

Merged
merged 43 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
defaf37
Simplify __main__.py
jfrost-mo Dec 19, 2023
eb12a6b
Specifically pin pyproject.toml as pytest config source
jfrost-mo Dec 19, 2023
83fe603
Only set minimum coverage in CI
jfrost-mo Dec 19, 2023
90b89f9
Don't configure conda-libmamba-solver as it is now default
jfrost-mo Dec 19, 2023
914ff57
Remove DB_LONG_JOB config, as its unused
jfrost-mo Dec 21, 2023
bc920ab
Add help text for more config settings
jfrost-mo Dec 21, 2023
e29df3e
Use python 3.12 for workflow
jfrost-mo Dec 22, 2023
584d1d8
Fix non-deterministic print ordering when installing local CSET
jfrost-mo Dec 22, 2023
e4e0d3e
Add plot mean surface fields include file
jfrost-mo Dec 21, 2023
9c6f05d
Use setuptool_scm for version numbering
jfrost-mo Dec 22, 2023
3e32dce
Add listing and filtering to cookbook
jfrost-mo Dec 14, 2023
0378353
Use CLI options for recipe, input, and output
jfrost-mo Dec 18, 2023
e701253
Add recipe variables
jfrost-mo Dec 18, 2023
2790912
Refactor test cube loading into fixture
jfrost-mo Dec 19, 2023
21a6a2e
Add test for failure creating output directory
jfrost-mo Dec 19, 2023
9608ff7
Simplyfy, and make stricter, cookbook cli tests
jfrost-mo Dec 19, 2023
5df5724
Test additional graph cases
jfrost-mo Dec 19, 2023
3c7b4d8
Improve test docstrings
jfrost-mo Dec 19, 2023
258c8b2
Remove test plot as it is unused
jfrost-mo Dec 5, 2023
a46a3d6
Replace box shadow with border as iframe overlapped
jfrost-mo Dec 5, 2023
9dd5b0e
Remove tagline to minimise header height
jfrost-mo Dec 5, 2023
d5a5bc9
Add download link to diagnostic ZIP
jfrost-mo Dec 4, 2023
b74b104
Log diagnostic steps to file in output
jfrost-mo Dec 5, 2023
f545ca1
Allow script to take install target as argument
jfrost-mo Dec 11, 2023
26c7641
Filter iris warning that don't affect us
jfrost-mo Dec 21, 2023
1b7fe50
Documentation improvements
jfrost-mo Dec 21, 2023
53db37c
Use TIME variable in CAPE ratio recipe
jfrost-mo Dec 21, 2023
f847f69
Increate cookbook verbosity in workflow
jfrost-mo Dec 22, 2023
c1f360e
Take additional CLI arguments from CSET_ADDOPTS env var
jfrost-mo Dec 22, 2023
ce00b29
Update CLI reference documentation
jfrost-mo Dec 22, 2023
64e1b73
Remove undeveloped include files
jfrost-mo Dec 22, 2023
17ad743
Remove unused dependabot configuration
jfrost-mo Jan 8, 2024
9bb6a6b
Merge branch 'main' into 296_recipe_parameterisation
jfrost-mo Jan 15, 2024
6160974
Update rose-meta.conf
Sylviabohnenstengel Jan 15, 2024
73a78e8
Don't cache pip install as it is slower
jfrost-mo Jan 15, 2024
2278367
Update workflow-installation.rst
Sylviabohnenstengel Jan 15, 2024
118d2e4
Update __init__.py
Sylviabohnenstengel Jan 15, 2024
071dccd
Order CLI flags alphabetically
jfrost-mo Jan 16, 2024
63a76f6
Clarify that the variable value can be any string
jfrost-mo Jan 16, 2024
852b501
Merge branch 'main' into 296_recipe_parameterisation
jfrost-mo Jan 16, 2024
217d272
Merge branch 'main' into 296_recipe_parameterisation
jfrost-mo Jan 19, 2024
16d9c1d
Merge branch 'main' into 296_recipe_parameterisation
jfrost-mo Jan 29, 2024
ddb5bf6
Merge branch 'main' into 296_recipe_parameterisation
jfrost-mo Jan 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@

version: 2
updates:
# Check for python dependency updates.
- package-ecosystem: "pip" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"

# Check for GitHub Actions updates.
- package-ecosystem: "github-actions"
directory: "/"
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/conda-lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ jobs:
run: python3 -m pip install tox tox-conda conda-lock

- name: Update conda
run: |
conda update -q conda
# Install and use libmamba solver as it is much faster.
conda install -q -n base conda-libmamba-solver
conda config --set solver libmamba
run: conda update -q conda

- name: Hash existing lock files
run: sha256sum **/locks/*.txt > ${{ runner.temp }}/lock_file_hashes
Expand Down
15 changes: 5 additions & 10 deletions .github/workflows/pull_request_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
PY_COLORS: "1"
run: |
python3 -m pip install -e .
pytest --verbose --cov --cov-append
pytest --verbose --cov --cov-append --cov-config=pyproject.toml
mv .coverage ".coverage.${{ matrix.py-ver }}"
- uses: actions/upload-artifact@v4
with:
Expand All @@ -50,19 +50,12 @@ jobs:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Get week number for cache
id: week
run: echo "week=$(date '+W%V')" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
with:
key: coverage-report|${{ env.pythonLocation }}|${{ steps.week.outputs.week }}
path: ~/.cache/pip
- name: Install coverage
run: python3 -m pip install coverage
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
pattern: coverage-data-*
Expand All @@ -84,10 +77,13 @@ jobs:
if ! gh pr comment --edit-last ${{ github.head_ref }} --body-file ${{ runner.temp }}/cov-report.md ; then
gh pr comment ${{ github.head_ref }} --body-file ${{ runner.temp }}/cov-report.md
fi
- name: Check 95% minimum coverage
run: coverage report --fail-under=95

pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
Expand All @@ -98,7 +94,6 @@ jobs:
path: ~/.cache/pre-commit
- name: Set up pre-commit
run: python3 -m pip install pre-commit
- uses: actions/checkout@v4
- name: Run pre-commit
run: pre-commit run --show-diff-on-failure --color=always --all-files

Expand Down
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
prune .github
prune cset-workflow
exclude .gitignore .pre-commit-config.yaml .git-blame-ignore-revs
2 changes: 1 addition & 1 deletion cset-workflow/app/build_conda/bin/build_conda_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ else
fi

# Find environment definition file, abort if not found.
env_lock_file="${CYLC_WORKFLOW_RUN_DIR}/requirements/locks/py311-lock-linux-64.txt"
env_lock_file="${CYLC_WORKFLOW_RUN_DIR}/requirements/locks/py312-lock-linux-64.txt"
if [[ -f "$env_lock_file" ]]; then
echo "Using environment file $env_lock_file"
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
check=True,
)

print("Using CSET version:")
subprocess.run(("cset", "--version"), check=True)
result = subprocess.run(("cset", "--version"), check=True, capture_output=True)
print(f"Using CSET version: {result.stdout}")
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@

<body>
<nav class="topbar">
<div>
<h1>CSET</h1>
<div>TODO: Think of a tagline</div>
</div>
<h1>CSET</h1>
<menu>
<li><a href="index.html"><button>Home</button></a></li>
<li><a href="single.html"><button>Single plot</button></a></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@

<body>
<nav class="topbar">
<div>
<h1>CSET</h1>
<div>TODO: Think of a tagline</div>
</div>
<h1>CSET</h1>
<menu>
<li><a href="index.html"><button>Home</button></a></li>
<li><a href="single.html"><button>Single plot</button></a></li>
Expand Down

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@

<body>
<nav class="topbar">
<div>
<h1>CSET</h1>
<div>TODO: Think of a tagline</div>
</div>
<h1>CSET</h1>
<menu>
<li><a href="index.html"><button>Home</button></a></li>
<li><a href="single.html"><button>Single plot</button></a></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ a:hover {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
box-shadow: 0 4px 4px grey;
border-bottom: 1px solid black;
padding: 0.5em 1em;
}

Expand Down
24 changes: 20 additions & 4 deletions cset-workflow/app/run_cset_recipe/bin/run-cset-recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def append_to_index(index_path: Path, record: dict):
json.dump(index, fp)


input_file = (
input_path = (
Path(
f"{os.getenv('CYLC_WORKFLOW_SHARE_DIR')}/cycle/{os.getenv('CYLC_TASK_CYCLE_POINT')}/input_path"
)
Expand All @@ -63,8 +63,25 @@ def append_to_index(index_path: Path, record: dict):
plot_id = str(uuid4())
output_directory = Path.cwd() / plot_id

# Takes recipe from CSET_RECIPE environment variable.
subprocess.run(("cset", "-v", "bake", input_file, output_directory), check=True)
# Takes recipe from CSET_RECIPE environment variable if not given.
cset_recipe = os.getenv("CSET_RECIPE_NAME")
if cset_recipe:
subprocess.run(("cset", "-v", "cookbook", cset_recipe), check=True)
else:
cset_recipe = Path("recipe.yaml")
cset_recipe.write_bytes(os.getenvb("CSET_RECIPE"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our installation getenvb causes a type error, at the end of the traceback, in _check_bytes (line 781 of os.py) bails with TypeError("bytes expected, not %s" % type(value).__name__)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably related to the problems with my conda environments, so feel free to ignore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here I was hoping that not having to deal with any encoding would be better for portability.

Re: conda environment issues, have you tried doing a fresh install? conda update does some funny things, and as we resolve from lock files it is more reliable to remove the conda environment and recreate it.

# Remove existing conda env
conda env remove -n cset-dev
# Create new one (from inside CSET directory)
conda create -n cset-dev --file requirements/locks/py312-lock-linux-64.txt


subprocess.run(
(
"cset",
"-v",
"bake",
f"--recipe={cset_recipe}",
f"--input-dir={input_path}",
f"--output-dir={output_directory}",
),
check=True,
)

with open(output_directory / "meta.json", "rt", encoding="UTF=8") as fp:
recipe_meta = json.load(fp)
Expand All @@ -73,7 +90,6 @@ def append_to_index(index_path: Path, record: dict):
# TODO: Save model in meta.json. Currently this always returns "Unknown".
source_model = recipe_meta.get("model", "Unknown")

# TODO: Give archive a meaningful name, probably a slugified title.
archive_path = output_directory / "diagnostic.zip"
with zipfile.ZipFile(archive_path, "w", compression=zipfile.ZIP_DEFLATED) as archive:
for path in output_directory.rglob("*"):
Expand Down
13 changes: 10 additions & 3 deletions cset-workflow/app/send_email/bin/send-email.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@ def get_home_page_addr():
if len(path) == 1:
path = os.getenv("WEB_DIR").split("/Public/")
if len(path) == 1:
raise RuntimeError("Cannot determine web address.")
return f"{os.getenv('WEB_ADDR').strip('/')}/{path[-1]}"
raise ValueError("Cannot determine web address.")
try:
base_address = os.getenv("WEB_ADDR", "").strip("/")
except AttributeError as err:
raise ValueError("WEB_ADDR not set.") from err
return f"{base_address}/{path[-1]}"


if __name__ == "__main__":
subject = "CSET webpage ready"
body = f"""The webpage for your run of CSET is now ready. You can view it here:\n{get_home_page_addr()}"""
try:
body = f"The webpage for your run of CSET is now ready. You can view it here:\n{get_home_page_addr()}"
except ValueError:
body = "The webpage for your run of CSET is now ready, though the address could not be determined.\nCheck that WEB_ADDR and WEB_DIR are set correctly, then consider filing a bug report at https://github.com/MetOffice/CSET"
subprocess.run(
f'printf "{body}" | mail -s "{subject}" -S "from=notifications" "$USER"',
check=True,
Expand Down
37 changes: 2 additions & 35 deletions cset-workflow/includes/deterministic_plot_cape_ratio.cylc
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,5 @@
script = rose task-run -v --app-key=run_cset_recipe
execution time limit = PT15M
[[[environment]]]
CSET_RECIPE = """
title: CAPE ratio plot
description: |
Extracts data required for, and calculates the CAPE ratio diagnostic, plotting on a map.

steps:
- operator: read.read_cubes

- operator: convection.cape_ratio
SBCAPE:
operator: filters.filter_cubes
constraint:
operator: constraints.generate_stash_constraint
stash: m01s20i114
MUCAPE:
operator: filters.filter_cubes
constraint:
operator: constraints.generate_stash_constraint
stash: m01s20i112
MUCIN:
operator: filters.filter_cubes
constraint:
operator: constraints.generate_stash_constraint
stash: m01s20i113
MUCIN_thresh: -75

- operator: filters.filter_cubes
constraint:
operator: constraints.generate_time_constraint
time_start: 2020-07-30T13:00Z

- operator: plot.postage_stamp_contour_plot

- operator: write.write_cube_to_nc
"""
CSET_RECIPE_NAME = "CAPE_ratio_plot.yaml"
CSET_ADDOPTS = "--TIME={{CAPE_RATIO_TIME}}"
11 changes: 9 additions & 2 deletions cset-workflow/install_restricted_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ fi
# Don't copy some files, like README.md or top-level hidden files.
rm "${tempdir}/README.md"

cp -rv "${tempdir}"/* .
if [[ -z "${1-}" ]]
then
target_directory="$PWD"
else
target_directory="$1"
fi

cp -rv "${tempdir}"/* "${target_directory}"

# Clean up
# Clean up, must force here to remove .git folder.
rm -rf "${tempdir}"
Loading