Exemplo n.º 1
0
data_glob = "*2010-10-14T00:15:40.98*.dat"
data_files=glob.glob(data_path + os.sep + data_glob)

hdr_file="%s/grid.500m.search.hdr"%lib_path

# creat the object to contain the stations
pd = tvtk.PolyData()
pd.points = [[s.x/1000.0, s.y/1000.0, -s.elev/1000.0] for s in sta.stations.values()]

# create the DEM
dem_data=tvtk.PolyData()
dem_data.points = numpy.array([demx, demy, demz]).T

for data_file in data_files : 
  print data_file
  data=QDGrid()
  data.read_NLL_hdr_file(hdr_file)
  data.buf=numpy.fromfile(data_file, dtype=numpy.int16)
  data.buf=numpy.array(data.buf, dtype=numpy.float)
  print data.buf.min(), data.buf.max()
  data.buf.shape = (data.nx, data.ny, data.nz)
  max_ib=numpy.argmax(data.buf)
  ix,iy,iz=data.get_ix_iy_iz(max_ib)


  

  # 'mayavi' is always defined on the interpreter.
  e = OffScreenEngine()
  #e = Engine()
  e.start()
Exemplo n.º 2
0
sta = StationList()
sta.read_from_file(stations_filename)

cha = ChannelList()
cha.populate_from_station_list(sta, comp_string=["HHZ"])

time_grid = QDTimeGrid()
time_grid.read_NLL_hdr_file(search_grid_filename)
load_ttimes_buf = wo.opdict['load_ttimes_buf']
if recalc_grids:
    time_grid.populate_from_time_grids(grid_filename_base, cha, out_dir,
                                       load_ttimes_buf)

# set up basic grid information for test
grid_filename = os.path.join(base_path, 'lib', wo.opdict['search_grid'])
dummy_grid = QDGrid()
dummy_grid.read_NLL_hdr_file(grid_filename)
# set up projection information for test
f = open(grid_filename)
lines = f.readlines()
f.close()
proj_line = lines[1]
proj_info = {}
proj_info['orig_lat'] = np.float(proj_line.split()[3])
proj_info['orig_lon'] = np.float(proj_line.split()[5])
proj_info['map_rot'] = np.float(proj_line.split()[7])

print proj_info

event1ll = (44.9235, 11.1418)
event2ll = (44.8833, 11.1350)
Exemplo n.º 3
0
# read the time-grid
sta=StationList()
sta.read_from_file(stations_filename)

cha=ChannelList()
cha.populate_from_station_list(sta,comp_string=["HHZ"])

time_grid=QDTimeGrid()
time_grid.read_NLL_hdr_file(search_grid_filename)
load_ttimes_buf=wo.opdict['load_ttimes_buf']
if recalc_grids : time_grid.populate_from_time_grids(grid_filename_base,cha,out_dir,load_ttimes_buf)


# set up basic grid information for test
grid_filename=os.path.join(base_path,'lib',wo.opdict['search_grid'])
dummy_grid=QDGrid()
dummy_grid.read_NLL_hdr_file(grid_filename)
# set up projection information for test
f=open(grid_filename)
lines=f.readlines()
f.close()
proj_line=lines[1]
proj_info={}
proj_info['orig_lat'] = np.float(proj_line.split()[3])
proj_info['orig_lon'] = np.float(proj_line.split()[5])
proj_info['map_rot'] = np.float(proj_line.split()[7])

print proj_info


event1ll=(44.9235 , 11.1418)
Exemplo n.º 4
0
data_files = glob.glob(data_path + os.sep + data_glob)

hdr_file = "%s/grid.500m.search.hdr" % lib_path

# creat the object to contain the stations
pd = tvtk.PolyData()
pd.points = [[s.x / 1000.0, s.y / 1000.0, -s.elev / 1000.0]
             for s in sta.stations.values()]

