mt_metadata.utils package

Submodules

mt_metadata.utils.exceptions module

Created on Thu Dec 24 11:59:18 2020

copyright:

Jared Peacock (jpeacock@usgs.gov)

license:

MIT

exception mt_metadata.utils.exceptions.MTSchemaError[source]

Bases: Exception

exception mt_metadata.utils.exceptions.MTTimeError[source]

Bases: Exception

exception mt_metadata.utils.exceptions.MTValidatorError[source]

Bases: Exception

mt_metadata.utils.mttime module

Created on Wed May 13 19:10:46 2020

@author: jpeacock

class mt_metadata.utils.mttime.MTime(time=None, gps_time=False)[source]

Bases: object

Date and Time container based on pandas.Timestamp

Will read in a string or a epoch seconds into a pandas.Timestamp object assuming the time zone is UTC. If UTC is not the timezone then the time is corrected to UTC.

The benefit of using pandas.Timestamp is that it can handle nanoseconds.

Outputs can be an ISO formatted string YYYY-MM-DDThh:mm:ss.ssssss+00:00:

>>> t = MTtime()
>>> t.iso_str
'1980-01-01T00:00:00+00:00'

Note

if microseconds are 0 they are omitted. Same with nanoseconds.

or Epoch seconds (float):

>>> t.epoch_seconds
315532800.0

Convenience getters/setters are provided as properties for the different parts of time.

>>> t = MTtime()
>>> t.year = 2020
>>> t.year
2020

Note

If the input data is greater than pandas.Timestamp.max then the value is set to pandas.Timestamp.max = ‘2262-04-11 23:47:16.854775807’. Similarly, If the input data is less than pandas.Timestamp.min then the value is set to pandas.Timestamp.min = ‘1677-09-21 00:12:43.145224193’

>>> t = MTime("3000-01-01")
[line 295] mt_metadata.utils.mttime.MTime.parse -
INFO: 3000-01-01 is too large setting to 2262-04-11 23:47:16.854775807
copy()[source]

make a copy of the time

property date
property day
property epoch_seconds
property hour
property iso_no_tz
property iso_str
isocalendar()[source]
Returns:

Calendar Date in ISO format

Return type:

string

isodate()[source]
Returns:

Date in ISO format

Return type:

string

isoformat()[source]
Returns:

Date-time in ISO format

Return type:

string

property microseconds
property minutes
property month
property nanoseconds
now()[source]

set date time to now

Returns:

current UTC time

Return type:

datetime with UTC timezone

parse(dt_str)[source]

Parse a date-time string using dateutil.parser

Need to use dateutil.parser.isoparser to get correct tzinfo=tzutc If the input is a weird date string then try to use parse.

Parameters:

dt_str – date-time string

Type:

string

property seconds
property year
mt_metadata.utils.mttime.calculate_leap_seconds(year, month, day)[source]

get the leap seconds for the given year to convert GPS time to UTC time

Note

GPS time started in 1980

Note

GPS time is leap seconds ahead of UTC time, therefore you should subtract leap seconds from GPS time to get UTC time.

Date Range

Leap Seconds

1981-07-01 - 1982-07-01

1

1982-07-01 - 1983-07-01

2

1983-07-01 - 1985-07-01

3

1985-07-01 - 1988-01-01

4

1988-01-01 - 1990-01-01

5

1990-01-01 - 1991-01-01

6

1991-01-01 - 1992-07-01

7

1992-07-01 - 1993-07-01

8

1993-07-01 - 1994-07-01

9

1994-07-01 - 1996-01-01

10

1996-01-01 - 1997-07-01

11

1997-07-01 - 1999-01-01

12

1999-01-01 - 2006-01-01

13

2006-01-01 - 2009-01-01

14

2009-01-01 - 2012-07-01

15

2012-07-01 - 2015-07-01

16

2015-07-01 - 2017-01-01

17

2017-01-01 - ????-??-??

18

mt_metadata.utils.mttime.get_now_utc()[source]

Get the current time in UTC format :return: ISO formatted string of current time in UTC :rtype: string

mt_metadata.utils.summarize module

Created on Tue Feb 23 11:52:35 2021

copyright:

Jared Peacock (jpeacock@usgs.gov)

license:

MIT

mt_metadata.utils.summarize.summarize_standards(metadata_type='timeseries', csv_fn=None)[source]

Summarize standards into a numpy array and write a csv if specified

