def operation_fa2sa(src, dst, damping, method, fixed_spacing): '''Compute the Fourier amplitude spectrum from a acceleration response spectrum.''' if fixed_spacing: period = np.logspace(-2, 1, 100) osc_freq = 1. / period for filename_src in glob.iglob(src): ext, freq, events = read_events(filename_src, 'fa') if not fixed_spacing: osc_freq = freq period = 1. / osc_freq for e in events: m = motions.RvtMotion( freq=freq, fourier_amp=e['fa'], duration=e['duration'], peak_calculator=get_peak_calculator(method) ) e['sa'] = m.compute_osc_resp(osc_freq, damping) if not os.path.exists(dst): os.makedirs(dst) basename = os.path.basename(filename_src) pathname_dst = os.path.join(dst, basename.rsplit('_', 1)[0]) write_events(pathname_dst + '_sa' + ext, period, 'Period (s)', 'sa', 'PSA (g)', events)
def compute_compatible_spectra(method, periods, events, damping): """ Compute the response spectrum compatible motions. """ target_freqs = 1. / periods for e in events: crm = motions.CompatibleRvtMotion( target_freqs, e['psa_target'], damping=damping, magnitude=e['magnitude'], distance=e['distance'], duration=e['duration'], region=e['region'], peak_calculator=get_peak_calculator(method) ) freqs = crm.freqs if not e['duration']: e['duration'] = crm.duration e['fa'] = crm.fourier_amp e['psa_calc'] = crm.compute_osc_resp(target_freqs, damping) return freqs
def _calc_psa(osc_freqs, damping, method, freqs, event): """Calculate the response spectra for an event. Note that this is intended as a helper function to be called by multiprocessing.Pool. """ m = motions.RvtMotion(freqs=freqs, fourier_amps=event['fa'], duration=event['duration'], peak_calculator=get_peak_calculator( method, dict(region=event['region'], mag=event['magnitude'], dist=event['distance']))) psa = m.calc_osc_accels(osc_freqs, damping) return psa
def _calc_psa(osc_freqs, damping, method, freqs, event): """Calculate the response spectra for an event. Note that this is intended as a helper function to be called by multiprocessing.Pool. """ m = motions.RvtMotion( freqs=freqs, fourier_amps=event['fa'], duration=event['duration'], peak_calculator=get_peak_calculator(method, dict( region=event['region'], mag=event['magnitude'], dist=event['distance']))) psa = m.calc_osc_accels(osc_freqs, damping) return psa
def _calc_fa(target_freqs, damping, method, event): """Calculate the fourier amplitudes for an event. Note that this is intended as a helper function to be called by multiprocessing.Pool. """ event_keys = ['magnitude', 'distance', 'region'] event_kwds = {key: event[key] for key in event_keys} crm = motions.CompatibleRvtMotion( target_freqs, event['psa'], duration=event['duration'], osc_damping=damping, event_kwds=event_kwds, peak_calculator=get_peak_calculator(method, event_kwds)) psa_calc = crm.calc_osc_accels(target_freqs, damping) return crm, psa_calc
def _calc_fa(target_freqs, damping, method, event): """Calculate the fourier amplitudes for an event. Note that this is intended as a helper function to be called by multiprocessing.Pool. """ event_keys = ['magnitude', 'distance', 'region'] event_kwds = {key: event[key] for key in event_keys} crm = motions.CompatibleRvtMotion(target_freqs, event['psa'], duration=event['duration'], osc_damping=damping, event_kwds=event_kwds, peak_calculator=get_peak_calculator( method, event_kwds)) psa_calc = crm.calc_osc_accels(target_freqs, damping) return crm, psa_calc
def operation_fa2psa(src, dst, damping, method='LP99', fixed_spacing=True, verbose=True): """Compute the Fourier amplitude spectrum from a acceleration response spectrum. Parameters ---------- src : str Source for the Fourier amplitudes. This can be a filename or pattern used in :func:`glob.glob`. dst : str Destination directory for the output PSA. The directory is created if it does not exist. damping : float Fractional damping of the oscillator (decimal). method : str RVT peak factor method, see :func:`~.peak_calculators.get_peak_calculator`. fixed_spacing : bool, optional If `True`, then the periods are interpolated to 301 points equally space in log-space from 0.01 to 10. verbose : bool, optional Print status of calculation. """ if fixed_spacing: periods = np.logspace(-2, 1, 301) osc_freqs = 1. / periods for filename_src in glob.iglob(src): if verbose: print('Processing:', filename_src) ext, freqs, events = read_events(filename_src, 'fa') if not fixed_spacing: osc_freqs = freqs periods = 1. / osc_freqs bar = pyprind.ProgPercent(len(events)) if verbose else None for e in events: m = motions.RvtMotion( freqs=freqs, fourier_amps=e['fa'], duration=e['duration'], peak_calculator=get_peak_calculator( method, dict(region=e['region'], mag=e['magnitude'], dist=e['distance'])) ) e['psa'] = m.calc_osc_accels(osc_freqs, damping) if bar: bar.update() if not os.path.exists(dst): os.makedirs(dst) basename = os.path.basename(filename_src) pathname_dst = os.path.join(dst, basename.rsplit('_', 1)[0]) write_events(pathname_dst + '_sa' + ext, periods, 'Period (s)', 'psa', 'PSA (g)', events)
def calc_compatible_spectra(method, periods, events, damping=0.05, verbose=True): """Compute the response spectrum compatible motions. Parameters ---------- method : str RVT peak factor method, see :func:`~.peak_calculators.get_peak_calculator`. periods : array_like Periods of the oscillator response shared across all events. events : List[dict] All events to consider. See ``Note``. damping : float, optional Fractional damping of the oscillator (decimal). Default value of 0.05 for a damping ratio of 5%. verbose : bool, optional Print status of calculation. Default is `True`. Returns ------- :class:`numpy.ndarray` Frequency of the computed Fourier amplitude spectra. Note ---- Each event dictionary should have the following keys: - **psa** : :class:`numpy.ndarray` -- pseudo-spectral accelerations. This is the target for the :class:`~.motions.CompatibleRvtMotion`. - **duration** : float, optional -- duration of the ground motion - **magnitude** : float, optional -- earthquake magnitude - **distance** : float, optional -- earthquake distance (km) - **region** : str, optional -- earthquake source region, see :func:`~.peak_calculators.get_region` If no duration is provided one is estimated from the magnitude, distance, and region. The `events` dictionary is modified by this function and adds the following keys: - **duration** : float -- duration of the ground motion if one was not specified - **fa** : :class:`numpy.ndarray` -- Fourier amplitude spectra in units of g/sec - **psa_calc** : :class:`numpy.ndarray` -- Pseudo-spectral acceleration calculated from `fa`. This will differ slightly from `psa_target`. """ target_freqs = 1. / periods event_keys = ['magnitude', 'distance', 'region'] bar = pyprind.ProgPercent(len(events)) if verbose else None for e in events: event_kwds = {key: e[key] for key in event_keys} crm = motions.CompatibleRvtMotion( target_freqs, e['psa'], duration=e['duration'], osc_damping=damping, event_kwds=event_kwds, peak_calculator=get_peak_calculator( method, event_kwds) ) freqs = crm.freqs if not e['duration']: e['duration'] = crm.duration e['fa'] = crm.fourier_amps e['psa_calc'] = crm.calc_osc_accels(target_freqs, damping) if bar: bar.update() return freqs
def operation_fa2psa(src, dst, damping, method='LP99', fixed_spacing=True, verbose=True): """Compute the Fourier amplitude spectrum from a acceleration response spectrum. Parameters ---------- src : str Source for the Fourier amplitudes. This can be a filename or pattern used in :func:`glob.glob`. dst : str Destination directory for the output PSA. The directory is created if it does not exist. damping : float Fractional damping of the oscillator (decimal). method : str RVT peak factor method, see :func:`~.peak_calculators.get_peak_calculator`. fixed_spacing : bool, optional If `True`, then the periods are interpolated to 301 points equally space in log-space from 0.01 to 10. verbose : bool, optional Print status of calculation. """ if fixed_spacing: periods = np.logspace(-2, 1, 301) osc_freqs = 1. / periods for filename_src in glob.iglob(src): if verbose: print('Processing:', filename_src) ext, freqs, events = read_events(filename_src, 'fa') if not fixed_spacing: osc_freq = freqs periods = 1. / osc_freq bar = pyprind.ProgPercent(len(events)) if verbose else None for e in events: m = motions.RvtMotion(freqs=freqs, fourier_amps=e['fa'], duration=e['duration'], peak_calculator=get_peak_calculator( method, dict(region=e['region'], mag=e['magnitude'], dist=e['distance']))) e['psa'] = m.calc_osc_accels(osc_freqs, damping) if bar: bar.update() if not os.path.exists(dst): os.makedirs(dst) basename = os.path.basename(filename_src) pathname_dst = os.path.join(dst, basename.rsplit('_', 1)[0]) write_events(pathname_dst + '_sa' + ext, periods, 'Period (s)', 'psa', 'PSA (g)', events)
def calc_compatible_spectra(method, periods, events, damping=0.05, verbose=True): """Compute the response spectrum compatible motions. Parameters ---------- method : str RVT peak factor method, see :func:`~.peak_calculators.get_peak_calculator`. periods : array_like Periods of the oscillator response shared across all events. events : List[dict] All events to consider. See ``Note``. damping : float, optional Fractional damping of the oscillator (decimal). Default value of 0.05 for a damping ratio of 5%. verbose : bool, optional Print status of calculation. Default is `True`. Returns ------- :class:`numpy.ndarray` Frequency of the computed Fourier amplitude spectra. Note ---- Each event dictionary should have the following keys: - **psa** : :class:`numpy.ndarray` -- pseudo-spectral accelerations. This is the target for the :class:`~.motions.CompatibleRvtMotion`. - **duration** : float, optional -- duration of the ground motion - **magnitude** : float, optional -- earthquake magnitude - **distance** : float, optional -- earthquake distance (km) - **region** : str, optional -- earthquake source region, see :func:`~.peak_calculators.get_region` If no duration is provided one is estimated from the magnitude, distance, and region. The `events` dictionary is modified by this function and adds the following keys: - **duration** : float -- duration of the ground motion if one was not specified - **fa** : :class:`numpy.ndarray` -- Fourier amplitude spectra in units of g/sec - **psa_calc** : :class:`numpy.ndarray` -- Pseudo-spectral acceleration calculated from `fa`. This will differ slightly from `psa_target`. """ target_freqs = 1. / periods event_keys = ['magnitude', 'distance', 'region'] bar = pyprind.ProgPercent(len(events)) if verbose else None for e in events: event_kwds = {key: e[key] for key in event_keys} crm = motions.CompatibleRvtMotion(target_freqs, e['psa'], duration=e['duration'], osc_damping=damping, event_kwds=event_kwds, peak_calculator=get_peak_calculator( method, event_kwds)) freqs = crm.freqs if not e['duration']: e['duration'] = crm.duration e['fa'] = crm.fourier_amps e['psa_calc'] = crm.calc_osc_accels(target_freqs, damping) if bar: bar.update() return freqs