Esempio n. 1
0
def make_amplitudes(scnls=None, picks=None):
    """Create amplitudes for testing."""
    counter = 1
    amps = []
    scnls = scnls or []
    params = {
        "type": "A",
        "unit": "dimensionless",
        "method_id": "mag_calculator",
        "filter_id": ev.ResourceIdentifier("Wood-Anderson"),
        "magnitude_hint": "M",
        "category": "point",
        "evaluation_mode": "manual",
        "evaluation_status": "confirmed",
    }
    for scnl in scnls:
        a = ev.Amplitude(
            generic_amplitude=counter,
            generic_amplitude_errors=ev.QuantityError(
                uncertainty=counter * 0.1, confidence_level=95
            ),
            period=counter * 2,
            snr=counter * 5,
            time_window=ev.TimeWindow(0, 0.1, UTCDateTime()),
            waveform_id=ev.WaveformStreamID(seed_string=scnl),
            scaling_time=UTCDateTime(),
            scaling_time_errors=ev.QuantityError(
                uncertainty=counter * 0.001, confidence_level=95
            ),
            creation_info=ev.CreationInfo(
                agency_id="dummy_agency", author="dummy", creation_time=UTCDateTime()
            ),
            **params,
        )
        amps.append(a)
        counter += 1
    picks = picks or []
    for pick in picks:
        a = ev.Amplitude(
            generic_amplitude=counter,
            generic_amplitude_errors=ev.QuantityError(
                uncertainty=counter * 0.1, confidence_level=95
            ),
            period=counter * 2,
            snr=counter * 5,
            time_window=ev.TimeWindow(0, 0.1, UTCDateTime()),
            pick_id=pick.resource_id,
            scaling_time=UTCDateTime(),
            scaling_time_errors=ev.QuantityError(
                uncertainty=counter * 0.001, confidence_level=95
            ),
            creation_info=ev.CreationInfo(
                agency_id="dummy_agency", author="dummy", creation_time=UTCDateTime()
            ),
            **params,
        )
        amps.append(a)
        counter += 1
    return amps
Esempio n. 2
0
    def _create_pick():
        # setup some of the classes
        creation = ev.CreationInfo(
            agency='SwanCo',
            author='Indago',
            creation_time=UTCDateTime(),
            version='10.10',
            author_url=ev.ResourceIdentifier('smi:local/me.com'),
        )

        pick = ev.Pick(
            time=state['time'],
            comments=[ev.Comment(x) for x in 'BOB'],
            evaluation_mode='manual',
            evaluation_status='final',
            creation_info=creation,
            phase_hint='P',
            polarity='positive',
            onset='emergent',
            back_azimith_errors={"uncertainty": 10},
            slowness_method_id=ev.ResourceIdentifier('smi:local/slow'),
            backazimuth=122.1,
            horizontal_slowness=12,
            method_id=ev.ResourceIdentifier(),
            horizontal_slowness_errors={'uncertainty': 12},
            filter_id=ev.ResourceIdentifier(),
            waveform_id=ev.WaveformStreamID('UU', 'FOO', '--', 'HHZ'),
        )
        state['pick_id'] = pick.resource_id
        return pick
Esempio n. 3
0
def make_arrivals(picks):
    """Create arrivals for testing."""
    counter = 1
    params = {"phase": "P"}
    arrivals = []
    picks = picks or []
    for pick in picks:
        a = ev.Arrival(
            pick_id=pick.resource_id,
            time_correction=counter * 0.05,
            azimuth=counter * 5,
            distance=counter * 0.1,
            takeoff_angle=counter * 2,
            time_residual=counter * 0.15,
            horizontal_slowness_residual=counter * 0.2,
            backazimuth_residual=counter * 0.25,
            time_weight=counter * 0.3,
            horizontal_slowness_weight=counter * 0.4,
            backazimuth_weight=counter * 0.5,
            earth_model_id=ev.ResourceIdentifier(),
            creation_info=ev.CreationInfo(
                agency_id="dummy_agency", author="dummy", creation_time=UTCDateTime()
            ),
            **params,
        )
        arrivals.append(a)
        counter += 1
    return arrivals
