-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from bopen/compliance-checker
Add one CF compliance checker
- Loading branch information
Showing
4 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import pathlib | ||
import typing as T | ||
|
||
from cfchecker import cfchecks | ||
import pytest | ||
import xarray as xr | ||
|
||
pytest.importorskip("netCDF4") | ||
|
||
DATA_FOLDER = pathlib.Path(__file__).parent / "data" | ||
|
||
|
||
def cfcheck(path: str): | ||
( | ||
badc, | ||
coards, | ||
debug, | ||
uploader, | ||
useFileName, | ||
regionnames, | ||
standardName, | ||
areaTypes, | ||
cacheDir, | ||
cacheTables, | ||
cacheTime, | ||
version, | ||
files, | ||
) = cfchecks.getargs(["cfchecks", path]) | ||
|
||
inst = cfchecks.CFChecker( | ||
uploader=uploader, | ||
useFileName=useFileName, | ||
badc=badc, | ||
coards=coards, | ||
cfRegionNamesXML=regionnames, | ||
cfStandardNamesXML=standardName, | ||
cfAreaTypesXML=areaTypes, | ||
cacheDir=cacheDir, | ||
cacheTables=cacheTables, | ||
cacheTime=cacheTime, | ||
version=version, | ||
debug=debug, | ||
) | ||
for file in files: | ||
try: | ||
inst.checker(file) | ||
except cfchecks.FatalCheckerError: | ||
print("Checking of file %s aborted due to error" % file) | ||
|
||
totals = inst.get_total_counts() | ||
|
||
return totals | ||
|
||
|
||
def test_cfcheck(tmpdir: T.Any) -> None: | ||
product_path = ( | ||
DATA_FOLDER | ||
/ "S1B_IW_GRDH_1SDV_20211223T051122_20211223T051147_030148_039993_5371.SAFE" | ||
) | ||
|
||
groups = [""] | ||
while groups: | ||
group = groups.pop() | ||
print(group) | ||
try: | ||
ds = xr.open_dataset(product_path, engine="sentinel-1", group=group) | ||
groups.extend(f"{group}/{g}" for g in ds.attrs.get("subgroups", [])) | ||
except: | ||
pass | ||
nc_path = tmpdir.join(group.replace("/", "-") + ".nc") | ||
ds.to_netcdf(nc_path) | ||
|
||
totals = cfcheck(str(nc_path)) | ||
|
||
assert totals["FATAL"] + totals["ERROR"] + totals["WARN"] == 0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters