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