Beispiel #1
0
 def setUp(self):
     self.ok = quakelib.Okada()
     self.slip_rad = math.pi
     self.slip_vec = quakelib.Vec3(math.sin(self.slip_rad),
                                   math.cos(self.slip_rad), 0)
     self.dip_rad = math.pi / 2.0
     # Tolerate at most a 1e-10 absolute difference in magnitude
     self.mag_tol = 1e-9
Beispiel #2
0
 def testDispCalcFaultSize(self):
     baseline = [
         0.102036860007, 0.152747014539, 0.178027759544, 0.182776615629,
         0.183223384675, 0.183254816562, 0.183256842643, 0.183256970265,
         0.183256978257, 0.183256978757
     ]
     for i in range(10):
         fault_length = math.pow(2, i)
         # Note that the location can't be too close or we trigger the boundary case and the results don't fit a curve
         loc = quakelib.Vec3(fault_length / 2.0, 1, 0)
         source_dim = quakelib.Vec3(fault_length, 1, 0)
         # Ensure displacement is within acceptable bounds
         disp = self.ok.calc_displacement_vector(
             loc, source_dim[2], self.dip_rad, source_dim[0], source_dim[1],
             self.slip_vec[0], self.slip_vec[1], self.slip_vec[2], 1, 1)
         rel_err = abs(baseline[i] - disp.mag()) / baseline[i]
         self.assertTrue(rel_err < 1e-8)
Beispiel #3
0
 def test_read_assign(self):
     x = quakelib.Vec3(1, 3, 5)
     self.assertEqual(x[0], 1)
     self.assertEqual(x[1], 3)
     self.assertEqual(x[2], 5)
     x[1] = -1
     self.assertEqual(x[1], -1)
     self.assertRaises(IndexError, x.__getitem__, 3)
Beispiel #4
0
 def testAddMultiRegular(self):
     lg2_num_pts = 2
     num_dim_pts = 2**lg2_num_pts
     step = 1.0 / float(num_dim_pts)
     half_step = 1.0 / float(2 * num_dim_pts)
     quarter_step = 1.0 / float(2 * 2 * num_dim_pts)
     quarter_step_vec = quakelib.Vec3(quarter_step, quarter_step,
                                      quarter_step)
     vec00 = quakelib.Vec3(0, 0, 0)
     vec10 = quakelib.Vec3(1, 1, 1)
     rb = quakelib.RectBound3(vec00, vec10)
     octree = quakelib.Octree3(rb)
     pt_list = [[
         quakelib.Vec3(x * step + half_step, y * step + half_step,
                       z * step + half_step),
         x + y * num_dim_pts + z * num_dim_pts * num_dim_pts
     ] for x in range(num_dim_pts) for y in range(num_dim_pts)
                for z in range(num_dim_pts)]
     for pt in pt_list:
         self.assertTrue(octree.add_point(pt[0], pt[1]))
     num_branches = 0
     for i in range(lg2_num_pts):
         num_branches += 8**i
     # Confirm that the number of branches is as expected
     self.assertEqual(octree.num_descendents() - octree.num_leaves(),
                      num_branches)
     self.assertEqual(octree.num_leaves(), num_dim_pts**3)
     # Confirm that the tree is correctly balanced
     self.assertEqual(octree.max_depth(), lg2_num_pts)
     # Confirm that identical points return the same id
     for pt in pt_list:
         self.assertEqual(
             octree.get_leaf_containing_point(pt[0]).id(), pt[1])
     # And that slightly offset points return the same id
     for pt in pt_list:
         self.assertEqual(
             octree.get_leaf_containing_point(pt[0] +
                                              quarter_step_vec).id(), pt[1])
     for pt in pt_list:
         self.assertEqual(
             octree.get_leaf_containing_point(pt[0] -
                                              quarter_step_vec).id(), pt[1])
