Beispiel #1
0
def from_event_mult_in():
    """Code to create files Fault.time, Fault.pos and Niu_model
    """
    if not os.path.isfile('Event_mult.in'):
        raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT),
                                'Event_mult.in')
    pk_dirs = mng.default_dirs()
    create_fault_files = pk_dirs['create_fault_files']
    compute_shear = pk_dirs['compute_shear']
    p = subprocess.Popen([create_fault_files, 'Event_mult.in', 'no'],
                         stdin=subprocess.PIPE,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE)
    p.wait()
    p2 = subprocess.Popen([
        compute_shear,
        'vel_model',
    ],
                          stdin=subprocess.PIPE,
                          stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE)
    p2.wait()
    ##
    ## create a json file with fault properties, and another for rise_time info
    ##
    #    segments, rise_time, point_sources = pl_mng.__read_planes_info()
    #    dictionary = {
    #            'segments': segments,
    #            'rise_time': rise_time
    #    }
    #    with open('segments_data.json', 'w') as outfile:
    #        json.dump(dictionary, outfile, sort_keys=True, indent=4,
    #                  separators=(',', ': '), ensure_ascii=False)
    return
Beispiel #2
0
            if line[i] == int(line[i]):
                line[i] = int(line[i])
        except:
            pass
    return line
    
    
if __name__ == '__main__':
    import argparse
    import management as mng
    parser = argparse.ArgumentParser()
    parser.add_argument("-o", "--output", help="name of output file")
    parser.add_argument("--lat", help="latitude of hypocenter location")
    parser.add_argument("--lon", help="longitude of hypocenter location")
    parser.add_argument("--depth", help="depth of hypocenter location")
    args = parser.parse_args()
    default_dirs = mng.default_dirs()
    tensor_info = {
        'lat': float(args.lat),
        'lon': float(args.lon),
        'depth': float(args.depth)
    }
    velmodel = select_velmodel(tensor_info, default_dirs)
    with open(args.output, 'w') as outf:
        nlen = len(velmodel['p_vel'])
        outf.write('{}\n'.format(nlen))
        zipped = zip(velmodel['p_vel'], velmodel['s_vel'], velmodel['thick'],
                     velmodel['dens'], velmodel['qa'], velmodel['qb'])
        for p, s, thick, dens, qa, qb in zipped:
            outf.write('{} {} {} {} {} {}\n'.format(p, s, dens, thick, qa, qb))
Beispiel #3
0
def input_chen_tele_surf(tensor_info, data_prop):
    """Based on the teleseismic surface body waves acquired, we write some
    files with such data as input for Chen's fortran scripts.

    :param tensor_info: dictionary with moment tensor information
    :param data_prop: dictionary with properties of waveform data
    :type tensor_info: dict
    :type data_prop: dict
    """
    if not os.path.isfile('surf_waves.json'):
        return
    dirs = mng.default_dirs()
    gf_bank = dirs['long_gf_bank']
    traces_info = json.load(open('surf_waves.json'))

    depth = tensor_info['depth']
    event_lat = tensor_info['lat']
    event_lon = tensor_info['lon']

    nsta = len(traces_info)

    date_origin = tensor_info['date_origin']
    string = '{:3d} {:>6} {:>8.3f} {:>9.3f} 31' + 3 * '  {:>1}'\
            + 2 * ' {:>7.2f}' + '  1' + 3 * '  {:>7.2f}' + ' 0\n'
    string_fun = lambda i, name, lat, lon, a, b, c, d, e, weight:\
        string.format(i, name, lat, lon, a, b, c, d, e,
                      weight, weight, weight)

    with open('Readlp.inf_low', 'w') as outfile:
        outfile.write('{}{}{}{}{}{}.{}\n'.format(
            date_origin.year, date_origin.month, date_origin.day,
            date_origin.hour, date_origin.minute, date_origin.second,
            date_origin.microsecond))
        outfile.write('{} {} {} {} {} {} {} {} {}\n'.format(
            event_lat, event_lon, depth, date_origin.year, date_origin.julday,
            date_origin.hour, date_origin.minute, date_origin.second,
            date_origin.microsecond))
        outfile.write('0.0 90.0 0.0 10 4.0 1.0e+26\n')
        outfile.write('4.0 4.0 10 1.0 {}\n'.format(0))
        outfile.write('{} {}\n'.format(nsta, nsta))
        outfile.write('No STA Lat Lon M V H1 H2 Angle1 Angle2 Io_s Weight\n')
        i = 0
        for file in traces_info:
            weight = file['trace_weight']
            name = file['name']
            channel = file['component']
            lat, lon = file['location']
            if channel == 'BHZ':  # Rayleigh
                outfile.write(
                    string_fun(i + 1, name, lat, lon, 1, 0, 0, 0, 0, weight))
            else:  # Love
                outfile.write(
                    string_fun(i + 1, name, lat, lon, 0, 1, 0, 90, 0, weight))
            i = i + 1

    with open('Wave.str_low', 'w') as file1, open('Obser.str_low',
                                                  'w') as file2:
        write_files_wavelet_observed(file1,
                                     file2,
                                     4.0,
                                     data_prop,
                                     traces_info,
                                     gf_bank=gf_bank)

    write_wavelet_freqs(4.0, 'Wavelets_surf_tele')
    return