mt_metadata.base.schema

Created on Thu Dec 24 12:02:12 2020

copyright:

Jared Peacock (jpeacock@usgs.gov)

license:

MIT

Classes

BaseDict

BaseDict is a convenience class that can help the metadata dictionaries

Functions

get_schema_fn(schema_element, paths)

Get the correct file name for the given schema element from the provided

get_schema(schema_element, paths)

Get a mt_metadata.schema_base.BaseDict object of the element

Module Contents

class mt_metadata.base.schema.BaseDict(*args, **kwargs)

Bases: collections.abc.MutableMapping

BaseDict is a convenience class that can help the metadata dictionaries act like classes so you can access variables by .name or [name]

Note

If the attribute has a . in the name then you will not be able to access that attribute by class.name.name You will get an attribute error. You need to access the attribute like a dictionary class[‘name.name’]

You can add an attribute by:

>>> b = BaseDict()
>>> b.update({name: value_dict})

Or you can add a whole dictionary:

>>> b.add_dict(ATTR_DICT['run'])

All attributes have a descriptive dictionary of the form:

>>> {'type': data type, 'required': [True | False],
>>> ... 'style': 'string style', 'units': attribute units}
  • type –> the data type [ str | int | float | bool ]

  • required –> required in the standards [ True | False ]

  • style –> style of the string

  • units –> units of the attribute, must be a string

property name
add_dict(add_dict, name=None, keys=None)

Add a dictionary to. If name is input it is added to the keys of the input dictionary

Parameters:
  • add_dict (dict or MutableMapping) – dictionary to add

  • name (str, optional) – name to add to keys, by default None

Examples

>>> s_obj = Standards()
>>> run_dict = s_obj.run_dict
>>> run_dict.add_dict(s_obj.declination_dict, 'declination')
copy()
to_latex(max_entries=7, first_table_len=7)

Convert to LaTeX format

Parameters:
  • max_entries (int, optional) – Maximum number of entries, by default 7

  • first_table_len (int, optional) – Length of first table, by default 7

Returns:

DESCRIPTION

Return type:

TYPE

from_csv(csv_fn)

Read in CSV file as a dictionary

Parameters:

csv_fn (pathlib.Path or str) – csv file to read metadata standards from

Returns:

dictionary of the contents of the file

Return type:

dict

Examples

>>> run_dict = BaseDict()
>>> run_dict.from_csv(get_level_fn('run'))
to_csv(csv_fn)

write dictionary to csv file

Parameters:

csv_fn (TYPE) – DESCRIPTION

Returns:

DESCRIPTION

Return type:

TYPE

to_json(json_fn, indent=' ' * 4)

Write schema standards to json

Parameters:
  • json_fn (str or Path) – full path to json file

  • indent (str, optional) – indentation string, by default “ “ * 4

Returns:

full path to json file

Return type:

Path

from_json(json_fn)

Read schema standards from json

Parameters:

json_fn (str or Path) – full path to json file

Returns:

full path to json file

Return type:

Path

mt_metadata.base.schema.get_schema_fn(schema_element, paths)

Get the correct file name for the given schema element from the provided list of valid file names

Parameters:
  • schema_element (str) – name of the schema element to get filename for

  • paths (list) – list of valid file paths

Returns:

correct file name for given element

Return type:

pathlib.Path

mt_metadata.base.schema.get_schema(schema_element, paths)

Get a mt_metadata.schema_base.BaseDict object of the element

Parameters:
  • schema_element (str) – name of the schema element to get filename for

  • paths (list) – list of valid file paths

Returns:

return a dictionary that describes the standards for the element

Return type:

mt_metadata.schema_base.BaseDict