Esempio n. 4
0
def mag_generator(mag_types):
    """Function to create magnitudes for testing."""
    params = {
        "origin_id": ev.ResourceIdentifier(),
        "method_id": ev.ResourceIdentifier("mag_calculator"),
        "station_count": 2,
        "azimuthal_gap": 30,
        "evaluation_mode": "manual",
        "evaluation_status": "reviewed",
    }
    mags = []
    counter = 1
    for mt in mag_types:
        m = ev.Magnitude(
            mag=counter,
            magnitude_type=mt,
            mag_errors=ev.QuantityError(uncertainty=counter * 0.1,
                                        confidence_level=95),
            creation_info=ev.CreationInfo(agency_id="dummy_agency",
                                          author="dummy",
                                          creation_time=UTCDateTime()),
            **params,
        )
        mags.append(m)
    return mags
Esempio n. 5
0
def _create_event(ser):
    """ create an event from a row from the event dataframe """
    event = oe.Event(
        resource_id=rid(ser.evid),
        creation=oe.CreationInfo(agency_id=ser.auth,
                                 creation_time=UTC(ser.lddate)),
        preferred_origin_id=str(ser.prefor),
    )
    return event
Esempio n. 6
0
def sm_generator(scnls=None, amplitudes=None):
    """Function to create station magntiudes for testing."""
    counter = 1
    sms = []
    scnls = scnls or []
    params = {
        "origin_id": ev.ResourceIdentifier(),
        "station_magnitude_type": "M",
        "method_id": "mag_calculator",
    }

    for scnl in scnls:
        sm = ev.StationMagnitude(
            mag=counter,
            mag_errors=ev.QuantityError(uncertainty=counter * 0.1,
                                        confidence_level=95),
            waveform_id=ev.WaveformStreamID(seed_string=scnl),
            creation_info=ev.CreationInfo(agency_id="dummy_agency",
                                          author="dummy",
                                          creation_time=UTCDateTime()),
            **params,
        )
        sms.append(sm)
        counter += 1
    amplitudes = amplitudes or []
    for amp in amplitudes:
        sm = ev.StationMagnitude(
            mag=counter,
            mag_errors=ev.QuantityError(uncertainty=counter * 0.1,
                                        confidence_level=95),
            amplitude_id=amp.resource_id,
            creation_info=ev.CreationInfo(agency_id="dummy_agency",
                                          author="dummy",
                                          creation_time=UTCDateTime()),
            **params,
        )
        sms.append(sm)
        counter += 1
    return sms
Esempio n. 7
0
def create_creation_info(agency_id=None, creation_time=None, author=None):
    '''

    :param agency_id:
    :param creation_time:
    :param author:
    :return:
    '''
    if author is None:
        author = getLogin()
    if creation_time is None:
        creation_time = UTCDateTime()
    return ope.CreationInfo(agency_id=agency_id,
                            author=author,
                            creation_time=creation_time)
Esempio n. 8
0
def _obj_extractor(obj, dtypes, seed_id=True, error_obj=None):
    """extract common information from event object"""
    # extract attributes that are floats/str
    overlap = set(obj.__dict__) & set(dtypes)
    base = {i: getattr(obj, i) for i in overlap}
    # get waveform_id stuff (seed_id, network, station, location, channel)
    if seed_id:
        base.update(_get_seed_id(obj))
    # extract error info, if applicable
    if error_obj:
        errors = obj.__dict__[error_obj]
        if errors:
            base.update(_get_uncertainty(errors))
    # get creation info
    cio = obj.creation_info or ev.CreationInfo()
    base.update(_get_creation_info(cio))
    return base
Esempio n. 9
0
    def _setPick(self,
                 xdata,
                 phase,
                 channel,
                 polarity='undecideable',
                 overwrite_existing=False):
        '''
        Write obspy.core.event.Pick into self._picks list
        '''
        picktime = self._current_st[0].stats.starttime +\
                (xdata * self._current_st[0].stats.delta)

        this_pick = event.Pick()
        overwrite = True
        # Overwrite existing phase's picktime
        if overwrite_existing:
            for _pick in self._getPicks():
                if _pick.phase_hint == phase and\
                        _pick.waveform_id.channel_code == channel:
                    this_pick = _pick
                    overwrite = False
                    break

        creation_info = event.CreationInfo(author='ObsPy.StreamPick',
                                           creation_time=UTCDateTime())
        # Create new event.Pick()
        this_pick.time = picktime
        this_pick.phase_hint = phase
        this_pick.waveform_id = event.WaveformStreamID(
            network_code=self._current_st[0].stats.network,
            station_code=self._current_st[0].stats.station,
            location_code=self._current_st[0].stats.location,
            channel_code=channel)
        this_pick.evaluation_mode = 'manual'
        this_pick.creation_info = creation_info
        this_pick.onset = self.onset_types[self.onsetGrp.checkedId()]
        this_pick.evaluation_status = 'preliminary'
        this_pick.polarity = polarity
        #if self._current_filter is not None:
        #    this_pick.comments.append(event.Comment(
        #                text=str(self.bpfilter[self.fltrcb.currentIndex()])))
        if overwrite:
            self._picks.append(this_pick)
