Skip to content

Commit

Permalink
Merge branch 'develop' into domain_variables_cell_measures_coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
benjwadams authored Dec 6, 2024
2 parents d9ee493 + beef6fb commit cee1b39
Show file tree
Hide file tree
Showing 31 changed files with 1,163 additions and 361 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cc-plugin-glider-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v4

- name: Setup Micromamba
uses: mamba-org/setup-micromamba@v1
uses: mamba-org/setup-micromamba@v2
with:
environment-name: TEST
init-shell: bash
Expand All @@ -33,6 +33,6 @@ jobs:
git clone https://github.com/ioos/cc-plugin-glider.git
&& cd cc-plugin-glider
&& micromamba install --file requirements.txt --file requirements-dev.txt --channel conda-forge
&& micromamba remove compliance-checker --no-prune --force
&& micromamba remove compliance-checker --no-prune-deps --force
&& python -m pip install -e . --no-deps --force-reinstall
&& python -m pytest -s -rxs -v cc_plugin_glider
4 changes: 2 additions & 2 deletions .github/workflows/cc-plugin-ncei-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v4

- name: Setup Micromamba
uses: mamba-org/setup-micromamba@v1
uses: mamba-org/setup-micromamba@v2
with:
environment-name: TEST
init-shell: bash
Expand All @@ -33,6 +33,6 @@ jobs:
git clone https://github.com/ioos/cc-plugin-ncei.git
&& cd cc-plugin-ncei
&& micromamba install --file requirements.txt --file requirements-dev.txt --channel conda-forge
&& micromamba remove compliance-checker --no-prune --force
&& micromamba remove compliance-checker --no-prune-deps --force
&& python -m pip install -e . --no-deps --force-reinstall
&& python -m pytest -s -rxs -v cc_plugin_ncei
4 changes: 2 additions & 2 deletions .github/workflows/cc-plugin-og-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v4

- name: Setup Micromamba
uses: mamba-org/setup-micromamba@v1
uses: mamba-org/setup-micromamba@v2
with:
environment-name: TEST
init-shell: bash
Expand All @@ -33,6 +33,6 @@ jobs:
git clone https://github.com/uw-farlab/cc-plugin-og.git
&& cd cc-plugin-og
&& micromamba install --file requirements.txt --channel conda-forge
&& micromamba remove compliance-checker --no-prune --force
&& micromamba remove compliance-checker --no-prune-deps --force
&& python -m pip install -e . --no-deps --force-reinstall
&& python -m pytest -s -rxs -v cc_plugin_og
4 changes: 2 additions & 2 deletions .github/workflows/cc-plugin-sgrid-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v4

- name: Setup Micromamba
uses: mamba-org/setup-micromamba@v1
uses: mamba-org/setup-micromamba@v2
with:
environment-name: TEST
init-shell: bash
Expand All @@ -33,6 +33,6 @@ jobs:
git clone https://github.com/ioos/cc-plugin-sgrid.git
&& cd cc-plugin-sgrid
&& micromamba install --file requirements.txt --file requirements-dev.txt --channel conda-forge
&& micromamba remove compliance-checker --no-prune --force
&& micromamba remove compliance-checker --no-prune-deps --force
&& python -m pip install -e . --no-deps --force-reinstall
&& python -m pytest -s -rxs -v cc_plugin_sgrid
4 changes: 2 additions & 2 deletions .github/workflows/cc-plugin-ugrid-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v4

- name: Setup Micromamba
uses: mamba-org/setup-micromamba@v1
uses: mamba-org/setup-micromamba@v2
with:
environment-name: TEST
init-shell: bash
Expand All @@ -33,6 +33,6 @@ jobs:
git clone https://github.com/ioos/cc-checker-ugrid.git
&& cd cc-checker-ugrid
&& micromamba install --file requirements.txt --file requirements-dev.txt --channel conda-forge
&& micromamba remove compliance-checker --no-prune --force
&& micromamba remove compliance-checker --no-prune-deps --force
&& python -m pip install -e . --no-deps --force-reinstall
&& python -m pytest -s -rxs -v cc_plugin_ugrid
4 changes: 2 additions & 2 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v4

- name: Setup Micromamba
uses: mamba-org/setup-micromamba@v1
uses: mamba-org/setup-micromamba@v2
with:
environment-name: TEST
init-shell: bash
Expand All @@ -37,6 +37,6 @@ jobs:
continue-on-error: true

- name: Upload to codecov
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v5
with:
files: coverage.xml
16 changes: 3 additions & 13 deletions .github/workflows/default-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [windows-latest, ubuntu-latest, macos-latest]
experimental: [false]
include:
- python-version: "3.12"
os: "ubuntu-latest"
experimental: true
python-version: [ "3.10", "3.11", "3.12", "3.13" ]
os: [ windows-latest, ubuntu-latest, macos-latest ]
fail-fast: false
defaults:
run:
Expand All @@ -25,7 +20,7 @@ jobs:
- uses: actions/checkout@v4

- name: Setup Micromamba ${{ matrix.python-version }}
uses: mamba-org/setup-micromamba@v1
uses: mamba-org/setup-micromamba@v2
with:
environment-name: TEST
init-shell: bash
Expand All @@ -35,11 +30,6 @@ jobs:
--file test_requirements.txt
--channel conda-forge
- name: Install unstable dependencies
if: matrix.experimental == true
run: |
micromamba install conda-forge/label/numpy_dev::numpy
- name: Install compliance-checker
run: |
python -m pip install -e . --no-deps --force-reinstall
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fetch-depth: 0

- name: Setup Micromamba
uses: mamba-org/setup-micromamba@v1
uses: mamba-org/setup-micromamba@v2
with:
environment-name: TEST
init-shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v4

- name: Setup Micromamba
uses: mamba-org/setup-micromamba@v1
uses: mamba-org/setup-micromamba@v2
with:
environment-name: TEST
init-shell: bash
Expand Down
13 changes: 7 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
exclude: compliance_checker/tests/data
Expand All @@ -19,7 +19,7 @@ repos:
- test_requirements.txt

- repo: https://github.com/psf/black
rev: 24.4.2
rev: 24.10.0
hooks:
- id: black
language_version: python3
Expand All @@ -31,21 +31,22 @@ repos:


- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.5
rev: v0.8.1
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]

