Exemplo n.º 1
0
    def test_calc_event_activity_generation_min_mag(self):
    
        # Create an event set
        Mw = [7.65, 7.75, 7.85, 7.95 ]
        event_set = Dummy_event_set(array(Mw))
        
        # Create a list of Sources  - eventually
        (handle, file_name) = tempfile.mkstemp('.xml', __name__+'_')
        os.close(handle)
        handle = open(file_name,'w')

        sample = '\n'.join(['<?xml version="1.0" encoding="UTF-8"?>',
                            '<event_type_controlfile>'
                            ' <event_group event_type = "background">'
                            '  <GMPE fault_type = "normal">'
                            '     <branch model = "Toro" weight = "1.0"/>'
                            '  </GMPE>'
                            '  <scaling scaling_rule = "Wells_and_Coppersmith_94" scaling_fault_type = "unspecified" />'
                            ' </event_group>'
                            '</event_type_controlfile>'])
        handle.write(sample)
        handle.close()
        
        generation_min_mag = 7.6
        recurrence_min_mag = 4
        #recurrence_min_mag = 7.6
        actual_generation_min_mag = max(generation_min_mag, recurrence_min_mag)
        recurrence_max_mag = 8.0
        A_min = 10
        b = 1.4
        distribution = 'distribution'
        
        dummy = Dummy()
        dummy.magnitude_dist = {}
        dummy.magnitude_dist['minimum'] = actual_generation_min_mag
        dummy.magnitude_dist['maximum'] = recurrence_max_mag        
        dummy.generation_min_mag = generation_min_mag
        dummy.event_type = "background"
        dummy.name = 'name'
        
        dummyRm = Dummy()
        dummyRm.max_magnitude  = recurrence_max_mag  
        dummyRm.min_magnitude  = recurrence_min_mag  
        dummyRm.A_min = A_min
        dummyRm.b = b
        dummyRm.recurrence_model_distribution = 'bounded_gutenberg_richter'
        dummyRm.raw_weight = 1.0
        dummy.recurrence_models = [dummyRm]
        
        fsg_list = [dummy]
            
        magnitude_type = 'Mw'
        
        source_model = create_fault_sources(file_name, 
                                           fsg_list, 
                                           magnitude_type)
        for sm in source_model:
            sm.set_event_set_indexes( range(len(event_set)))
        event_activity_matrix = calc_event_activity(event_set, source_model)
        lamba = A_min * grscale(b, recurrence_max_mag, 
                                generation_min_mag, recurrence_min_mag)
        
        self.assert_(allclose(lamba, sum(event_activity_matrix)))    
        os.remove(file_name)
Exemplo n.º 2
0
    def test_calc_event_activity_summing_MR(self):
        """Same as test_calc_event_activity_summing with added multiple 
        recurrence"""
    
        # Create an event set
        Mw = [4.5, 5.5, 6.5, 7.5]
        Mw = [7.65, 7.75, 7.85, 7.95 ]
        
        Mw = [4.5, 5.5, 6.5, 7.5]
        step = 0.1
        Mw = r_[4:8:step]
        #print "len(Mw)", len(Mw)
        event_set = Dummy_event_set(array(Mw))
        
        # Create a list of Sources  - eventually
        (handle, file_name) = tempfile.mkstemp('.xml', __name__+'_')
        os.close(handle)
        handle = open(file_name,'w')

        sample = '\n'.join(['<?xml version="1.0" encoding="UTF-8"?>',
                            '<event_type_controlfile>'
                            ' <event_group event_type = "background">'
                            '  <GMPE fault_type = "normal">'
                            '     <branch model = "Toro" weight = "1.0"/>'
                            '  </GMPE>'
                            '  <scaling scaling_rule = "Wells_and_Coppersmith_94" scaling_fault_type = "unspecified" />'
                            ' </event_group>'
                            '</event_type_controlfile>'])
        handle.write(sample)
        handle.close()
        
        generation_min_mag = 4
        generation_max_mag = 8
        
        dummy = Dummy()
        dummy.magnitude_dist = {}
        dummy.magnitude_dist['minimum'] = generation_min_mag
        dummy.magnitude_dist['maximum'] = generation_max_mag        
        dummy.generation_min_mag = generation_min_mag
        dummy.event_type = "background"
        dummy.name = 'name'
        
        dummyRm = Dummy()
        dummyRm.max_magnitude  = 8.0  
        dummyRm.min_magnitude  = 3.0
        dummyRm.A_min = 10
        dummyRm.b = 1.4
        dummyRm.recurrence_model_distribution = 'bounded_gutenberg_richter'
        dummyRm.raw_weight = 0.4
        
        dummyRm2 = Dummy()
        dummyRm2.max_magnitude  = 7.0  
        dummyRm2.min_magnitude  = 4.5  
        dummyRm2.A_min = 15
        dummyRm2.b = 1.0
        dummyRm2.recurrence_model_distribution = 'bounded_gutenberg_richter'
        dummyRm2.raw_weight = 0.6
        
        dummy.recurrence_models = [dummyRm, dummyRm2]
        
        fsg_list = [dummy]
            
        magnitude_type = 'Mw'
        
        source_model = create_fault_sources(file_name, 
                                            fsg_list, 
                                            magnitude_type)
        for sm in source_model:
            sm.set_event_set_indexes( range(len(event_set)))
        event_activity_matrix = calc_event_activity(event_set, source_model)
        
        dummyRm_sum = dummyRm.A_min * grscale(dummyRm.b, 
                                              dummyRm.max_magnitude, 
                                              generation_min_mag, 
                                              dummyRm.min_magnitude)

        dummyRm2_sum = dummyRm2.A_min * grscale(dummyRm2.b, 
                                                dummyRm2.max_magnitude, 
                                                generation_min_mag, 
                                                dummyRm2.min_magnitude)
        
        expected_sum = dummyRm_sum * dummyRm.raw_weight + \
                       dummyRm2_sum * dummyRm2.raw_weight
        
        self.assert_(allclose(expected_sum, sum(event_activity_matrix)))
        os.remove(file_name)
