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-12 07:58 +0000

1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

4# ---|P------/S----------~Lg---------- 

5 

6''' 

7Base class for Squirrel remote data clients. 

8''' 

9 

10from pyrocko.guts import Object, Timestamp, List 

11 

12from ..model import CodesNSLCE 

13 

14 

15guts_prefix = 'squirrel' 

16 

17 

18class Constraint(Object): 

19 

20 ''' 

21 Used by some data-sources to grow or join locally mirrored data selections. 

22 

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. 

27 

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 ''' 

32 

33 tmin = Timestamp.T(optional=True) 

34 tmax = Timestamp.T(optional=True) 

35 codes = List.T(CodesNSLCE.T(), optional=True) 

36 

37 def __init__(self, **kwargs): 

38 codes = kwargs.pop('codes', None) 

39 

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] 

46 

47 Object.__init__(self, codes=codes, **kwargs) 

48 

49 def contains(self, constraint): 

50 ''' 

51 Check if the constraint completely includes a more restrictive one. 

52 

53 :param constraint: 

54 Other constraint. 

55 :type constraint: 

56 :py:class:`Constraint` 

57 ''' 

58 

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 

65 

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 

72 

73 return b1 and b2 

74 

75 def expand(self, constraint): 

76 ''' 

77 Widen constraint to include another given constraint. 

78 

79 :param constraint: 

80 Other constraint. 

81 :type constraint: 

82 :py:class:`Constraint` 

83 

84 Update is done in-place. 

85 ''' 

86 

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) 

91 

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) 

96 

97 

98class Source(Object): 

99 

100 ''' 

101 Base class for Squirrel data-sources. 

102 

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`). 

108 

109 Derived classes implement the details of querying, caching, updating and 

110 bookkeeping of the accessed data. 

111 ''' 

112 

113 def update_channel_inventory(self, squirrel, constraint): 

114 ''' 

115 Let local inventory be up-to-date with remote for a given constraint. 

116 ''' 

117 

118 pass 

119 

120 def update_event_inventory(self, squirrel, constraint): 

121 ''' 

122 Let local inventory be up-to-date with remote for a given constraint. 

123 ''' 

124 

125 pass 

126 

127 def update_waveform_promises(self, squirrel, constraint): 

128 ''' 

129 Let local inventory be up-to-date with remote for a given constraint. 

130 ''' 

131 

132 pass 

133 

134 def remove_waveform_promises(self, squirrel, from_database='selection'): 

135 ''' 

136 Remove waveform promises from live selection or global database. 

137 

138 :param from_database: 

139 Remove from live selection ``'selection'`` or global database 

140 ``'global'``. 

141 ''' 

142 

143 pass 

144 

145 def update_response_inventory(self, squirrel, constraint): 

146 ''' 

147 Let local inventory be up-to-date with remote for a given constraint. 

148 ''' 

149 

150 pass 

151 

152 

153__all__ = [ 

154 'Source', 

155 'Constraint', 

156]