from mastodonutils import FTA
quant2006 = FTA.Quantification("gnf_2006", 
                           logic='logic.csv', 
                           basic_events='bas_events_2006.csv',
                           analysis='Fragility', 
                           hazard='seismic_hazard_2006.csv', 
                           IM=[0.04, 0.11, 0.21, 0.42, 0.64, 0.87, 1.09, 1.52, 3.26, 4.34, 6.51], 
                           lite=True,
                           nbins=10,
                           write_output=True)
print 'Risk of collapse for the 2006 assessment is:\t',quant2006.toprisk_2

"""
Explanation: Demonstration of the MASTODON FTA Python module
Analysis for the 2006 assessment
End of explanation
"""


from mastodonutils import FTA
quant2015 = FTA.Quantification("gnf_2015", 
                           logic='logic.csv', 
                           basic_events='bas_events_2015.csv',
                           analysis='Fragility', 
                           hazard='seismic_hazard_2015.csv', 
                           IM=[0.01, 0.02, 0.05, 0.1, 0.2, 0.3, 0.7, 2.0, 3.0, 5.0, 10.0], 
                           lite=True,
                           nbins=10,
                           write_output=True)
print 'Risk of collapse for the 2015 assessment is:\t',quant2015.toprisk_2

"""
Explanation: Analysis for the 2015 assessment
End of explanation
"""


import matplotlib.pyplot as plt
import matplotlib
matplotlib.rc('font',family='Times New Roman')
%matplotlib inline
plt.figure(figsize=(10,8))
plt.plot(quant2006.toprisk_2_info[0],quant2006.toprisk_2_info[4],color='blue',label='2006',marker='o',
     markerfacecolor='blue',markersize=8,linewidth=2)
plt.plot(quant2015.toprisk_2_info[0],quant2015.toprisk_2_info[4],color='red',label='2015',marker='o',
     markerfacecolor='red',markersize=8,linewidth=2)
plt.xscale('log')
plt.yscale('log')
plt.xlabel('Sa (10Hz)',fontname='Times New Roman',fontsize=18)
plt.ylabel('Collapse frequency',fontname='Times New Roman',fontsize=18)
plt.legend(loc='best',fontsize=18)
plt.grid(b=True,which='both')
plt.xticks(fontname='Times New Roman', fontsize=16)
plt.yticks(fontname='Times New Roman', fontsize=16)
# plt.savefig('collapse_frequencies.png',dpi=300)

"""
Explanation: Plotting the collapse frequencies of each bin
End of explanation
"""


