import numpy as np
import matplotlib.pyplot as plt


def load_fault_traces(mffile = 'Mapped_Faults', srfile = 'Surface_Ruptures', plot = False): 
# from mpl_toolkits.basemap import Basemap


# map = Basemap(projection='aeqd',
#           lon_0 = 13.5,
#           lat_0 = 42.4,
#           resolution = 'i',
#               ax = ax)
    
    # lons = []
    # lats = []
    # elv  = []
    all_faults = []
    with open(mffile, 'r') as file:
        file = file.readlines()
        for iline, line in enumerate(reversed(file)): # Reverse because name comes at end of a faults data
            if line[0] == '^':
                if (iline > 1) or (iline == len(file)-1): 
                    all_faults.append(fault)
    
                # break
                thing = line.split()
                txt = thing[4:]
                name = txt[0]
                style = txt[1]
    
                
                integer = thing[1]            
                lonlabel = float(thing[2])
                latlabel = float(thing[3])
                fault = {'name': name, 'style': style, 'lons':[], 'lats':[], 'elv':[], 
                          'integer':integer, 
                          'lonlabel':lonlabel, 'latlabel':latlabel}
            else:
                thing = line.split()
                fault['lons'].append(float(thing[0]))
                fault['lats'].append(float(thing[1]))
                fault['elv'] .append(float(thing[2]))
    
    # plt.scatter(lons, lats,s = 1)
    # bad = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    #bad_fault = ['mdibagno', 'M.Stabbiata', 'Pizzoli', 'Campotosto', 'VdelSaltoSud']
    # bad_fault = ['Campotosto']
    if plot: 
        plt.figure()
        for ifault, fault in enumerate(all_faults):
            # if fault['integer'] == 151:
            #     continue
            # fault['lons'] = fault['lons'][1:-1]; fault['lats'] = fault['lats'][1:-1]
            scattersize = 1
            
            # if fault['name'] in bad_fault:
            # plt.figure(); plt.title(fault['name'])
            if ('outcropping' in fault['style']):
                plt.plot(fault['lons'], fault['lats'], color = 'blue')#, s = scattersize)
            if ('buried' in fault['style']):
                plt.plot(fault['lons'], fault['lats'], color = 'red')#, s = scattersize)
            if ('doubtful' in fault['style']):
                plt.plot(fault['lons'], fault['lats'], color = 'orange')#, s = scattersize)
                
            # plt.plot(fault['lons'], fault['lats'], c = 'green')
            # plt.show()
            # bad.append(int(input()))
            # input('')
            # plt.show()
            # print(fault['integer'])
            # plt.annotate('txt', [fault['lonlabel'], fault['latlabel']]
        plt.show()
    mapped_faults = all_faults
    
    # The below loop shows that there are several instances of some faults, but they are different parts of the fault trace. 
    # bad_fault = []
    # for ifault, fault in enumerate(all_faults):
    #     if bad[ifault]:
    #         bad_fault.append(fault['name'])
    
    
    
    all_faults = []
    with open(srfile, 'r') as file:
        file = file.readlines()
        for iline, line in enumerate(reversed(file)): # Reverse because name comes at end of a faults data
            if line[0] == '^':
                if iline > 1: 
                    all_faults.append(fault)
    
                # # break
                # thing = line.split()
                # name = thing[4:]
                # name_join = '' 
                # for i in range(len(name)):
                #     name_join += name[i] + ' ' # Add space between words
                # name_join = name_join[0:-1] # Remove the extra space
                
                thing = line.split()
                integer = thing[-1]
                
                fault = {'name': '', 'lons':[], 'lats':[], 'elv':[], 'integer':integer}
                # thing = thing[1:4] # Just consider the data
                # fault['lons'].append(float(thing[0]))
                # fault['lats'].append(float(thing[1]))
                # fault['elv'] .append(float(thing[2]))
            else:
                thing = line.split()
                fault['lons'].append(float(thing[0]))
                fault['lats'].append(float(thing[1]))
                fault['elv'] .append(float(thing[2]))
    
    if plot: 
        for ifault, fault in enumerate(all_faults):
            plt.plot(fault['lons'], fault['lats'], linewidth = 2,  label = str(fault['integer']))
        plt.legend()
        plt.show()
        
    surface_ruptures = all_faults 
    
    return mapped_faults, surface_ruptures