Exemplo n.º 3
0
    def test_calc_event_activity(self):
    
        # Create an event set
        Mw = [4.5, 5.5, 6.5, 7.5]
        Mw = [7.65, 7.75, 7.85, 7.95 ]
        event_set = Dummy_event_set(array(Mw))
        
        # Create a list of Sources  - eventually
        (handle, file_name) = tempfile.mkstemp('.xml', __name__+'_')
        os.close(handle)
        handle = open(file_name,'w')

        sample = '\n'.join(['<?xml version="1.0" encoding="UTF-8"?>',
                            '<event_type_controlfile>'
                            ' <event_group event_type = "background">'
                            '  <GMPE fault_type = "normal">'
                            '     <branch model = "Toro" weight = "1.0"/>'
                            '  </GMPE>'
                            '  <scaling scaling_rule = "Wells_and_Coppersmith_94" scaling_fault_type = "unspecified" />'
                            ' </event_group>'
                            '</event_type_controlfile>'])
        handle.write(sample)
        handle.close()
        
        generation_min_mag = 7.6
        generation_min_mag = 4
        recurrence_min_mag = 4
        #recurrence_min_mag = 7.6
        actual_generation_min_mag = max(generation_min_mag, recurrence_min_mag)
        recurrence_max_mag = 8.0
        A_min = 10
        b = 1.4
        distribution = 'distribution'
        
        dummy = Dummy()
        dummy.magnitude_dist = {}
        dummy.magnitude_dist['minimum'] = actual_generation_min_mag
        dummy.magnitude_dist['maximum'] = recurrence_max_mag    
        dummy.generation_min_mag = generation_min_mag
        
        dummyRm = Dummy()
        dummyRm.max_magnitude  = recurrence_max_mag  
        dummyRm.min_magnitude  = recurrence_min_mag  
        dummyRm.A_min = A_min
        dummyRm.b = b
        dummyRm.recurrence_model_distribution = 'bounded_gutenberg_richter'
        dummyRm.raw_weight = 1.0
        dummy.recurrence_models = [dummyRm]
        
        dummy.event_type = "background"
        dummy.name = 'name'
        fsg_list = [dummy]
            
        magnitude_type = 'Mw'
        
        source_model = create_fault_sources(file_name, 
                                           fsg_list, 
                                           magnitude_type)
        for sm in source_model:
            sm.set_event_set_indexes( range(len(event_set)))
        event_activity_matrix = calc_event_activity(event_set, source_model)
        lamba = A_min * grscale(b, recurrence_max_mag, 
                                generation_min_mag, recurrence_min_mag)
        self.assert_(allclose(lamba, sum(event_activity_matrix)))
        
        # Check multiple recurrence models get weighted correctly
        w1 = 0.2
        w2 = 0.8
        boundary = [(0, 0.0), (100., 0.0), (100., 100.0), (0., 100.0) ]
        sm = Source_Model((Source_Zone(boundary, (),
                                       [RecurrenceModel(recurrence_min_mag, recurrence_max_mag,
                                                        A_min, b, None, w) for w in (w1, w2)],
                                       generation_min_mag,
                                       "background",
                                       'dummy_polygon_name'),),
                          magnitude_type)
        sm[0].set_event_set_indexes(range(len(event_set)))
        event_activity_matrix = calc_event_activity(event_set, sm)
        self.assert_(allclose(
                event_activity_matrix[0]/event_activity_matrix[1],
                w1/w2))
        os.remove(file_name)