obsinfo.helpers package
Helper classes, used by other classes
Functions
obsinfo.helpers.functions
- obsinfo.helpers.functions.str_indent(s, nchars: int)
Indents all lines of a string by a given # of spaces
Normally indents all but the first line, if nchars is negative then indents all lines including the first, by -nchars
- Parameters:
s (str) – string to be indented
nchars (int) – if > 0: indent all lines except the first by nchars. if < -: indent all lines by -nchars
- obsinfo.helpers.functions.str_list_str(slist, indent=0, n_subclasses=0)
Returns list of strings formatted for obsinfo printing :param slist: list of strs :type slist: list of str :param indent: # of characters to indent by :type indent: int :param n_subclasses: if < 0, return a one-line string :type n_subclasses: int
- obsinfo.helpers.functions.verify_dict_is_empty(attributes_dict)
obsinfo.helpers.logger
Application to print obsinfo information files.
- class obsinfo.helpers.logger.LogFormatter(color, *args, **kwargs)
Bases:
Formatter- COLOR_CODES = {10: '\x1b[1;30m', 20: '\x1b[0;37m', 30: '\x1b[1;33m', 40: '\x1b[1;31m', 50: '\x1b[1;35m'}
- RESET_CODE = '\x1b[0m'
- format(record, *args, **kwargs)
Format the specified record as text.
The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.
- class obsinfo.helpers.logger.ShutdownHandler(stream=None)
Bases:
StreamHandler- emit(record)
Emit a record.
If a formatter is specified, it is used to format the record. The record is then written to the stream with a trailing newline. If exception information is present, it is formatted using traceback.print_exception and appended to the stream. If the stream has an ‘encoding’ attribute, it is used to determine how to do the output to the stream.
- obsinfo.helpers.logger.init_logging(suffix='', file_level='DEBUG', console_level='WARNING', console_log_output='stdout')
Create or open a rotating logging file and add it to ObsinfoConfiguration
- Parameters:
suffix (str) – text to add to ‘obsinfolog-’ for output
file_level (str) – level to start printing to file
console_level (str) – level to start printing to screen
console_log_output (str) – “stdout” or “stderr”
valid levels are DEBUG, INFO, WARNING, ERROR, CRITICAL
Returns: object of Logger class
Classes
obsinfo.helpers.Comment/s
- class obsinfo.helpers.Comments(inps)
Bases:
ObsinfoClassListA list of
Commentobjects- classmethod from_extras(extras_dict)
Create Comments object from “extras” (freeform dict object)
- classmethod to_yaml(representer, data)
obsinfo.helpers.ExternalReference/s
- class obsinfo.helpers.ExternalReferences(attributes_list)
Bases:
ObsinfoClassListA list of ExternalReference objects
obsinfo.helpers.FloatWithUncert
- class obsinfo.helpers.FloatWithUncert(value, uncertainty=None, measurement_method=None, unit=None)
Bases:
objectPython equivalent of obspy
FloatWithUncertaintiesFixedUnitandFloatWithUncertaintiesAndUnit- value
float value
- Type:
float
- uncertainty
uncertainty in value
- Type:
float
- measurement_method
measurement method
- Type:
str
- classmethod from_dict(attributes_dict)
Create object and assign attributes from attributes_dict.
- Parameters:
attributes_dict (dict or
ObsMetadata) – dict with relevant keys
- to_obspy()
- Return obspy object:
FloatWithUncertaintiesFixedUnitif unit=NoneFloatWithUncertaintiesAndUnitotherwise
- classmethod to_yaml(representer, data)
obsinfo.helpers.Identifier/s
- class obsinfo.helpers.Identifiers(attributes_list)
Bases:
ObsinfoClassListA list of
Identifierobjects
obsinfo.helpers.Location/s
- class obsinfo.helpers.Locations(inp)
Bases:
ObsinfoClassListA list of
Locationobjects- classmethod from_locations_dict(locations_dict)
Create from a locations dict (key=location_code, value=location_dict)
- get_by_loc_code(loc_code)
- classmethod to_yaml(representer, data)
- class obsinfo.helpers.Location(attributes_dict, code: str | None = None)
Bases:
objectLocation class.
- code
location code
- Type:
str
- latitude
station latitude (degrees N)
- Type:
float
- longitude
station longitude (degrees E)
- Type:
float
- elevation
station elevation (meters above sea level)
- Type:
float
- uncertainties_m
‘lat’, ‘lon’, ‘elev’ in METERS
- Type:
dict
- geology
site geology
- Type:
str
- vault
vault type
- Type:
str
- depth_m
depth of station beneath surface (meters)
- Type:
float
- water_level_m
elevation of water_level (non-zero for lakes)
- Type:
float
- localisation_method
method used to determine position
- Type:
str
- obspy_latitude
latitude as an obspy object
- obspy_longitude
longitude as an obspy object
- classmethod to_yaml(representer, data)
- static verify_lat_lon(value)
Verifies lat or lon values, converting coded text to float if needed
- Accepts:
value as a float (decimal degrees) value as a str of format “i{.i}” (decimal degrees) value as a str of format “i_i{.i}” (degrees_minutes) value as a str of format “i_i_i{.i}” (degrees_minutes_seconds)
where i is any integer
obsinfo.helpers.OIDate/s
- class obsinfo.helpers.OIDates(seq)
Bases:
ObsinfoClassListA list of
OIDated objects
- class obsinfo.helpers.OIDate(datestr)
Bases:
objectStore dates before converting to
UTCDateTime- date
- to_obspy()
Return
UTCDateTimeobject:
- classmethod to_yaml(representer, data)
- static validated_date(str_date)
Reformats an individual date string
Uses regular expressions to match known dates, either in UTC date format or in UTC date and time format. The separator can be either “/” or “-”
- Parameters:
date (str) – a date in a given format
- Returns:
a reformatted date as string or None if no value
- Return type:
(str)
- static validated_dates(dates)
Convert list of dates to a standard format
- Parameters:
dates (list) – dates as strings
- Returns:
formatted dates as strings
- Return type:
(list)
- yaml_tag = '!myYamlStrTag\n'
obsinfo.helpers.Person/s
- class obsinfo.helpers.Persons(seq)
Bases:
ObsinfoClassListA list of
Personobjects- classmethod to_yaml(representer, data)
- class obsinfo.helpers.Person(attributes_dict)
Bases:
objectEquivalent of StationXMl Person
- names
Name(s) written out normally
- Type:
list of str
- agencies
agencies worked for
- Type:
list of str
- emails
emails
- Type:
list of str
- phones
person’s telephone number(s)
- Type:
list of
Phone`
- repr()
- to_obspy()
- classmethod to_yaml(representer, data)
obsinfo.helpers.Phone/s
- class obsinfo.helpers.Phones(seq)
Bases:
ObsinfoClassListList of
Phoneobjects- classmethod to_yaml(representer, data)
- yaml_tag = '!myYamlSeqTag'
- class obsinfo.helpers.Phone(attributes_dict_or_str)
Bases:
objectEquivalent of StationXML
<PhoneNumber>- description
Description of the phone # (work, mobile…)
- Type:
str
- country_code
Telephone country code
- Type:
str
- area_code
Telephone area code
- Type:
int
- phone_number
Telephone number
- Type:
str
- static str_to_dict(phone)
Return attribute_dict corresponding to phone number string Try to convert international numbers to the FDSN American standard. If already in American standard, use area code. Requires country codes, because we’re not just the USA!
- Parameters:
phone (str) – phone number in (hopefully) one of several recognisable formats
- Returns:
country_codearea_code: default=0phone_number- Return type:
(tuple)
>>> Phone("+33 6 12345678") Phone(dict(country_code="33", phone_number="612345678")) >>> str(Phone("+33 6 12345678")) '+33 612345678' >>> Phone("+33 (6) 12345678") Phone(dict(country_code="33", phone_number="612345678")) >>> Phone("+1 (415) 123-4567") Phone(dict(country_code="1", area_code=415, phone_number="1234567")) >>> Phone("001 (415) 123-4567") Phone(dict(country_code="1", area_code=415, phone_number="1234567")) >>> Phone("+001 (415) 123-4567") Phone(dict(country_code="1", area_code=415, phone_number="1234567")) >>> Phone("(415) 123-4567") ValueError: "(415) 123-4567" returned no phone number
- to_obspy()
Stupidly, phone_number has to have a dash inside of it FDSN pattern search rule, copied by obspy
- classmethod to_yaml(representer, data)
Force to a obspy-compatible string, to satiate yasmine
- yaml_tag = '!myYamlStrTag'