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