In [1]:
import os
import sys
import numpy
import pickle

sys.path.append('/Users/mpagani/Projects/original/oq-engine/')

from openquake.hmtk.seismicity.catalogue import Catalogue
from openquake.hmtk.parsers.catalogue.csv_catalogue_parser import CsvCatalogueParser
from openquake.hmtk.seismicity.selector import CatalogueSelector

In [2]:
filename = '/Users/mpagani/GDrive/GEM_hazard/Data/Catalogues/extended/Weatherill_Pagani_Garcia_Extended_Global_Earthquake_Catalogue.csv'

parser = CsvCatalogueParser(filename)
cat = parser.read_file()


Catalogue Attribute Identifier is not a recognised catalogue key
Catalogue Attribute sourceIdentifier is not a recognised catalogue key
280758 latitude
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
~/Projects/original/oq-engine/openquake/hmtk/parsers/catalogue/csv_catalogue_parser.py in _float_check(self, attribute_array, value, irow, key)
    119             if value:
--> 120                 attribute_array = np.hstack([attribute_array, float(value)])
    121             else:

/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/numpy/core/shape_base.py in hstack(tup)
    290     if arrs and arrs[0].ndim == 1:
--> 291         return _nx.concatenate(arrs, 0)
    292     else:

KeyboardInterrupt: 

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-2-8e97bb1f95f1> in <module>()
      1 filename = '/Users/mpagani/GDrive/GEM_hazard/Data/Catalogues/extended/Weatherill_Pagani_Garcia_Extended_Global_Earthquake_Catalogue.csv'
      2 parser = CsvCatalogueParser(filename)
----> 3 cat = parser.read_file()

~/Projects/original/oq-engine/openquake/hmtk/parsers/catalogue/csv_catalogue_parser.py in read_file(self, start_year, end_year)
     79                 if key in catalogue.FLOAT_ATTRIBUTE_LIST:
     80                     catalogue.data[key] = self._float_check(
---> 81                         catalogue.data[key], row[key], irow, key)
     82                 elif key in catalogue.INT_ATTRIBUTE_LIST:
     83                     catalogue.data[key] = self._int_check(

~/Projects/original/oq-engine/openquake/hmtk/parsers/catalogue/csv_catalogue_parser.py in _float_check(self, attribute_array, value, irow, key)
    125             msg = 'Input file format error at line: %d' % (irow+2)
    126             msg += ' key: %s' % (key)
--> 127             raise ValueError(msg)
    128         return attribute_array
    129 

ValueError: Input file format error at line: 280760 key: latitude

In [ ]:
output_path = './catalogue_ext.p'
fou = open(output_path,'wb') 
pickle.dump(cat, fou)
fou.close()

In [4]:
idxo = numpy.nonzero((cat.data['longitude'] >= -121) & (cat.data['longitude'] <= -51) & 
                     (cat.data['latitude'] >= 5) & (cat.data['latitude'] <= 34))
idxs = idxo[0].astype(int)

boo = numpy.zeros_like(cat.data['magnitude'], dtype=int)
boo[idxs] = 1
print (len(boo))


562840

In [6]:
selector = CatalogueSelector(cat, create_copy=True)
newcat = selector.select_catalogue(boo)
print (len(newcat.data['magnitude']))


34414

In [7]:
output_path = './catalogue_ext_cac.p'
fou = open(output_path,'wb') 
pickle.dump(newcat, fou)
fou.close()

In [ ]: