Exemplo n.º 1
0
def nrml_from_shapefile(shapefile, shapefile_faultname_attribute,
                        shapefile_dip_attribute, shapefile_sliprate_attribute,
                        source_model_name, simple_fault_tectonic_region,
                        magnitude_scaling_relation, rupture_aspect_ratio,
                        upper_depth, lower_depth, a_value, b_value, min_mag,
                        max_mag, rake, output_dir, quiet):
    """Driver routine to convert nrml to shapefile
     
    """
    # Get geometry
    fault_traces, faultnames, dips, \
    sliprate, fault_lengths = parse_line_shapefile(shapefile,
                                                  shapefile_faultname_attribute,
                                                  shapefile_dip_attribute,
                                                  shapefile_sliprate_attribute)

    # Output is written line-by-line to this list
    output_xml = []

    append_xml_header(output_xml, source_model_name)

    # Loop through each fault and add source specific info
    for i in range(len(fault_traces)):
        simple_fault_id = i
        A = fault_lengths[i] * (float(lower_depth) - float(upper_depth))
        # Calculate M_max from scaling relations
        scalrel = WC1994()
        max_mag = scalrel.get_median_mag(A, float(rake))
        #        print A
        # Calculate GR a values from slip rate
        if sliprate[i] != '""':
            print sliprate[i]
            a_value, moment_rate = fault_slip_rate_GR_conversion.slip2GR(
                sliprate[i], A, float(b_value), float(max_mag), M_min=0.0)
        append_rupture_geometry(output_xml, fault_traces[i], dips[i],
                                simple_fault_id, faultnames[i], upper_depth,
                                lower_depth, simple_fault_tectonic_region)

        append_earthquake_information(output_xml, magnitude_scaling_relation,
                                      rupture_aspect_ratio, a_value, b_value,
                                      min_mag, max_mag, rake)

    # Close xml
    output_xml.append('  </sourceModel>')
    output_xml.append('</nrml>')

    # Add newlines
    output_xml = [oxml + '\n' for oxml in output_xml]

    return output_xml
Exemplo n.º 2
0
def sliprate2GR_incremental(sliprate,
                            fault_area,
                            b_value,
                            max_mag,
                            min_mag=0.0,
                            bin_width=0.1):
    """Converts a sliprate and b-value into a Gutenberg-
    Richter distribution, then converts this to an
    OpenQuake incremental MFD (to facilitate collapsing of rates
    with other MFDs)
    """
    a_value, moment_rate = fault_slip_rate_GR_conversion.slip2GR(
        sliprate, fault_area, float(b_value), float(max_mag), M_min=min_mag)

    mfd = TruncatedGRMFD(min_mag, max_mag, bin_width, a_value, b_value)
    mags, rates = zip(*mfd.get_annual_occurrence_rates())
    mags = np.array(mags)
    rates = np.array(rates)
    return mags, rates, moment_rate
def nrml_from_shapefile(shapefile,
                        shapefile_faultname_attribute,
                        shapefile_dip_attribute,
                        shapefile_sliprate_attribute,
                        source_model_name,
                        simple_fault_tectonic_region,
                        magnitude_scaling_relation,
                        rupture_aspect_ratio,
                        upper_depth,
                        lower_depth,
                        a_value,
                        b_value,
                        min_mag,
                        max_mag,
                        rake,
                        output_dir,
                        incremental_mfd,
                        shapefile_uplift_attribute=None,
                        quiet=True):
    """Driver routine to convert nrml to shapefile
     
    """
    # Get geometry
    fault_traces, faultnames, dips, \
    sliprate, fault_lengths = parse_line_shapefile(shapefile,
                                                  shapefile_faultname_attribute,
                                                  shapefile_dip_attribute, 
                                                  shapefile_sliprate_attribute,
                                                  shapefile_uplift_attribute)

     # Output is written line-by-line to this list
    output_xml = []

    append_xml_header(output_xml, source_model_name)

    # If b-value is not given, take from Leonard 2008 model
    region_shapefile = '../zones/Leonard2008/shapefiles/LEONARD08_NSHA18_MFD.shp'
    if b_value is None:
        b_value = b_value_from_region(fault_traces, region_shapefile)
    
    # If tectonic region type is not given, take from domains model
    domains_shapefile = '../zones/Domains/shapefiles/DOMAINS_NSHA18.shp'
    if simple_fault_tectonic_region is None:
        simple_fault_tectonic_region = trt_from_domains(fault_traces, domains_shapefile)

    # Loop through each fault and add source specific info
    for i in range(len(fault_traces)):
       # Skip faults with zero or null sliprate
        if sliprate[i] == "" or sliprate[i] == 0:
            continue 
        simple_fault_id = i
        A = fault_lengths[i]*(float(lower_depth)-float(upper_depth))
        # Calculate M_max from scaling relations
        scalrel = Leonard2014_SCR()
        bin_width = 0.1
        max_mag = scalrel.get_median_mag(A, float(rake))
        char_mag = max_mag - 0.25 #characteristic magnitude for OQ def
