Exemple #1
0
def get_phase_dataframe(detail, catalog='preferred'):
    """Return a Pandas DataFrame consisting of Phase arrival data.

    Args:
        detail (DetailEvent): DetailEvent object.
        catalog (str): Source network ('us','ak', etc. ,or 'preferred'.)

    Returns:
        DataFrame: Pandas DataFrame containing columns:
            - Channel: Network.Station.Channel.Location (NSCL) style station
                       description. ("--" indicates missing information)
            - Distance: Distance (kilometers) from epicenter to station.
            - Azimuth: Azimuth (degrees) from epicenter to station.
            - Phase: Name of the phase (Pn,Pg, etc.)
            - Arrival Time: Pick arrival time (UTC).
            - Status: "manual" or "automatic".
            - Residual: Arrival time residual.
            - Weight: Arrival weight.
            - Agency: Agency ID.
    Raises:
        AttributeError: If input DetailEvent does not have a phase-data product
            for the input catalog.
    """
    if catalog is None:
        catalog = 'preferred'
    df = pd.DataFrame(columns=[
        'Channel', 'Distance', 'Azimuth', 'Phase', 'Arrival Time', 'Status',
        'Residual', 'Weight', 'Agency'
    ])

    phasedata = detail.getProducts('phase-data', source=catalog)[0]
    quakeurl = phasedata.getContentURL('quakeml.xml')
    try:
        fh = urlopen(quakeurl, timeout=TIMEOUT)
        data = fh.read()
        fh.close()
    except Exception:
        return None
    unpickler = Unpickler()
    with warnings.catch_warnings():
        warnings.filterwarnings("ignore", category=UserWarning)
        catalog = unpickler.loads(data)
        catevent = catalog.events[0]
        for pick in catevent.picks:
            phaserow = _get_phaserow(pick, catevent)
            if phaserow is None:
                continue
            df = df.append(phaserow, ignore_index=True)
    return df
Exemple #2
0
def get_phase_dataframe(detail, catalog='preferred'):
    """Return a Pandas DataFrame consisting of Phase arrival data.

    Args:
        detail (DetailEvent): DetailEvent object.
        catalog (str): Source network ('us','ak', etc. ,or 'preferred'.)

    Returns:
        DataFrame: Pandas DataFrame containing columns:
            - Channel: Network.Station.Channel.Location (NSCL) style station
                       description. ("--" indicates missing information)
            - Distance: Distance (kilometers) from epicenter to station.
            - Azimuth: Azimuth (degrees) from epicenter to station.
            - Phase: Name of the phase (Pn,Pg, etc.)
            - Arrival Time: Pick arrival time (UTC).
            - Status: "manual" or "automatic".
            - Residual: Arrival time residual.
            - Weight: Arrival weight.
            - Agency: Agency ID.
    Raises:
        AttributeError: If input DetailEvent does not have a phase-data product
            for the input catalog.
    """
    if catalog is None:
        catalog = 'preferred'
    df = pd.DataFrame(columns=['Channel', 'Distance', 'Azimuth',
                               'Phase', 'Arrival Time', 'Status',
                               'Residual', 'Weight', 'Agency'])

    phasedata = detail.getProducts('phase-data', source=catalog)[0]
    quakeurl = phasedata.getContentURL('quakeml.xml')
    try:
        fh = urlopen(quakeurl, timeout=TIMEOUT)
        data = fh.read()
        fh.close()
    except Exception:
        return None
    unpickler = Unpickler()
    with warnings.catch_warnings():
        warnings.filterwarnings("ignore", category=UserWarning)
        catalog = unpickler.loads(data)
        catevent = catalog.events[0]
        for pick in catevent.picks:
            phaserow = _get_phaserow(pick, catevent)
            if phaserow is None:
                continue
            df = df.append(phaserow, ignore_index=True)
    return df
