mt_metadata.base.schema ======================= .. py:module:: mt_metadata.base.schema .. autoapi-nested-parse:: Created on Thu Dec 24 12:02:12 2020 :copyright: Jared Peacock (jpeacock@usgs.gov) :license: MIT Classes ------- .. autoapisummary:: mt_metadata.base.schema.BaseDict Functions --------- .. autoapisummary:: mt_metadata.base.schema.get_schema_fn mt_metadata.base.schema.get_schema Module Contents --------------- .. py:class:: BaseDict(*args, **kwargs) Bases: :py:obj:`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 .. py:property:: name .. py:method:: 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 :param add_dict: dictionary to add :type add_dict: dict or MutableMapping :param name: name to add to keys, by default None :type name: str, optional .. rubric:: Examples >>> s_obj = Standards() >>> run_dict = s_obj.run_dict >>> run_dict.add_dict(s_obj.declination_dict, 'declination') .. py:method:: copy() .. py:method:: to_latex(max_entries=7, first_table_len=7) Convert to LaTeX format :param max_entries: Maximum number of entries, by default 7 :type max_entries: int, optional :param first_table_len: Length of first table, by default 7 :type first_table_len: int, optional :returns: DESCRIPTION :rtype: TYPE .. py:method:: from_csv(csv_fn) Read in CSV file as a dictionary :param csv_fn: csv file to read metadata standards from :type csv_fn: pathlib.Path or str :returns: dictionary of the contents of the file :rtype: dict .. rubric:: Examples >>> run_dict = BaseDict() >>> run_dict.from_csv(get_level_fn('run')) .. py:method:: to_csv(csv_fn) write dictionary to csv file :param csv_fn: DESCRIPTION :type csv_fn: TYPE :returns: DESCRIPTION :rtype: TYPE .. py:method:: to_json(json_fn, indent=' ' * 4) Write schema standards to json :param json_fn: full path to json file :type json_fn: str or Path :param indent: indentation string, by default " " * 4 :type indent: str, optional :returns: full path to json file :rtype: Path .. py:method:: from_json(json_fn) Read schema standards from json :param json_fn: full path to json file :type json_fn: str or Path :returns: full path to json file :rtype: Path .. py:function:: get_schema_fn(schema_element, paths) Get the correct file name for the given schema element from the provided list of valid file names :param schema_element: name of the schema element to get filename for :type schema_element: str :param paths: list of valid file paths :type paths: list :returns: correct file name for given element :rtype: pathlib.Path .. py:function:: get_schema(schema_element, paths) Get a :class:`mt_metadata.schema_base.BaseDict` object of the element :param schema_element: name of the schema element to get filename for :type schema_element: str :param paths: list of valid file paths :type paths: list :returns: return a dictionary that describes the standards for the element :rtype: mt_metadata.schema_base.BaseDict