standard_names.cmd package¶
Submodules¶
standard_names.cmd.snbuild module¶
- Example usage:
- snbuild data/models.yaml data/scraped.yaml > standard_names/data/standard_names.yaml
-
standard_names.cmd.snbuild.
main
(args=None)[source]¶ Build a list of CSDMS standard names for YAML description files.
-
standard_names.cmd.snbuild.
snbuild
(file, newline=None)[source]¶ Build a YAML-formatted database of names.
Parameters: - file : str
Text file of names.
- newline : str, optional
Newline character to use for output.
Returns: - str
YAML-formatted text of the names database.
Examples
>>> from __future__ import print_function >>> import os >>> from six.moves import StringIO >>> import standard_names as csn
>>> lines = os.linesep.join(['air__temperature', 'water__temperature']) >>> names = StringIO(lines)
>>> print(csn.cmd.snbuild.snbuild(names, newline='\n')) %YAML 1.2 --- names: - air__temperature - water__temperature --- objects: - air - water --- quantities: - temperature --- operators: [] ...
standard_names.cmd.sndump module¶
- Example usage:
- sndump -n -o -q -op –format=wiki > standard_names.wiki
-
class
standard_names.cmd.sndump.
CustomAction
(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]¶ Bases:
argparse.Action
Keep track of the order of options are given on the command line.
Methods
__call__
-
standard_names.cmd.sndump.
main
(args=None)[source]¶ Dump a list of known standard names.
Parameters: - args : iterable of str, optional
Arguments to pass to parse_args. If not provided, use
sys.argv
.
Examples
>>> import os >>> import standard_names as csn >>> (fname, _) = csn.registry._get_latest_names_file() >>> registry = csn.NamesRegistry()
>>> names = csn.cmd.sndump.main(['-n', fname]).split(os.linesep) >>> len(names) == len(registry) True
>>> objects = csn.cmd.sndump.main(['-o', fname]).split(os.linesep) >>> len(objects) == len(registry.objects) True
>>> names = csn.cmd.sndump.main(['-n', '-o', fname]).split(os.linesep) >>> len(names) == len(registry) + len(registry.objects) True
-
standard_names.cmd.sndump.
sndump
(file=None, format='plain', sorted=True, keys=None, newline=None)[source]¶ Dump a registry to different formats.
Parameters: - file : str, optional
Name of a registry file of names.
- format : {‘plain’}, optional
Output format.
- sorted : bool, optional
Sort results.
- keys : {‘names, ‘objects’, ‘quantities’, ‘operators’} or iterable
Standard Name element or elements to print.
- newline : str, optional
Specify the newline character to use for output.
Examples
>>> from __future__ import print_function >>> import os >>> from six.moves import StringIO >>> import standard_names as csn
>>> lines = os.linesep.join(['air__temperature', 'water__temperature']) >>> names = StringIO(lines)
>>> print(csn.cmd.sndump.sndump(names, newline='\n')) ... air__temperature water__temperature
standard_names.cmd.snscrape module¶
- Example usage:
- snscrape http://csdms.colorado.edu/wiki/CSN_Quantity_Templates http://csdms.colorado.edu/wiki/CSN_Object_Templates http://csdms.colorado.edu/wiki/CSN_Operation_Templates > data/scraped.yaml
-
standard_names.cmd.snscrape.
main
(args=None)[source]¶ Scrape standard names from a file or URL.
Examples
>>> import os >>> import tempfile >>> import standard_names as csn
>>> contents = """ ... A file with text and names (air__temperature) mixed in. Some names ... have double underscores (like, Water__Temperature) by are not ... valid names. Others, like water__temperature, are good. ... """
>>> (fd, fname) = tempfile.mkstemp() >>> os.close(fd)
>>> with open(fname, 'w') as fp: ... print(contents, file=fp)
>>> names = csn.cmd.snscrape.main( ... [fp.name, '--reader=plain_text', '--no-headers']) >>> names.split(os.linesep) ['air__temperature', 'water__temperature']
>>> os.remove(fname)
-
standard_names.cmd.snscrape.
snscrape
(files, with_headers=False, regex=None, format='url', newline=None)[source]¶ Scrape names from a URL.
Parameters: - files : iterable of str
List of files or URL to scrape.
- with_headers : bool, optional
Include headers in the output that indicate the name of the source.
- regex : str, optional
A regular expression that defines what a Standard Name is.
- format : {‘url’, ‘plain_text’}, optional
The format of the target that’s being scraped.
- newline : str, optional
Newline character to use for output.
Returns: - str
The scraped names.
Examples
>>> from __future__ import print_function >>> from six.moves import StringIO >>> import standard_names as csn
>>> file1 = StringIO(""" ... A file is one name, which is air__temperature. ... """) >>> file2 = StringIO(""" ... A file is two names: air__temperature, and water__temperature. ... """)
>>> lines = csn.cmd.snscrape.snscrape([file1, file2], format='plain_text') >>> sorted(lines.split(os.linesep)) ['air__temperature', 'air__temperature', 'water__temperature']
standard_names.cmd.snsql module¶
-
standard_names.cmd.snsql.
as_sql_commands
(names, newline=None)[source]¶ Create an sql database from a NamesRegistry.
Parameters: - names : NamesRegistry
A collection of CSDMS Standard Names.
- newline : str, optional
Newline character to use for output.
Returns: - str
The SQL commands to create the database.
Examples
>>> import standard_names as csn >>> names = csn.NamesRegistry(None) >>> names.add('air__temperature') >>> print(csn.cmd.snsql.as_sql_commands(names, newline='\n')) ... BEGIN TRANSACTION; CREATE TABLE names ( id integer primary key, name text, unique(name) ); INSERT INTO "names" VALUES(1,'air__temperature'); CREATE TABLE objects ( id integer primary key, name text, unique(name) ); INSERT INTO "objects" VALUES(1,'air'); CREATE TABLE operators ( id integer primary key, name text, unique(name) ); CREATE TABLE quantities ( id integer primary key, name text, unique(name) ); INSERT INTO "quantities" VALUES(1,'temperature'); COMMIT;
standard_names.cmd.snvalidate module¶
Validate a list of names.
-
standard_names.cmd.snvalidate.
main
(args=None)[source]¶ Validate a list of names.
Examples
>>> from __future__ import print_function >>> import os >>> import standard_names as csn
>>> (fname, _) = csn.registry._get_latest_names_file() >>> csn.cmd.snvalidate.main([fname]) 0
>>> import tempfile >>> (fd, fname) = tempfile.mkstemp() >>> os.close(fd)
>>> with open(fname, 'w') as fp: ... print('air__temperature', file=fp) ... print('Water__temperature', file=fp) ... print('water_temperature', file=fp)
>>> csn.cmd.snvalidate.main([fp.name]) 2
>>> os.remove(fname)