How to use the obspy.io.nordic.utils._str_conv function in obspy

To help you get started, we’ve selected a few obspy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github obspy / obspy / obspy / io / nordic / core.py View on Github external
get_referred_object()
    # Sort out the first line
    lines[0][1:5] = str(origin.time.year).rjust(4)
    lines[0][6:8] = str(origin.time.month).rjust(2)
    lines[0][8:10] = str(origin.time.day).rjust(2)
    lines[0][11:13] = str(origin.time.hour).rjust(2)
    lines[0][13:15] = str(origin.time.minute).rjust(2)
    lines[0][16:20] = str(origin.time.second).rjust(2) + '.' +\
        str(origin.time.microsecond).ljust(1)[0:1]
    lines[0][23:30] = _str_conv(origin.latitude, 3).rjust(7)
    lines[0][30:38] = _str_conv(origin.longitude, 3).rjust(8)
    lines[0][38:43] = _str_conv(origin.depth / 1000.0, 1).rjust(5)
    if hasattr(origin, 'creation_info') and hasattr(
            origin.creation_info, 'agency_id'):
        lines[0][45:48] = origin.creation_info.agency_id.rjust(3)[0:3]
    lines[0][55:59] = _str_conv(magnitude.mag, 1).rjust(4)
    lines[0][59] = _evmagtonor(magnitude.magnitude_type)
    if hasattr(magnitude, 'creation_info') and hasattr(
            magnitude.creation_info, 'agency_id'):
        lines[0][60:63] = magnitude.creation_info.agency_id.rjust(3)[0:3]
    lines[0][70:77] = (str(
        focal_mechanism.moment_tensor.method_id).split('/')[-1]).rjust(7)
    # Sort out the second line
    lines[1][1:3] = 'MT'
    lines[1][3:9] = _str_conv(
        focal_mechanism.moment_tensor.tensor.m_rr, 3)[0:6].rjust(6)
    lines[1][10:16] = _str_conv(
        focal_mechanism.moment_tensor.tensor.m_tt, 3)[0:6].rjust(6)
    lines[1][17:23] = _str_conv(
        focal_mechanism.moment_tensor.tensor.m_pp, 3)[0:6].rjust(6)
    lines[1][24:30] = _str_conv(
        focal_mechanism.moment_tensor.tensor.m_rt, 3)[0:6].rjust(6)
github obspy / obspy / obspy / io / nordic / core.py View on Github external
lines[0][55:59] = _str_conv(magnitude.mag, 1).rjust(4)
    lines[0][59] = _evmagtonor(magnitude.magnitude_type)
    if hasattr(magnitude, 'creation_info') and hasattr(
            magnitude.creation_info, 'agency_id'):
        lines[0][60:63] = magnitude.creation_info.agency_id.rjust(3)[0:3]
    lines[0][70:77] = (str(
        focal_mechanism.moment_tensor.method_id).split('/')[-1]).rjust(7)
    # Sort out the second line
    lines[1][1:3] = 'MT'
    lines[1][3:9] = _str_conv(
        focal_mechanism.moment_tensor.tensor.m_rr, 3)[0:6].rjust(6)
    lines[1][10:16] = _str_conv(
        focal_mechanism.moment_tensor.tensor.m_tt, 3)[0:6].rjust(6)
    lines[1][17:23] = _str_conv(
        focal_mechanism.moment_tensor.tensor.m_pp, 3)[0:6].rjust(6)
    lines[1][24:30] = _str_conv(
        focal_mechanism.moment_tensor.tensor.m_rt, 3)[0:6].rjust(6)
    lines[1][31:37] = _str_conv(
        focal_mechanism.moment_tensor.tensor.m_rp, 3)[0:6].rjust(6)
    lines[1][38:44] = _str_conv(
        focal_mechanism.moment_tensor.tensor.m_tp, 3)[0:6].rjust(6)
    if hasattr(magnitude, 'creation_info') and hasattr(
            magnitude.creation_info, 'agency_id'):
        lines[1][45:48] = magnitude.creation_info.agency_id.rjust(3)[0:3]
    lines[1][48] = 'S'
    lines[1][52:62] = (
        "%.3e" % focal_mechanism.moment_tensor.scalar_moment).rjust(10)
    lines[1][70:77] = (
        str(focal_mechanism.moment_tensor.method_id).split('/')[-1]).rjust(7)
    return '\n'.join([''.join(line) for line in lines])
