def state(self): """return state for testing.""" from obspy.core.util import AttribDict out = AttribDict() # path to test files # self.path = # general constants tmax = 6. out.dt = 0.01 npts = int(tmax / out.dt + 1) t = np.linspace(0., tmax, npts) out.fmin = .5 out.fmax = 10 # constants for the signal a1 = 4. t1 = 2. f1 = 2. phi1 = 0. # amplitude and phase error phase_shift = 0.1 amp_fac = 1.2 # generate the signal h1 = (np.sign(t - t1) + 1) / 2 out.st1 = a1 * (t - t1) * np.exp(-2 * (t - t1)) out.st1 *= np.cos(2. * np.pi * f1 * (t - t1) + phi1 * np.pi) * h1 # reference signal out.st2 = out.st1.copy() # generate analytical signal (hilbert transform) and add phase shift out.st1p = hilbert(out.st1) out.st1p = np.real( np.abs(out.st1p) * np.exp( (np.angle(out.st1p) + phase_shift * np.pi) * 1j)) # signal with amplitude error out.st1p /= amp_fac return out
def __init__(self, filename): if type(filename) is str: output_ = AttribDict() grid = output_.setdefault('grid', []) reciever = output_.setdefault('reciever', []) corners = output_.setdefault('corners', []) fh = open(filename, 'r') while True: line = fh.readline() if not line: fh.close() break else: line = line.strip() if 'reading input file' in line: output_.read_input_file_phase = line.split( 'reading input file')[1] continue if 'start up phase' in line: output_.start_up_phase = line.split('start up phase')[1] continue if 'solver phase' in line: output_.solver_phase = line.split('solver phase')[1] continue if line.startswith('Grid'): line = line.split() keys = line while True: line = fh.readline() if line.startswith('Total'): grid.append( AttribDict( {'points': int(float(line.split()[-1]))})) break else: line = line.split() grid_i = AttribDict() for k, v in zip(keys, line): grid_i[k] = int(v) grid.append(grid_i) if line.startswith('Receiver INFO'): name = line.split()[-1][:-1] while True: line = fh.readline().strip() if line.startswith('nearest'): x, y, z = [ float(item) for item in line.split()[5:8]] station = AttribDict( {'station': name, 'x': x, 'y': y, 'z': z}) reciever.append(station) break if line.startswith('Geographic and Cartesian'): for i in range(4): line = fh.readline().split(',') number, lon = line[0].split(':') line[0] = lon corner = AttribDict({'number': number}) for item in line: k, v = item.split('=') corner[k.strip()] = float(v) corners.append(corner) continue if line.startswith('Start Time'): start_time, goal_time = line.split('Goal Time =') output_.start_time = float(start_time.split('=')[1]) output_.goal_time = float(goal_time) continue if line.startswith('Number of time steps'): npts, dt = line.split('dt:') output_.npts = int(npts.split('=')[1]) output_.dt = float(dt) continue if line.startswith('Total seismic moment'): output_.M0 = float(line.split()[4]) continue if line.startswith('Moment magnitude'): output_.Mw = float(line.split()[3]) else: output_ = filename super(Outputfile, self).__init__(output_)