예제 #1
0
  def test_gaussian_trigger(self):

    x=np.arange(100)
    max_val=10.*np.exp(-(x-50.)*(x-50.)/(10.*10.))
    max_x=np.random.rand(100)
    max_y=np.random.rand(100)
    max_z=np.random.rand(100)

    left_trig=right_trig=3
    locs=trigger_locations_inner(max_val,max_x,max_y,max_z,left_trig,right_trig,0.0,1.0)
    self.assertAlmostEqual(locs[0]['max_trig'],10)
    self.assertAlmostEqual(locs[0]['o_time'],50)
예제 #2
0
    def test_gaussian_trigger(self):

        x = np.arange(100)
        max_val = 10. * np.exp(-(x - 50.) * (x - 50.) / (10. * 10.))
        max_x = np.random.rand(100)
        max_y = np.random.rand(100)
        max_z = np.random.rand(100)

        left_trig = right_trig = 3
        locs = trigger_locations_inner(max_val, max_x, max_y, max_z, left_trig,
                                       right_trig, 0.0, 1.0)
        self.assertAlmostEqual(locs[0]['max_trig'], 10)
        self.assertAlmostEqual(locs[0]['o_time'], 50)
예제 #3
0
  def test_smoothing(self):

    from filters import smooth

    x=np.arange(100)
    max_val=100.*np.exp(-(x-50.)*(x-50.)/(10.*10.))+np.random.rand(100)
    max_x=np.random.rand(100)
    max_y=np.random.rand(100)
    max_z=np.random.rand(100)

    max_val_smooth=smooth(max_val)

    left_trig=right_trig=3
    locs_smooth=trigger_locations_inner(max_val_smooth,max_x,max_y,max_z,left_trig,right_trig,0.0,1.0)
    self.assertAlmostEqual(locs_smooth[0]['o_time'],50.,2)
예제 #4
0
    def test_smoothing(self):

        from filters import smooth

        x = np.arange(100)
        max_val = 100. * np.exp(-(x - 50.) * (x - 50.) /
                                (10. * 10.)) + np.random.rand(100)
        max_x = np.random.rand(100)
        max_y = np.random.rand(100)
        max_z = np.random.rand(100)

        max_val_smooth = smooth(max_val)

        left_trig = right_trig = 3
        locs_smooth = trigger_locations_inner(max_val_smooth, max_x, max_y,
                                              max_z, left_trig, right_trig,
                                              0.0, 1.0)
        self.assertAlmostEqual(locs_smooth[0]['o_time'], 50., 2)
예제 #5
0
  def test_simple_trigger(self):

    max_val=np.random.rand(100)
    max_x=np.random.rand(100)
    max_y=np.random.rand(100)
    max_z=np.random.rand(100)

    max_val[10]=5
    max_val[20]=7
    max_val[45]=2
    max_val[80]=10

    left_trig=right_trig=3
    locs=trigger_locations_inner(max_val,max_x,max_y,max_z,left_trig,right_trig,0.0,1.0)
    self.assertEqual(len(locs),3)
    self.assertAlmostEqual(locs[0]['max_trig'],5)
    self.assertAlmostEqual(locs[1]['max_trig'],7)
    self.assertAlmostEqual(locs[2]['max_trig'],10)
    self.assertAlmostEqual(locs[0]['o_time'],10)
    self.assertAlmostEqual(locs[1]['o_time'],20)
    self.assertAlmostEqual(locs[2]['o_time'],80)
예제 #6
0
    def test_simple_trigger(self):

        max_val = np.random.rand(100)
        max_x = np.random.rand(100)
        max_y = np.random.rand(100)
        max_z = np.random.rand(100)

        max_val[10] = 5
        max_val[20] = 7
        max_val[45] = 2
        max_val[80] = 10

        left_trig = right_trig = 3
        locs = trigger_locations_inner(max_val, max_x, max_y, max_z, left_trig,
                                       right_trig, 0.0, 1.0)
        self.assertEqual(len(locs), 3)
        self.assertAlmostEqual(locs[0]['max_trig'], 5)
        self.assertAlmostEqual(locs[1]['max_trig'], 7)
        self.assertAlmostEqual(locs[2]['max_trig'], 10)
        self.assertAlmostEqual(locs[0]['o_time'], 10)
        self.assertAlmostEqual(locs[1]['o_time'], 20)
        self.assertAlmostEqual(locs[2]['o_time'], 80)
