Example #1
0
    def testGlobalCMT(self):
        
        def is_the_haiti_event(ev): 
            assert near(ev.magnitude, 7.0, 0.1)
            assert near(ev.lat, 18.61, 0.01)
            assert near(ev.lon, -72.62, 0.01)
            assert near(ev.depth, 12000., 1.)
            assert ev.region.lower() == 'haiti region'

        cat = catalog.GlobalCMT()

        tmin = util.ctimegm('2010-01-12 21:50:00')
        tmax = util.ctimegm('2010-01-13 03:17:00')
        
        names = cat.get_event_names( time_range=(tmin,tmax), magmin=5.)
        ident = None
        for name in names:
            ev = cat.get_event(name)
            if ev.magnitude > 7:
                is_the_haiti_event(ev)
                ident = ev.name

        assert ident is not None 
        cat.flush()
        ev = cat.get_event(ident)
        is_the_haiti_event(ev)
Example #2
0
    def testGlobalCMT(self):
        def is_the_haiti_event(ev):
            assert near(ev.magnitude, 7.0, 0.1)
            assert near(ev.lat, 18.61, 0.01)
            assert near(ev.lon, -72.62, 0.01)
            assert near(ev.depth, 12000., 1.)
            assert ev.region.lower() == 'haiti region'

        cat = catalog.GlobalCMT()

        tmin = util.ctimegm('2010-01-12 21:50:00')
        tmax = util.ctimegm('2010-01-13 03:17:00')

        names = cat.get_event_names(time_range=(tmin, tmax), magmin=5.)
        ident = None
        for name in names:
            ev = cat.get_event(name)
            if ev.magnitude > 7:
                is_the_haiti_event(ev)
                ident = ev.name

        assert ident is not None
        cat.flush()
        ev = cat.get_event(ident)
        is_the_haiti_event(ev)
Example #3
0
    def testGeofon(self):
        def is_the_haiti_event(ev): 
            assert near(ev.magnitude, 7.2, 0.001)
            assert near(ev.lat, 18.37, 0.001)
            assert near(ev.lon, -72.55, 0.001)
            assert near(ev.depth, 17000., 1.)
            assert ev.region == 'Haiti Region'

        cat = catalog.Geofon()
        
        tmin = util.ctimegm('2010-01-12 21:50:00')
        tmax = util.ctimegm('2010-01-13 03:17:00')
        
        names = cat.get_event_names( time_range=(tmin,tmax), nmax=10, magmin=5.)
        
        assert len(names) > 0
        ident = None 
        for name in names:
            ev = cat.get_event(name)
            if ev.magnitude >= 7:
                is_the_haiti_event(ev)
                ident = ev.name
        
        assert ident is not None

        cat.flush()
        ev = cat.get_event(ident)
        is_the_haiti_event(ev)
Example #4
0
    def testUSGS(self):

        def is_the_haiti_event(ev): 
            assert near(ev.magnitude, 7.0, 0.1)
            assert near(ev.lat, 18.443, 0.01)
            assert near(ev.lon, -72.571, 0.01)
            assert near(ev.depth, 13000., 1.)

        cat = catalog.USGS()

        tmin = util.ctimegm('2010-01-12 21:50:00')
        tmax = util.ctimegm('2010-01-13 03:17:00')

        names = cat.get_event_names( time_range=(tmin,tmax), magmin=5.)
        assert len(names) == 13
        for name in names:
            ev = cat.get_event(name)
            if ev.magnitude >= 7.:
                is_the_haiti_event(ev)
                ident = ev.name

        assert ident is not None
        cat.flush()
        ev = cat.get_event(ident)
        is_the_haiti_event(ev)
Example #5
0
def get_badness(streams_badness_dir, time):
    fns = os.listdir(streams_badness_dir)
    fns.sort()
    bef = {}
    for fn in fns:
        toks = fn.split('_')
        if len(toks) != 5 or toks[0] != 'badness': continue
        beg_d, beg_t, end_d, end_t = toks[1:]
        begin = util.ctimegm(beg_d+' '+beg_t.replace('-',':'))
        end = util.ctimegm(end_d+' '+end_t.replace('-',':'))
        dist = 0.
        if time < begin:
            dist = begin-time
        if time > end:
            dist = time-end
        
        bef[dist] = fn
        
    fn = bef[sorted(bef.keys())[0]]
    
    f = open(pjoin(streams_badness_dir, fn), 'r')
    badness = {}
    for line in f:
        toks = line.split()
        if len(toks) != 2: continue
        nslc = toks[0].split('.')
        if len(nslc) != 4: continue
        val = float(toks[1])
        badness[tuple(nslc)] = val
    f.close()
    return badness
