def __init__(self, acceleration, time_step, periods, damping=0.05, units="cm/s/s"): ''' Setup the response spectrum calculator :param numpy.ndarray time_hist: Acceleration time history [Time, Acceleration] :param numpy.ndarray periods: Spectral periods (s) for calculation :param float damping: Fractional coefficient of damping :param str units: Units of the acceleration time history {"g", "m/s", "cm/s/s"} ''' self.periods = periods self.num_per = len(periods) self.acceleration = convert_accel_units(acceleration, units) self.damping = damping self.d_t = time_step self.velocity, self.displacement = get_velocity_displacement( self.d_t, self.acceleration) self.num_steps = len(self.acceleration) self.omega = (2. * np.pi) / self.periods self.response_spectrum = None
def build_time_series_hdf5(self, record, sm_data, record_dir): """ Constructs the hdf5 file for storing the strong motion record :param record: Strong motion record as instance of :class: GroundMotionRecord :param dict sm_data: Data dictionary for the strong motion record :param str record_dir: Directory in which to save the record """ output_file = os.path.join(record_dir, record.id + ".hdf5") fle = h5py.File(output_file, "w-") grp = fle.create_group("Time Series") for key in sm_data.keys(): if not sm_data[key]["Original"]: continue grp_comp = grp.create_group(key) grp_orig = grp_comp.create_group("Original Record") for attribute in self.TS_ATTRIBUTE_LIST: if attribute in sm_data[key]["Original"].keys(): grp_orig.attrs[attribute] =\ sm_data[key]["Original"][attribute] ts_dset = grp_orig.create_dataset( "Acceleration", (sm_data[key]["Original"]["Number Steps"], ), dtype="f") ts_dset.attrs["Units"] = "cm/s/s" time_step = sm_data[key]["Original"]["Time-step"] ts_dset.attrs["Time-step"] = time_step number_steps = sm_data[key]["Original"]["Number Steps"] ts_dset.attrs["Number Steps"] = number_steps ts_dset.attrs["PGA"] = utils.convert_accel_units( sm_data[key]["Original"]["PGA"], sm_data[key]["Original"]["Units"]) # Store acceleration as cm/s/s ts_dset[:] = utils.convert_accel_units( sm_data[key]["Original"]["Acceleration"], sm_data[key]["Original"]["Units"]) # Get velocity and displacement vel, dis = utils.get_velocity_displacement(time_step, ts_dset[:], "cm/s/s") # Build velocity data set v_dset = grp_orig.create_dataset("Velocity", (number_steps, ), dtype="f") v_dset.attrs["Units"] = "cm/s" v_dset.attrs["Time-step"] = time_step v_dset.attrs["Number Steps"] = number_steps v_dset[:] = vel # Build displacement data set d_dset = grp_orig.create_dataset("Displacement", (number_steps, ), dtype="f") d_dset.attrs["Units"] = "cm" d_dset.attrs["Time-step"] = time_step d_dset.attrs["Number Steps"] = number_steps d_dset[:] = dis # Get the velocity and displacement time series and build scalar IMS return fle, output_file
def plot_time_series(acceleration, time_step, velocity=[], displacement=[], units="cm/s/s", figure_size=(8, 6), filename=None, filetype="png", dpi=300, linewidth=1.5): """ Creates a plot of acceleration, velocity and displacement for a specific ground motion record """ acceleration = convert_accel_units(acceleration, units) accel_time = get_time_vector(time_step, len(acceleration)) if not len(velocity): velocity, dspl = get_velocity_displacement(time_step, acceleration) vel_time = get_time_vector(time_step, len(velocity)) if not len(displacement): displacement = dspl disp_time = get_time_vector(time_step, len(displacement)) fig = plt.figure(figsize=figure_size) fig.set_tight_layout(True) ax = plt.subplot(3, 1, 1) # Accleration ax.plot(accel_time, acceleration, 'k-', linewidth=linewidth) ax.set_xlabel("Time (s)", fontsize=12) ax.set_ylabel("Acceleration (cm/s/s)", fontsize=12) end_time = np.max(np.array([accel_time[-1], vel_time[-1], disp_time[-1]])) pga = np.max(np.fabs(acceleration)) ax.set_xlim(0, end_time) ax.set_ylim(-1.1 * pga, 1.1 * pga) ax.grid() # Velocity ax = plt.subplot(3, 1, 2) ax.plot(vel_time, velocity, 'b-', linewidth=linewidth) ax.set_xlabel("Time (s)", fontsize=12) ax.set_ylabel("Velocity (cm/s)", fontsize=12) pgv = np.max(np.fabs(velocity)) ax.set_xlim(0, end_time) ax.set_ylim(-1.1 * pgv, 1.1 * pgv) ax.grid() # Displacement ax = plt.subplot(3, 1, 3) ax.plot(disp_time, displacement, 'r-', linewidth=linewidth) ax.set_xlabel("Time (s)", fontsize=12) ax.set_ylabel("Displacement (cm)", fontsize=12) pgd = np.max(np.fabs(displacement)) ax.set_xlim(0, end_time) ax.set_ylim(-1.1 * pgd, 1.1 * pgd) ax.grid() _save_image(filename, filetype, dpi) plt.show()
def build_time_series_hdf5(self, record, sm_data, record_dir): """ Constructs the hdf5 file for storing the strong motion record :param record: Strong motion record as instance of :class: GroundMotionRecord :param dict sm_data: Data dictionary for the strong motion record :param str record_dir: Directory in which to save the record """ output_file = os.path.join(record_dir, record.id + ".hdf5") fle = h5py.File(output_file, "w-") grp = fle.create_group("Time Series") for key in sm_data.keys(): if not sm_data[key]["Original"]: continue grp_comp = grp.create_group(key) grp_orig = grp_comp.create_group("Original Record") for attribute in self.TS_ATTRIBUTE_LIST: if attribute in sm_data[key]["Original"].keys(): grp_orig.attrs[attribute] = sm_data[key]["Original"][attribute] ts_dset = grp_orig.create_dataset("Acceleration", (sm_data[key]["Original"]["Number Steps"],), dtype="f") ts_dset.attrs["Units"] = "cm/s/s" time_step = sm_data[key]["Original"]["Time-step"] ts_dset.attrs["Time-step"] = time_step number_steps = sm_data[key]["Original"]["Number Steps"] ts_dset.attrs["Number Steps"] = number_steps ts_dset.attrs["PGA"] = utils.convert_accel_units( sm_data[key]["Original"]["PGA"], sm_data[key]["Original"]["Units"] ) # Store acceleration as cm/s/s ts_dset[:] = utils.convert_accel_units( sm_data[key]["Original"]["Acceleration"], sm_data[key]["Original"]["Units"] ) # Get velocity and displacement vel, dis = utils.get_velocity_displacement(time_step, ts_dset[:], "cm/s/s") # Build velocity data set v_dset = grp_orig.create_dataset("Velocity", (number_steps,), dtype="f") v_dset.attrs["Units"] = "cm/s" v_dset.attrs["Time-step"] = time_step v_dset.attrs["Number Steps"] = number_steps v_dset[:] = vel # Build displacement data set d_dset = grp_orig.create_dataset("Displacement", (number_steps,), dtype="f") d_dset.attrs["Units"] = "cm" d_dset.attrs["Time-step"] = time_step d_dset.attrs["Number Steps"] = number_steps d_dset[:] = dis # Get the velocity and displacement time series and build scalar IMS return fle, output_file