#        print A
        # Calculate characteristic incremental occurrence rates from slip rate
        if sliprate[i] != '""':
            print sliprate[i]
            # just to calculate the moment rate, need to fix this function
            a_value, moment_rate = fault_slip_rate_GR_conversion.slip2GR(sliprate[i], A,
                                                                         float(b_value[i]), 
                                                                         float(max_mag),
                                                                         M_min=0.0)
            a_value=None # We aren't using the a value
            
            
#            mfd = YoungsCoppersmith1985MFD.from_total_moment_rate(min_mag=min_mag,
#                                                                  b_val=float(b_value), 
#                                                                  char_mag=float(max_mag), 
#                                                                  total_moment_rate=moment_rate, 
#                                                                  bin_width=0.1)
#            mags,rates=zip(*mfd.get_annual_occurrence_rates())


        append_rupture_geometry(output_xml, fault_traces[i],
                                dips[i], simple_fault_id,
                                faultnames[i], upper_depth,
                                lower_depth, simple_fault_tectonic_region[i])

        if incremental_mfd:
            append_earthquake_information_inc(output_xml,
                                          magnitude_scaling_relation,
                                          rupture_aspect_ratio, char_mag, b_value[i],
                                          min_mag, max_mag, rake, moment_rate, bin_width)
        else:
            append_earthquake_information_YC(output_xml,
                                          magnitude_scaling_relation,
                                          rupture_aspect_ratio, char_mag, b_value[i],
                                          min_mag, max_mag, rake, moment_rate, bin_width)

    # Close xml
    output_xml.append('  </sourceModel>')
    output_xml.append('</nrml>')

    # Add newlines
    output_xml = [oxml + '\n' for oxml in output_xml]

    return output_xml
Exemplo n.º 4
0
def nrml_from_shapefile(shapefile, shapefile_faultname_attribute,
                        shapefile_dip_attribute, shapefile_sliprate_attribute,
                        source_model_name, simple_fault_tectonic_region,
                        magnitude_scaling_relation, rupture_aspect_ratio,
                        upper_depth, lower_depth, a_value, b_value, min_mag,
                        max_mag, rake, output_dir, incremental_mfd, quiet):
    """Driver routine to convert nrml to shapefile
     
    """
    # Get geometry
    fault_traces, faultnames, dips, \
    sliprate, fault_lengths = parse_line_shapefile(shapefile,
                                                  shapefile_faultname_attribute,
                                                  shapefile_dip_attribute,
                                                  shapefile_sliprate_attribute)

    # Output is written line-by-line to this list
    output_xml = []

    append_xml_header(output_xml, source_model_name)

    # Loop through each fault and add source specific info
    for i in range(len(fault_traces)):
        simple_fault_id = i
        A = fault_lengths[i] * (float(lower_depth) - float(upper_depth))
        # Calculate M_max from scaling relations
        scalrel = WC1994()
        bin_width = 0.1
        max_mag = scalrel.get_median_mag(A, float(rake))
        char_mag = max_mag - 0.25  #characteristic magnitude for OQ def
        #        print A
        # Calculate characteristic incremental occurrence rates from slip rate
        if sliprate[i] != '""':
            print sliprate[i]
            # just to calculate the moment rate, need to fix this function
            a_value, moment_rate = fault_slip_rate_GR_conversion.slip2GR(
                sliprate[i], A, float(b_value), float(max_mag), M_min=0.0)
            a_value = None  # We aren't using the a value