Example #6
0
    def testUSGS(self):

        def is_the_haiti_event(ev):
            assert near(ev.magnitude, 7.0, 0.1)
            assert near(ev.lat, 18.443, 0.01)
            assert near(ev.lon, -72.571, 0.01)
            assert near(ev.depth, 13000., 1.)

        cat = catalog.USGS()

        tmin = util.ctimegm('2010-01-12 21:50:00')
        tmax = util.ctimegm('2010-01-13 03:17:00')

        names = cat.get_event_names(time_range=(tmin, tmax), magmin=5.)
        assert len(names) == 13
        for name in names:
            ev = cat.get_event(name)
            if ev.magnitude >= 7.:
                is_the_haiti_event(ev)
                ident = ev.name

        assert ident is not None
        cat.flush()
        ev = cat.get_event(ident)
        is_the_haiti_event(ev)
Example #7
0
    def testGeofon(self):
        def is_the_haiti_event(ev):
            assert near(ev.magnitude, 7.2, 0.001)
            assert near(ev.lat, 18.37, 0.001)
            assert near(ev.lon, -72.55, 0.001)
            assert near(ev.depth, 17000., 1.)
            assert ev.region == 'Haiti Region'

        cat = catalog.Geofon()

        tmin = util.ctimegm('2010-01-12 21:50:00')
        tmax = util.ctimegm('2010-01-13 03:17:00')

        names = cat.get_event_names(time_range=(tmin, tmax),
                                    nmax=10,
                                    magmin=5.)

        assert len(names) > 0
        ident = None
        for name in names:
            ev = cat.get_event(name)
            if ev.magnitude >= 7:
                is_the_haiti_event(ev)
                ident = ev.name

        assert ident is not None

        cat.flush()
        ev = cat.get_event(ident)
        is_the_haiti_event(ev)
Example #8
0
 def testGeofonMT(self):
     cat = catalog.Geofon()
     tmin = util.ctimegm('2014-01-01 00:00:00')
     tmax = util.ctimegm('2017-01-01 00:00:00')
     events = cat.get_events((tmin, tmax), magmin=8)
     self.assertEqual(len(events), 2)
     mt1, mt2 = [ev.moment_tensor for ev in events]
     angle = moment_tensor.kagan_angle(mt1, mt2)
     self.assertEqual(round(angle - 7.7, 1), 0.0)
 def testGeofonMT(self):
     cat = catalog.Geofon()
     tmin = util.ctimegm('2014-01-01 00:00:00')
     tmax = util.ctimegm('2017-01-01 00:00:00')
     events = cat.get_events((tmin, tmax), magmin=8)
     self.assertEqual(len(events), 2)
     mt1, mt2 = [ev.moment_tensor for ev in events]
     angle = moment_tensor.kagan_angle(mt1, mt2)
     self.assertEqual(round(angle - 7.7, 1), 0.0)
Example #10
0
def load_kps_event_list(filename):
    elist = []
    f = open(filename, 'r')
    for line in f:
        toks = line.split()
        if len(toks) < 7:
            continue

        tim = util.ctimegm(toks[0] + ' ' + toks[1])
        lat, lon, depth, magnitude = [float(x) for x in toks[2:6]]
        duration = float(toks[10])
        region = toks[-1]
        name = util.gmctime_fn(tim)
        e = Event(lat,
                  lon,
                  tim,
                  name=name,
                  depth=depth,
                  magnitude=magnitude,
                  duration=duration,
                  region=region)

        elist.append(e)

    f.close()
    return elist
Example #11
0
def load_kps_event_list(filename):
    elist = []
    f = open(filename, 'r')
    for line in f:
        toks = line.split()
        if len(toks) < 7:
            continue

        tim = util.ctimegm(toks[0]+' '+toks[1])
        lat, lon, depth, magnitude = [float(x) for x in toks[2:6]]
        duration = float(toks[10])
        region = toks[-1]
        name = util.gmctime_fn(tim)
        e = Event(
            lat, lon, tim,
            name=name,
            depth=depth,
            magnitude=magnitude,
            duration=duration,
            region=region)

        elist.append(e)

    f.close()
    return elist