Beispiel #5
0
    def testGreenSymmetricDGDV(self):
        source_dim = quakelib.Vec3(1, 1, 1)

        for x in range(-2, 8):
            for y in range(-2, 8):
                # Set up the test location and mirror location
                z = 0
                xloc = source_dim[0] / 2.0 + 2**x
                yloc = 2**y
                zloc = -z
                orig_loc_dg = quakelib.Vec2(xloc, yloc)
                orig_loc_dv = quakelib.Vec3(xloc, yloc, zloc)
                xloc = source_dim[0] / 2.0 - 2**x
                yloc = -2**y
                mirror_loc_dg = quakelib.Vec2(xloc, yloc)
                mirror_loc_dv = quakelib.Vec3(xloc, yloc, zloc)

                # Calculate dudz
                orig_dg = self.ok.calc_dg(orig_loc_dg, source_dim[2],
                                          self.dip_rad, source_dim[0],
                                          source_dim[1], self.slip_vec[0],
                                          self.slip_vec[1], self.slip_vec[2],
                                          1, 1)
                mirror_dg = self.ok.calc_dg(mirror_loc_dg, source_dim[2],
                                            self.dip_rad, source_dim[0],
                                            source_dim[1], self.slip_vec[0],
                                            self.slip_vec[1], self.slip_vec[2],
                                            1, 1)
                orig_dv = self.ok.calc_dV(orig_loc_dv, source_dim[2],
                                          self.dip_rad, source_dim[0],
                                          source_dim[1], self.slip_vec[0],
                                          self.slip_vec[1], self.slip_vec[2],
                                          1, 1)
                mirror_dv = self.ok.calc_dV(mirror_loc_dv, source_dim[2],
                                            self.dip_rad, source_dim[0],
                                            source_dim[1], self.slip_vec[0],
                                            self.slip_vec[1], self.slip_vec[2],
                                            1, 1)
                abs_err_dg = abs(orig_dg + mirror_dg)
                abs_err_dv = abs(orig_dv + mirror_dv)
                self.assertTrue(abs_err_dg < self.mag_tol)
                self.assertTrue(abs_err_dv < self.mag_tol)
Beispiel #6
0
 def testInvalidRB(self):
     rb = quakelib.RectBound3()
     vec = quakelib.Vec3()
     self.assertTrue(math.isnan(rb.max_length()))
     self.assertTrue(math.isnan(rb.center()[0]))
     self.assertEqual(rb.get_child_subdivision(vec), 0)
     self.assertFalse(rb.get_child_bound(0).valid())
     self.assertFalse(rb.in_bound(vec))
     self.assertNotEqual(rb, quakelib.RectBound3())
     rb.extend_bound(vec)
     self.assertTrue(rb.valid())
Beispiel #7
0
 def testNormalRB(self):
     vec00 = quakelib.Vec3(0.0, 0.0, 0.0)
     vec05 = quakelib.Vec3(0.5, 0.5, 0.5)
     vec10 = quakelib.Vec3(1.0, 1.0, 1.0)
     vecneg = quakelib.Vec3(-1.0, -1.0, -1.0)
     rb = quakelib.RectBound3(vec00, vec10)
     rb2 = quakelib.RectBound3(vec00, vec05)
     self.assertEqual(rb.max_length(), 1.0)
     self.assertEqual(rb.center(), vec05)
     self.assertEqual(rb.get_child_subdivision(vec00), 0)
     self.assertEqual(rb.get_child_subdivision(vec05), 0)
     self.assertEqual(rb.get_child_subdivision(vec10), 7)
     self.assertEqual(rb.get_child_bound(0), rb2)
     self.assertTrue(rb.in_bound(vec00))
     self.assertTrue(rb.in_bound(vec05))
     self.assertFalse(rb.in_bound(vec10))
     self.assertFalse(rb.in_bound(vecneg))
     rb.extend_bound(vecneg)
     self.assertTrue(rb.in_bound(vecneg))
     rb.extend_bound(vec10)
     self.assertTrue(rb.in_bound(vec10))
    def testGreenSymmetricTensor(self):
        source_dim = quakelib.Vec3(1, 1, 1)

        for x in range(-2, 8):
            for y in range(-2, 8):
                # Set up the test location and mirror location
                z = 0
                xloc = source_dim[0] / 2.0 + 2**x
                yloc = 2**y
                zloc = -z
                orig_loc = quakelib.Vec3(xloc, yloc, zloc)
                xloc = source_dim[0] / 2.0 - 2**x
                yloc = -2**y
                mirror_loc = quakelib.Vec3(xloc, yloc, zloc)

                # Calculate tensor and determine shear/normal stresses
                orig_tensor = self.ok.calc_stress_tensor(
                    orig_loc, source_dim[2], self.dip_rad, source_dim[0],
                    source_dim[1], self.slip_vec[0], self.slip_vec[1],
                    self.slip_vec[2], 1, 1)
                mirror_tensor = self.ok.calc_stress_tensor(
                    mirror_loc, source_dim[2], self.dip_rad, source_dim[0],
                    source_dim[1], self.slip_vec[0], self.slip_vec[1],
                    self.slip_vec[2], 1, 1)
                rake_vec = quakelib.Vec3(1, 0, 0)
                normal_vec = quakelib.Vec3(0, 1, 0)
                orig_stress_vec = orig_tensor * normal_vec
                mirror_stress_vec = mirror_tensor * normal_vec
                # Shear stresses should be exactly opposite in sign
                orig_shear_stress = orig_stress_vec.dot_product(rake_vec)
                mirror_shear_stress = mirror_stress_vec.dot_product(rake_vec)
                abs_err = abs(orig_shear_stress + mirror_shear_stress)
                self.assertTrue(abs_err < self.mag_tol)
                # Normal stresses
                orig_normal_stress = orig_stress_vec.dot_product(normal_vec)
                mirror_normal_stress = mirror_stress_vec.dot_product(
                    normal_vec)
                abs_err = abs(orig_normal_stress + mirror_normal_stress)
                self.assertTrue(abs_err < self.mag_tol)
