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
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)
32 def contains(self, constraint):
33 '''
34 Check if the constraint completely includes a more restrictive one.
36 :param constraint:
37 Other constraint.
38 :type constraint:
39 :py:class:`Constraint`
40 '''
42 if self.tmin is not None and constraint.tmin is not None:
43 b1 = self.tmin <= constraint.tmin
44 elif self.tmin is None:
45 b1 = True
46 else:
47 b1 = False
49 if self.tmax is not None and constraint.tmax is not None:
50 b2 = constraint.tmax <= self.tmax
51 elif self.tmax is None:
52 b2 = True
53 else:
54 b2 = False
56 return b1 and b2
58 def expand(self, constraint):
59 '''
60 Widen constraint to include another given constraint.
62 :param constraint:
63 Other constraint.
64 :type constraint:
65 :py:class:`Constraint`
67 Update is done in-place.
68 '''
70 if constraint.tmin is None or self.tmin is None:
71 self.tmin = None
72 else:
73 self.tmin = min(constraint.tmin, self.tmin)
75 if constraint.tmax is None or self.tmax is None:
76 self.tmax = None
77 else:
78 self.tmax = max(constraint.tmax, self.tmax)
81class Source(Object):
83 '''
84 Base class for Squirrel data-sources.
86 Data-sources can be attached to a Squirrel instance to allow transparent
87 access to remote (or otherwise generated) resources, e.g. through FDSN web
88 services (:py:class:`~pyrocko.squirrel.client.fdsn.FDSNSource`) or online
89 event catalogs (:py:class:`~pyrocko.client.catalog.CatalogSource`).
91 Derived classes implement the details of querying, caching, updating and
92 bookkeeping of the accessed data.
93 '''
95 def update_channel_inventory(self, squirrel, constraint):
96 '''
97 Let local inventory be up-to-date with remote for a given constraint.
98 '''
100 pass
102 def update_event_inventory(self, squirrel, constraint):
103 '''
104 Let local inventory be up-to-date with remote for a given constraint.
105 '''
107 pass
109 def update_waveform_promises(self, squirrel, constraint):
110 '''
111 Let local inventory be up-to-date with remote for a given constraint.
112 '''
114 pass
117__all__ = [
118 'Source',
119 'Constraint',
120]