1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

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

5 

6from __future__ import absolute_import, print_function 

7 

8from pyrocko import io 

9from pyrocko.apps.jackseis import process, tfmt 

10 

11from .. import common 

12 

13 

14def setup_subcommand(subparsers): 

15 return common.add_parser( 

16 subparsers, 'jackseis-classic', 

17 help='Squirrel\'s adaption of classic Jackseis.') 

18 

19 

20def setup(parser): 

21 parser.add_argument( 

22 '--pattern', 

23 dest='regex', 

24 metavar='REGEX', 

25 help='only include files whose paths match REGEX') 

26 

27 parser.add_argument( 

28 '--quiet', 

29 dest='quiet', 

30 action='store_true', 

31 default=False, 

32 help='disable output of progress information') 

33 

34 parser.add_argument( 

35 '--debug', 

36 dest='debug', 

37 action='store_true', 

38 default=False, 

39 help='print debugging information to stderr') 

40 

41 parser.add_argument( 

42 '--tmin', 

43 dest='tmin', 

44 help='start time as "%s"' % tfmt) 

45 

46 parser.add_argument( 

47 '--tmax', 

48 dest='tmax', 

49 help='end time as "%s"' % tfmt) 

50 

51 parser.add_argument( 

52 '--tinc', 

53 dest='tinc', 

54 help='set time length of output files [s] or "auto" to automatically ' 

55 'choose an appropriate time increment or "huge" to allow to use ' 

56 'a lot of system memory to merge input traces into huge output ' 

57 'files.') 

58 

59 sample_snap_choices = ('shift', 'interpolate') 

60 parser.add_argument( 

61 '--sample-snap', 

62 dest='sample_snap', 

63 choices=sample_snap_choices, 

64 help='shift/interpolate traces so that samples are at even multiples ' 

65 'of sampling rate. Choices: %s' % ', '.join(sample_snap_choices)) 

66 

67 parser.add_argument( 

68 '--downsample', 

69 dest='downsample', 

70 metavar='RATE', 

71 help='downsample to RATE [Hz]') 

72 

73 parser.add_argument( 

74 '--output', 

75 dest='output_path', 

76 metavar='TEMPLATE', 

77 help='set output path to TEMPLATE. Available placeholders ' 

78 'are %%n: network, %%s: station, %%l: location, %%c: channel, ' 

79 '%%b: begin time, %%e: end time, %%j: julian day of year. The ' 

80 'following additional placeholders use the window begin and end ' 

81 'times rather than trace begin and end times (to suppress ' 

82 'producing many small files for gappy traces), %%(wmin_year)s, ' 

83 '%%(wmin_month)s, %%(wmin_day)s, %%(wmin)s, %%(wmax_year)s, ' 

84 '%%(wmax_month)s, %%(wmax_day)s, %%(wmax)s. Example: ' 

85 '--output=\'data/%%s/trace-%%s-%%c.mseed\'') 

86 

87 parser.add_argument( 

88 '--output-dir', 

89 metavar='TEMPLATE', 

90 dest='output_dir', 

91 help='set output directory to TEMPLATE (see --output for details) ' 

92 'and automatically choose filenames. ' 

93 'Produces files like TEMPLATE/NET-STA-LOC-CHA_BEGINTIME.FORMAT') 

94 

95 parser.add_argument( 

96 '--output-format', 

97 dest='output_format', 

98 default='mseed', 

99 choices=io.allowed_formats('save'), 

100 help='set output file format. Choices: %s' % 

101 io.allowed_formats('save', 'cli_help', 'mseed')) 

102 

103 parser.add_argument( 

104 '--force', 

105 dest='force', 

106 action='store_true', 

107 default=False, 

108 help='force overwriting of existing files') 

109 

110 parser.add_argument( 

111 '--no-snap', 

112 dest='snap', 

113 action='store_false', 

114 default=True, 

115 help='do not start output files at even multiples of file length') 

116 

