obsinfo.obsMetadata package

obsinfo.obsMetadata.obsmetadata module

obsinfo information file routines, contained in superclass ObsMetadata for generality

class obsinfo.obsMetadata.obsmetadata.ObsMetadata(*args, **kwargs)

Bases: dict

__init__(*args, **kwargs)

Constructor, create a dict subclass object

Parameters
  • args (*list) – positional arguments

  • kwargs (**dict) – keyword arguments

static check_schema(schema, verbose, quiet=False)

This is really slow! (45s for instrumentation, 240s for subnetwork!)

Returns

True if schema checks out, false if not

Return type

result (bool)

copy() a shallow copy of D
get_configured_modified_base(higher_modifs={})

Return a fully configured and modified base_dict

Handles base, modifications and configuration fields in self and higher_modifs. Doest not handle any of these subelements in modifications or configuration: they simply get added into base using the safe_update() method.

Values in higher-modifs outrank those in self. Modifications outrank configurations. Uses safe_update() to only change specified elements.

Parameters
  • self (ObsMetadata) – base-configuration-modification dictionary. Must have “base”, can have “configuration” and “modification” AND NOTHING ELSE.

  • higher_modifs (dict or ObsMetadata) – modifications dictionary. Can have “base”, “configuration” and/or “modification” AND NOTHING ELSE

Returns

class:`ObsMetadata): fully configured and modified

attribute dictionary

Return type

base_dict (

Raises

ValueError – if self or higher_modifs contain keys other than “base”, “configuration” and/or “modification”

get_information_file_format()

Determines if the information file is in JSON or YAML format.

Assumes that the filename is “.{FORMAT}

Parameters

filename (str) – filename to determine the type of

Returns

file_format

Raises

(ValueError) – on unknown format

get_information_file_type()

Determines the type of a file.

Assumes that the filename is “.{TYPE}.{SOMETHING}

Parameters

filename (str) – filename to determine the type of

Returns

file type

Return type

(str)

Raises

ValueError

static is_valid_type(type)

Returns true if input is a valid schema type

list_valid_types()

Returns a list of valid information file types

Returns

list of valid information file types

static read_info_file(filename, datapath, remote=False, validate=True, file_format=None, verbose=False, quiet=False)

Reads an information file

Parameters
  • filename (str) – filename

  • datapath (Datapath) – stores list of directories to search info files

  • validate (bool) – validate before reading

  • remote (bool) – whether to use absolute/relative path locally or OBSINFO_DATAPATH

  • file_format (str) – “YAML” or “JSON”

  • verbose (bool) – say more

  • quiet (bool) – say nothing

Returns

JSON or YAML parsed info files

Return type

(ObsMetadata)

read_json_yaml(file_format=None)

Reads a JSON or YAML file. Does NOT use jsonReference DEPRECATED.

DEPRECATED. Not being used by any obsinfo method or function. Kept for compatibility

Parameters
  • filename (str) – filename

  • file_format (str) – “YAML” or “JSON”

Returns

JSON or YAML parsed information files

Return type

(dict)

Raises
  • (JSONDecodeError) – problem with JSON read

  • (FileNotFoundError) – file not found

  • (IOError) – File input/output erre

read_json_yaml_ref(datapath, file_format=None)

Reads a JSON or YAML file using jsonReference

Like read_json_yaml_ref, but does not look for files in OBSINFO_DATAPATH $ref within the data files without absolute or relative path will be still looked for in OBSINFO_DATAPATH

Parameters
  • filename (str) – filename

  • datapath (Datapath) – object to store list of

  • dummy. (directories to search info files. Used as a) –

  • file_format (str) – “YAML” or “JSON”

Returns

JSON or YAML parsed information files

Return type

(dict)

Raises
  • (JSONDecodeError) – problem with JSON read

  • (FileNotFoundError) – file not found

  • (IOError) – File input/output erre

read_json_yaml_ref_datapath(datapath, file_format=None)

Reads a JSON or YAML file using jsonReference using OBSINFO_DATAPATH

Parameters
  • filename (str) – filename

  • datapath (Datapath) – list of directories to search for info files

  • file_format (str) – “YAML” or “JSON”

Returns

JSON or YAML parsed information files

Return type

(dict)

Raises
  • (JSONDecodeError) – problem with JSON read

  • (FileNotFoundError) – file not found

  • (IOError) – File input/output erre

safe_update(update_dict, allow_overwrite=True, warn_crush=False)

Update that only changes explicitly specfied fields

Drills recursively through dicts inside the dict, only changing fields which are specified in update_dict

Parameters
  • update_dict (dict or ObsMetadata) – dictionary containing fields to update

  • allow_overwrite (bool) – allow a field that was originally a dict to be overwritten by a field that is not a dict. Same for lists.

  • warn_crush (bool) – write out a warning when a value is replaced

validate(info_filename, schemas_path=None, remote=False, file_format=None, file_type=None, verbose=False, schema_filename=None, quiet=False, dp=None, check_schema=False)

Validates a YAML or JSON file against schema

Parameters
  • info_filename (str or path-like) – name of information file to validate

  • schemas_path (str or Path) – path to schema files. If None, uses DEFAULT_SCHEMA_PATH

  • remote (bool) – whether to search for info_filename in a remote repository

  • file_format (str) – “JSON” or “YAML”

  • file_type (str) – type of info file: “network”, “station”, “instrumentation”, “datalogger”, “preamplifier”, “sensor”, “stage”, “filter”

  • verbose (bool) – Print progression of validation steps with filenames

  • schema_file (str) – name (without path) of schema file

  • quiet (bool) – No output at all

  • dp (Datapath) – datapath for information files. If None, defaults to values stored in .obsinforc

  • check_schema (bool) – validate schema file as well

If file_type and/or format are not provided, tries to figure them out from the info_filename, which should end with “{FILETYPE}.{FORMAT}

validate_infodict(info_dict, schema_filename, verbose=False, quiet=False, schemas_path=None, check_schema=True)

Validates an infofile dict file against schema

Parameters
  • info_dict (dict or ObsMetadata`) – information to validate

  • verbose (bool) – Print progression of validation steps with filenames

  • schema_filename (str) – name (without path) of schema file

  • schemas_path (str or Path) – path to schema files. If None, uses DEFAULT_SCHEMA_PATH

  • check_schema (bool) – validate schema file as well