In [2]:
%matplotlib inline
import os
import glob
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import oq_output.hazard_curve_converter as hazard_converter
mpl.rcParams['lines.linewidth'] = 2
import

In [5]:
CALCULATION_ID = 9
path = './output/calc_%d/hazard_curve/PGA/' % CALCULATION_ID
file_wild = '*.xml'

for file_name in glob.glob(path + file_wild):
    hcm = hazard_converter.read_hazard_curves(file_name)
    for row in hcm["curves"]:
        if hcm["gsim_tree_path"] is not None:
            label="GSIM %s Source %s" % (hcm["gsim_tree_path"], 
                                         hcm["source_model_tree_path"])
        else:
            label="%s" % (hcm["statistics"])
        plt.loglog(hcm["imls"], row[2:], label=label)
    plt.xlabel(hcm['imt'])
plt.ylabel('Probability of exceedence in %s years' % 
           hcm['investigation_time'])
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5), frameon=False)
#plt.autoscale('x', tight=True)
plt.xlim((1e-2, 1))
plt.ylim((1e-2, 1))
plt.show()


{'source_model_tree_path': None, 'statistics': 'quantile', 'curves': array([[  5.00000000e-01,  -5.00000000e-01,   9.99999799e-01,
          9.99999663e-01,   9.99999113e-01,   9.99996062e-01,
          9.99966966e-01,   9.99525226e-01,   9.94178751e-01,
          9.55199070e-01,   8.12916972e-01,   5.53610200e-01,
          2.96151911e-01,   1.30857900e-01,   4.84540968e-02,
          1.53327814e-02,   4.08526917e-03,   8.83752163e-04,
          1.35603634e-04,   1.08708386e-05,   4.54269810e-08]]), 'gsim_tree_path': None, 'investigation_time': 50.0, 'imls': array([ 0.005 ,  0.007 ,  0.0098,  0.0137,  0.0192,  0.0269,  0.0376,
        0.0527,  0.0738,  0.103 ,  0.145 ,  0.203 ,  0.284 ,  0.397 ,
        0.556 ,  0.778 ,  1.09  ,  1.52  ,  2.13  ]), 'imt': 'PGA'}
{'source_model_tree_path': None, 'statistics': 'quantile', 'curves': array([[  5.00000000e-01,  -5.00000000e-01,   9.99999838e-01,
          9.99999780e-01,   9.99999550e-01,   9.99998317e-01,
          9.99988222e-01,   9.99879907e-01,   9.98779242e-01,
          9.90499948e-01,   9.52139482e-01,   8.46605378e-01,
          6.56218448e-01,   4.32909364e-01,   2.39986448e-01,
          1.11816974e-01,   4.33864858e-02,   1.39090189e-02,
          3.52332833e-03,   9.83971568e-04,   2.53461121e-04]]), 'gsim_tree_path': None, 'investigation_time': 50.0, 'imls': array([ 0.005 ,  0.007 ,  0.0098,  0.0137,  0.0192,  0.0269,  0.0376,
        0.0527,  0.0738,  0.103 ,  0.145 ,  0.203 ,  0.284 ,  0.397 ,
        0.556 ,  0.778 ,  1.09  ,  1.52  ,  2.13  ]), 'imt': 'PGA'}
{'source_model_tree_path': None, 'statistics': 'quantile', 'curves': array([[  5.00000000e-01,  -5.00000000e-01,   9.99999775e-01,
          9.99999559e-01,   9.99998508e-01,   9.99990875e-01,
          9.99910178e-01,   9.98971171e-01,   9.90438613e-01,
          9.41859721e-01,   7.92988387e-01,   5.46592830e-01,
          2.81563904e-01,   1.11122868e-01,   3.38781796e-02,
          7.79094436e-03,   1.26405250e-03,   1.22418680e-04,
          4.18125795e-06,   0.00000000e+00,   0.00000000e+00]]), 'gsim_tree_path': None, 'investigation_time': 50.0, 'imls': array([ 0.005 ,  0.007 ,  0.0098,  0.0137,  0.0192,  0.0269,  0.0376,
        0.0527,  0.0738,  0.103 ,  0.145 ,  0.203 ,  0.284 ,  0.397 ,
        0.556 ,  0.778 ,  1.09  ,  1.52  ,  2.13  ]), 'imt': 'PGA'}
{'source_model_tree_path': None, 'statistics': 'mean', 'curves': array([[  5.00000000e-01,  -5.00000000e-01,   9.99999811e-01,
          9.99999688e-01,   9.99999137e-01,   9.99995514e-01,
          9.99959303e-01,   9.99529194e-01,   9.95272391e-01,
          9.67884195e-01,   8.71126432e-01,   6.82734644e-01,
          4.48266489e-01,   2.52326256e-01,   1.23107706e-01,
          5.26319584e-02,   1.96168930e-02,   6.36079071e-03,
          1.75522605e-03,   4.22925631e-04,   8.63349800e-05]]), 'gsim_tree_path': None, 'investigation_time': 50.0, 'imls': array([ 0.005 ,  0.007 ,  0.0098,  0.0137,  0.0192,  0.0269,  0.0376,
        0.0527,  0.0738,  0.103 ,  0.145 ,  0.203 ,  0.284 ,  0.397 ,
        0.556 ,  0.778 ,  1.09  ,  1.52  ,  2.13  ]), 'imt': 'PGA'}

In [22]:
hcm


Out[22]:
{'curves': array([[  5.00000000e-01,  -5.00000000e-01,   9.99999799e-01,
           9.99999663e-01,   9.99999113e-01,   9.99996062e-01,
           9.99971770e-01,   9.99739258e-01,   9.97686840e-01,
           9.84003644e-01,   9.26693304e-01,   7.84604909e-01,
           5.59521679e-01,   3.34588787e-01,   1.70155238e-01,
           7.55928437e-02,   2.97317647e-02,   1.05279731e-02,
           3.35779099e-03,   9.83971568e-04,   2.53461121e-04]]),
 'gsim_tree_path': ['b12', 'b21'],
 'imls': array([ 0.005 ,  0.007 ,  0.0098,  0.0137,  0.0192,  0.0269,  0.0376,
         0.0527,  0.0738,  0.103 ,  0.145 ,  0.203 ,  0.284 ,  0.397 ,
         0.556 ,  0.778 ,  1.09  ,  1.52  ,  2.13  ]),
 'imt': 'PGA',
 'investigation_time': 50.0,
 'source_model_tree_path': ['b2'],
 'statistics': None}