Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/squirrel/client/base.py: 74%
47 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-06 15:01 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-06 15:01 +0000
1# http://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
6'''
7Base class for Squirrel remote data clients.
8'''
10from pyrocko.guts import Object, Timestamp, List
12from ..model import CodesNSLCE
15guts_prefix = 'squirrel'
18class Constraint(Object):
20 '''
21 Used by some data-sources to grow or join locally mirrored data selections.
23 Squirrel data-sources typically try to mirror only a subset of the remotely
24 available data. This subset may need to be grown or updated when data from
25 other time intervals or from locations outside the initially requested
26 region is requested. This class helps in the involved bookeeping.
28 The current implementation only supports a time interval selection with a
29 single time span but more sophisticated constraints, including e.g.
30 location boxes could be thought of.
31 '''
33 tmin = Timestamp.T(optional=True)
34 tmax = Timestamp.T(optional=True)
35 codes = List.T(CodesNSLCE.T(), optional=True)
37 def __init__(self, **kwargs):
38 codes = kwargs.pop('codes', None)
40 if codes is None:
41 pass
42 elif not isinstance(codes, list):
43 codes = [CodesNSLCE(codes)]
44 else:
45 codes = [CodesNSLCE(sc) for sc in codes]
47 Object.__init__(self, codes=codes, **kwargs)
49 def contains(self, constraint):
50 '''
51 Check if the constraint completely includes a more restrictive one.
53 :param constraint:
54 Other constraint.
55 :type constraint:
56 :py:class:`Constraint`
57 '''
59 if self.tmin is not None and constraint.tmin is not None:
60 b1 = self.tmin <= constraint.tmin
61 elif self.tmin is None:
62 b1 = True
63 else:
64 b1 = False
66 if self.tmax is not None and constraint.tmax is not None:
67 b2 = constraint.tmax <= self.tmax
68 elif self.tmax is None:
69 b2 = True
70 else:
71 b2 = False
73 return b1 and b2
75 def expand(self, constraint):
76 '''
77 Widen constraint to include another given constraint.
79 :param constraint:
80 Other constraint.
81 :type constraint:
82 :py:class:`Constraint`
84 Update is done in-place.
85 '''
87 if constraint.tmin is None or self.tmin is None:
88 self.tmin = None
89 else:
90 self.tmin = min(constraint.tmin, self.tmin)
92 if constraint.tmax is None or self.tmax is None:
93 self.tmax = None
94 else:
95 self.tmax = max(constraint.tmax, self.tmax)
98class Source(Object):
100 '''
101 Base class for Squirrel data-sources.
103 Data-sources can be attached to a Squirrel instance to allow transparent
104 access to remote (or otherwise generated) resources, e.g. through FDSN web
105 services (:py:class:`~pyrocko.squirrel.client.fdsn.FDSNSource`) or online
106 event catalogs
107 (:py:class:`~pyrocko.squirrel.client.catalog.CatalogSource`).
109 Derived classes implement the details of querying, caching, updating and
110 bookkeeping of the accessed data.
111 '''
113 def update_channel_inventory(self, squirrel, constraint):
114 '''
115 Let local inventory be up-to-date with remote for a given constraint.
116 '''
118 pass
120 def update_event_inventory(self, squirrel, constraint):
121 '''
122 Let local inventory be up-to-date with remote for a given constraint.
123 '''
125 pass
127 def update_waveform_promises(self, squirrel, constraint):
128 '''
129 Let local inventory be up-to-date with remote for a given constraint.
130 '''
132 pass
134 def remove_waveform_promises(self, squirrel, from_database='selection'):
135 '''
136 Remove waveform promises from live selection or global database.
138 :param from_database:
139 Remove from live selection ``'selection'`` or global database
140 ``'global'``.
141 '''
143 pass
145 def update_response_inventory(self, squirrel, constraint):
146 '''
147 Let local inventory be up-to-date with remote for a given constraint.
148 '''
150 pass
153__all__ = [
154 'Source',
155 'Constraint',
156]