Coverage for /opt/obspy/update-docs/src/obspy/obspy/signal/calibration : 77%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/env python #------------------------------------------------------------------- # Filename: calibration.py # Purpose: Functions for relative calibration (e.g. Huddle test calibration) # Author: Felix Bernauer, Simon Kremers # Email: bernauer@geophysik.uni-muenchen.de # # Copyright (C) 2011 Felix Bernauer, Simon Kremers #--------------------------------------------------------------------- Functions for relative calibration.
:copyright: The ObsPy Development Team (devs@obspy.org) :license: GNU Lesser General Public License, Version 3 (http://www.gnu.org/copyleft/lesser.html) """
save_data=True): """ Method for relative calibration of sensors using a sensor with known transfer function
:param st1: Stream or Trace object, (known) :param st2: Stream or Trace object, (unknown) :type calib_file: String :param calib_file: file name of calibration file containing the PAZ of the known instrument in GSE2 standard. :type window_len: Float :param window_len: length of sliding window in seconds :type overlap_frac: float :param overlap_frac: fraction of overlap, defaults to fifty percent (0.5) :type smooth: Float :param smooth: variable that defines if the Konno-Ohmachi taper is used or not. default = 0 -> no taper generally used in geopsy: smooth = 40 :type save_data: Boolean :param save_data: Whether or not to save the result to a file. If True, two output files will be created: * The new response in station_name.window_length.resp * The ref response in station_name.refResp Defaults to True :returns: frequency, amplitude and phase spectrum
implemented after relcalstack.c by M.Ohrnberger and J.Wassermann. """ # transform given trace objects to streams # check if sampling rate and trace length is the same msg = "Traces don't have the same length!" raise ValueError(msg) msg = "Traces don't have the same sampling rate!" raise ValueError(msg) else:
# read waveforms
# get window length, nfft and frequency step
# read calib file and calculate response function
# calculate number of windows and overlap
spectral_helper(tr1, tr1, NFFT=nfft, Fs=sampfreq, noverlap=noverlap) spectral_helper(tr1, tr2, NFFT=nfft, Fs=sampfreq, noverlap=noverlap)
# 180 Grad Phasenverschiebung
# Replaces the following in compact form: # res = np.zeros(nfft / 2 + 1, dtype='complex128') # for i in range(nwin): # res += (cross[:, i] / auto[:, i]) * gg
# The first item might be zero. Problems with phase calculations.
# apply Konno-Ohmachi smoothing taper if chosen # Write in one matrix for performance reasons. count=1, max_memory_usage=1024, normalize=True)
trans_new = st2[0].stats.station + "." + str(window_len) + ".resp" trans_ref = st1[0].stats.station + ".refResp" # Create empty array for easy saving temp = np.empty((len(freq), 3)) temp[:, 0] = freq temp[:, 1] = amp temp[:, 2] = phase np.savetxt(trans_new, temp, fmt="%.10f") temp[:, 1] = ra temp[:, 2] = rpha np.savetxt(trans_ref, temp, fmt="%.10f")
""" Calculate transfer function of known system.
:type calfile: String :param calfile: file containing poles, zeros and scale factor for known system :returns: complex transfer function, array of frequencies """ # calculate transfer function nfft, freq=True)
# A modified copy of the Matplotlib 0.99.1.1 method spectral_helper found in # .../matlab/mlab.py. # Some function were changed to avoid additional dependencies. Included here as # it is essential for the above relcalstack function and only present in recent # matplotlib versions.
#This is a helper function that implements the commonality between the #psd, csd, and spectrogram. It is *NOT* meant to be used outside of mlab sides='default', scale_by_freq=None): #The checks for if y is x are so that we can use the same function to #implement the core of psd(), csd(), and spectrogram() without doing #extra calculations. We return the unaveraged Pxy, freqs, and t.
#Make sure we're dealing with a numpy array. If y and x were the same #object to start with, keep them that way
# zero pad x and y up to NFFT if they are shorter than NFFT n = len(x) x = np.resize(x, (NFFT,)) x[n:] = 0
n = len(y) y = np.resize(y, (NFFT,)) y[n:] = 0
# For real x, ignore the negative frequencies unless told otherwise numFreqs = pad_to scaling_factor = 1. else: raise ValueError("sides must be one of: 'default', 'onesided', or " "'twosided'")
# Matlab divides by the sampling frequency so that density function # has units of dB/Hz and can be integrated by the plotted frequency # values. Perform the same scaling here.
# do the ffts of the slices
else:
# Scale the spectrum by the norm of the window to compensate for # windowing loss; see Bendat & Piersol Sec 11.5.2. Also include # scaling factors for one-sided densities and dividing by the sampling # frequency, if desired.
# center the frequency range at zero freqs = np.concatenate((freqs[numFreqs // 2:] - Fs, freqs[:numFreqs // 2])) Pxy = np.concatenate((Pxy[numFreqs // 2:, :], Pxy[:numFreqs // 2, :]), 0)
|