Skip to content

TimeHistory

TimeHistory

TimeHistory(time: ndarray, acceleration: ndarray, unit_in_g: bool = True, gravity: float = 9.81, metadata: Optional[Dict[str, Any]] = None)

Class to store and process acceleration time history data. This class supports loading time history data from various formats. The class give access to the time history data, computes velocity and displacement from acceleration, and provides methods to compute response spectra and transfer functions.

Attributes:

Name Type Description
time ndarray

Time array in seconds

acceleration ndarray

Acceleration array

gravity float

Gravitational acceleration in m/s² (default: 9.81)

unit_in_g bool

If True, acceleration is in g (default: True)

metadata Optional[Dict[str, Any]]

Metadata about the time history

dt Optional[float]

Time step if time is uniform, otherwise None

Raises: ValueError: If time and acceleration arrays are not of the same length ValueError: If time array is not strictly increasing ValueError: If time or acceleration arrays are empty Returns: TimeHistory: An instance of the TimeHistory class containing the time and acceleration data.

Example: from femora.tools.transferFunction import TimeHistory import numpy as np

# Create a TimeHistory instance with time and acceleration data

time = np.array([0.0, 0.1, 0.2, 0.3]) acceleration = np.array([0.0, 1.0, 0.5, -0.5]) th = TimeHistory(time, acceleration) print(th.duration) # Output: 0.3

# create a TimeHistory from a file

th = TimeHistory.load(file_path='path/to/time_history.csv', format='csv') th = TimeHistory.load(file_path='path/to/time_history.peer', format='peer') th = TimeHistory.load(time_file='path/to/time_values.txt', acc_file='path/to/acceleration_values.txt', delimiter=',')

Initialize time history data.

Parameters:

Name Type Description Default
time ndarray

Time array in seconds

required
acceleration ndarray

Acceleration array

required
unit_in_g bool

If True, acceleration is in g (default: True)

True
gravity float

Gravitational acceleration in if unit is in g (default: 9.81 m/s²)

9.81
metadata Optional[Dict]

Dictionary containing metadata about the time history

None

Raises:

Type Description
ValueError

If time and acceleration arrays are not of the same length

ValueError

If time array is not strictly increasing

Returns:

Type Description

None

Attributes

time instance-attribute

time = array(time)

acceleration instance-attribute

acceleration = array(acceleration)

gravity instance-attribute

gravity = gravity

unit_in_g instance-attribute

unit_in_g = unit_in_g

metadata instance-attribute

metadata = metadata or {}

dt instance-attribute

dt = diffs[0]

duration property

duration: float

Get the duration of the time history in seconds.

velocity property

velocity: ndarray

Compute the velocity from the acceleration time history.

displacement property

displacement: ndarray

Compute the displacement from the acceleration time history.

npts property

npts: int

Get the number of points in the time history.

Methods:

load staticmethod

load(file_path: str = None, format: str = 'auto', time_file: str = None, dt: float = None, acc_file: str = None, delimiter: str = ',', unit_in_g: bool = True, gravity: float = 9.81, skiprows: int = 0) -> TimeHistory

Load a time history from a single file (auto, peer, csv) or from two files (time and acceleration). Args: file_path (str): Path to the time history file (peer/csv) format (str): Format of the file ('peer', 'csv', 'auto'). time_file (str): Path to file containing time values (for two-file mode) acc_file (str): Path to file containing acceleration values (for two-file mode) delimiter (str): Delimiter for text files (default ',') skiprows (int): Number of rows to skip (default 0) Returns: TimeHistory: Loaded time history object

_detect_format staticmethod

_detect_format(file_path: str) -> str

_load_peer_format staticmethod

_load_peer_format(file_path: str) -> TimeHistory

_load_csv_format staticmethod

_load_csv_format(file_path: str) -> TimeHistory

get_spectrum

get_spectrum(periods: Optional[ndarray] = None, damping: float = 0.05) -> Tuple[np.ndarray, np.ndarray]

Compute the response spectrum for the time history.

Parameters:

Name Type Description Default
periods Optional[ndarray]

Array of periods to compute spectrum at

None
damping float

Damping ratio (default: 0.05)

0.05

Returns:

Type Description
Tuple[ndarray, ndarray]

Tuple[np.ndarray, np.ndarray]: Periods and spectral accelerations

plot

plot() -> None

Plot the acceleration time history.