Exemple #3
0
def get_magnitude_data_frame(detail, catalog, magtype):
    """Return a Pandas DataFrame consisting of magnitude data.

    Args:
        detail (DetailEvent): DetailEvent object.
        catalog (str): Source catalog ('us','ak', etc. ,or 'preferred'.)
        magtype (str): Magnitude type (mb, ml, etc.)

    Returns:
        DataFrame: Pandas DataFrame containing columns:
            - Channel: Network.Station.Channel.Location (NSCL) style station
                       description. ("--" indicates missing information)
            - Type: Magnitude type.
            - Amplitude: Amplitude of seismic wave at each station (m).
            - Period: Period of seismic wave at each station (s).
            - Status: "manual" or "automatic".
            - Magnitude: Locally determined magnitude.
            - Weight: Magnitude weight.
    Raises:
        AttributeError if input DetailEvent does not have a phase-data product
            for the input catalog.
    """
    columns = columns = [
        'Channel', 'Type', 'Amplitude', 'Period', 'Status', 'Magnitude',
        'Weight'
    ]
    df = pd.DataFrame(columns=columns)
    phasedata = detail.getProducts('phase-data', source=catalog)[0]
    quakeurl = phasedata.getContentURL('quakeml.xml')
    try:
        fh = urlopen(quakeurl, timeout=TIMEOUT)
        data = fh.read()
        fh.close()
    except Exception:
        return None
    fmt = '%s.%s.%s.%s'
    unpickler = Unpickler()
    with warnings.catch_warnings():
        warnings.filterwarnings("ignore", category=UserWarning)
        catalog = unpickler.loads(data)
        catevent = catalog.events[0]  # match this to input catalog
        for magnitude in catevent.magnitudes:
            if magnitude.magnitude_type.lower() != magtype.lower():
                continue
            for contribution in magnitude.station_magnitude_contributions:
                row = {}
                smag = contribution.station_magnitude_id.get_referred_object()
                ampid = smag.amplitude_id
                amp = None
                if ampid is None:
                    waveid = smag.waveform_id
                    tpl = (waveid.network_code, waveid.station_code, '--',
                           '--')
                else:
                    amp = ampid.get_referred_object()
                    if amp is None:
                        waveid = smag.waveform_id
                        tpl = (waveid.network_code, waveid.station_code, '--',
                               '--')
                    else:
                        waveid = amp.waveform_id
                        tpl = (waveid.network_code, waveid.station_code,
                               waveid.channel_code, waveid.location_code)

                row['Channel'] = fmt % tpl
                row['Type'] = smag.station_magnitude_type
                if amp is not None:
                    row['Amplitude'] = amp.generic_amplitude
                    row['Period'] = amp.period
                    row['Status'] = amp.evaluation_mode
                else:
                    row['Amplitude'] = np.nan
                    row['Period'] = np.nan
                    row['Status'] = 'automatic'
                row['Magnitude'] = smag.mag
                row['Weight'] = contribution.weight
                df = df.append(row, ignore_index=True)
    df = df[columns]
    return df
Exemple #4
0
def get_magnitude_data_frame(detail, catalog, magtype):
    """Return a Pandas DataFrame consisting of magnitude data.

    Args:
        detail (DetailEvent): DetailEvent object.
        catalog (str): Source catalog ('us','ak', etc. ,or 'preferred'.)
        magtype (str): Magnitude type (mb, ml, etc.)

    Returns:
        DataFrame: Pandas DataFrame containing columns:
            - Channel: Network.Station.Channel.Location (NSCL) style station
                       description. ("--" indicates missing information)
            - Type: Magnitude type.
            - Amplitude: Amplitude of seismic wave at each station (m).
            - Period: Period of seismic wave at each station (s).
            - Status: "manual" or "automatic".
            - Magnitude: Locally determined magnitude.
            - Weight: Magnitude weight.
    Raises:
        AttributeError if input DetailEvent does not have a phase-data product
            for the input catalog.
    """
    columns = columns = ['Channel', 'Type', 'Amplitude',
                         'Period', 'Status', 'Magnitude',
                         'Weight']
    df = pd.DataFrame(columns=columns)
    phasedata = detail.getProducts('phase-data', source=catalog)[0]
    quakeurl = phasedata.getContentURL('quakeml.xml')
    try:
        fh = urlopen(quakeurl, timeout=TIMEOUT)
        data = fh.read()
        fh.close()
    except Exception:
        return None
    fmt = '%s.%s.%s.%s'
    unpickler = Unpickler()
    with warnings.catch_warnings():
        warnings.filterwarnings("ignore", category=UserWarning)
        catalog = unpickler.loads(data)
        catevent = catalog.events[0]  # match this to input catalog
        for magnitude in catevent.magnitudes:
            if magnitude.magnitude_type.lower() != magtype.lower():
                continue
            for contribution in magnitude.station_magnitude_contributions:
                row = {}
                smag = contribution.station_magnitude_id.get_referred_object()
                ampid = smag.amplitude_id
                amp = None
                if ampid is None:
                    waveid = smag.waveform_id
                    tpl = (waveid.network_code,
                           waveid.station_code,
                           '--',
                           '--')
                else:
                    amp = ampid.get_referred_object()
                    if amp is None:
                        waveid = smag.waveform_id
                        tpl = (waveid.network_code,
                               waveid.station_code,
                               '--',
                               '--')
                    else:
                        waveid = amp.waveform_id
                        tpl = (waveid.network_code,
                               waveid.station_code,
                               waveid.channel_code,
                               waveid.location_code)

                row['Channel'] = fmt % tpl
                row['Type'] = smag.station_magnitude_type
                if amp is not None:
                    row['Amplitude'] = amp.generic_amplitude
                    row['Period'] = amp.period
                    row['Status'] = amp.evaluation_mode
                else:
                    row['Amplitude'] = np.nan
                    row['Period'] = np.nan
                    row['Status'] = 'automatic'
                row['Magnitude'] = smag.mag
                row['Weight'] = contribution.weight
                df = df.append(row, ignore_index=True)
    df = df[columns]
    return df