117 parser.add_argument( 

118 '--traversal', 

119 dest='traversal', 

120 choices=('station-by-station', 'channel-by-channel', 'chronological'), 

121 default='station-by-station', 

122 help='set traversal order for traces processing. ' 

123 'Choices are \'station-by-station\' [default], ' 

124 '\'channel-by-channel\', and \'chronological\'. Chronological ' 

125 'traversal uses more processing memory but makes it possible to ' 

126 'join multiple stations into single output files') 

127 

128 parser.add_argument( 

129 '--rename-network', 

130 action='append', 

131 default=[], 

132 dest='rename_network', 

133 metavar='/PATTERN/REPLACEMENT/', 

134 help='update network code, can be given more than once') 

135 

136 parser.add_argument( 

137 '--rename-station', 

138 action='append', 

139 default=[], 

140 dest='rename_station', 

141 metavar='/PATTERN/REPLACEMENT/', 

142 help='update station code, can be given more than once') 

143 

144 parser.add_argument( 

145 '--rename-location', 

146 action='append', 

147 default=[], 

148 dest='rename_location', 

149 metavar='/PATTERN/REPLACEMENT/', 

150 help='update location code, can be given more than once') 

151 

152 parser.add_argument( 

153 '--rename-channel', 

154 action='append', 

155 default=[], 

156 dest='rename_channel', 

157 metavar='/PATTERN/REPLACEMENT/', 

158 help='update channel code, can be given more than once') 

159 

160 parser.add_argument( 

161 '--output-data-type', 

162 dest='output_data_type', 

163 choices=('same', 'int32', 'int64', 'float32', 'float64'), 

164 default='same', 

165 metavar='DTYPE', 

166 help='set data type. Choices: same [default], int32, ' 

167 'int64, float32, float64. The output file format must support ' 

168 'the given type.') 

169 

170 parser.add_argument( 

171 '--output-record-length', 

172 dest='record_length', 

173 default=4096, 

174 choices=[b for b in io.mseed.VALID_RECORD_LENGTHS], 

175 type=int, 

176 metavar='RECORD_LENGTH', 

177 help='set the mseed record length in bytes. Choices: %s. ' 

178 'Default is 4096 bytes, which is commonly used for archiving.' 

179 % ', '.join(str(b) for b in io.mseed.VALID_RECORD_LENGTHS)) 

180 

181 parser.add_argument( 

182 '--output-steim', 

183 dest='steim', 

184 choices=[1, 2], 

185 default=2, 

186 type=int, 

187 metavar='STEIM_COMPRESSION', 

188 help='set the mseed STEIM compression. Choices: 1 or 2. ' 

189 'Default is STEIM-2, which can compress full range int32. ' 

190 'NOTE: STEIM-2 is limited to 30 bit dynamic range.') 

191 

192 quantity_choices = ('acceleration', 'velocity', 'displacement') 

193 parser.add_argument( 

194 '--output-quantity', 

195 dest='output_quantity', 

196 choices=quantity_choices, 

197 help='deconvolve instrument transfer function. Choices: %s' 

198 % ', '.join(quantity_choices)) 

199 

200 parser.add_argument( 

201 '--restitution-frequency-band', 

202 default='0.001,100.0', 

203 dest='str_fmin_fmax', 

204 metavar='FMIN,FMAX', 

205 help='frequency band for instrument deconvolution as FMIN,FMAX in Hz. ' 

206 'Default: "%(default)s"') 

207 

208 parser.add_argument( 

209 '--nthreads', 

210 metavar='NTHREADS', 

211 default=1, 

212 help='number of threads for processing, ' 

213 'this can speed-up CPU bound tasks (Python 3.5+ only)') 

214 

215 common.add_selection_arguments(parser) 

216 

217 

218def call(parser, args): 

219 

220 def get_pile(): 

221 squirrel = common.squirrel_from_selection_arguments(args) 

222 return squirrel.pile 

223 

224 args.station_fns = [] 

225 args.event_fns = [] 

226 args.station_xml_fns = [] 

227 args.record_length = int(args.record_length) 

228 

229 return process(get_pile, args)