# create the DEM
dem_data = tvtk.PolyData()
dem_data.points = numpy.array([demx, demy, demz]).T

for data_file in data_files:
    print data_file
    data = QDGrid()
    data.read_NLL_hdr_file(hdr_file)
    data.buf = numpy.fromfile(data_file, dtype=numpy.int16)
    data.buf = numpy.array(data.buf, dtype=numpy.float)
    print data.buf.min(), data.buf.max()
    data.buf.shape = (data.nx, data.ny, data.nz)
    max_ib = numpy.argmax(data.buf)
    ix, iy, iz = data.get_ix_iy_iz(max_ib)

    # 'mayavi' is always defined on the interpreter.
    e = OffScreenEngine()
    #e = Engine()
    e.start()
    win = e.new_scene(magnification=1)
    win.scene.isometric_view()
Exemplo n.º 5
0
def plot_slice_mayavi(dat_filename,output_file,hyp_x,hyp_y,hyp_z,search_grid_file_name,max_stack_value):

  base_path=os.getenv('WAVELOC_PATH')
  lib_path="%s/lib"%base_path

  # grid geometry
  hdr_file=lib_path + os.sep + search_grid_file_name

  # detection
  detection=50

  # stations
  stations_file="%s/coord_stations_piton"%lib_path
  sta=StationList()
  sta.read_from_file(stations_file)

  # create the object to contain the stations
  pd = tvtk.PolyData()
  pd.points = [[s.x/1000.0, s.y/1000.0, -s.elev/1000.0] for s in sta.stations.values()]

  # create the object to contain the stations
  try:
    pd_hyp = tvtk.PolyData()
    pd_hyp.points=[[hyp_x,hyp_y,hyp_z]]
  except TypeError:
    pass

  # read the dat file
  print dat_filename
  data=QDGrid()
  data.read_NLL_hdr_file(hdr_file)
  data.buf=numpy.fromfile(dat_filename, dtype=numpy.int16)
  max_ib=numpy.argmax(data.buf)
  print max_ib
  max_val=data.buf[max_ib]
  ix,iy,iz=data.get_ix_iy_iz(max_ib)
  #data.buf=numpy.array(data.buf, dtype=numpy.float)
  data.buf.shape = (data.nx, data.ny, data.nz)


  # 'mayavi' is always defined on the interpreter.
  e = OffScreenEngine()
  #e = Engine()
  e.start()
  win = e.new_scene(magnification=1)
  e.current_scene.scene.off_screen_rendering = True
  win.scene.isometric_view()
  
  # Make the data and add it to the pipeline.
  src = ArraySource(transpose_input_array=True)
  src.scalar_data = data.buf
  src.spacing=(data.dx, data.dy, -data.dz)
  src.origin=(data.x_orig, data.y_orig, -data.z_orig)
  e.add_source(src)

  # Visualize the data.
  o = Outline()
  e.add_module(o)

  lut=e.scenes[0].children[0].children[0].scalar_lut_manager
  lut.data_range=[-1,max_stack_value]
  lut.show_legend = True
  lut.data_name = 'Stack'


  # Create one ContourGridPlane normal to the 'x' axis.
  cgp = ContourGridPlane()
  e.add_module(cgp)
  # Set the position to the middle of the data.
  if max_val > detection:
    cgp.grid_plane.position = ix
  else:
    cgp.grid_plane.position = data.nx/2
  cgp.contour.filled_contours = True
  cgp.actor.property.opacity = 0.6
  output=cgp.grid_plane.outputs[0]
  x_data=numpy.array(output.point_data.scalars.to_array())

  # Another with filled contours normal to 'y' axis.
  cgp = ContourGridPlane()
  e.add_module(cgp)
  # Set the axis and position to the middle of the data.
  cgp.grid_plane.axis = 'y'
  if max_val > detection:
    cgp.grid_plane.position = iy
  else:
    cgp.grid_plane.position = data.ny/2
  cgp.contour.filled_contours = True
  cgp.actor.property.opacity = 0.6
  output=cgp.grid_plane.outputs[0]
  y_data=numpy.array(output.point_data.scalars.to_array())

  # Another with filled contours normal to 'z' axis.
  cgp = ContourGridPlane()
  e.add_module(cgp)
  # Set the axis and position to the middle of the data.
  cgp.grid_plane.axis = 'z'
  if max_val > detection:
    cgp.grid_plane.position = iz
  else:
    cgp.grid_plane.position = data.nz/2
  cgp.contour.filled_contours = True
  cgp.actor.property.opacity = 0.6
  output=cgp.grid_plane.outputs[0]
  z_data=numpy.array(output.point_data.scalars.to_array())

  a=Axes()
  e.add_module(a)

  d=VTKDataSource()
  d.data=pd
  e.add_source(d)
  
  g=Glyph()
  e.add_module(g)
  g.glyph.glyph_source.glyph_source=g.glyph.glyph_source.glyph_list[4]
  g.glyph.glyph_source.glyph_source.radius=0.1

  d=VTKDataSource()
  d.data=pd_hyp
  e.add_source(d)
  
  g=Glyph()
  e.add_module(g)
  g.glyph.glyph_source.glyph_source=g.glyph.glyph_source.glyph_list[4]
  g.glyph.glyph_source.glyph_source.radius=0.5
  g.actor.property.color=(0.0,0.0,0.0)



  #view(azimuth=-60,elevation=60,distance=120)
  win.scene.save(output_file,size=(800,800))

  e.stop()
  del win
  del e

  return (x_data, y_data, z_data)