Beispiel #9
0
 def test_index_error(self):
     x = quakelib.Vec3(1, 2, 3)
     y = quakelib.Vec2(1, 2)
     with self.assertRaises(OverflowError):
         x[-1]
     with self.assertRaises(OverflowError):
         x[-1] = 0
     with self.assertRaises(IndexError):
         x[3]
     with self.assertRaises(IndexError):
         x[3] = 0
     with self.assertRaises(OverflowError):
         y[-1]
     with self.assertRaises(OverflowError):
         y[-1] = 0
     with self.assertRaises(IndexError):
         y[2]
     with self.assertRaises(IndexError):
         y[2] = 0
Beispiel #10
0
 def testRBCreation(self):
     vec00 = quakelib.Vec3(0.0, 0.0, 0.0)
     vec05 = quakelib.Vec3(0.5, 0.5, 0.5)
     rb1 = quakelib.RectBound3(vec00, vec05)
     rb2 = quakelib.RectBound3(vec05, vec00)
     self.assertEqual(rb1, rb2)
Beispiel #11
0
    fault_id = model.section(section).fault_id()
    try:
        if section not in fault_sections[fault_id]:
            fault_sections[fault_id].append(section)
    except KeyError:
        fault_sections[fault_id] = [section]

new_sec_id_map = {}
strike_diffs = []
segment_strikes = []
section_mean_xyz = {}

### Compute the mean xyz of each section from the elements
for sid in section_elements.keys():
    mean_xyz = quakelib.Vec3()
    for eid in section_elements[sid]:
        this_xyz = model.element_mean_xyz(eid)
        mean_xyz[0] += this_xyz[0]
        mean_xyz[1] += this_xyz[1]
        mean_xyz[2] += this_xyz[2]
    section_mean_xyz[sid] = mean_xyz / float(len(section_elements[sid]))

for fid in fault_ids:
    section_lines = []
    section_points_dict = {}
    sec_distances = {}
    point_distances = {}
    sec_points = []
    section_ids = fault_sections[fid]
    first_section_id = min(section_ids)
