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