Exemplo n.º 6
0
def plot_slice_mayavi(dat_filename, output_file, hyp_x, hyp_y, hyp_z,
                      search_grid_file_name, max_stack_value):

    base_path = os.getenv('WAVELOC_PATH')
    lib_path = "%s/lib" % base_path

    # grid geometry
    hdr_file = lib_path + os.sep + search_grid_file_name

    # detection
    detection = 50

    # stations
    stations_file = "%s/coord_stations_piton" % lib_path
    sta = StationList()
    sta.read_from_file(stations_file)

    # create the object to contain the stations
    pd = tvtk.PolyData()
    pd.points = [[s.x / 1000.0, s.y / 1000.0, -s.elev / 1000.0]
                 for s in sta.stations.values()]

    # create the object to contain the stations
    try:
        pd_hyp = tvtk.PolyData()
        pd_hyp.points = [[hyp_x, hyp_y, hyp_z]]
    except TypeError:
        pass

    # read the dat file
    print dat_filename
    data = QDGrid()
    data.read_NLL_hdr_file(hdr_file)
    data.buf = numpy.fromfile(dat_filename, dtype=numpy.int16)
    max_ib = numpy.argmax(data.buf)
    print max_ib
    max_val = data.buf[max_ib]
    ix, iy, iz = data.get_ix_iy_iz(max_ib)
    #data.buf=numpy.array(data.buf, dtype=numpy.float)
    data.buf.shape = (data.nx, data.ny, data.nz)

    # 'mayavi' is always defined on the interpreter.
    e = OffScreenEngine()
    #e = Engine()
    e.start()
    win = e.new_scene(magnification=1)
    e.current_scene.scene.off_screen_rendering = True
    win.scene.isometric_view()

    # Make the data and add it to the pipeline.
    src = ArraySource(transpose_input_array=True)
    src.scalar_data = data.buf
    src.spacing = (data.dx, data.dy, -data.dz)
    src.origin = (data.x_orig, data.y_orig, -data.z_orig)
    e.add_source(src)

    # Visualize the data.
    o = Outline()
    e.add_module(o)

    lut = e.scenes[0].children[0].children[0].scalar_lut_manager
    lut.data_range = [-1, max_stack_value]
    lut.show_legend = True
    lut.data_name = 'Stack'

    # Create one ContourGridPlane normal to the 'x' axis.
    cgp = ContourGridPlane()
    e.add_module(cgp)
    # Set the position to the middle of the data.
    if max_val > detection:
        cgp.grid_plane.position = ix
    else:
        cgp.grid_plane.position = data.nx / 2
    cgp.contour.filled_contours = True
    cgp.actor.property.opacity = 0.6
    output = cgp.grid_plane.outputs[0]
    x_data = numpy.array(output.point_data.scalars.to_array())

    # Another with filled contours normal to 'y' axis.
    cgp = ContourGridPlane()
    e.add_module(cgp)
    # Set the axis and position to the middle of the data.
    cgp.grid_plane.axis = 'y'
    if max_val > detection:
        cgp.grid_plane.position = iy
    else:
        cgp.grid_plane.position = data.ny / 2
    cgp.contour.filled_contours = True
    cgp.actor.property.opacity = 0.6
    output = cgp.grid_plane.outputs[0]
    y_data = numpy.array(output.point_data.scalars.to_array())

    # Another with filled contours normal to 'z' axis.
    cgp = ContourGridPlane()
    e.add_module(cgp)
    # Set the axis and position to the middle of the data.
    cgp.grid_plane.axis = 'z'
    if max_val > detection:
        cgp.grid_plane.position = iz
    else:
        cgp.grid_plane.position = data.nz / 2
    cgp.contour.filled_contours = True
    cgp.actor.property.opacity = 0.6
    output = cgp.grid_plane.outputs[0]
    z_data = numpy.array(output.point_data.scalars.to_array())

    a = Axes()
    e.add_module(a)

    d = VTKDataSource()
    d.data = pd
    e.add_source(d)

    g = Glyph()
    e.add_module(g)
    g.glyph.glyph_source.glyph_source = g.glyph.glyph_source.glyph_list[4]
    g.glyph.glyph_source.glyph_source.radius = 0.1

    d = VTKDataSource()
    d.data = pd_hyp
    e.add_source(d)

    g = Glyph()
    e.add_module(g)
    g.glyph.glyph_source.glyph_source = g.glyph.glyph_source.glyph_list[4]
    g.glyph.glyph_source.glyph_source.radius = 0.5
    g.actor.property.color = (0.0, 0.0, 0.0)

    #view(azimuth=-60,elevation=60,distance=120)
    win.scene.save(output_file, size=(800, 800))

    e.stop()
    del win
    del e

    return (x_data, y_data, z_data)