Parameters:
  • metadata_type (string, optional) – [ timeseries | transfer function | edi | emtf | j | zmm ], defaults to “timeseries”

  • csv_fn (string or Path, optional) – full path to write a csv file, defaults to None

Returns:

structured numpy array

Return type:

numpy.ndarray

mt_metadata.utils.summarize.summarize_timeseries_standards()[source]

Summarize the standards for time series metadata.

mt_metadata.utils.summarize.summary_to_array(summary_dict)[source]

Summarize all metadata from a summarized dictionary of standards

Parameters:

summary_dict (dict) – Dictionary of summarized standards

Returns:

numpy structured array

Return type:

np.array

mt_metadata.utils.units module

This is a placeholder module. See github issue #30

In the mt_metadata packaage, the standard is that units are described by all lower case strings.

The dictionaries UNITS is keyed by these lower case strings.

class mt_metadata.utils.units.Unit(**kwargs)[source]

Bases: object

from_dict(value)[source]
to_dict()[source]
mt_metadata.utils.units.get_unit_object(unit, allow_none=True)[source]
Parameters:

unit – unit name or abbreviation

Returns:

unit dictionary

Return type:

dict

mt_metadata.utils.validators module

schema

Convenience Classes and Functions to deal with the base metadata standards described by the csv file.

The hope is that only the csv files will need to be changed as the standards are modified. The attribute dictionaries are stored in ATTRICT

Created on Wed Apr 29 11:11:31 2020

@author: jpeacock

mt_metadata.utils.validators.validate_alias(alias)[source]

validate alias names :param alias: DESCRIPTION :type alias: TYPE :return: DESCRIPTION :rtype: TYPE

mt_metadata.utils.validators.validate_attribute(name)[source]

validate the name to conform to the standards name must be:

  • all lower case {a-z; 1-9}

  • must start with a letter

  • categories are separated by ‘.’

  • words separated by ‘_’

{object}.{name_name}

‘/’ will be replaced with ‘.’ converted to all lower case

Parameters:

name (string) – name name

Returns:

valid name name

Return type:

string

mt_metadata.utils.validators.validate_default(value_dict)[source]

validate default value

Parameters:

default (TYPE) – DESCRIPTION

Returns:

DESCRIPTION

Return type:

TYPE

mt_metadata.utils.validators.validate_description(description)[source]

make sure the description is a string

Parameters:

description (str) – detailed description of an attribute

Returns:

validated string of description

Return type:

string

mt_metadata.utils.validators.validate_example(example)[source]
Parameters:

example (TYPE) – DESCRIPTION

Returns:

DESCRIPTION

Return type:

TYPE

mt_metadata.utils.validators.validate_header(header, attribute=False)[source]
validate header to make sure it includes the required keys:
  • ‘attribute’

  • ‘type’

  • ‘required’

  • ‘style’

  • ‘units’

Parameters:
  • header (list) – list of header names

  • attribute ([ True | False ]) – include attribute in test or not

Returns:

validated header

Return type:

list

mt_metadata.utils.validators.validate_options(options)[source]

turn options into a list of strings

Parameters:

options (TYPE) – DESCRIPTION

Returns:

DESCRIPTION

Return type:

TYPE

mt_metadata.utils.validators.validate_required(value)[source]

Validate required, must be True or False

Parameters:

value ([ string | bool ]) – required value

Returns:

validated required value

Return type:

boolean

mt_metadata.utils.validators.validate_style(value)[source]

Validate string style

..todo:: make list of accepted style formats

Parameters:

value (string) – style to be validated

Returns:

validated style

Return type:

string

mt_metadata.utils.validators.validate_type(value)[source]
Validate required type. Must be:
  • str

  • float

  • int

  • bool

Parameters:

value ([ type | string ]) – required type

Returns:

validated type

Return type:

string

mt_metadata.utils.validators.validate_units(value)[source]

Validate units

..todo:: make a list of acceptable unit names

Parameters:

value (string) – unit value to be validated

Returns:

validated units

Return type:

string

mt_metadata.utils.validators.validate_value_dict(value_dict)[source]

Validate an input value dictionary

Must be of the form:

{‘type’: str, ‘required’: True, ‘style’: ‘name’, ‘units’: units}

Parameters:

value_dict (TYPE) – DESCRIPTION

Returns:

DESCRIPTION

Return type:

TYPE

mt_metadata.utils.validators.validate_value_type(value, v_type, style=None)[source]

validate type from standards

Module contents

Unit test package for mth5.