Example #12
0
def getevents(searchparameter, cat):

    tmin = util.ctimegm(searchparameter["date_min"])
    tmax = util.ctimegm(searchparameter["date_max"])

    names = cat.get_event_names(time_range=(tmin, tmax),
                                nmax=10,
                                magmin=float(searchparameter["magmin"]))

    print names

    assert len(names) > 0
    ident = None
    for name in names:
        ev = cat.get_event(name)
        print ev
Example #13
0
    def read(self, filename, load_data=True):
        '''Read SAC file.

           filename -- Name of KAN file.
           load_data -- If True, the data is read, otherwise only read headers.
        '''
        nbh = KanFile.nbytes_header

        # read in all data
        f = open(filename, 'rb')
        if load_data:
            filedata = f.read()
        else:
            filedata = f.read(nbh)
        f.close()

        if len(filedata) < nbh:
            raise KanError('File too short to be a KAN file.')

        header_records = int(filedata[0:8])
        npts = int(filedata[8:20])
        leven = int(filedata[20:28])
        datatype = int(filedata[28:36])
        rate = float(filedata[36:50])
        offset = float(filedata[50:64])
        byte_sex = ('little', 'big')[int(filedata[382:390])]

        assert header_records == 1
        assert leven == 1
        assert datatype == 2
        assert offset == 0.0

        date = filedata[393:405].strip()
        tim = filedata[405:415].strip()
        microseconds = int(filedata[415:423])
        ref_time = util.ctimegm('%s %s' % (date, tim)) + microseconds/1.0e6

        stationname = os.path.basename(filename)
        stationname = stationname.replace('.kan', '')
        stationname = stationname.replace('.KAN', '')

        self.npts = npts
        self.delta = 1.0/rate
        self.kstnm = stationname
        self.ref_time = ref_time

        if load_data:
            if byte_sex == 'little':
                dtype = '<i4'
            else:
                dtype = '>i4'

            self.data = num.fromstring(filedata[nbh:], dtype=dtype)

            assert self.data.size == self.npts
        else:
            self.data = None
Example #14
0
 def testGeofon(self):
     
     cat = catalog.Geofon()
     
     tmin = util.ctimegm('2010-01-12 21:50:00')
     tmax = util.ctimegm('2010-01-13 03:17:00')
     
     names = cat.get_event_names( time_range=(tmin,tmax))
     
     assert len(names) > 0
     
     for name in names:
         ev = cat.get_event(name)
         if ev.magnitude >= 7:
             assert near(ev.magnitude, 7.2, 0.001)
             assert near(ev.lat, 18.37, 0.001)
             assert near(ev.lon, -72.55, 0.001)
             assert near(ev.depth, 17000., 1.)
             assert ev.region == 'Haiti Region'
Example #15
0
from pyrocko import util
from pyrocko.client import catalog

tmin = util.ctimegm('2018-06-11 01:18:00')
tmax = util.ctimegm('2018-06-11 01:19:00')
mag = 4.5

# download event information from GEOFON web page

geofon = catalog.Geofon()
event_names = geofon.get_event_names(time_range=(tmin, tmax), magmin=mag)

for event_name in event_names:
    event = geofon.get_event(event_name)
    print(event)
Example #16
0
from pyrocko import util
from pyrocko.client import catalog

tmin = util.ctimegm('2010-01-12 21:50:00')
tmax = util.ctimegm('2010-01-13 03:17:00')  # ending time of query
mag = 6.  # minimum magntiude (open end)

# download event information from GEOFON web page

geofon = catalog.Geofon()
event_names = geofon.get_event_names(time_range=(tmin, tmax), magmin=mag)

for event_name in event_names:
    event = geofon.get_event(event_name)
    print(event)
from pyrocko import util
from pyrocko.client import catalog

tmin = util.ctimegm('2010-01-12 21:50:00')
tmax = util.ctimegm('2010-01-13 03:17:00')  # ending time of query
mag = 6.                                    # minimum magntiude (open end)

# download event information from GEOFON web page

geofon = catalog.Geofon()
event_names = geofon.get_event_names(
    time_range=(tmin, tmax),
    magmin=mag)

for event_name in event_names:
    event = geofon.get_event(event_name)
    print(event)
Example #18
0
from pyrocko import util
from pyrocko.client import catalog

tmin = util.ctimegm('2018-06-11 08:23:00')
tmax = util.ctimegm('2018-06-11 08:24:00')
mag = 4.0

# download event information from GEOFON web page

geofon = catalog.Geofon()
event_names = geofon.get_event_names(time_range=(tmin, tmax), magmin=mag)

for event_name in event_names:
    event = geofon.get_event(event_name)
    print(event)