github obspy / obspy / obspy / io / nordic / core.py View on Github external
lines[0][60:63] = magnitude.creation_info.agency_id.rjust(3)[0:3]
    lines[0][70:77] = (str(
        focal_mechanism.moment_tensor.method_id).split('/')[-1]).rjust(7)
    # Sort out the second line
    lines[1][1:3] = 'MT'
    lines[1][3:9] = _str_conv(
        focal_mechanism.moment_tensor.tensor.m_rr, 3)[0:6].rjust(6)
    lines[1][10:16] = _str_conv(
        focal_mechanism.moment_tensor.tensor.m_tt, 3)[0:6].rjust(6)
    lines[1][17:23] = _str_conv(
        focal_mechanism.moment_tensor.tensor.m_pp, 3)[0:6].rjust(6)
    lines[1][24:30] = _str_conv(
        focal_mechanism.moment_tensor.tensor.m_rt, 3)[0:6].rjust(6)
    lines[1][31:37] = _str_conv(
        focal_mechanism.moment_tensor.tensor.m_rp, 3)[0:6].rjust(6)
    lines[1][38:44] = _str_conv(
        focal_mechanism.moment_tensor.tensor.m_tp, 3)[0:6].rjust(6)
    if hasattr(magnitude, 'creation_info') and hasattr(
            magnitude.creation_info, 'agency_id'):
        lines[1][45:48] = magnitude.creation_info.agency_id.rjust(3)[0:3]
    lines[1][48] = 'S'
    lines[1][52:62] = (
        "%.3e" % focal_mechanism.moment_tensor.scalar_moment).rjust(10)
    lines[1][70:77] = (
        str(focal_mechanism.moment_tensor.method_id).split('/')[-1]).rjust(7)
    return '\n'.join([''.join(line) for line in lines])
github obspy / obspy / obspy / io / nordic / core.py View on Github external
#     # velocity = 1.0 / pick.horizontal_slowness
        #     velocity = ' '  # Currently this conversion is unsupported.
        # else:
        #     velocity = ' '
        velocity = ' '
        azimuth = _str_conv(pick.backazimuth)
        # Extract the correct arrival info for this pick - assuming only one
        # arrival per pick...
        arrival = [arrival for arrival in origin.arrivals
                   if arrival.pick_id == pick.resource_id]
        if len(arrival) > 0:
            if len(arrival) > 1:
                warnings.warn("Multiple arrivals for pick - only writing one")
            arrival = arrival[0]
            # Extract weight - should be stored as 0-4, or 9 for seisan.
            weight = _str_conv(int(arrival.time_weight or 0))
            # Extract azimuth residual
            if arrival.backazimuth_residual is not None:
                azimuthres = _str_conv(int(arrival.backazimuth_residual))
            else:
                azimuthres = ' '
            if arrival.takeoff_angle is not None:
                ain = _str_conv(int(arrival.takeoff_angle))
            else:
                ain = ' '
            # Extract time residual
            if arrival.time_residual is not None:
                timeres = _str_conv(arrival.time_residual, rounded=2)
            else:
                timeres = ' '
            # Extract distance
            if arrival.distance is not None:
github obspy / obspy / obspy / io / nordic / core.py View on Github external
# Note that pick seconds rounding only works because SEISAN does not
        # enforce that seconds stay 0 <= seconds < 60, so rounding something
        # like seconds = 59.997 to 2dp gets to 60.00, which SEISAN is happy
        # with.  It appears that SEISAN is happy with large numbers of seconds
        # see #2348.
        pick_strings.append(pick_string_formatter.format(
            station=pick.waveform_id.station_code,
            instrument=channel_code[0], component=channel_code[-1],
            phase_info=phase_info, hour=pick_hour,
            minute=pick.time.minute,
            seconds=_str_conv(pick_seconds, rounded=pick_rounding),
            coda=_str_conv(coda).rjust(5)[0:5],
            amp=_str_conv(amp, rounded=1).rjust(7)[0:7],
            period=_str_conv(peri, rounded=peri_round).rjust(5)[0:5],
            azimuth=_str_conv(azimuth).rjust(6)[0:6],
            velocity=_str_conv(velocity).rjust(5)[0:5],
            ain=ain.rjust(4)[0:4],
            azimuthres=_str_conv(azimuthres).rjust(3)[0:3],
            timeres=_str_conv(timeres, rounded=2).rjust(5)[0:5],
            distance=distance.rjust(5)[0:5],
            caz=_str_conv(caz).rjust(4)[0:4]))
        # Note that currently finalweight is unsupported, nor is velocity, or
        # angle of incidence.  This is because obspy.event stores slowness in
        # s/deg and takeoff angle, which would require computation from the
        # values stored in seisan.  Multiple weights are also not supported in
        # Obspy.event
    return pick_strings
github obspy / obspy / obspy / io / nordic / core.py View on Github external
" {station:5s}{instrument:1s}{component:1s}{phase_info:10s}"
            "{hour:2d}{minute:2d}{seconds:>6s}{coda:5s}{amp:7s}{period:5s}"
            "{azimuth:6s}{velocity:5s}{ain:4s}{azimuthres:3s}{timeres:5s}  "
            "{distance:5s}{caz:4s} ")
        # Note that pick seconds rounding only works because SEISAN does not
        # enforce that seconds stay 0 <= seconds < 60, so rounding something
        # like seconds = 59.997 to 2dp gets to 60.00, which SEISAN is happy
        # with.  It appears that SEISAN is happy with large numbers of seconds
        # see #2348.
        pick_strings.append(pick_string_formatter.format(
            station=pick.waveform_id.station_code,
            instrument=channel_code[0], component=channel_code[-1],
            phase_info=phase_info, hour=pick_hour,
            minute=pick.time.minute,
            seconds=_str_conv(pick_seconds, rounded=pick_rounding),
            coda=_str_conv(coda).rjust(5)[0:5],
            amp=_str_conv(amp, rounded=1).rjust(7)[0:7],
            period=_str_conv(peri, rounded=peri_round).rjust(5)[0:5],
            azimuth=_str_conv(azimuth).rjust(6)[0:6],
            velocity=_str_conv(velocity).rjust(5)[0:5],
            ain=ain.rjust(4)[0:4],
            azimuthres=_str_conv(azimuthres).rjust(3)[0:3],
            timeres=_str_conv(timeres, rounded=2).rjust(5)[0:5],
            distance=distance.rjust(5)[0:5],
            caz=_str_conv(caz).rjust(4)[0:4]))
        # Note that currently finalweight is unsupported, nor is velocity, or
        # angle of incidence.  This is because obspy.event stores slowness in
        # s/deg and takeoff angle, which would require computation from the
        # values stored in seisan.  Multiple weights are also not supported in
        # Obspy.event
    return pick_strings
