1# http://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
6from pyrocko.guts import Object, Timestamp, List
8from ..model import CodesNSLCE
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 = List.T(CodesNSLCE.T(), optional=True)
33 def __init__(self, **kwargs):
34 codes = kwargs.pop('codes', None)
36 if codes is None:
37 pass
38 elif not isinstance(codes, list):
39 codes = [CodesNSLCE(codes)]
40 else:
41 codes = [CodesNSLCE(sc) for sc in codes]
43 Object.__init__(self, codes=codes, **kwargs)
45 def contains(self, constraint):
46 '''
47 Check if the constraint completely includes a more restrictive one.
49 :param constraint:
50 Other constraint.
51 :type constraint:
52 :py:class:`Constraint`
53 '''
55 if self.tmin is not None and constraint.tmin is not None:
56 b1 = self.tmin <= constraint.tmin
57 elif self.tmin is None:
58 b1 = True
59 else:
60 b1 = False
62 if self.tmax is not None and constraint.tmax is not None:
63 b2 = constraint.tmax <= self.tmax
64 elif self.tmax is None:
65 b2 = True
66 else:
67 b2 = False
69 return b1 and b2
71 def expand(self, constraint):
72 '''
73 Widen constraint to include another given constraint.
75 :param constraint:
76 Other constraint.
77 :type constraint:
78 :py:class:`Constraint`
80 Update is done in-place.
81 '''
83 if constraint.tmin is None or self.tmin is None:
84 self.tmin = None
85 else:
86 self.tmin = min(constraint.tmin, self.tmin)
88 if constraint.tmax is None or self.tmax is None:
89 self.tmax = None
90 else:
91 self.tmax = max(constraint.tmax, self.tmax)
94class Source(Object):
96 '''
97 Base class for Squirrel data-sources.
99 Data-sources can be attached to a Squirrel instance to allow transparent
100 access to remote (or otherwise generated) resources, e.g. through FDSN web
101 services (:py:class:`~pyrocko.squirrel.client.fdsn.FDSNSource`) or online
102 event catalogs (:py:class:`~pyrocko.client.catalog.CatalogSource`).
104 Derived classes implement the details of querying, caching, updating and
105 bookkeeping of the accessed data.
106 '''
108 def update_channel_inventory(self, squirrel, constraint):
109 '''
110 Let local inventory be up-to-date with remote for a given constraint.
111 '''
113 pass
115 def update_event_inventory(self, squirrel, constraint):
116 '''
117 Let local inventory be up-to-date with remote for a given constraint.
118 '''
120 pass
122 def update_waveform_promises(self, squirrel, constraint):
123 '''
124 Let local inventory be up-to-date with remote for a given constraint.
125 '''
127 pass
129 def remove_waveform_promises(self, squirrel, from_database='selection'):
130 '''
131 Remove waveform promises from live selection or global database.
133 :param from_database:
134 Remove from live selection ``'selection'`` or global database
135 ``'global'``.
136 '''
138 pass
140 def update_response_inventory(self, squirrel, constraint):
141 '''
142 Let local inventory be up-to-date with remote for a given constraint.
143 '''
145 pass
148__all__ = [
149 'Source',
150 'Constraint',
151]