def get_oscillator(self):
        """
        Calculated the oscillator of each trace's data.

        Returns:
            spectrals: StationStream or numpy.ndarray with the
                    differentiated data.
        """
        spectrals = get_spectral(self.period,
                self.transform_data, damping=self.damping, times=self.times)
        return spectrals
Пример #2
0
    def get_oscillator(self):
        """
        Calculated the oscillator of each trace's data.

        Returns:
            spectrals: StationStream or numpy.ndarray with the oscillator data.
        """
        spectrals = get_spectral(self.period,
                                 self.transform_data,
                                 damping=self.damping,
                                 times=self.times)
        return spectrals
Пример #3
0
    def get_oscillator(self, config=None):
        """
        Calculated the oscillator of each trace's data.

        Args:
            config (dict):
                Configuration options.

        Returns:
            spectrals: StationStream or numpy.ndarray with the oscillator data.
        """
        spectrals = get_spectral(self.period,
                                 self.transform_data,
                                 damping=self.damping,
                                 times=self.times,
                                 config=config)
        return spectrals
Пример #4
0
    def generate_oscillators(self,
                             imts,
                             sa_periods,
                             fas_periods,
                             rotate=False):
        """
        Create dictionary of requested imt and its coinciding oscillators.

        Args:
            imts (list): List of imts.
            sa_periods (list): List of periods. Used to generate the SA
                    oscillators.
            fas_periods (list): List of periods. Used to generate the FAS
                    oscillators.
            rotate (bool): Whether to rotate the sa oscillators for the ROTD
                    component.

        Returns:
            dictionary: dictionary of oscillators for each imt.

        Notes:
            Damping value must be set.
        """
        if self.stream is None:
            raise Exception('StationSummary.stream is not set.')
        oscillator_dict = OrderedDict()
        for imt in imts:
            stream = self.stream.copy()
            if imt.upper() == 'PGA':
                oscillator = get_acceleration(stream)
                oscillator_dict['PGA'] = oscillator
            elif imt.upper() == 'PGV':
                oscillator = get_velocity(stream)
                oscillator_dict['PGV'] = oscillator
            elif imt.upper() == 'FAS':
                oscillator = get_acceleration(stream, 'cm/s/s')
                oscillator_dict['FAS'] = oscillator
            elif imt.upper().startswith('SA'):
                for period in sa_periods:
                    tag = 'SA(' + str(period) + ')'
                    oscillator = get_spectral(period,
                                              stream,
                                              damping=self.damping)
                    oscillator_dict[tag] = oscillator
                    if rotate:
                        oscillator = get_spectral(period,
                                                  stream,
                                                  damping=self.damping,
                                                  rotation='nongm')
                        oscillator_dict[tag + '_ROT'] = oscillator
            elif imt.upper() == 'ARIAS':
                oscillator = get_acceleration(stream, units='m/s/s')
                oscillator_dict['ARIAS'] = oscillator
            else:
                fmt = "Invalid imt: %r. Skipping..."
                logging.warning(fmt % (imt))
        imts = []
        for key in oscillator_dict:
            if key == 'FAS':
                for period in fas_periods:
                    imts += ['FAS(' + str(period) + ')']
            elif key.find('ROT') < 0:
                imts += [key]

        self.imts = imts
        self.oscillators = oscillator_dict
def test_spectral():
    datafiles, _ = read_data_dir("geonet", "us1000778i", "20161113_110259_WTMC_20.V2A")
    acc_file = datafiles[0]
    acc = read_data(acc_file)[0]
    get_spectral(1.0, acc, 0.05)
Пример #6
0
def plot_oscillators(st, periods=[0.1, 2, 5, 10], file=None, show=False):
    """
    Produces a figure of the oscillator responses for a StationStream. The
    figure will plot the acceleration traces in the first row, and then an
    additional row for each oscillator period. The number of columns is the
    number of channels in the stream.

    Args:
        st (gmprocess.core.stationstream.StationStream):
            StaionStream of data.
        periods (list):
            A list of periods (floats, in seconds).
        file (str):
            File where the image will be saved. Default is None.
        show (bool):
            Show the figure. Default is False.
    """

    fig, axes = plt.subplots(nrows=len(periods) + 1, ncols=len(st), figsize=(
        4 * len(st), 2 * len(periods)))
    if len(st) == 1:
        # Ensure that axes is a 2D numpy array
        axes = axes.reshape(-1, 1)

    for i in range(axes.shape[0]):
        if i == 0:
            plot_st = st
            ylabel = 'Acceleration (cm/s$^2$)'
            textstr = 'T: %s s \nPGA: %.2g cm/s$^2$'
        else:
            prd = periods[i - 1]
            plot_st = get_spectral(prd, st)
            ylabel = 'SA %s s (%%g)' % prd
            textstr = 'T: %s s \nSA: %.2g %%g'

        for j, tr in enumerate(plot_st):
            ax = axes[i, j]
            dtimes = np.linspace(
                0, tr.stats.endtime - tr.stats.starttime, tr.stats.npts)
            ax.plot(dtimes, tr.data, 'k', linewidth=0.5)

            # Get time and amplitude of max SA (using absolute value)
            tmax = dtimes[np.argmax(abs(tr.data))]
            sa_max = max(tr.data, key=abs)

            ax.axvline(tmax, c='r', ls='--')
            ax.scatter([tmax], [sa_max], c='r', edgecolors='k', zorder=10)
            ax.text(0.01, 0.98, textstr % (tmax, sa_max),
                    transform=ax.transAxes, va='top')

            if i == 0:
                ax.set_title(tr.id)
            if i == len(periods):
                ax.set_xlabel('Time (s)')
            ax.set_ylabel(ylabel)

    plt.tight_layout()

    if file is not None:
        plt.savefig(file)
    if show:
        plt.show()
def test_spectral():
    datafiles, _ = read_data_dir('geonet', 'us1000778i',
                                 '20161113_110259_WTMC_20.V2A')
    acc_file = datafiles[0]
    acc = read_data(acc_file)[0]
    get_spectral(1.0, acc, 0.05, rotation='gm')
def test_spectral():
    datafiles, _ = read_data_dir(
        'geonet', 'us1000778i', '20161113_110259_WTMC_20.V2A')
    acc_file = datafiles[0]
    acc = read_data(acc_file)[0]
    get_spectral(1.0, acc, 0.05)