standard_names package¶
Submodules¶
standard_names.decorators module¶
standard_names.io module¶
standard_names.registry module¶
-
class
standard_names.registry.NamesRegistry(*args, **kwds)[source]¶ Bases:
objectA registry of CSDMS Standard Names.
Parameters: - paths : str or iterable of str, optional
Name(s) of the data file(s) from which to read. If not given, use a default database. If
None, create an empty registry.- version : str, optional
The version of the names registry.
Examples
>>> from standard_names import NamesRegistry
Get the default set of names.
>>> registry = NamesRegistry() >>> len(registry) > 0 True
Create an empty registry and add a name to it.
>>> registry = NamesRegistry(None) >>> len(registry) 0 >>> registry.add('air__temperature') >>> len(registry) 1
Use the
names,objects,quantities, andoperatorsto get lists of each in the registry.>>> registry.names ('air__temperature',) >>> registry.objects ('air',) >>> registry.quantities ('temperature',) >>> registry.operators ()
You can search the registry for names using the
names_with,match, andsearchmethods.Use
names_withto look for names that contain a given string or strings.>>> registry.add('water__temperature') >>> sorted(registry.names_with('temperature')) ['air__temperature', 'water__temperature'] >>> registry.names_with(['temperature', 'air']) ['air__temperature']
Use
matchto match names using a glob-style pattern.>>> registry.match('air*') ['air__temperature']
Use
searchto do a fuzzy search of the list.>>> registry.search('air__temp') ['air__temperature']
Attributes: versionThe version of the names database.
namesAll names in the registry.
objectsAll objects in the registry.
quantitiesAll quantities in the registry.
operatorsAll operators in the registry.
Methods
add(name)Add a name to the registry. from_path(path)Create a new registry from a text file. match(pattern)Search the registry for names that match a pattern. names_with(parts)Search the registry for names containing words. search(name)Search the registry for a name. -
classmethod
from_path(path)[source]¶ Create a new registry from a text file.
Parameters: - path : str
Path to a text file of Standard Names.
Returns: - NamesRegistry
A newly-created registry filled with names from the file.
-
match(pattern)[source]¶ Search the registry for names that match a pattern.
Parameters: - pattern : str
Glob-style pattern with which to search the registry.
Returns: - list of str
List of names matching the pattern.
-
names¶ All names in the registry.
Returns: - tuple of str
All of the names in the registry.
-
names_with(parts)[source]¶ Search the registry for names containing words.
Parameters: - parts : str or iterable of str
Word(s) to search for.
Returns: - tuple of str
Names from the registry that contains the given words.
-
objects¶ All objects in the registry.
Returns: - tuple of str
All of the objects in the registry.
-
operators¶ All operators in the registry.
Returns: - tuple of str
All of the operators in the registry.
-
quantities¶ All quantities in the registry.
Returns: - tuple of str
All of the quantities in the registry.
-
search(name)[source]¶ Search the registry for a name.
Parameters: - name : str
Name to search for.
Returns: - tuple of str
Names that closely match the given name.
-
version¶ The version of the names database.
Returns: - str
The registry version.
-
standard_names.registry.load_names_from_txt(file_like, onerror='raise')[source]¶ Load names from a text file.
Parameters: - file_like : file-like
A file-like object that represents the contents of a text file (only a
readlinemethod need be available).- onerror : {‘raise’, ‘warn’, ‘pass’}
What to do if a bad name is encountered in the file.
Returns: - set of str
The Standard Names read from the file.
Examples
>>> from six.moves import StringIO >>> import standard_names as csn >>> names = StringIO(""" ... air__temperature ... Water__Temperature ... """) >>> set_of_names = csn.registry.load_names_from_txt(names, onerror='warn') >>> [name.name for name in set_of_names] ['air__temperature']
standard_names.standardname module¶
A CSDMS standard name.
-
class
standard_names.standardname.StandardName(name)[source]¶ Bases:
objectA CSDMS standard name.
Examples
>>> import standard_names as csn >>> name = csn.StandardName('air__temperature')
>>> name == 'air__temperature' True >>> repr(name) "StandardName('air__temperature')"
>>> name.object = 'water' >>> repr(name) "StandardName('water__temperature')"
>>> name.quantity = 'density' >>> repr(name) "StandardName('water__density')"
>>> name.operators = ('max', ) >>> repr(name) "StandardName('water__max_of_density')"
>>> name.operators = 'min' >>> repr(name) "StandardName('water__min_of_density')"
Attributes: Methods
compose_name(object, quantity[, operators])Create a string from the parts of StandardName. decompose_name(name)Decompose a name into its parts. decompose_quantity(quantity_clause)Decompose a quantity into operators and quantities. -
static
compose_name(object, quantity, operators=())[source]¶ Create a string from the parts of StandardName.
Parameters: - object : str
An StandardName object.
- quantity : str
An StandardName quantity.
- operators : iterable of str, optional
Operators applied to the quantity.
Returns: - str
The standard name composed of the given elements.
Examples
>>> import standard_names as csn >>> name = 'atmosphere_air__elevation_angle_of_gradient_of_temperature' >>> parts = csn.StandardName.decompose_name(name) >>> csn.StandardName.compose_name(*parts) == name True >>> csn.StandardName.compose_name('air', 'temperature') 'air__temperature'
-
static
decompose_name(name)[source]¶ Decompose a name into its parts.
Decompose the name standard name string into it’s constituent parts (object, quantity, and operator). Returns a tuple of (object, quantity, operator) where object and quantitiy are strings, and operator is itself a tuple of strings (or empty).
Parameters: - name : str
A CSDMS Standard Name.
Returns: - tuple of str
The parts of a name as
(object, quantity, operators)
Examples
>>> import standard_names as csn >>> name = 'atmosphere_air__elevation_angle_of_gradient_of_temperature' >>> csn.StandardName.decompose_name(name) ('atmosphere_air', 'temperature', ('elevation_angle', 'gradient'))
>>> try: ... StandardName.decompose_name('air_temperature') ... except BadNameError: ... pass
-
static
decompose_quantity(quantity_clause)[source]¶ Decompose a quantity into operators and quantities.
Decompose the quantity_clause string into operator and base quantity constituents. Because multiple operators can act on a quantity, the operators are given as a tuple regardless of the number of operators actually present. Returns the parts of the quantity as a tuple of (operators, base_quantity)
Parameters: - quantity_clause : str
A CSDMS Standard Name quantity.
Returns: - tuple of str
The parts of the quantity as
(operators, quantity).
-
name¶ The full standard name as a string.
-
object¶ The object part of the standard name.
-
operators¶ The operator part of the standard name.
-
quantity¶ The quantity part of the standard name.
-
re= '^[a-z]([a-zA-Z0-9~-]|_(?!_))*(__)[a-z0-9]([a-z0-9~-]|_(?!_))*[a-z0-9]$'¶
-
static
Module contents¶
The CSDMS Standard Names