1# http://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
6from __future__ import absolute_import, print_function
8import os.path as op
9import logging
11from pyrocko.guts import List, load, StringPattern
13from ..has_paths import HasPaths
14from .client.base import Source
15from .error import SquirrelError
16from .selection import re_persistent_name
17from .operators.base import Operator
19guts_prefix = 'squirrel'
21logger = logging.getLogger('psq.dataset')
24class PersistentID(StringPattern):
25 pattern = re_persistent_name
28class Dataset(HasPaths):
29 '''
30 Dataset description.
31 '''
32 sources = List.T(Source.T())
33 operators = List.T(Operator.T())
35 def setup(self, squirrel, check=True):
36 for source in self.sources:
37 squirrel.add_source(
38 source, check=check)
40 for operator in self.operators:
41 squirrel.add_operator(operator)
43 squirrel.update_operator_mappings()
46def read_dataset(path):
47 '''
48 Read dataset description file.
49 '''
50 try:
51 dataset = load(filename=path)
52 except OSError:
53 raise SquirrelError(
54 'Cannot read dataset file: %s' % path)
56 if not isinstance(dataset, Dataset):
57 raise SquirrelError('Invalid dataset file "%s".' % path)
59 dataset.set_basepath(op.dirname(path) or '.')
60 return dataset
63__all__ = [
64 'PersistentID',
65 'Dataset',
66 'read_dataset',
67]