if __name__ == '__main__':
    load_fault_traces(plot = True)
# lons = []
# lats = []
# elv  = []
# integer = []
# with open('Surface_Ruptures', 'r') as file:
#     for line in file:
#         if line[0] == '^':
#             continue
#         else:
#             thing = line.split()
#             lons.append(float(thing[0]))
#             lats.append(float(thing[1]))
#             elv .append(float(thing[2]))
#             integer.append(float(thing[3]))
            
            
# plt.scatter(fault['lons'], fault['lats'], s=1, c = integer)
# plt.show()
89913e8059aa2a4724b530f87663c2d4f3ecfa02
<mask token>

<mask token>


def load_fault_traces(mffile='Mapped_Faults', srfile='Surface_Ruptures',
    plot=False):
    all_faults = []
    with open(mffile, 'r') as file:
        file = file.readlines()
        for iline, line in enumerate(reversed(file)):
            if line[0] == '^':
                if iline > 1 or iline == len(file) - 1:
                    all_faults.append(fault)
                thing = line.split()
                txt = thing[4:]
                name = txt[0]
                style = txt[1]
                integer = thing[1]
                lonlabel = float(thing[2])
                latlabel = float(thing[3])
                fault = {'name': name, 'style': style, 'lons': [], 'lats':
                    [], 'elv': [], 'integer': integer, 'lonlabel': lonlabel,
                    'latlabel': latlabel}
            else:
                thing = line.split()
                fault['lons'].append(float(thing[0]))
                fault['lats'].append(float(thing[1]))
                fault['elv'].append(float(thing[2]))
    if plot:
        plt.figure()
        for ifault, fault in enumerate(all_faults):
            scattersize = 1
            if 'outcropping' in fault['style']:
                plt.plot(fault['lons'], fault['lats'], color='blue')
            if 'buried' in fault['style']:
                plt.plot(fault['lons'], fault['lats'], color='red')
            if 'doubtful' in fault['style']:
                plt.plot(fault['lons'], fault['lats'], color='orange')
        plt.show()
    mapped_faults = all_faults
    all_faults = []
    with open(srfile, 'r') as file:
        file = file.readlines()
        for iline, line in enumerate(reversed(file)):
            if line[0] == '^':
                if iline > 1:
                    all_faults.append(fault)
                thing = line.split()
                integer = thing[-1]
                fault = {'name': '', 'lons': [], 'lats': [], 'elv': [],
                    'integer': integer}
            else:
                thing = line.split()
                fault['lons'].append(float(thing[0]))
                fault['lats'].append(float(thing[1]))
                fault['elv'].append(float(thing[2]))
    if plot:
        for ifault, fault in enumerate(all_faults):
            plt.plot(fault['lons'], fault['lats'], linewidth=2, label=str(
                fault['integer']))
        plt.legend()
        plt.show()
    surface_ruptures = all_faults
    return mapped_faults, surface_ruptures


<mask token>

<mask token>


def load_fault_traces(mffile='Mapped_Faults', srfile='Surface_Ruptures',
    plot=False):
    all_faults = []
    with open(mffile, 'r') as file:
        file = file.readlines()
        for iline, line in enumerate(reversed(file)):
            if line[0] == '^':
                if iline > 1 or iline == len(file) - 1:
                    all_faults.append(fault)
                thing = line.split()
                txt = thing[4:]
                name = txt[0]
                style = txt[1]
                integer = thing[1]
                lonlabel = float(thing[2])
                latlabel = float(thing[3])
                fault = {'name': name, 'style': style, 'lons': [], 'lats':
                    [], 'elv': [], 'integer': integer, 'lonlabel': lonlabel,
                    'latlabel': latlabel}
            else:
                thing = line.split()
                fault['lons'].append(float(thing[0]))
                fault['lats'].append(float(thing[1]))
                fault['elv'].append(float(thing[2]))
    if plot:
        plt.figure()
        for ifault, fault in enumerate(all_faults):
            scattersize = 1
            if 'outcropping' in fault['style']:
                plt.plot(fault['lons'], fault['lats'], color='blue')
            if 'buried' in fault['style']:
                plt.plot(fault['lons'], fault['lats'], color='red')
            if 'doubtful' in fault['style']:
                plt.plot(fault['lons'], fault['lats'], color='orange')
        plt.show()
    mapped_faults = all_faults
    all_faults = []
    with open(srfile, 'r') as file:
        file = file.readlines()
        for iline, line in enumerate(reversed(file)):
            if line[0] == '^':
                if iline > 1:
                    all_faults.append(fault)
                thing = line.split()
                integer = thing[-1]
                fault = {'name': '', 'lons': [], 'lats': [], 'elv': [],
                    'integer': integer}
            else:
                thing = line.split()
                fault['lons'].append(float(thing[0]))
                fault['lats'].append(float(thing[1]))
                fault['elv'].append(float(thing[2]))
    if plot:
        for ifault, fault in enumerate(all_faults):
            plt.plot(fault['lons'], fault['lats'], linewidth=2, label=str(
                fault['integer']))
        plt.legend()
        plt.show()
    surface_ruptures = all_faults
    return mapped_faults, surface_ruptures


