Repository: ioos/compliance-checker

Issue:
Errors while running Compliance Checker
Here are the two Error messages for the two files:

```
(compliance-checker)➜  compliance-checker git:(master) compliance-checker ~/Downloads/CP02PMCI-WFP01-03-CTDPFK000-recovered-ctdpf_ckl_wfp_instrument_recovered_1.nc -t cf -v --criteria strict
Running Compliance Checker on the dataset from: /Users/danielmaher/Downloads/CP02PMCI-WFP01-03-CTDPFK000-recovered-ctdpf_ckl_wfp_instrument_recovered_1.nc
Traceback (most recent call last):
  File "/Users/danielmaher/.virtualenvs/compliance-checker/bin/compliance-checker", line 9, in <module>
    load_entry_point('compliance-checker==1.0.0', 'console_scripts', 'compliance-checker')()
  File "/Users/danielmaher/.virtualenvs/compliance-checker/bin/cchecker.py", line 21, in main
    args.criteria)
  File "/Users/danielmaher/work/compliance-checker/compliance_checker/runner.py", line 39, in run_checker
    score_groups = cs.run(ds, *checker_names)
  File "/Users/danielmaher/work/compliance-checker/compliance_checker/suite.py", line 87, in run
    vals = list(itertools.chain.from_iterable(map(lambda c: self._run_check(c, dsp), checks)))
  File "/Users/danielmaher/work/compliance-checker/compliance_checker/suite.py", line 87, in <lambda>
    vals = list(itertools.chain.from_iterable(map(lambda c: self._run_check(c, dsp), checks)))
  File "/Users/danielmaher/work/compliance-checker/compliance_checker/suite.py", line 31, in _run_check
    val = check_method(ds)
  File "/Users/danielmaher/work/compliance-checker/compliance_checker/cf/cf.py", line 502, in check_units
    if v.dtype.char == 'S':
AttributeError: type object 'str' has no attribute 'char'
```

```
(compliance-checker)➜  compliance-checker git:(master) compliance-checker ~/Downloads/derived_1.nc -t cf -v --criteria strict
Running Compliance Checker on the dataset from: /Users/danielmaher/Downloads/derived_1.nc
Traceback (most recent call last):
  File "/Users/danielmaher/.virtualenvs/compliance-checker/bin/compliance-checker", line 9, in <module>
    load_entry_point('compliance-checker==1.0.0', 'console_scripts', 'compliance-checker')()
  File "/Users/danielmaher/.virtualenvs/compliance-checker/bin/cchecker.py", line 21, in main
    args.criteria)
  File "/Users/danielmaher/work/compliance-checker/compliance_checker/runner.py", line 39, in run_checker
    score_groups = cs.run(ds, *checker_names)
  File "/Users/danielmaher/work/compliance-checker/compliance_checker/suite.py", line 83, in run
    dsp = checker.load_datapair(ds)
  File "/Users/danielmaher/work/compliance-checker/compliance_checker/base.py", line 77, in load_datapair
    data_object = NetCDFDogma('ds', self.beliefs(), ds, namespaces=namespaces)
  File "/Users/danielmaher/.virtualenvs/compliance-checker/lib/python2.7/site-packages/wicken/dogma.py", line 136, in __call__
    obj = super(MetaReligion, clsType).__call__(religion, beliefs, *args, **kwargs)
  File "/Users/danielmaher/.virtualenvs/compliance-checker/lib/python2.7/site-packages/wicken/netcdf_dogma.py", line 45, in __init__
    root = parse_nc_dataset_as_etree(dataObject)
  File "/Users/danielmaher/.virtualenvs/compliance-checker/lib/python2.7/site-packages/petulantbear/netcdf_etree.py", line 443, in parse_nc_dataset_as_etree
    dataset2ncml_buffer(dataset,output)
  File "/Users/danielmaher/.virtualenvs/compliance-checker/lib/python2.7/site-packages/petulantbear/netcdf2ncml.py", line 241, in dataset2ncml_buffer
    parse_var(output, var, indent)
  File "/Users/danielmaher/.virtualenvs/compliance-checker/lib/python2.7/site-packages/petulantbear/netcdf2ncml.py", line 179, in parse_var
    parse_att(output,(attname,var.getncattr(attname)), new_indent)
  File "/Users/danielmaher/.virtualenvs/compliance-checker/lib/python2.7/site-packages/petulantbear/netcdf2ncml.py", line 124, in parse_att
    attvalue=sanatize(att[1])
UnicodeEncodeError: 'ascii' codec can't encode character u'\xb0' in position 184: ordinal not in range(128)
```

