示例#1
0
    def test_deg_km_accuracy(self):
        c = quakelib.Conversion(quakelib.LatLonDepth(0, 0))

        # Check that 360 * length of 1 longitude degree is equal to the circumference of the equator
        # Confirm accuracy is within 1 meter
        one_deg_len = c.convert2xyz(quakelib.LatLonDepth(0, 1)).mag()
        self.assertAlmostEqual(one_deg_len * 360.0 / 1000, 40075.016, 2)

        # Check that 4 * length of 90 degree vertical arc is equal to the polar circumference
        # Confirm accuracy is within 1 meter
        ninety_deg_len = c.convert2xyz(quakelib.LatLonDepth(90, 0)).mag()
        self.assertAlmostEqual(ninety_deg_len * 4.0 / 1000, 40007.860, 2)

        # Check that inverse of conversion results in the same value
        for base_lat in range(-90, 91, 5):
            for base_lon in range(-180, 180, 5):
                base_pt = quakelib.LatLonDepth(base_lat, base_lon)
                conv = quakelib.Conversion(base_pt)
                test_lat = math.fmod(base_lat + random.uniform(-45, 45), 90)
                test_lon = math.fmod(base_lon + random.uniform(-45, 45), 180)
                test_pt = quakelib.LatLonDepth(test_lat, test_lon)
                new_xyz = conv.convert2xyz(test_pt)
                rev_pt = conv.convert2LatLon(new_xyz)
                # Ensure accuracy to within 1e-7 degrees (~1 cm)
                self.assertAlmostEqual(test_lat, rev_pt.lat(), 7)
                self.assertAlmostEqual(test_lon, rev_pt.lon(), 7)
示例#2
0
 def test_assign(self):
     self.assertRaises(ValueError, quakelib.LatLonDepth, 91, 0, 0)
     self.assertRaises(ValueError, quakelib.LatLonDepth, -91, 0, 0)
     self.assertRaises(ValueError, quakelib.LatLonDepth, 0, 181, 0)
     self.assertRaises(ValueError, quakelib.LatLonDepth, 0, -181, 0)
     x = quakelib.LatLonDepth(1, 2, 3)
     y = quakelib.LatLonDepth(1, 2, 3)
     z = quakelib.LatLonDepth(3, 2, 3)
     self.assertRaises(ValueError, x.set_lat, -91)
     self.assertRaises(ValueError, x.set_lon, -181)
     self.assertEqual(x, y)
     self.assertNotEqual(x, z)
示例#3
0
    def testGetSetCompareVertex(self):
        ind_val = 123
        latlonval = quakelib.LatLonDepth(30, 40, 1000)
        das_val = 456.78
        trace_val = quakelib.MIDDLE_TRACE
        err = quakelib.EQSimErrors()

        # Set up v1
        v1 = quakelib.EQSimGeometryVertex()
        v1.set_index(ind_val)
        v1.set_loc(latlonval)
        v1.set_das(das_val)
        v1.set_trace_flag(trace_val)

        # Set up v2 in the same way
        v2 = quakelib.EQSimGeometryVertex()
        v2.set_index(ind_val)
        v2.set_loc(latlonval)
        v2.set_das(das_val)
        v2.set_trace_flag(trace_val)

        # Confirm that v1 retains the values assigned to it
        self.assertEqual(v1.line_num(), -1)
        self.assertEqual(v1.index(), ind_val)
        self.assertEqual(v1.loc(), latlonval)
        self.assertEqual(v1.das(), das_val)
        self.assertEqual(v1.trace_flag(), trace_val)

        # Confirm that v1 is equal to v2
        self.assertEqual(v1, v2)

        # Change an attribute of v2 and confirm it is no longer equal to v1
        v2.set_loc(quakelib.LatLonDepth(40, 40, 1000))
        self.assertNotEqual(v1, v2)

        # Confirm that v1 and v2 pass correctness checks
        v1.validate(err)
        self.assertEqual(err.count(), 0)
        v2.validate(err)
        self.assertEqual(err.count(), 0)

        # Confirm that changing trace_flag to invalid value breaks correctness
        v1.set_trace_flag(quakelib.UNDEFINED_TRACE_STATUS)
        v1.validate(err)
        self.assertEqual(err.count(), 1)
示例#4
0
    #print("{:60s}\t{:.2f}".format(sec_name,this_mean_strike))

model = quakelib.ModelWorld()
model.read_files_eqsim(UCERF3_FILE_GEO, "", UCERF3_FILE_FRIC, "none")

model.create_faults_minimal()
fault_ids = model.getFaultIDs()
section_ids = model.getSectionIDs()
element_ids = model.getElementIDs()
sys.stdout.write("Read {} faults...\n".format(len(fault_ids)))
sys.stdout.write("Read {} sections...\n".format(len(section_ids)))
sys.stdout.write("Read {} elements...\n".format(len(element_ids)))

# Get the Lat/Lon/Depth object for model basis
model_base = model.get_base()
base_lld = quakelib.LatLonDepth(model_base[0], model_base[1], 0.0)

elem_to_section_map = {
    elem_num: model.element(elem_num).section_id()
    for elem_num in model.getElementIDs()
}
section_elements = {}
fault_sections = {}
elements_to_reverse = []

for elem, section in elem_to_section_map.items():
    try:
        section_elements[section].append(elem)
    except KeyError:
        section_elements[section] = [elem]
示例#5
0
 def test_str_repr(self):
     x = quakelib.LatLonDepth(1, 2, 3)
     y = eval(repr(x))
     self.assertEqual(x, y)