Skip to content

Commit

Permalink
Merge pull request #98 from bopen/compliance-checker
Browse files Browse the repository at this point in the history
Add one CF compliance checker
  • Loading branch information
alexamici authored Mar 27, 2022
2 parents aee310c + fa37e83 commit 3899a86
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 2 deletions.
2 changes: 1 addition & 1 deletion environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ channels:
dependencies:
- adlfs
- build
- cfchecker
- gcsfs
- ipytree
- matplotlib
- mamba
- notebook
- sentinelsat

File renamed without changes.
76 changes: 76 additions & 0 deletions tests/slow_test_50_cfchecker.py
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

14 changes: 13 additions & 1 deletion xarray_sentinel/conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"gamma": {"units": "m m-1", "long_name": "gamma calibration LUT"},
"dn": {"units": "1", "long_name": "original digital number calibration LUT"},
"noiseRangeLut": {"units": "1", "long_name": "range thermal noise correction LUT"},
"noiseAzimithLut": {
"noiseAzimuthLut": {
"units": "1",
"long_name": "azimuth thermal noise correction LUT",
},
Expand All @@ -96,6 +96,18 @@
"units": "1",
"long_name": "polynomial to convert from slant range to ground range",
},
"t0": {
"units": "s",
"long_name": "Two-way slant range time origin",
},
"data_dc_polynomial": {
"units": "1",
"long_name": "Coppler centroid estimated from data",
},
"azimuth_fm_rate_polynomial": {
"units": "1",
"long_name": "Azimuth FM rate coefficient array",
},
"measurement": {"units": "1", "long_name": "digital number"},
}

Expand Down

0 comments on commit 3899a86

Please sign in to comment.