Are the files to blame or is the compliance checker not robust enough?

I can't attach the files (Git Hub issue), but you can message me on here and get my email address.



Discussion:
Looks like an environment problem.  `sanatize` was renamed up in ioos/petulant-bear@b615ccbed5698882c9c, released in [petulant-bear 1.3](https://github.com/ioos/petulant-bear/releases/tag/v0.1.3).   Update and see if that clears it up.

Fixed the second one, but the same error pops back up from the first

```
compliance-checker ~/Downloads/derived_1.nc -t cf -v --criteria strict
Running Compliance Checker on the dataset from: /Users/danielmaher/Downloads/derived_1.nc
Traceback (most recent call last):
  File "/Users/danielmaher/.virtualenvs/compliance-checker/bin/compliance-checker", line 9, in <module>
    load_entry_point('compliance-checker==1.0.0', 'console_scripts', 'compliance-checker')()
  File "/Users/danielmaher/.virtualenvs/compliance-checker/bin/cchecker.py", line 21, in main
    args.criteria)
  File "/Users/danielmaher/work/compliance-checker/compliance_checker/runner.py", line 39, in run_checker
    score_groups = cs.run(ds, *checker_names)
  File "/Users/danielmaher/work/compliance-checker/compliance_checker/suite.py", line 87, in run
    vals = list(itertools.chain.from_iterable(map(lambda c: self._run_check(c, dsp), checks)))
  File "/Users/danielmaher/work/compliance-checker/compliance_checker/suite.py", line 87, in <lambda>
    vals = list(itertools.chain.from_iterable(map(lambda c: self._run_check(c, dsp), checks)))
  File "/Users/danielmaher/work/compliance-checker/compliance_checker/suite.py", line 31, in _run_check
    val = check_method(ds)
  File "/Users/danielmaher/work/compliance-checker/compliance_checker/cf/cf.py", line 502, in check_units
    if v.dtype.char == 'S':
AttributeError: type object 'str' has no attribute 'char'
```

Also, I would not recommend including your email in public commit messages. There are spam scrapers all over the world that scrape emails from public forums like this and add you to their mailing lists. So... enjoy the ads for viagra!

Looking at derived_1.nc, the variable in question is `l0_provenance_data` with a type of String.  NetCDF4 gives the dtype as a straight up `str` instead of a `dtype(...)` like the rest of the code expects.  @lukecampbell do you think this is a NetCDF issue or just a quirk to deal with?

``` python
In [3]: ds.variables['l0_provenance_data']
Out[3]: 
<type 'netCDF4._netCDF4.Variable'>
vlen l0_provenance_data(l0_provenance)
vlen data type: <type 'str'>
unlimited dimensions: 
current shape = (1,)

In [4]: ds.variables['l0_provenance_data'].dtype
Out[4]: str

In [6]: ds.variables['l0_provenance_keys'].dtype
Out[6]: dtype('S1')
```


Resolving patch:
diff --git a/compliance_checker/cf/cf.py b/compliance_checker/cf/cf.py
--- a/compliance_checker/cf/cf.py
+++ b/compliance_checker/cf/cf.py
@@ -490,7 +490,7 @@ def check_units(self, ds):
                continue
 
             # skip string type vars
-            if v.dtype.char == 'S':
+            if (isinstance(v.dtype, type) and issubclass(v.dtype, basestring)) or v.dtype.char == 'S':
                 continue
             
             # skip quality control vars


Test patch: