Coverage for /opt/obspy/update-docs/src/obspy/obspy/signal/util : 83%

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 Various additional utilities for obspy.signal.
:copyright: The ObsPy Development Team (devs@obspy.org) :license: GNU Lesser General Public License, Version 3 (http://www.gnu.org/copyleft/lesser.html) """
""" Transform lon, lat to km in reference to orig_lon and orig_lat
>>> utlGeoKm(12.0, 48.0, 12.0, 48.0) (0.0, 0.0) >>> x, y = utlGeoKm(12.0, 48.0, 13.0, 49.0) >>> print(round(x,7)) 73.9041417 >>> print(round(y,7)) 111.1908262
:param orig_lon: Longitude of reference origin :param orig_lat: Latitude of reference origin :param lat: Latitude to calculate relative coordinate in km :param lon: Longitude to calculate relative coordinate in km :return: x, y coordinate in km (in reference to origin) """ # 2009-10-11 Moritz
""" Transform x, y [km] to decimal degree in reference to orig_lon and orig_lat
>>> utlLonLat(12.0, 48.0, 0.0, 0.0) (12.0, 48.0) >>> lon, lat = utlLonLat(12.0, 48.0, 73.9041, 111.1908) >>> print("%.4f, %.4f" % (lon, lat)) 13.0000, 49.0000
:param orig_lon: Longitude of reference origin :param orig_lat: Latitude of reference origin :param x: value [km] to calculate relative coordinate in degree :param y: value [km] to calculate relative coordinate in degree :return: lon, lat coordinate in degree (absolute) """ # 2009-10-11 Moritz
C.c_double, C.POINTER(C.c_double), C.POINTER(C.c_double)]
""" Find the next power of two
>>> nextpow2(5) 8 >>> nextpow2(250) 256 """ # do not use numpy here, math is much faster for single values
""" Find the previous power of two
>>> prevpow2(5) 4 >>> prevpow2(250) 128 """ # do not use numpy here, math is much faster for single values
""" Finds the nearest integer that is a power of 2. In contrast to :func:`nextpow2` also searches for numbers smaller than the input and returns them if they are closer than the next bigger power of 2. """ a = M.pow(2, M.ceil(M.log(x, 2))) b = M.pow(2, M.floor(M.log(x, 2))) if abs(a - x) < abs(b - x): return int(a) else: return int(b)
""" Splits the vector up into (overlapping) frames beginning at increments of inc. Each frame is multiplied by the window win(). The length of the frames is given by the length of the window win(). The centre of frame I is x((I-1)*inc+(length(win)+1)/2) for I=1,2,...
:param x: signal to split in frames :param win: window multiplied to each frame, length determines frame length :param inc: increment to shift frames, in samples :return f: output matrix, each frame occupies one row :return length, no_win: length of each frame in samples, number of frames """ length = win else: #length = nextpow2(nwin) #f = np.zeros((nf, length)) np.vstack([inds] * nf)) - 1]
""" Smoothes a given signal by computing a central moving average.
:param x: signal to smooth :param smoothie: number of past/future values to calculate moving average :return out: smoothed signal """ #out_add = append(append([x[0,:]]*smoothie,x,axis=0), # [x[(len(x)-1),:]]*smoothie,axis=0) #out_add = (np.append([x[0, :]]*int(smoothie), x, axis=0)) [x[(len(x) - 1), :]] * int(smoothie))) #out = signal.lfilter(np.ones(smoothie) / smoothie, 1, help) 0, np.ones(smoothie) / (2 * smoothie))), 1, help) #out = out[smoothie:len(out), :] #out = filter(ones(1,smoothie)/smoothie,1,out_add) #out[1:smoothie,:] = [] else: #out_add = np.append(np.append([x[0]] * smoothie, x), # [x[size_x - 1]] * smoothie) [x[(len(x) - 1)]] * int(smoothie))) 0, np.ones(smoothie) / (2 * smoothie))), 1, out_add) #for i in xrange(smoothie, len(x) + smoothie): # sum = 0 # for k in xrange(-smoothie, smoothie): # sum = sum + out_add[i + k] # suma[i - smoothie] = float(sum) / (2 * smoothie) # out = suma # out[0:smoothie] = out[smoothie] # out[size_x - 1 - smoothie:size_x] = \ # out[size_x - 1 - smoothie] else: out = x
""" Computes discrete cosine transform of given signal. Signal is truncated/padded to length n.
:params x: signal to compute discrete cosine transform :params n: window length (default: signal length) :return y: discrete cosine transform """ np.arange(1, n))) np.transpose(np.array([z])) * np.ones(k))) / float(a)
""" Helper function to convert from azimuth to backazimuth or from backazimuth to azimuth.
:type angle: float or int :param angle: azimuth or backazimuth value in degrees between 0 and 360. :return: corresponding backazimuth or azimuth value in degrees. """ if 0 <= angle <= 180: new_angle = angle + 180 elif 180 < angle <= 360: new_angle = angle - 180 else: raise ValueError("Input (back)azimuth out of bounds: %s" % angle) return new_angle
if __name__ == '__main__': import doctest doctest.testmod(exclude_empty=True) |