1# http://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
6from __future__ import absolute_import, print_function
8from pyrocko.guts import Object, Timestamp, String
11guts_prefix = 'squirrel'
14class Constraint(Object):
16 '''
17 Used by some data-sources to grow or join locally mirrored data selections.
19 Squirrel data-sources typically try to mirror only a subset of the remotely
20 available data. This subset may need to be grown or updated when data from
21 other time intervals or from locations outside the initially requested
22 region is requested. This class helps in the involved bookeeping.
24 The current implementation only supports a time interval selection with a
25 single time span but more sophisticated constraints, including e.g.
26 location boxes could be thought of.
27 '''
29 tmin = Timestamp.T(optional=True)
30 tmax = Timestamp.T(optional=True)
31 codes = String.T(optional=True)
33 def contains(self, constraint):
34 '''
35 Check if the constraint completely includes a more restrictive one.
37 :param constraint:
38 Other constraint.
39 :type constraint:
40 :py:class:`Constraint`
41 '''
43 if self.tmin is not None and constraint.tmin is not None:
44 b1 = self.tmin <= constraint.tmin
45 elif self.tmin is None:
46 b1 = True
47 else:
48 b1 = False
50 if self.tmax is not None and constraint.tmax is not None:
51 b2 = constraint.tmax <= self.tmax
52 elif self.tmax is None:
53 b2 = True
54 else:
55 b2 = False
57 return b1 and b2
59 def expand(self, constraint):
60 '''
61 Widen constraint to include another given constraint.
63 :param constraint:
64 Other constraint.
65 :type constraint:
66 :py:class:`Constraint`
68 Update is done in-place.
69 '''
71 if constraint.tmin is None or self.tmin is None:
72 self.tmin = None
73 else:
74 self.tmin = min(constraint.tmin, self.tmin)
76 if constraint.tmax is None or self.tmax is None:
77 self.tmax = None
78 else:
79 self.tmax = max(constraint.tmax, self.tmax)
82class Source(Object):
84 '''
85 Base class for Squirrel data-sources.
87 Data-sources can be attached to a Squirrel instance to allow transparent
88 access to remote (or otherwise generated) resources, e.g. through FDSN web
89 services (:py:class:`~pyrocko.squirrel.client.fdsn.FDSNSource`) or online
90 event catalogs (:py:class:`~pyrocko.client.catalog.CatalogSource`).
92 Derived classes implement the details of querying, caching, updating and
93 bookkeeping of the accessed data.
94 '''
96 def update_channel_inventory(self, squirrel, constraint):
97 '''
98 Let local inventory be up-to-date with remote for a given constraint.
99 '''
101 pass
103 def update_event_inventory(self, squirrel, constraint):
104 '''
105 Let local inventory be up-to-date with remote for a given constraint.
106 '''
108 pass
110 def update_waveform_promises(self, squirrel, constraint):
111 '''
112 Let local inventory be up-to-date with remote for a given constraint.
113 '''
115 pass
118__all__ = [
119 'Source',
120 'Constraint',
121]