Create the “standard_names” vocab

This section demonstrates setting up a vocabulary for CF standard_names to be used with known OMSA servers and assuming a set of variables of interest. These vocabularies can then be saved and combined to create one for regular use, or used individually, or input together to OMSA.run().

The workflow for making the vocabulary is to

  1. enter the variable nickname in the first text box

  2. enter strings to include and exclude to filter the list of variable names down

  3. select however many options that will be used as exact matches to be equivalent to your variable

  4. click save

  5. repeat with each variable for vocabulary

  6. save to disk

Shown below is example use of the built-in widget for selecting one variable in the given vocabulary, and then something similar was done for all the other variables. (The widget can be saved to html and show the last state but not to fully function without a kernel.)

import cf_pandas as cfp
import ocean_model_skill_assessor as omsa

CF Standard Names

In the best case scenarios, model and data variables will have a standard_name associated with them, so we create a vocabulary that can be used to exactly match those names. Even if a given server or file doesn’t include many of these variables, they will be matched if present.

sn = cfp.standard_names()
w = cfp.Selector(options=sn)
---------------------------------------------------------------------------
FeatureNotFound                           Traceback (most recent call last)
Cell In[2], line 1
----> 1 sn = cfp.standard_names()
      2 w = cfp.Selector(options=sn)

File ~/checkouts/readthedocs.org/user_builds/ocean-model-skill-assessor/conda/latest/lib/python3.9/site-packages/cf_pandas/utils.py:152, in standard_names()
    150 url = "https://cfconventions.org/Data/cf-standard-names/79/src/cf-standard-name-table.xml"
    151 req = requests.get(url)
--> 152 soup = BeautifulSoup(req.content, features="xml")
    154 standard_names = [entry.get("id") for entry in soup.find_all("entry")]
    156 return standard_names

File ~/checkouts/readthedocs.org/user_builds/ocean-model-skill-assessor/conda/latest/lib/python3.9/site-packages/bs4/__init__.py:250, in BeautifulSoup.__init__(self, markup, features, builder, parse_only, from_encoding, exclude_encodings, element_classes, **kwargs)
    248     builder_class = builder_registry.lookup(*features)
    249     if builder_class is None:
--> 250         raise FeatureNotFound(
    251             "Couldn't find a tree builder with the features you "
    252             "requested: %s. Do you need to install a parser library?"
    253             % ",".join(features))
    255 # At this point either we have a TreeBuilder instance in
    256 # builder, or we have a builder_class that we can instantiate
    257 # with the remaining **kwargs.
    258 if builder is None:

FeatureNotFound: Couldn't find a tree builder with the features you requested: xml. Do you need to install a parser library?
# w.vocab.save(omsa.VOCAB_PATH("standard_names"))