Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
# SPOC
# SPOC
Specific Preprocessing of Observations Configuration

This repository holds template configuration files, supporting scripts, and any other infrastructure needed to both convert observations to the JEDI IODA format offline as well as read them directly in JEDI applications.
This repository holds template configuration files, supporting scripts,
and other infrastructure needed to convert observations to the JEDI IODA
format offline as well as read them directly in JEDI applications.

## Testing

PyTest based regression tests reside in the `tests/` directory. Sample
BUFR inputs and reference NetCDF outputs are required to execute the
tests. Place the files in `tests/data` and `tests/baseline` and run:

```
pytest -v
```
14 changes: 14 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
The `tests` directory contains regression tests for SPOC mapping modules
using the `pytest` framework.

Sample BUFR inputs and reference NetCDF outputs are not provided in the
repository. They must be placed under `tests/data` and `tests/baseline`
respectively before the tests can be executed. The tests will be skipped
if the required files are not found or if the necessary dependencies
(e.g. `numpy`, `bufr`, `pyioda`, and the `nccmp` utility) are missing.

Run all tests with:

```
pytest -v
```
Empty file added tests/__init__.py
Empty file.
1 change: 1 addition & 0 deletions tests/baseline/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Place reference NetCDF files here
1 change: 1 addition & 0 deletions tests/data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Place BUFR sample files here
52 changes: 52 additions & 0 deletions tests/test_interfaces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import importlib
import os
import subprocess
import shutil
import pytest

# Define mapping specifications: module path, input BUFR, mapping yaml, baseline NetCDF
MAPPING_SPECS = [
{
'module': 'dump.mapping.bufr_adpupa_prepbufr',
'input': os.path.join('tests', 'data', 'adpupa.bufr'),
'mapping': os.path.join('dump', 'mapping', 'bufr_adpupa_prepbufr_mapping.yaml'),
'baseline': os.path.join('tests', 'baseline', 'adpupa.nc'),
'cycle': '2021010100',
},
]

required_packages = ['numpy', 'bufr', 'pyioda']


def require_dependencies():
"""Skip tests if required packages or tools are missing."""
for pkg in required_packages:
pytest.importorskip(pkg)
if shutil.which('nccmp') is None:
pytest.skip('nccmp utility not available')


@pytest.mark.parametrize('spec', MAPPING_SPECS, ids=[spec['module'] for spec in MAPPING_SPECS])
def test_create_obs_file(spec, tmp_path):
require_dependencies()
if not os.path.exists(spec['input']) or not os.path.exists(spec['baseline']):
pytest.skip('Sample data not available')

mod = importlib.import_module(spec['module'])
output = tmp_path / 'out.nc'

mod.create_obs_file(spec['input'], spec['mapping'], str(output), spec['cycle'])
result = subprocess.run(['nccmp', '-d', str(output), spec['baseline']])
assert result.returncode == 0


@pytest.mark.parametrize('spec', MAPPING_SPECS, ids=[spec['module'] for spec in MAPPING_SPECS])
def test_create_obs_group(spec):
require_dependencies()
if not os.path.exists(spec['input']):
pytest.skip('Sample data not available')

mod = importlib.import_module(spec['module'])
env = {'comm_name': 'world'}
group = mod.create_obs_group(spec['input'], spec['mapping'], spec['cycle'], env)
assert group is not None