if __name__ == '__main__':
    load_fault_traces(plot=True)

import numpy as np
import matplotlib.pyplot as plt


def load_fault_traces(mffile='Mapped_Faults', srfile='Surface_Ruptures',
    plot=False):
    all_faults = []
    with open(mffile, 'r') as file:
        file = file.readlines()
        for iline, line in enumerate(reversed(file)):
            if line[0] == '^':
                if iline > 1 or iline == len(file) - 1:
                    all_faults.append(fault)
                thing = line.split()
                txt = thing[4:]
                name = txt[0]
                style = txt[1]
                integer = thing[1]
                lonlabel = float(thing[2])
                latlabel = float(thing[3])
                fault = {'name': name, 'style': style, 'lons': [], 'lats':
                    [], 'elv': [], 'integer': integer, 'lonlabel': lonlabel,
                    'latlabel': latlabel}
            else:
                thing = line.split()
                fault['lons'].append(float(thing[0]))
                fault['lats'].append(float(thing[1]))
                fault['elv'].append(float(thing[2]))
    if plot:
        plt.figure()
        for ifault, fault in enumerate(all_faults):
            scattersize = 1
            if 'outcropping' in fault['style']:
                plt.plot(fault['lons'], fault['lats'], color='blue')
            if 'buried' in fault['style']:
                plt.plot(fault['lons'], fault['lats'], color='red')
            if 'doubtful' in fault['style']:
                plt.plot(fault['lons'], fault['lats'], color='orange')
        plt.show()
    mapped_faults = all_faults
    all_faults = []
    with open(srfile, 'r') as file:
        file = file.readlines()
        for iline, line in enumerate(reversed(file)):
            if line[0] == '^':
                if iline > 1:
                    all_faults.append(fault)
                thing = line.split()
                integer = thing[-1]
                fault = {'name': '', 'lons': [], 'lats': [], 'elv': [],
                    'integer': integer}
            else:
                thing = line.split()
                fault['lons'].append(float(thing[0]))
                fault['lats'].append(float(thing[1]))
                fault['elv'].append(float(thing[2]))
    if plot:
        for ifault, fault in enumerate(all_faults):
            plt.plot(fault['lons'], fault['lats'], linewidth=2, label=str(
                fault['integer']))
        plt.legend()
        plt.show()
    surface_ruptures = all_faults
    return mapped_faults, surface_ruptures


if __name__ == '__main__':
    load_fault_traces(plot=True)

import numpy as np
import matplotlib.pyplot as plt


def load_fault_traces(mffile = 'Mapped_Faults', srfile = 'Surface_Ruptures', plot = False): 
# from mpl_toolkits.basemap import Basemap


