Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
3ec8155
added grib_parser
Jul 18, 2024
ae3a747
eccodes_definition in setup_env
Jul 19, 2024
56ab73e
applied changes for reading grib files
andleuth Jul 29, 2024
b3bc25e
Formatting
andleuth Jul 29, 2024
fd39159
update to master branch
andleuth Jul 30, 2024
3250783
dummy change
andleuth Jul 30, 2024
940f1f9
revert dummy change
andleuth Jul 30, 2024
fce5ac0
adapt get_ds()
andleuth Aug 5, 2024
b046756
unitest and change in grib_definition_path
andleuth Aug 7, 2024
dde8b24
old def_path for safety
andleuth Aug 7, 2024
ea0e431
Merge remote-tracking branch 'origin/main' into reading_grib_files
huppd Oct 1, 2024
6546223
improve formatting
huppd Oct 1, 2024
d3a942e
frist draft tests
huppd Oct 1, 2024
f62a22a
add unittest
huppd Oct 1, 2024
35e9821
rm deleted files
huppd Oct 1, 2024
c72eb96
update requirements
huppd Oct 1, 2024
5048f49
update requirements
huppd Oct 1, 2024
e2f426e
Merge branch 'reading_grib_files' of github.com:MeteoSwiss/probtest i…
huppd Oct 2, 2024
f9d04a9
use pinned version for ci and make python version consistent
huppd Oct 2, 2024
145dd49
pin env and set python version
huppd Oct 2, 2024
7dd8c18
add author
huppd Oct 2, 2024
e450ff7
fix gitignore
huppd Oct 2, 2024
cb5d76c
update gitignore
huppd Oct 2, 2024
13ce70c
small improvement
huppd Oct 3, 2024
7be1ac4
change to pytest
huppd Oct 3, 2024
99320d8
cleanup tmp path
huppd Oct 3, 2024
92677de
fix tmp
huppd Oct 3, 2024
658c249
cleanup gitignore
huppd Oct 3, 2024
32a180b
fix utest
huppd Oct 4, 2024
c16e221
fix env
huppd Oct 4, 2024
d2d84d3
improve github actions
huppd Oct 4, 2024
4f7e183
fix env
huppd Oct 4, 2024
74ad301
step by step refactor
huppd Oct 4, 2024
3996217
next step
huppd Oct 4, 2024
3b467e5
next step
huppd Oct 4, 2024
30bbcd3
next step
huppd Oct 4, 2024
bc0be67
last step
huppd Oct 4, 2024
b5c2866
last step
huppd Oct 4, 2024
7c59155
Merge branch 'reading_grib_files' of github.com:MeteoSwiss/probtest i…
huppd Oct 4, 2024
ad6e44e
cleanup gitignore
huppd Oct 4, 2024
8b074d7
minor change
huppd Oct 4, 2024
7e1427b
fix readme
huppd Oct 4, 2024
3f9bd0d
fix definitions version
huppd Oct 4, 2024
8f89c85
make icon consistent
huppd Oct 4, 2024
6039666
fix naming
huppd Oct 4, 2024
7bfcea5
fix naming
huppd Oct 4, 2024
903f8a4
fix eccodes version
huppd Oct 4, 2024
d9a1797
inlcude sample path
huppd Oct 4, 2024
a584fca
use eccodes=2.35.0
huppd Oct 4, 2024
59a0833
fix python version
huppd Oct 7, 2024
21c6d24
might not be needed
huppd Oct 7, 2024
c357b92
Merge remote-tracking branch 'origin/main' into reading_grib_files
huppd Oct 8, 2024
8000bdf
revert hotfix
huppd Oct 8, 2024
f2ab296
Merge remote-tracking branch 'origin/main' into reading_grib_files
huppd Oct 15, 2024
43a3985
update README.md
huppd Oct 16, 2024
2ed2845
refactor
huppd Oct 16, 2024
586d5a1
use closets possiblle eccodes to 2.25.0
huppd Oct 16, 2024
9b94a3a
refactor
huppd Oct 16, 2024
f51fcd4
not so nice workaround
huppd Oct 16, 2024
e50ec27
workaround
huppd Oct 17, 2024
427a954
update env
huppd Nov 7, 2024
68ee283
rename var
huppd Nov 7, 2024
0a2fc58
fix name
huppd Nov 7, 2024
282a9d3
rm mamba option
huppd Nov 8, 2024
937184e
fix name
huppd Nov 8, 2024
4321bbc
update requirements
huppd Nov 8, 2024
8ca9638
update eccodes, needs test fixing
huppd Nov 22, 2024
a438460
fix environment
huppd Nov 22, 2024
5eefdce
add loadenv
huppd Nov 29, 2024
dc498e5
road to somewhere
huppd Dec 2, 2024
f95f0d8
add setup_env.py
huppd Dec 4, 2024
7a02af9
test ci
huppd Dec 4, 2024
1971018
ws
huppd Dec 4, 2024
3fe2edb
python version
huppd Dec 4, 2024
a410f10
next try
huppd Dec 4, 2024
43c450f
fix ws
huppd Dec 4, 2024
0686fdc
rm stage
huppd Dec 4, 2024
3a1609a
rvert jenkins
huppd Dec 4, 2024
f89dd25
update
huppd Dec 6, 2024
f55f147
add autogen pip
huppd Dec 18, 2024
d8362c6
rm conda requirements
huppd Dec 18, 2024
910d79c
add requirements.txt
huppd Dec 18, 2024
988d8d8
change wf
huppd Dec 18, 2024
b12bedb
update pre-commit
huppd Dec 18, 2024
11912cc
rm setup_miniconda
huppd Dec 18, 2024
7400040
cleanup
huppd Dec 18, 2024
66174c0
update gitignore
huppd Dec 18, 2024
8205772
fix jenkins
huppd Dec 18, 2024
4a50cad
update gitignore
huppd Dec 18, 2024
5bb31b0
fix jenkins
huppd Dec 18, 2024
f4b0378
cleanup
huppd Dec 18, 2024
31ea0b1
fix python module
huppd Dec 18, 2024
4fd1181
fix coverage
huppd Dec 20, 2024
0a4ddae
fix name
huppd Dec 20, 2024
9bac498
fix python version
huppd Dec 20, 2024
d1df993
update readme
huppd Dec 20, 2024
defb7f4
fix typos
huppd Dec 20, 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
9 changes: 4 additions & 5 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[run]
source =
engine/
visualize/
probtest.py
util/
engine
util
visualize
omit =
tests/*
tests/*
15 changes: 5 additions & 10 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,13 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: 3.10.8
- uses: conda-incubator/setup-miniconda@v2
with:
miniconda-version: "latest"
channels: conda-forge
channel-priority: flexible
show-channel-urls: true
- name: Create env from pinned environment
- name: Install dependencies with pip
run: |
conda env create --name dev_env --file requirements/environment.yml
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Install pre-commit hooks
run: |
conda run --name dev_env pre-commit install-hooks
pre-commit install-hooks
- name: Run pre-commit hooks
run: |
conda run --name dev_env pre-commit run --all-files
pre-commit run --all-files
25 changes: 15 additions & 10 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,28 @@ jobs:
defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.10.8
- uses: conda-incubator/setup-miniconda@v2
with:
miniconda-version: "latest"
channels: conda-forge
channel-priority: flexible
show-channel-urls: true
- name: Create env from pinned environment
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
- name: Configure Poetry to use the right Python version
run: |
poetry env use python3.10
- name: Install dependencies with Poetry
run: |
poetry install
- name: Run setup_env for eccodes definition
run: |
./setup_env.sh -n probtest
- name: Run Pytest
poetry run python setup_env.py
- name: Run Pytest with Poetry
env:
TZ: Europe/Zurich
run: |
conda run --name probtest pytest -v -s --cov --cov-report=term tests/
poetry run pytest -v -s --cov --cov-report=term tests/
11 changes: 5 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.coverage
.env
.idea*
.vscode
*pycache*
Expand All @@ -6,12 +8,9 @@
*.png
*.log
*.nc
.coverage
coverage.xml
miniconda
resource

# output from unittest
test_stats.csv
test_stats_csv.csv
test_stats_csv.dat
# output from pytest
random_tolerance.csv
random_tolerance_None.csv
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ repos:
description: Check for spelling errors
language: system
entry: codespell
exclude: tests/data/
exclude: ^(poetry.lock|tests/data/.*)$
args: ['-L astroid,fof']
- repo: local
hooks:
Expand Down
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
| Marek Jacob | DWD |
| Jonas Jucker | C2SM |
| Annika Lauber | C2SM |
| Andrea Leuthard | MeteoSwiss |
| Giacomo Serafini | MeteoSwiss |
| Mikael Stellio | C2SM |
| Ben Weber | MeteoSwiss |
52 changes: 38 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,31 +80,45 @@ Visualize the performance database generated with `performance`.

Even though probtest is used exclusively with ICON at the moment, it does not contain any information about the model or its directory structure. This makes it very flexible and applicable to any circumstance (e.g. usable by Buildbot, Jenkins and human users alike). However, it also requires a lot of information about the model and the data to be processed upon invocation. Since a typical probtest usage involves multiple commands (e.g. run-ensemble -> stats -> tolerance -> check) this leads to a lot of redundancy in the invocation. Therefore, probtest can read commonly used input variables (e.g. the model output directory, the experiment name, the name of the submit script, ...) from a configuration file in json format. To further ease the process, these configuration files can be created from templates using the `init` command. A template for ICON is contained in this repository in the `templates` subdirectory.

### Setup conda
### Setup probtest

All requirements for using probtest can be easily installed with conda using the
setup scripts.
All requirements for using probtest can be easily installed with pip or poetry.

For setting up conda you use
#### Setup with pip
The setup with pip is recommended for users.

For setting up the venv you use
```console
./setup_miniconda.sh -u
python3.10 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
```
which will modify your `.bashrc`, or you can use
To check that everything is setup correctly (note this requires
[eccodes definition](#Setup-the-eccodes-definition)), you can do
```console
./setup_miniconda.sh
source miniconda/bin/activate
pytest -v -s --cov --cov-report=term tests/
```
which requires to source minconda.

The pinned requirements can be installed by
#### Setup with poetry
The setup with poetry is recommended for developers and needed for changing or
adding requirements.
It is assumed you are having a poetry installation.
```console
./setup_env.sh
poetry env use python3.10
poetry install
```
The unpinned requirements and updating the environment can be done by
To check that everything is setup correctly (note this requires
[eccodes definition](#Setup-the-eccodes-definition)), you can do
```console
./setup_env.sh -u -e
poetry run pytest -v -s --cov --cov-report=term tests/
```

#### Setup the eccodes definition
For setting up the eccode definition, you can use
```console
python setup_env.py
```

### The init command

Expand Down Expand Up @@ -138,7 +152,17 @@ here should refer to your experiment script:

```console
cd icon-base-dir/reference-build
python ../externals/probtest/probtest.py init --codebase-install $PWD --experiment-name exp_name --reference $PWD --file-id NetCDF "*atm_3d_ml*.nc" --file-id NetCDF "*atm_3d_il*.nc" --file-id NetCDF "*atm_3d_hl*.nc" --file-id NetCDF "*atm_3d_pl*.nc" --file-id latlon "*atm_2d_ll*.nc" --file-id meteogram "Meteogram*.nc"
python ../externals/probtest/probtest.py init \
--codebase-install $PWD \
--experiment-name exp_name \
--reference $PWD \
--file-id NetCDF "*atm_3d_ml*.nc" \
--file-id NetCDF "*atm_3d_il*.nc" \
--file-id NetCDF "*atm_3d_hl*.nc" \
--file-id NetCDF "*atm_3d_pl*.nc" \
--file-id latlon "*atm_2d_ll*.nc" \
--file-id meteogram "Meteogram*.nc" \
--file-id GRIB "lfff0*z"
```
You might need to update the used account in the json file.
The perturbation amplitude may also need to be changed in the json file
Expand Down
12 changes: 6 additions & 6 deletions engine/cdo_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from util.click_util import CommaSeperatedInts, cli_help
from util.constants import cdo_bins
from util.dataframe_ops import df_from_file_ids
from util.file_system import file_names_from_pattern
from util.file_system import get_file_names_from_pattern
from util.log_handler import logger


Expand Down Expand Up @@ -139,21 +139,21 @@ def cdo_table(
assert isinstance(file_specification, dict), "must be dict"

# save original method and restore at the end of this module
dataframe_from_ncfile_orig = model_output_parser.dataframe_from_ncfile
dataframe_from_ncfile_orig = model_output_parser.create_statistics_dataframe
# modify netcdf parse method:
model_output_parser.dataframe_from_ncfile = rel_diff_stats
model_output_parser.create_statistics_dataframe = rel_diff_stats

# step 1: compute rel-diff netcdf files
with tempfile.TemporaryDirectory() as tmpdir:
for _, file_pattern in file_id:
ref_files, err = file_names_from_pattern(model_output_dir, file_pattern)
ref_files, err = get_file_names_from_pattern(model_output_dir, file_pattern)
if err > 0:
logger.info(
"did not find any files for pattern %s. Continue.", file_pattern
)
continue
ref_files.sort()
perturb_files, err = file_names_from_pattern(
perturb_files, err = get_file_names_from_pattern(
perturbed_model_output_dir.format(member_id=member_id), file_pattern
)
if err > 0:
Expand Down Expand Up @@ -202,4 +202,4 @@ def cdo_table(

Path(cdo_table_file).parent.mkdir(parents=True, exist_ok=True)
df.to_csv(cdo_table_file)
model_output_parser.dataframe_from_ncfile = dataframe_from_ncfile_orig
model_output_parser.create_statistics_dataframe = dataframe_from_ncfile_orig
6 changes: 4 additions & 2 deletions engine/performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import click

from util.click_util import cli_help
from util.file_system import file_names_from_pattern
from util.file_system import get_file_names_from_pattern
from util.icon.extract_timings import read_logfile
from util.log_handler import logger
from util.tree import TREEFILE_TEMPLATE, TimingTree
Expand All @@ -36,7 +36,9 @@ def performance(timing_regex, timing_database, append_time):
if timing_file_name_base == "":
timing_file_name_base = "."

timing_file_name, err = file_names_from_pattern(timing_file_name_base, timing_regex)
timing_file_name, err = get_file_names_from_pattern(
timing_file_name_base, timing_regex
)
if err > 0:
logger.info("Did not find any files for regex %s", timing_regex)
sys.exit(1)
Expand Down
38 changes: 34 additions & 4 deletions jenkins/mergerequest
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,43 @@ pipeline {
}

stages {
stage('Pytest') {
stage('Setup Python Environment') {
steps {
sh'''
source $SCRATCH/project/icon/probtest/conda/miniconda/bin/activate probtest
pytest -v tests/*
sh '''
module use /mch-environment/v7/modules
module load python/3.10.4
python3.10 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
'''
}
}
stage('Run setup_env.py Script') {
steps {
sh '''
source venv/bin/activate
python setup_env.py
'''
}
}
stage('Run Pytest') {
steps {
sh '''
source venv/bin/activate
pytest -v -s --cov --cov-report=term tests/
'''
}
}
}
post {
always {
sh '''
deactivate || true
rm -rf venv
rm -rf .env
rm -rf resource
'''
}
}
}
Loading