# http://pyrocko.org - GPLv3 # # The Pyrocko Developers, 21st Century # ---|P------/S----------~Lg----------
''' Read SAC Pole-Zero file.
:returns: ``(zeros, poles, constant)`` or ``(zeros, poles, constant, comments)`` if ``get_comments`` is True. '''
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
''' Read SAC pole-zero file into Pyrocko response object.
:returns: Response as a :py:class:~pyrocko.trace.PoleZeroResponse` object. '''
filename=filename, file=file, string=string)
input_unit, output_unit, normalization_frequency=1.0, filename=None, file=None, string=None): ''' Read SAC pole-zero file into StationXML response object.
:param input_unit: Input unit to be reported in the StationXML response. :type input_unit: str :param output_unit: Output unit to be reported in the StationXML response. :type output_unit: str :param normalization_frequency: Frequency where the normalization factor for the StationXML response should be computed. :type normalization_frequency: float
:returns: Response as a :py:class:~pyrocko.io.stationxml.Response` object with a single pole-zero response stage. '''
filename=filename, file=file, string=string)
presponse, input_unit, output_unit, normalization_frequency)
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) |