Esempio n. 10
0
def _create_magnitude(ser):
    """ create magnitude objects """
    event = get_object(ser.evid)

    creation_info = oe.CreationInfo(
        creation_time=timestamp(ser.lddate),
        agency_id=ser.auth,
    )

    errors = oe.QuantityError(uncertainty=ser.uncertainty, )

    magnitude = oe.Magnitude(
        origin_id=str(ser.orid),
        mag=ser.magnitude,
        magnitude_type=ser.magtype,
        station_count=ser.nsta,
        creation_info=creation_info,
        mag_errors=errors,
    )
    event.magnitudes.append(magnitude)
Esempio n. 11
0
def _create_pick(ser):
    """ create picks """
    ser = ser[(ser != -1) & ~(ser.isnull())]

    co = oe.CreationInfo(
        agencey_idr=ser.get('auth'),
        creation_time=UTC(ser.get('lddate')),
    )

    seed_str = _get_seed_str(ser)

    wid = oe.WaveformStreamID(seed_string=seed_str)

    pick = oe.Pick(
        time=UTC(ser.time),
        resource_id=rid(ser.arid),
        creation_info=co,
        waveform_id=wid,
    )
    return pick
Esempio n. 12
0
def readPILOTEvent(phasfn=None, locfn=None, authority_id='RUB', **kwargs):
    """
    readPILOTEvent - function

    Reads Matlab PHASES and LOC files written by Matlab versions of PILOT and
    converts the data into an ObsPy Event object which is returned to the
    calling program.

    :rtype : ~obspy.core.event.Event
    :param eventID:
    :param authority:
    :param kwargs:
    :param phasfn: filename of the old PILOT Matlab PHASES file
    :param locfn: filename of the old PILOT Matlab LOC file
    :return event:  event object containing event and phase information
    """
    if phasfn is not None and os.path.isfile(phasfn):
        phases = sio.loadmat(phasfn)
        phasctime = UTCDateTime(os.path.getmtime(phasfn))
        phasauthor = getOwner(phasfn)
    else:
        phases = None
        phasctime = None
        phasauthor = None
    if locfn is not None and os.path.isfile(locfn):
        loc = sio.loadmat(locfn)
        locctime = UTCDateTime(os.path.getmtime(locfn))
        locauthor = getOwner(locfn)
    else:
        loc = None
        locctime = None
        locauthor = None
    pickcinfo = ope.CreationInfo(agency_id=authority_id,
                                 author=phasauthor,
                                 creation_time=phasctime)
    loccinfo = ope.CreationInfo(agency_id=authority_id,
                                author=locauthor,
                                creation_time=locctime)

    eventNum = str(loc['ID'][0])

    # retrieve eventID for the actual database
    idsplit = eventNum.split('.')

    # retrieve date information
    julday = int(idsplit[1])
    year = int(idsplit[2])
    hour = int(loc['hh'])
    minute = int(loc['mm'])
    second = int(loc['ss'])

    year = four_digits(year)

    eventDate = UTCDateTime(year=year,
                            julday=julday,
                            hour=hour,
                            minute=minute,
                            second=second)

    stations = [stat for stat in phases['stat'][0:-1:3]]

    lat = float(loc['LAT'])
    lon = float(loc['LON'])
    dep = float(loc['DEP'])

    event = create_event(eventDate,
                         loccinfo,
                         originloc=(lat, lon, dep),
                         etype='earthquake',
                         resID=eventNum,
                         authority_id=authority_id)

    picks = picksdict_from_pilot(phasfn)

    event.picks = picks_from_picksdict(picks, creation_info=pickcinfo)

    if event.origins:
        origin = event.origins[0]
        magnitude = create_magnitude(origin.get('id'), loccinfo)
        magnitude.mag = float(loc['Mnet'])
        magnitude.magnitude_type = 'Ml'
        event.magnitudes.append(magnitude)
    return event