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 import io
9from pyrocko.apps.jackseis import process, tfmt
12def make_subparser(subparsers):
13 return subparsers.add_parser(
14 'jackseis-classic',
15 help='Squirrel\'s adaption of classic Jackseis.')
18def setup(parser):
19 parser.add_argument(
20 '--pattern',
21 dest='regex',
22 metavar='REGEX',
23 help='only include files whose paths match REGEX')
25 parser.add_argument(
26 '--quiet',
27 dest='quiet',
28 action='store_true',
29 default=False,
30 help='disable output of progress information')
32 parser.add_argument(
33 '--debug',
34 dest='debug',
35 action='store_true',
36 default=False,
37 help='print debugging information to stderr')
39 parser.add_argument(
40 '--tmin',
41 dest='tmin',
42 help='start time as "%s"' % tfmt)
44 parser.add_argument(
45 '--tmax',
46 dest='tmax',
47 help='end time as "%s"' % tfmt)
49 parser.add_argument(
50 '--tinc',
51 dest='tinc',
52 help='set time length of output files [s] or "auto" to automatically '
53 'choose an appropriate time increment or "huge" to allow to use '
54 'a lot of system memory to merge input traces into huge output '
55 'files.')
57 sample_snap_choices = ('shift', 'interpolate')
58 parser.add_argument(
59 '--sample-snap',
60 dest='sample_snap',
61 choices=sample_snap_choices,
62 help='shift/interpolate traces so that samples are at even multiples '
63 'of sampling rate. Choices: %s' % ', '.join(sample_snap_choices))
65 parser.add_argument(
66 '--downsample',
67 dest='downsample',
68 metavar='RATE',
69 help='downsample to RATE [Hz]')
71 parser.add_argument(
72 '--output',
73 dest='output_path',
74 metavar='TEMPLATE',
75 help='set output path to TEMPLATE. Available placeholders '
76 'are %%n: network, %%s: station, %%l: location, %%c: channel, '
77 '%%b: begin time, %%e: end time, %%j: julian day of year. The '
78 'following additional placeholders use the window begin and end '
79 'times rather than trace begin and end times (to suppress '
80 'producing many small files for gappy traces), %%(wmin_year)s, '
81 '%%(wmin_month)s, %%(wmin_day)s, %%(wmin)s, %%(wmax_year)s, '
82 '%%(wmax_month)s, %%(wmax_day)s, %%(wmax)s. Example: '
83 '--output=\'data/%%s/trace-%%s-%%c.mseed\'')
85 parser.add_argument(
86 '--output-dir',
87 metavar='TEMPLATE',
88 dest='output_dir',
89 help='set output directory to TEMPLATE (see --output for details) '
90 'and automatically choose filenames. '
91 'Produces files like TEMPLATE/NET-STA-LOC-CHA_BEGINTIME.FORMAT')
93 parser.add_argument(
94 '--output-format',
95 dest='output_format',
96 default='mseed',
97 choices=io.allowed_formats('save'),
98 help='set output file format. Choices: %s' %
99 io.allowed_formats('save', 'cli_help', 'mseed'))
101 parser.add_argument(
102 '--force',
103 dest='force',
104 action='store_true',
105 default=False,
106 help='force overwriting of existing files')
108 parser.add_argument(
109 '--no-snap',
110 dest='snap',
111 action='store_false',
112 default=True,
113 help='do not start output files at even multiples of file length')
115 parser.add_argument(
116 '--traversal',
117 dest='traversal',
118 choices=('station-by-station', 'channel-by-channel', 'chronological'),
119 default='station-by-station',
120 help='set traversal order for traces processing. '
121 'Choices are \'station-by-station\' [default], '
122 '\'channel-by-channel\', and \'chronological\'. Chronological '
123 'traversal uses more processing memory but makes it possible to '
124 'join multiple stations into single output files')
126 parser.add_argument(
127 '--rename-network',
128 action='append',
129 default=[],
130 dest='rename_network',
131 metavar='/PATTERN/REPLACEMENT/',
132 help='update network code, can be given more than once')
134 parser.add_argument(
135 '--rename-station',
136 action='append',
137 default=[],
138 dest='rename_station',
139 metavar='/PATTERN/REPLACEMENT/',
140 help='update station code, can be given more than once')
142 parser.add_argument(
143 '--rename-location',
144 action='append',
145 default=[],
146 dest='rename_location',
147 metavar='/PATTERN/REPLACEMENT/',
148 help='update location code, can be given more than once')
150 parser.add_argument(
151 '--rename-channel',
152 action='append',
153 default=[],
154 dest='rename_channel',
155 metavar='/PATTERN/REPLACEMENT/',
156 help='update channel code, can be given more than once')
158 parser.add_argument(
159 '--output-data-type',
160 dest='output_data_type',
161 choices=('same', 'int32', 'int64', 'float32', 'float64'),
162 default='same',
163 metavar='DTYPE',
164 help='set data type. Choices: same [default], int32, '
165 'int64, float32, float64. The output file format must support '
166 'the given type.')
168 parser.add_argument(
169 '--output-record-length',
170 dest='record_length',
171 default=4096,
172 choices=[b for b in io.mseed.VALID_RECORD_LENGTHS],
173 type=int,
174 metavar='RECORD_LENGTH',
175 help='set the mseed record length in bytes. Choices: %s. '
176 'Default is 4096 bytes, which is commonly used for archiving.'
177 % ', '.join(str(b) for b in io.mseed.VALID_RECORD_LENGTHS))
179 parser.add_argument(
180 '--output-steim',
181 dest='steim',
182 choices=[1, 2],
183 default=2,
184 type=int,
185 metavar='STEIM_COMPRESSION',
186 help='set the mseed STEIM compression. Choices: 1 or 2. '
187 'Default is STEIM-2, which can compress full range int32. '
188 'NOTE: STEIM-2 is limited to 30 bit dynamic range.')
190 quantity_choices = ('acceleration', 'velocity', 'displacement')
191 parser.add_argument(
192 '--output-quantity',
193 dest='output_quantity',
194 choices=quantity_choices,
195 help='deconvolve instrument transfer function. Choices: %s'
196 % ', '.join(quantity_choices))
198 parser.add_argument(
199 '--restitution-frequency-band',
200 default='0.001,100.0',
201 dest='str_fmin_fmax',
202 metavar='FMIN,FMAX',
203 help='frequency band for instrument deconvolution as FMIN,FMAX in Hz. '
204 'Default: "%(default)s"')
206 parser.add_argument(
207 '--nthreads',
208 metavar='NTHREADS',
209 default=1,
210 help='number of threads for processing, '
211 'this can speed-up CPU bound tasks (Python 3.5+ only)')
213 parser.add_squirrel_selection_arguments()
216def run(parser, args):
218 def get_pile():
219 squirrel = args.make_squirrel()
220 return squirrel.pile
222 args.station_fns = []
223 args.event_fns = []
224 args.station_xml_fns = []
225 args.record_length = int(args.record_length)
227 return process(get_pile, args)