def save(traces, filename_template, additional={}): from pyrocko import mseed_ext fn_tr = {} for tr in traces: for code, maxlen, val in zip( ['network', 'station', 'location', 'channel'], [2, 5, 2, 3], tr.nslc_id): if len(val) > maxlen: raise CodeTooLong( '%s code too long to be stored in MSeed file: %s' % (code, val)) fn = tr.fill_template(filename_template, **additional) if fn not in fn_tr: fn_tr[fn] = [] fn_tr[fn].append(tr) for fn, traces_thisfile in fn_tr.items(): trtups = [] traces_thisfile.sort(lambda a,b: cmp(a.full_id, b.full_id)) for tr in traces_thisfile: trtups.append(as_tuple(tr)) ensuredirs(fn) try: mseed_ext.store_traces(trtups, fn) except mseed_ext.MSeedError, e: raise FileSaveError( str(e) + ' (while storing traces to file \'%s\')' % fn)
def save(traces, filename_template, additional={}, overwrite=True): from pyrocko import mseed_ext fn_tr = {} for tr in traces: for code, maxlen, val in zip( ['network', 'station', 'location', 'channel'], [2, 5, 2, 3], tr.nslc_id): if len(val) > maxlen: raise CodeTooLong( '%s code too long to be stored in MSeed file: %s' % (code, val)) fn = tr.fill_template(filename_template, **additional) if not overwrite and os.path.exists(fn): raise FileSaveError('file exists: %s' % fn) if fn not in fn_tr: fn_tr[fn] = [] fn_tr[fn].append(tr) for fn, traces_thisfile in fn_tr.items(): trtups = [] traces_thisfile.sort(lambda a, b: cmp(a.full_id, b.full_id)) for tr in traces_thisfile: trtups.append(as_tuple(tr)) ensuredirs(fn) try: mseed_ext.store_traces(trtups, fn) except mseed_ext.MSeedError, e: raise FileSaveError( str(e) + ' (while storing traces to file \'%s\')' % fn)
def save(traces, filename_template, additional={}, overwrite=True, steim=1, record_length=4096): from pyrocko import mseed_ext assert record_length in VALID_RECORD_LENGTHS fn_tr = {} for tr in traces: for code, maxlen, val in zip( ['network', 'station', 'location', 'channel'], [2, 5, 2, 3], tr.nslc_id): if len(val) > maxlen: raise CodeTooLong( '%s code too long to be stored in MSeed file: %s' % (code, val)) fn = tr.fill_template(filename_template, **additional) if not overwrite and os.path.exists(fn): raise FileSaveError('File exists: %s' % fn) if fn not in fn_tr: fn_tr[fn] = [] fn_tr[fn].append(tr) for fn, traces_thisfile in fn_tr.items(): trtups = [] traces_thisfile.sort(key=lambda a: a.full_id) for tr in traces_thisfile: trtups.append(as_tuple(tr)) ensuredirs(fn) try: mseed_ext.store_traces(trtups, fn, record_length=record_length, steim=steim) except mseed_ext.MSeedError as e: raise FileSaveError( str(e) + ' (while storing traces to file \'%s\')' % fn) return list(fn_tr.keys())