Exemplo n.º 7
0
######### INTERPOLATE TRAVEL TIMES #############

# The time grid will contain as array values just the travel-times needed 
# (interpolated from the full NLL files) so we can free up the memory as soon as possible

time_grid=QDTimeGrid()
time_grid.read_NLL_hdr_file(hdr_file)
if options.twoD:
  time_grid.populate_from_2D_time_grids(grid_filename_base,cha)
else:
  time_grid.populate_from_time_grids(grid_filename_base,cha,out_path,load_buf=True)


print "Getting Grid geometry"
dummy_grid=QDGrid()
dummy_grid.read_NLL_hdr_file(hdr_file)
(nx,ny,nz)=(dummy_grid.nx, dummy_grid.ny, dummy_grid.nz)

if do_hyp:
  logging.info("Reading hyp parameters")
  hyp_parameters=[]
  for hyp_file in hyp_files:
    logging.debug("Hyp info from %s"%hyp_file)
    (otime,hypo_x,sigma_x,hypo_y,sigma_y,hypo_z,sigma_z)=qd_read_hyp_file(hyp_file)
    phase_dict=qd_read_picks_from_hyp_file(hyp_file)
    hyp_parameters.append(((otime,hypo_x,sigma_x,hypo_y,sigma_y,hypo_z,sigma_z),phase_dict))

  info.debug(hyp_parameters[0])

# read location file