# map = Basemap(projection='aeqd',
#           lon_0 = 13.5,
#           lat_0 = 42.4,
#           resolution = 'i',
#               ax = ax)
    
    # lons = []
    # lats = []
    # elv  = []
    all_faults = []
    with open(mffile, 'r') as file:
        file = file.readlines()
        for iline, line in enumerate(reversed(file)): # Reverse because name comes at end of a faults data
            if line[0] == '^':
                if (iline > 1) or (iline == len(file)-1): 
                    all_faults.append(fault)
    
                # break
                thing = line.split()
                txt = thing[4:]
                name = txt[0]
                style = txt[1]
    
                
                integer = thing[1]            
                lonlabel = float(thing[2])
                latlabel = float(thing[3])
                fault = {'name': name, 'style': style, 'lons':[], 'lats':[], 'elv':[], 
                          'integer':integer, 
                          'lonlabel':lonlabel, 'latlabel':latlabel}
            else:
                thing = line.split()
                fault['lons'].append(float(thing[0]))
                fault['lats'].append(float(thing[1]))
                fault['elv'] .append(float(thing[2]))
    
    # plt.scatter(lons, lats,s = 1)
    # bad = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    #bad_fault = ['mdibagno', 'M.Stabbiata', 'Pizzoli', 'Campotosto', 'VdelSaltoSud']
    # bad_fault = ['Campotosto']
    if plot: 
        plt.figure()
        for ifault, fault in enumerate(all_faults):
            # if fault['integer'] == 151:
            #     continue
            # fault['lons'] = fault['lons'][1:-1]; fault['lats'] = fault['lats'][1:-1]
            scattersize = 1
            
            # if fault['name'] in bad_fault:
            # plt.figure(); plt.title(fault['name'])
            if ('outcropping' in fault['style']):
                plt.plot(fault['lons'], fault['lats'], color = 'blue')#, s = scattersize)
            if ('buried' in fault['style']):
                plt.plot(fault['lons'], fault['lats'], color = 'red')#, s = scattersize)
            if ('doubtful' in fault['style']):
                plt.plot(fault['lons'], fault['lats'], color = 'orange')#, s = scattersize)
                
            # plt.plot(fault['lons'], fault['lats'], c = 'green')
            # plt.show()
            # bad.append(int(input()))
            # input('')
            # plt.show()
            # print(fault['integer'])
            # plt.annotate('txt', [fault['lonlabel'], fault['latlabel']]
        plt.show()
    mapped_faults = all_faults
    
    # The below loop shows that there are several instances of some faults, but they are different parts of the fault trace. 
    # bad_fault = []
    # for ifault, fault in enumerate(all_faults):
    #     if bad[ifault]:
    #         bad_fault.append(fault['name'])
    
    
    
    all_faults = []
    with open(srfile, 'r') as file:
        file = file.readlines()
        for iline, line in enumerate(reversed(file)): # Reverse because name comes at end of a faults data
            if line[0] == '^':
                if iline > 1: 
                    all_faults.append(fault)
    
                # # break
                # thing = line.split()
                # name = thing[4:]
                # name_join = '' 
                # for i in range(len(name)):
                #     name_join += name[i] + ' ' # Add space between words
                # name_join = name_join[0:-1] # Remove the extra space
                
                thing = line.split()
                integer = thing[-1]
                
                fault = {'name': '', 'lons':[], 'lats':[], 'elv':[], 'integer':integer}
                # thing = thing[1:4] # Just consider the data
                # fault['lons'].append(float(thing[0]))
                # fault['lats'].append(float(thing[1]))
                # fault['elv'] .append(float(thing[2]))
            else:
                thing = line.split()
                fault['lons'].append(float(thing[0]))
                fault['lats'].append(float(thing[1]))
                fault['elv'] .append(float(thing[2]))
    
    if plot: 
        for ifault, fault in enumerate(all_faults):
            plt.plot(fault['lons'], fault['lats'], linewidth = 2,  label = str(fault['integer']))
        plt.legend()
        plt.show()
        
    surface_ruptures = all_faults 
    
    return mapped_faults, surface_ruptures


if __name__ == '__main__':
    load_fault_traces(plot = True)
# lons = []
# lats = []
# elv  = []
# integer = []
# with open('Surface_Ruptures', 'r') as file:
#     for line in file:
#         if line[0] == '^':
#             continue
#         else:
#             thing = line.split()
#             lons.append(float(thing[0]))
#             lats.append(float(thing[1]))
#             elv .append(float(thing[2]))
#             integer.append(float(thing[3]))
            
            
# plt.scatter(fault['lons'], fault['lats'], s=1, c = integer)
# plt.show()