Beispiel #12
0
    def calculate_model_extents(self):
        #-----------------------------------------------------------------------
        # get info from the original file
        #-----------------------------------------------------------------------
        block_info_table = self.file.root.block_info_table

        #-----------------------------------------------------------------------
        # calculate the model extents
        #-----------------------------------------------------------------------
        print 'Calculating model extents'

        start_time = time.time()

        sys_max_z = -sys.float_info.max
        sys_min_z = sys.float_info.max
        sys_max_x = -sys.float_info.max
        sys_min_x = sys.float_info.max
        sys_max_y = -sys.float_info.max
        sys_min_y = sys.float_info.max

        for block in block_info_table:
            min_x = min((block['m_x_pt1'], block['m_x_pt2'], block['m_x_pt3'],
                         block['m_x_pt4']))
            max_x = max((block['m_x_pt1'], block['m_x_pt2'], block['m_x_pt3'],
                         block['m_x_pt4']))

            min_y = min((block['m_y_pt1'], block['m_y_pt2'], block['m_y_pt3'],
                         block['m_y_pt4']))
            max_y = max((block['m_y_pt1'], block['m_y_pt2'], block['m_y_pt3'],
                         block['m_y_pt4']))

            min_z = min((block['m_z_pt1'], block['m_z_pt2'], block['m_z_pt3'],
                         block['m_z_pt4']))
            max_z = max((block['m_z_pt1'], block['m_z_pt2'], block['m_z_pt3'],
                         block['m_z_pt4']))

            if min_x < sys_min_x:
                sys_min_x = min_x
            if max_x > sys_max_x:
                sys_max_x = max_x

            if min_y < sys_min_y:
                sys_min_y = min_y
            if max_y > sys_max_y:
                sys_max_y = max_y

            if min_z < sys_min_z:
                sys_min_z = min_z
            if max_z > sys_max_z:
                sys_max_z = max_z

        base_lat_lon_table = self.file.root.base_lat_lon
        conv = quakelib.Conversion(base_lat_lon_table[0],
                                   base_lat_lon_table[1])

        ne_corner = conv.convert2LatLon(
            quakelib.Vec3(sys_max_x, sys_max_y, 0.0))
        sw_corner = conv.convert2LatLon(
            quakelib.Vec3(sys_min_x, sys_min_y, 0.0))

        self.file.close()

        print 'Done! {} seconds'.format(time.time() - start_time)

        print 'Creating new tables'
        table_start_time = time.time()

        self.file = tables.open_file(self.file_path, 'a')

        desc = {
            'min_x': tables.Float64Col(dflt=0.0),
            'max_x': tables.Float64Col(dflt=0.0),
            'min_y': tables.Float64Col(dflt=0.0),
            'max_y': tables.Float64Col(dflt=0.0),
            'min_z': tables.Float64Col(dflt=0.0),
            'max_z': tables.Float64Col(dflt=0.0),
            'min_lat': tables.Float64Col(dflt=0.0),
            'max_lat': tables.Float64Col(dflt=0.0),
            'min_lon': tables.Float64Col(dflt=0.0),
            'max_lon': tables.Float64Col(dflt=0.0)
        }

        model_extents = self.file.create_table('/', 'model_extents', desc,
                                               'Model Extents')

        model_extents.row.append()
        model_extents.flush()

        model_extents.cols.min_x[0] = sys_min_x
        model_extents.cols.max_x[0] = sys_max_x
        model_extents.cols.min_y[0] = sys_min_y
        model_extents.cols.max_y[0] = sys_max_y
        model_extents.cols.min_z[0] = sys_min_z
        model_extents.cols.max_z[0] = sys_max_z
        model_extents.cols.min_lat[0] = sw_corner.lat()
        model_extents.cols.max_lat[0] = ne_corner.lat()
        model_extents.cols.min_lon[0] = sw_corner.lon()
        model_extents.cols.max_lon[0] = ne_corner.lon()

        print 'Done! {} seconds'.format(time.time() - table_start_time)

        #-----------------------------------------------------------------------
        # close the file and reopen it with the new table
        #-----------------------------------------------------------------------
        self.file.close()
        self.file = tables.open_file(self.file_path)

        print 'Total time {} seconds'.format(time.time() - start_time)
Beispiel #13
0
 def test_cross_prod(self):
     self.assertEqual(self.x.cross(self.y), quakelib.Vec3())
     self.assertEqual(self.y.cross(self.x), quakelib.Vec3())
     self.assertEqual(self.x.cross(self.z), quakelib.Vec3(-5, -5, 5))
     self.assertRaises(ValueError, quakelib.Vec2().cross, (quakelib.Vec2()))
Beispiel #14
0
 def test_arithmetic(self):
     self.assertEqual(self.x * 2, self.y)
     self.assertEqual(self.x * 2 - self.y, quakelib.Vec3())
Beispiel #15
0
 def setUp(self):
     self.x = quakelib.Vec3(1, 2, 3)
     self.y = quakelib.Vec3(2, 4, 6)
     self.z = quakelib.Vec3(-1, 3, 2)
     self.xax = quakelib.Vec3(1, 0, 0)
     self.yax = quakelib.Vec3(0, 1, 0)