예제 #7
0
    def test_dirac_migration(self):
        from locations_trigger import trigger_locations_inner
        from filters import smooth

        wo = WavelocOptions()
        wo.set_test_options()

        wo.opdict['outdir'] = 'TEST_Dirac'
        wo.opdict['search_grid'] = 'grid.Taisne.search.hdr'
        wo.opdict['loclevel'] = 10
        wo.opdict[
            'load_ttimes_buf'] = True  # Optimized in time, but you must be usre you're reading the right grid for the test
        wo.opdict['syn_addnoise'] = False
        wo.opdict['syn_amplitude'] = 1.0
        wo.opdict['syn_datalength'] = 20.0
        wo.opdict['syn_samplefreq'] = 100.0
        wo.opdict['syn_kwidth'] = 0.1
        wo.opdict['syn_otime'] = 6.0
        wo.opdict['syn_ix'] = 16
        wo.opdict['syn_iy'] = 8
        wo.opdict['syn_iz'] = 6
        wo.opdict['syn_filename'] = 'test_grid4D_hires.hdf5'

        wo.verify_migration_options()
        wo.verify_location_options()
        wo.verify_synthetic_options()

        ##########################
        # generate the test case and retrieve necessary information
        ##########################

        logging.info('Running synthetic test case generation...')
        test_info = generateSyntheticDirac(wo.opdict)
        logging.debug(test_info)

        # retrieve info
        grid_filename = test_info['dat_file']
        stack_filename = test_info['stack_file']
        nx, ny, nz, nt = test_info['grid_shape']
        dx, dy, dz, dt = test_info['grid_spacing']
        x_orig, y_orig, z_orig = test_info['grid_orig']
        ix_true, iy_true, iz_true, it_true = test_info['true_indexes']
        stack_start_time = test_info['start_time']

        # plot base filename
        base_path = wo.opdict['base_path']
        outdir = wo.opdict['outdir']

        # loclevel for triggers
        loclevel = wo.opdict['loclevel']

        # set up x, y, z, t arrays
        x = np.arange(nx) * dx
        y = np.arange(ny) * dy
        z = np.arange(nz) * dz
        t = np.arange(nt) * dt + stack_start_time

        # extract the max stacks
        f_stack = h5py.File(stack_filename, 'r')
        max_val = f_stack['max_val']
        max_x = f_stack['max_x']
        max_y = f_stack['max_y']
        max_z = f_stack['max_z']

        locs = trigger_locations_inner(max_val, max_x, max_y, max_z, loclevel,
                                       loclevel, stack_start_time, dt)

        self.assertTrue(len(locs) > 0)

        #print locs
        # This is a dirac test, so only have one element in locs
        imax = np.argmax([loc['max_trig'] for loc in locs])
        trig_loc = locs[imax]
        self.assertAlmostEqual(wo.opdict['syn_otime'], trig_loc['o_time'], 2)
        self.assertAlmostEqual(wo.opdict['syn_ix'] * dx + x_orig,
                               trig_loc['x_mean'])
        self.assertAlmostEqual(wo.opdict['syn_iy'] * dy + y_orig,
                               trig_loc['y_mean'])
        self.assertAlmostEqual(wo.opdict['syn_iz'] * dz + z_orig,
                               trig_loc['z_mean'])

        f_stack.close()
예제 #8
0
  def test_dirac_migration(self):
    from locations_trigger import trigger_locations_inner
    from filters import smooth

    wo=WavelocOptions()
    wo.set_test_options()

    wo.opdict['outdir'] = 'TEST_Dirac'
    wo.opdict['search_grid']='grid.Taisne.search.hdr'
    wo.opdict['loclevel'] = 10
    wo.opdict['load_ttimes_buf'] = True # Optimized in time, but you must be usre you're reading the right grid for the test
    wo.opdict['syn_addnoise']=False
    wo.opdict['syn_amplitude']=1.0
    wo.opdict['syn_datalength']=20.0
    wo.opdict['syn_samplefreq']=100.0
    wo.opdict['syn_kwidth']=0.1
    wo.opdict['syn_otime']=6.0
    wo.opdict['syn_ix']=16
    wo.opdict['syn_iy']=8
    wo.opdict['syn_iz']=6
    wo.opdict['syn_filename']='test_grid4D_hires.hdf5'

    wo.verify_migration_options()
    wo.verify_location_options()
    wo.verify_synthetic_options()

    ##########################
    # generate the test case and retrieve necessary information
    ##########################

    logging.info('Running synthetic test case generation...')
    test_info=generateSyntheticDirac(wo.opdict)
    logging.debug(test_info)

    # retrieve info
    grid_filename=test_info['dat_file']
    stack_filename=test_info['stack_file']
    nx,ny,nz,nt=test_info['grid_shape']
    dx,dy,dz,dt=test_info['grid_spacing']
    x_orig,y_orig,z_orig=test_info['grid_orig']
    ix_true,iy_true,iz_true,it_true=test_info['true_indexes']
    stack_start_time=test_info['start_time']

    # plot base filename
    base_path=wo.opdict['base_path']
    outdir=wo.opdict['outdir']

    # loclevel for triggers
    loclevel=wo.opdict['loclevel']

    # set up x, y, z, t arrays
    x=np.arange(nx)*dx
    y=np.arange(ny)*dy
    z=np.arange(nz)*dz
    t=np.arange(nt)*dt+stack_start_time

    # extract the max stacks
    f_stack=h5py.File(stack_filename,'r')
    max_val=f_stack['max_val']
    max_x=f_stack['max_x']
    max_y=f_stack['max_y']
    max_z=f_stack['max_z']


    locs=trigger_locations_inner(max_val,max_x,max_y,max_z,loclevel,loclevel,stack_start_time,dt)

    self.assertTrue(len(locs)>0)
    
    #print locs
    # This is a dirac test, so only have one element in locs
    imax=np.argmax([loc['max_trig'] for loc in locs])
    trig_loc=locs[imax]
    self.assertAlmostEqual(wo.opdict['syn_otime'],trig_loc['o_time'],2)
    self.assertAlmostEqual(wo.opdict['syn_ix']*dx+x_orig,trig_loc['x_mean'])
    self.assertAlmostEqual(wo.opdict['syn_iy']*dy+y_orig,trig_loc['y_mean'])
    self.assertAlmostEqual(wo.opdict['syn_iz']*dz+z_orig,trig_loc['z_mean'])
  
    f_stack.close()