#            mfd = YoungsCoppersmith1985MFD.from_total_moment_rate(min_mag=min_mag,
#                                                                  b_val=float(b_value),
#                                                                  char_mag=float(max_mag),
#                                                                  total_moment_rate=moment_rate,
#                                                                  bin_width=0.1)
#            mags,rates=zip(*mfd.get_annual_occurrence_rates())

        append_rupture_geometry(output_xml, fault_traces[i], dips[i],
                                simple_fault_id, faultnames[i], upper_depth,
                                lower_depth, simple_fault_tectonic_region)

        if incremental_mfd:
            append_earthquake_information_inc(output_xml,
                                              magnitude_scaling_relation,
                                              rupture_aspect_ratio, char_mag,
                                              b_value, min_mag, max_mag, rake,
                                              moment_rate, bin_width)
        else:
            append_earthquake_information_YC(output_xml,
                                             magnitude_scaling_relation,
                                             rupture_aspect_ratio, char_mag,
                                             b_value, min_mag, max_mag, rake,
                                             moment_rate, bin_width)

    # Close xml
    output_xml.append('  </sourceModel>')
    output_xml.append('</nrml>')

    # Add newlines
    output_xml = [oxml + '\n' for oxml in output_xml]

    return output_xml
def nrml_from_shapefile(shapefile,
                        shapefile_faultname_attribute,
                        shapefile_dip_attribute,
                        shapefile_sliprate_attribute,
                        source_model_name,
                        simple_fault_tectonic_region,
                        magnitude_scaling_relation,
                        rupture_aspect_ratio,
                        upper_depth,
                        lower_depth,
                        a_value,
                        b_value,
                        min_mag,
                        max_mag,
                        rake,
                        output_dir,
                        shapefile_uplift_attribute=None,
                        quiet=True):
    """Driver routine to convert nrml to shapefile
     
    """
    # Get geometry
    fault_traces, faultnames, dips, \
    sliprate, fault_lengths = parse_line_shapefile(shapefile,
                                                   shapefile_faultname_attribute,
                                                   shapefile_dip_attribute,
                                                   shapefile_sliprate_attribute,
                                                   shapefile_uplift_attribute)

    # Output is written line-by-line to this list
    output_xml = []

    append_xml_header(output_xml, source_model_name)

    # If b-value is not given, take from Leonard 2008 model
    region_shapefile = '../zones/Leonard2008/shapefiles/LEONARD08_NSHA18_MFD.shp'
    if b_value is None:
        b_value = b_value_from_region(fault_traces, region_shapefile)

    # If tectonic region type is not given, take from domains model
    domains_shapefile = '../zones/Domains/shapefiles/DOMAINS_NSHA18.shp'
    if simple_fault_tectonic_region is None:
        simple_fault_tectonic_region = trt_from_domains(
            fault_traces, domains_shapefile)

    # Loop through each fault and add source specific info
    for i in range(len(fault_traces)):
        # Skip faults with zero or null sliprate
        if sliprate[i] == "" or sliprate[i] == 0:
            continue
        simple_fault_id = i
        A = fault_lengths[i] * (float(lower_depth) - float(upper_depth))
        # Calculate M_max from scaling relations
        scalrel = Leonard2014_SCR()
        max_mag = scalrel.get_median_mag(A, float(rake))
        #        print A
        # Calculate GR a values from slip rate
        if sliprate[i] != '""':
            # print sliprate[i]
            a_value, moment_rate = fault_slip_rate_GR_conversion.slip2GR(
                sliprate[i], A, float(b_value[i]), float(max_mag), M_min=0.0)
        append_rupture_geometry(output_xml, fault_traces[i], dips[i],
                                simple_fault_id, faultnames[i], upper_depth,
                                lower_depth, simple_fault_tectonic_region[i])

        append_earthquake_information(output_xml, magnitude_scaling_relation,
                                      rupture_aspect_ratio, a_value,
                                      b_value[i], min_mag, max_mag, rake)

    # Close xml
    output_xml.append('  </sourceModel>')
    output_xml.append('</nrml>')

    # Add newlines
    output_xml = [oxml + '\n' for oxml in output_xml]

    return output_xml