- repo: https://github.com/tox-dev/pyproject-fmt
rev: 2.1.3
rev: v2.5.0
hooks:
- id: pyproject-fmt

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
rev: v2.3.0
hooks:
- id: codespell
args:
- --ignore-words-list=degreeE,degreee,varn,poit,uint,sur,herat,claus,tung,messsages
- --ignore-words-list=degreeE,degreee,varn,poit,uint,sur,herat,claus,tung,messsages,assertin
exclude: >
(?x)^(
.*\.xml|
Expand Down
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ It currently supports the following sources and standards:
| Standard | Source | .nc/OPeNDAP/.cdl | SOS |
| ---------------------------------------------------------------------------------------------------- | ----------- | ------ | ------------------------------- |
| [ACDD (1.1, 1.3)](https://wiki.esipfed.org/Attribute_Convention_for_Data_Discovery_1-3) | Built-in | X | - |
| [CF (1.9)](http://cfconventions.org/Data/cf-conventions/cf-conventions-1.9/cf-conventions.html) | Built-in | X | - |
| [CF (1.8)](http://cfconventions.org/Data/cf-conventions/cf-conventions-1.8/cf-conventions.html) | Built-in | X | - |
| [CF (1.7)](http://cfconventions.org/Data/cf-conventions/cf-conventions-1.7/cf-conventions.html) | Built-in | X | - |
| [CF (1.6)](http://cfconventions.org/cf-conventions/v1.6.0/cf-conventions.html) | Built-in | X | - |
Expand Down Expand Up @@ -204,9 +205,10 @@ optional arguments:

### Check a local file against CF 1.6
```
$ compliance-checker --test=cf:1.6 compliance_checker/tests/data/examples/hycom_global.nc
compliance-checker --test=cf:1.6 compliance_checker/tests/data/examples/hycom_global.nc
```

```
--------------------------------------------------------------------------------
IOOS Compliance Checker Report
cf:1.6 check
Expand Down Expand Up @@ -247,15 +249,15 @@ contains valid packing: are not of type float or double.
The remote dataset url is taken from the Data URL section of an OPeNDAP endpoint.

```shell
$ compliance-checker --test=acdd:1.3 "http://sos.maracoos.org/stable/dodsC/hrecos/stationHRMARPH-agg.ncml"
compliance-checker --test=acdd:1.3 "http://sos.maracoos.org/stable/dodsC/hrecos/stationHRMARPH-agg.ncml"
```

### Checking against remote ERDDAP Datasets

ERDDAP datasets are becoming a popular way to access data. Supply an ERDDAP `TableDAP` or `GridDAP` URL to the checker:

```shell
$ compliance-checker --test ioos:1.2 "https://pae-paha.pacioos.hawaii.edu/erddap/griddap/pibhmc_bathy_60m_guam"
compliance-checker --test ioos:1.2 "https://pae-paha.pacioos.hawaii.edu/erddap/griddap/pibhmc_bathy_60m_guam"
```

Ensure to supply the URL *without* the format extension at the end (no `.nc`, `.ncCF`, etc.).
Expand All @@ -276,37 +278,37 @@ Some examples of ERDDAP datasets:
### Write results to text file

```shell
$ compliance-checker --test=acdd:1.3 --format=text --output=/tmp/report.txt compliance_checker/tests/data/examples/hycom_global.nc
compliance-checker --test=acdd:1.3 --format=text --output=/tmp/report.txt compliance_checker/tests/data/examples/hycom_global.nc
```

### Write results to JSON file

```shell
$ compliance-checker --test=acdd:1.3 --format=json --output=/tmp/report.json compliance_checker/tests/data/examples/hycom_global.nc
compliance-checker --test=acdd:1.3 --format=json --output=/tmp/report.json compliance_checker/tests/data/examples/hycom_global.nc
```

### Write results to HTML file

```shell
$ compliance-checker --test=acdd:1.3 --format=html --output=/tmp/report.html compliance_checker/tests/data/examples/hycom_global.nc
compliance-checker --test=acdd:1.3 --format=html --output=/tmp/report.html compliance_checker/tests/data/examples/hycom_global.nc
```

### Output text from multiple input files to one output file

```
$ compliance-checker --test=cf:1.6 --format text --output=/tmp/combined_output.txt compliance_checker/tests/data/examples/hycom_global.nc compliance_checker/tests/data/examples/ww3.nc
compliance-checker --test=cf:1.6 --format text --output=/tmp/combined_output.txt compliance_checker/tests/data/examples/hycom_global.nc compliance_checker/tests/data/examples/ww3.nc
```

### Output html and text files from multiple input files (part 1)
In this case you'll get 2 files ```/tmp/combined_output.txt``` and ```/tmp/combined_output.html``` that contain cf check results for both input files because you only specified 1 output filename.
```
$ compliance-checker --test=cf:1.6 --format text --format html --output=/tmp/combined_output.txt compliance_checker/tests/data/examples/hycom_global.nc compliance_checker/tests/data/examples/ww3.nc
compliance-checker --test=cf:1.6 --format text --format html --output=/tmp/combined_output.txt compliance_checker/tests/data/examples/hycom_global.nc compliance_checker/tests/data/examples/ww3.nc
```

### Output html and text files from multiple input files (part 2)
In this case you'll get 4 files ```/tmp/hycom.txt```, ```/tmp/hycom.html```, ```/tmp/ww3.txt```, and ```/tmp/ww3.html``` that contain cf check results because you specified as many output filenames as input filenames.
```
$ compliance-checker --test=cf:1.6 --format text --format html --output=/tmp/hycom.txt --output=/tmp/ww3.txt compliance_checker/tests/data/examples/hycom_global.nc compliance_checker/tests/data/examples/ww3.nc
compliance-checker --test=cf:1.6 --format text --format html --output=/tmp/hycom.txt --output=/tmp/ww3.txt compliance_checker/tests/data/examples/hycom_global.nc compliance_checker/tests/data/examples/ww3.nc
```

### Download a particular CF standard names table for use in the test
Expand All @@ -317,7 +319,8 @@ During the CF test, if a file has a particular version of the cf standard name t
try to download the specified version. If it fails, it will fall back to packaged version.

```
$ compliance-checker -d 35
compliance-checker -d 35
```

Downloading cf-standard-names table version 35 from: http://cfconventions.org/Data/cf-standard-names/35/src/cf-standard-name-table.xml
```
Expand Down
23 changes: 14 additions & 9 deletions cchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,25 @@ def _print_checker_name_header(checker_str):

def parse_options(opts):
"""
Helper function to parse possible options. Splits option after the first
colon to split into key/value pairs.
Helper function to parse possible options. Splits option into key/value
pairs and optionally a value for the checker option. The separator
is a colon.
:param opts: Iterable of strings with options
:rtype: dict
:return: Dictionary with keys as checker type (i.e. "cf", "acdd")
:return: Dictionary with keys as checker type (i.e. "cf", "acdd").
Each value is a dictionary where keys are checker options and values
are checker option values or None if not provided.
"""
options_dict = defaultdict(set)
options_dict = defaultdict(dict)
for opt_str in opts:
try:
checker_type, checker_opt = opt_str.split(":", 1)
checker_type, checker_opt, *checker_val = opt_str.split(":", 2)
checker_val = checker_val[0] if checker_val else None
except ValueError:
warnings.warn(f"Could not split option {opt_str}, ignoring", stacklevel=2)
else:
options_dict[checker_type].add(checker_opt)
options_dict[checker_type][checker_opt] = checker_val
return options_dict


Expand Down Expand Up @@ -174,8 +178,9 @@ def main():
checkers. Multiple options can be specified
via multiple invocations of this switch.
Options should be prefixed with a the
checker name followed by the option, e.g.
'<checker>:<option_name>'
checker name followed by the option,
potentially followed by a value, e.g.
'<checker>:<option_name>[:<option_value>]'
Available options:
'cf:enable_appendix_a_checks' - Allow check
Expand Down Expand Up @@ -235,7 +240,7 @@ def main():
print(f"IOOS compliance checker version {__version__}")
sys.exit(0)

options_dict = parse_options(args.option) if args.option else defaultdict(set)
options_dict = parse_options(args.option) if args.option else defaultdict(dict)

if args.describe_checks:
error_stat = 0
Expand Down
3 changes: 2 additions & 1 deletion compliance_checker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections.abc import Generator
from contextlib import contextmanager
from tempfile import NamedTemporaryFile
from typing import BinaryIO, Generator
from typing import BinaryIO

try:
from ._version import __version__
Expand Down
4 changes: 2 additions & 2 deletions compliance_checker/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

# Python 3.5+ should work, also have a fallback
try:
from typing import Pattern
from re import Pattern

re_pattern_type = Pattern
except ImportError:
Expand Down Expand Up @@ -157,7 +157,7 @@ def setup(self, ds):
def __init__(self, options=None):
self._defined_results = defaultdict(lambda: defaultdict(dict))
if options is None:
self.options = set()
self.options = {}
else:
self.options = options

Expand Down
Loading

0 comments on commit cee1b39

Please sign in to comment.