Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/squirrel/io/backends/yaml.py: 83%
29 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-04 09:52 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-04 09:52 +0000
1# http://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
6'''
7Squirrel IO adaptor to read YAML files.
8'''
10import logging
12from pyrocko.io.io_common import get_stats, touch # noqa
13from pyrocko import model as pmodel
14from ... import model
16from pyrocko import guts
18logger = logging.getLogger('psq.io.yaml')
21def provided_formats():
22 return ['yaml']
25def detect_pyrocko_yaml(first512):
26 try:
27 first512 = first512.decode('utf-8')
28 except UnicodeDecodeError:
29 return False
31 for line in first512.splitlines():
32 if line.startswith('--- !pf.'):
33 return True
35 return False
38def detect(first512):
39 if detect_pyrocko_yaml(first512):
40 return 'yaml'
42 return None
45def iload(format, file_path, segment, content):
46 for iobj, obj in enumerate(guts.iload_all(filename=file_path)):
47 if isinstance(obj, pmodel.Event):
48 nut = model.make_event_nut(
49 file_segment=0,
50 file_element=iobj,
51 codes=model.CodesX(obj.catalog or ''),
52 tmin=obj.time,
53 tmax=obj.time)
55 if 'event' in content:
56 nut.content = obj
58 yield nut