github obspy / obspy / obspy / io / nordic / core.py View on Github external
# Extract time residual
            if arrival.time_residual is not None:
                timeres = _str_conv(arrival.time_residual, rounded=2)
            else:
                timeres = ' '
            # Extract distance
            if arrival.distance is not None:
                distance = degrees2kilometers(arrival.distance)
                if distance >= 100.0:
                    distance = str(_int_conv(distance))
                elif 10.0 < distance < 100.0:
                    distance = _str_conv(round(distance, 1), rounded=1)
                elif distance < 10.0:
                    distance = _str_conv(round(distance, 2), rounded=2)
                else:
                    distance = _str_conv(distance, False)
            else:
                distance = ' '
            # Extract CAZ
            if arrival.azimuth is not None:
                caz = _str_conv(int(arrival.azimuth))
            else:
                caz = ' '
        else:
            caz, distance, timeres, azimuthres, azimuth, weight, ain = (
                ' ', ' ', ' ', ' ', ' ', 0, ' ')
        phase_hint = pick.phase_hint or ' '
        # Extract amplitude: note there can be multiple amplitudes, but they
        # should be associated with different picks.
        amplitude = [amplitude for amplitude in event.amplitudes
                     if amplitude.pick_id == pick.resource_id]
        if len(amplitude) > 0:
github obspy / obspy / obspy / io / nordic / core.py View on Github external
if days_diff > 1:
                raise NordicParsingError(
                    "Pick is {0} days from the origin, must be < 48 "
                    "hours".format(days_diff))
            pick_hour += 24
        pick_seconds = pick.time.second + (pick.time.microsecond / 1e6)
        if len(phase_hint) > 4:
            # Weight goes in 9 and phase_hint runs through 11-18
            if polarity != ' ':
                UserWarning("Polarity not written due to phase hint length")
            phase_info = (
                _str_conv(weight).rjust(1) + impulsivity + phase_hint.ljust(8))
        else:
            phase_info = (
                ' ' + impulsivity + phase_hint.ljust(4) +
                _str_conv(weight).rjust(1) + eval_mode +
                polarity.rjust(1) + ' ')
        pick_string_formatter = (
            " {station:5s}{instrument:1s}{component:1s}{phase_info:10s}"
            "{hour:2d}{minute:2d}{seconds:>6s}{coda:5s}{amp:7s}{period:5s}"
            "{azimuth:6s}{velocity:5s}{ain:4s}{azimuthres:3s}{timeres:5s}  "
            "{distance:5s}{caz:4s} ")
        # Note that pick seconds rounding only works because SEISAN does not
        # enforce that seconds stay 0 <= seconds < 60, so rounding something
        # like seconds = 59.997 to 2dp gets to 60.00, which SEISAN is happy
        # with.  It appears that SEISAN is happy with large numbers of seconds
        # see #2348.
        pick_strings.append(pick_string_formatter.format(
            station=pick.waveform_id.station_code,
            instrument=channel_code[0], component=channel_code[-1],
            phase_info=phase_info, hour=pick_hour,
            minute=pick.time.minute,
github obspy / obspy / obspy / io / nordic / core.py View on Github external
origin_date = origin.time.date
    except IndexError:
        origin = Origin()
        origin_date = min([p.time for p in event.picks]).date
    pick_strings = []
    if high_accuracy:
        pick_rounding = 3
    else:
        pick_rounding = 2
    for pick in event.picks:
        if not pick.waveform_id:
            msg = ('No waveform id for pick at time %s, skipping' % pick.time)
            warnings.warn(msg)
            continue
        impulsivity = _str_conv(INV_ONSET_MAPPING.get(pick.onset))
        polarity = _str_conv(INV_POLARITY_MAPPING.get(pick.polarity))
        # Extract velocity: Note that horizontal slowness in quakeML is stored
        # as s/deg
        # if pick.horizontal_slowness is not None:
        #     # velocity = 1.0 / pick.horizontal_slowness
        #     velocity = ' '  # Currently this conversion is unsupported.
        # else:
        #     velocity = ' '
        velocity = ' '
        azimuth = _str_conv(pick.backazimuth)
        # Extract the correct arrival info for this pick - assuming only one
        # arrival per pick...
        arrival = [arrival for arrival in origin.arrivals
                   if arrival.pick_id == pick.resource_id]
        if len(arrival) > 0:
            if len(arrival) > 1:
                warnings.warn("Multiple arrivals for pick - only writing one")