# http://pyrocko.org - GPLv3 # # The Pyrocko Developers, 21st Century # ---|P------/S----------~Lg----------
''' Read SAC Pole-Zero file.
Returns (zeros, poles, constant). '''
elif string is not None: f = BytesIO(string)
f.close() raise SacPoleZeroError( 'Expected 2 tokens in line %i of file %s' % (iline+1, filename))
continue
else: complex(float(toks[0]), float(toks[1])))
raise SacPoleZeroError( 'Expected %i poles but found %i in pole-zero file "%s"' % (npoles, npoles_, filename)) raise SacPoleZeroError( 'Expected %i zeros but found %i in pole-zero file "%s"' % (nzeros, nzeros_, filename))
poles.extend([complex(0.)]*(npoles-npoles_))
raise SacPoleZeroError( 'No poles and zeros found in file "%s"' % (filename))
raise SacPoleZeroError( 'Not finite pole(s) found in pole-zero file "%s"' % filename)
raise SacPoleZeroError( 'Not finite zero(s) found in pole-zero file "%s"' % filename)
raise SacPoleZeroError( 'Ivalid constant (%g) found in pole-zero file "%s"' % (constant, filename))
else:
if hasattr(filename, 'write'): f = filename else: f = open('w', filename)
def write_complex(x): f.write('%12.8g %12.8g\n' % (complex(x).real, complex(x).imag))
f.write('POLES %i\n' % len(poles)) for p in poles: if p != 0.0: write_complex(p)
f.write('ZEROS %i\n' % len(zeros)) for z in zeros: if z != 0.0: write_complex(z)
f.write('CONSTANT %12.8g\n' % constant) if not hasattr(filename, 'write'): f.close()
logfmin = math.log(fmin) logfmax = math.log(fmax) logf = num.linspace(logfmin, logfmax, nf) f = num.exp(logf) trans = trace.PoleZeroResponse(zeros, poles, constant) return f, trans.evaluate(f)
jomeg = 1.0j * 2. * math.pi * f
a = constant for z in zeros: a *= jomeg-z for p in poles: a /= jomeg-p
return a
zpks, filename_pdf, fmin=0.001, fmax=100., nf=100, fnorm=None):
from pyrocko.plot import gmtpy
p = gmtpy.LogLogPlot(width=30*gmtpy.cm, yexp=0) for i, (zeros, poles, constant) in enumerate(zpks): f, h = evaluate(zeros, poles, constant, fmin, fmax, nf) if fnorm is not None: h /= evaluate_at(zeros, poles, constant, fnorm)
amp = num.abs(h) p.plot((f, amp), '-W2p,%s' % gmtpy.color(i))
p.save(filename_pdf)
from pyrocko.plot import gmtpy
p = gmtpy.LogLinPlot(width=30*gmtpy.cm) for i, (zeros, poles, constant) in enumerate(zpks): f, h = evaluate(zeros, poles, constant, fmin, fmax, nf) phase = num.unwrap(num.angle(h)) / d2r p.plot((f, phase), '-W1p,%s' % gmtpy.color(i))
p.save(filename_pdf) |