utils
constants
Constants used in the project.
- configuration.utils.constants.PIXEL_TO_CM_PEDESTRIAN: float = 0.036948040610921565
Conversion factor from pixels to centimeters used to map the cadaver torso image with superimposed disks to the modeled 2D shape.
- configuration.utils.constants.PIXEL_TO_CM_BIKE: float = 0.696078431372549
Conversion factor from pixels to centimeters used to map the bike image with superimposed rectangles to the modeled 2D shape.
- configuration.utils.constants.MM_TO_CM: float = 0.1
Conversion factor from millimeters to centimeters.
- configuration.utils.constants.INCH_TO_CM: float = 2.54
Conversion factor from inches to centimeters.
- configuration.utils.constants.LB_TO_KG: float = 0.453592
Conversion factor from pounds to kilograms.
- configuration.utils.constants.DISK_QUAD_SEGS: int = 10
Fixed number of segments per quarter circle for approximating disk boundaries as Shapely polygons.
- configuration.utils.constants.POLYGON_TOLERANCE: float = 0.04
Size of the minimum distance between two points when simplifying polygons representing one contour of a 3D agent.
- configuration.utils.constants.DISTANCE_BTW_TARGET_KEYS_ALTITUDES: float = 2.0
Size of the altitude bins, chosen to reduce the number of contours used to represent a 3D agent
- configuration.utils.constants.NB_FUNCTION_EVALS: int = 80
Maximum number of iterations for the dual annealing optimization algorithm used to fit the 2D shape of an agent.
- configuration.utils.constants.DISK_NUMBER: int = 5
Default number of disks used to approximate the 2D shape of a pedestrian.
- configuration.utils.constants.DEFAULT_FLOOR_DAMPING: float = 2.0
Default damping coefficient for the fluid friction force between floor and agents (1/s)
- configuration.utils.constants.DEFAULT_ANGULAR_DAMPING: float = 2.0
Default damping coefficient for the fluid friction torque between floor and agents (1/s)
- configuration.utils.constants.EPSILON_SMOOTHING_KNEES: float = 8.0
Width of the sigmoid used to fit the 3D shape to anthropometric data, with the transition at knee height (cm).
- configuration.utils.constants.EPSILON_SMOOTHING_NECK: float = 2.0
Width of the sigmoid used to fit the 3D shape to anthropometric data, with the transition at neck height (cm).
- configuration.utils.constants.NECK_HEIGHT_MALE: float = 160.0
Altitude of the neck for the default male 3D pedestrian (cm).
- configuration.utils.constants.NECK_HEIGHT_FEMALE: float = 150.0
Altitude of the neck for the default female 3D pedestrian (cm).
- configuration.utils.constants.KNEES_HEIGHT_MALE: float = 59.0
Altitude of the knees for the default male 3D pedestrian (cm).
- configuration.utils.constants.KNEES_HEIGHT_FEMALE: float = 50.0
Altitude of the knees for the default female 3D pedestrian (cm).
- configuration.utils.constants.HEIGHT_OF_BIDELTOID_OVER_HEIGHT: float = 0.812433011789925
Ratio of the altitude of the horizontal slice used to measure bideltoid breadth in the 186.6 cm reference cryogenic male specimen to its total height (identical for male and female).
- configuration.utils.constants.YOUNG_MODULUS_CONCRETE: float = 1700000000.0
Default young modulus of the concrete material used for obstacles (N/m).
- configuration.utils.constants.YOUNG_MODULUS_HUMAN_NAKED: float = 4000000.0
Default young modulus of the naked human body material (N/m).
- configuration.utils.constants.YOUNG_MODULUS_HUMAN_CLOTHES: float = 3100000.0
Default young modulus of the clothed human body material (N/m).
- configuration.utils.constants.SHEAR_MODULUS_CONCRETE: float = 710000000.0
Default shear modulus of the concrete material used for obstacles (N/m).
- configuration.utils.constants.SHEAR_MODULUS_HUMAN_NAKED: float = 1380000.0
Default shear modulus of the naked human body material (N/m) under the incompressibility hypothesis i.e. nu = 0.5.
- configuration.utils.constants.SHEAR_MODULUS_HUMAN_CLOTHES: float = 900000.0
Default shear modulus of the clothed human body material (N/m) under the incompressibility hypothesis i.e. nu = 0.5.
- configuration.utils.constants.GAMMA_NORMAL: float = 1300.0
Default normal-contact damping coefficient (N·s/m), used both for agent–agent and agent–obstacle interactions.
- configuration.utils.constants.GAMMA_NORMAL_HUMANNAKED_HUMANNAKED: float = 700.0
Default normal-contact damping coefficient (N·s/m) for interactions between two human naked agents.
- configuration.utils.constants.GAMMA_NORMAL_CONCRETE_HUMANNAKED: float = 1230.0
Default normal-contact damping coefficient (N·s/m) for interactions between a naked human agent and a concrete obstacle.
- configuration.utils.constants.GAMMA_TANGENTIAL: float = 1300.0
Default tangential-contact damping coefficient (N·s/m), used both for agent–agent and agent–obstacle interactions.
- configuration.utils.constants.GAMMA_TANGENTIAL_HUMANNAKED_HUMANNAKED: float = 700.0
Default normal-contact damping coefficient (N·s/m) for interactions between two naked human agents.
- configuration.utils.constants.GAMMA_TANGENTIAL_CONCRETE_HUMANNAKED: float = 1230.0
Default tangential-contact damping coefficient (N·s/m) for interactions between a naked human agent and a concrete obstacle.
- configuration.utils.constants.KINETIC_FRICTION: float = 0.5
Default coefficient of kinetic friction (dimensionless), used both for agent–agent and agent–obstacle interactions.
- configuration.utils.constants.KINETIC_FRICTION_HUMANNAKED_HUMANNAKED: float = 0.4
Default coefficient of kinetic friction (dimensionless) for interactions between two human naked agents.
- configuration.utils.constants.MAX_NB_ITERATIONS: int = 130
Maximum number of attempts to place an agent in the crowd without overlap for the packing algorithm.
- configuration.utils.constants.DEFAULT_REPULSION_LENGTH: float = 5.0
Default repulsion length (cm) used in the packing algorithm to avoid initial overlaps between agents.
- configuration.utils.constants.DEFAULT_DESIRED_DIRECTION: float = 0.0
Default desired direction (degrees) for all agents in the crowd.
- configuration.utils.constants.DEFAULT_VARIABLE_ORIENTATION: bool = False
Boolean variable selecting between pseudo‑random orientation and perfect alignment for all agents in the crowd.
- configuration.utils.constants.INFINITE: float = 10000000000.0
Large value used to represent infinity.
- configuration.utils.constants.INTENSITY_ROTATIONAL_FORCE: float = 10.0
Intensity of the random forces (degrees) applied to agents during the packing algorithm to help them escape local overlaps.
- configuration.utils.constants.INTENSITY_TRANSLATIONAL_FORCE: float = 5.0
Intensity of the random forces (cm) applied to agents during the packing algorithm to help them escape local overlaps.
- configuration.utils.constants.GRID_SIZE_X: float = 31.0
Default grid size in the X direction (cm) for the packing of the pedestrians on a grid.
- configuration.utils.constants.GRID_SIZE_Y: float = 60.0
Default grid size in the Y direction (cm) for the packing of the pedestrians on a grid.
- configuration.utils.constants.GRID_SIZE_X_BIKE: float = 200.0
Default grid size in the X direction (cm) for the packing of the bikes on a grid.
- configuration.utils.constants.GRID_SIZE_Y_BIKE: float = 200.0
Default grid size in the Y direction (cm) for the packing of the bikes on a grid.
- configuration.utils.constants.INITIAL_TEMPERATURE: float = 1.0
Initial temperature used to stabilize crowd packing by gradually reducing the magnitude of rotations.
- configuration.utils.constants.ADDITIVE_COOLING: float = 0.1
Cooling rate for the packing algorithm T<- max(T, T - COOLING_RATE)
- configuration.utils.constants.DEFAULT_BIKE_WEIGHT: float = 30.0
Default weight of a bike (kg) used for the initialization of a bike.
- configuration.utils.constants.DEFAULT_PEDESTRIAN_WEIGHT: float = 70.0
Default weight of a pedestrian (kg) used for the initialization of a pedestrian.
- configuration.utils.constants.DECISIONAL_TRANSLATIONAL_FORCE_X: float = 100.0
Default propulsion force in the X direction (N) used to populate the AgentDynamics file.
- configuration.utils.constants.DECISIONAL_TRANSLATIONAL_FORCE_Y: float = 100.0
Default propulsion force in the Y direction (N) used to populate the AgentDynamics file.
- configuration.utils.constants.DECISIONAL_TORQUE: float = 0.0
Default propulsion torque (N.m) used to populate the AgentDynamics file.
- configuration.utils.constants.INITIAL_TRANSLATIONAL_VELOCITY_X: float = 0.0
Default initial translational velocity in the X direction (m/s) used to populate the AgentDynamics file.
- configuration.utils.constants.INITIAL_TRANSLATIONAL_VELOCITY_Y: float = 0.0
Default initial translational velocity in the Y direction (m/s) used to populate the AgentDynamics file.
- configuration.utils.constants.INITIAL_ROTATIONAL_VELOCITY: float = 0.0
Default initial rotational velocity (rad/s) used to populate the AgentDynamics file.
- configuration.utils.constants.INITIAL_TANGENTIAL_FORCE_X: float = 0.0
Default initial tangential force in the X direction (N) used to populate the AgentInteractions file.
- configuration.utils.constants.INITIAL_TANGENTIAL_FORCE_Y: float = 0.0
Default initial tangential force in the Y direction (N) used to populate the AgentInteractions file.
- configuration.utils.constants.INITIAL_NORMAL_FORCE_X: float = 0.0
Default initial normal force in the X direction (N) used to populate the AgentInteractions file.
- configuration.utils.constants.INITIAL_NORMAL_FORCE_Y: float = 0.0
Default initial normal force in the Y direction (N) used to populate the AgentInteractions file.
- configuration.utils.constants.INITIAL_TANGENTIAL_RELATIVE_DISPLACEMENT_X: float = 0.0
Default initial tangential relative displacement in the X direction (m) used to populate the AgentInteractions file.
- configuration.utils.constants.INITIAL_TANGENTIAL_RELATIVE_DISPLACEMENT_Y: float = 0.0
Default initial tangential relative displacement in the Y direction (m) used to populate the AgentInteractions file.
- class configuration.utils.constants.BackupDataTypes(*values)[source]
Bases:
EnumEnum for backup data types.
- zip = 1
- pickle = 2
- xml = 3
- class configuration.utils.constants.AgentTypes(*values)[source]
Bases:
EnumEnum for agent types.
- pedestrian = 1
- bike = 2
- custom = 3
- class configuration.utils.constants.ShapeTypes(*values)[source]
Bases:
EnumEnum for shape types.
- disk = 1
- rectangle = 2
- polygon = 3
- class configuration.utils.constants.PedestrianParts(*values)[source]
Bases:
EnumEnum for pedestrian parts.
- sex = 1
- bideltoid_breadth = 2
- chest_depth = 3
- height = 4
- class configuration.utils.constants.Sex(*values)[source]
Bases:
EnumEnum for pedestrian sex.
- male = 1
- female = 2
- class configuration.utils.constants.BikeParts(*values)[source]
Bases:
EnumBike is an enumeration that defines different parts of a bike.
- wheel_width = 1
- total_length = 2
- handlebar_length = 3
- top_tube_length = 4
- class configuration.utils.constants.CommonMeasures(*values)[source]
Bases:
EnumCommonMeasures is an enumeration that defines different common measures.
- weight = 1
- moment_of_inertia = 2
- class configuration.utils.constants.StatType(*values)[source]
Bases:
EnumStatType is an enumeration that defines different types of statistics.
- mean = 1
- std_dev = 2
- min = 3
- max = 4
- configuration.utils.constants.CrowdStat = mappingproxy({'male_proportion': 0.5, 'pedestrian_proportion': 1.0, 'bike_proportion': 0.0, 'male_bideltoid_breadth_min': 30.0, 'male_bideltoid_breadth_max': 65.0, 'male_bideltoid_breadth_mean': 51.0, 'male_bideltoid_breadth_std_dev': 2.0, 'male_chest_depth_min': 15.0, 'male_chest_depth_max': 45.0, 'male_chest_depth_mean': 26.0, 'male_chest_depth_std_dev': 2.0, 'male_height_min': 140.0, 'male_height_max': 240.0, 'male_height_mean': 178.0, 'male_height_std_dev': 8.0, 'male_weight_min': 30.0, 'male_weight_max': 160.0, 'male_weight_mean': 85.0, 'male_weight_std_dev': 15.0, 'female_bideltoid_breadth_min': 30.0, 'female_bideltoid_breadth_max': 60.0, 'female_bideltoid_breadth_mean': 45.0, 'female_bideltoid_breadth_std_dev': 1.5, 'female_chest_depth_min': 15.0, 'female_chest_depth_max': 45.0, 'female_chest_depth_mean': 24.0, 'female_chest_depth_std_dev': 1.5, 'female_height_min': 140.0, 'female_height_max': 210.0, 'female_height_mean': 164.0, 'female_height_std_dev': 7.0, 'female_weight_min': 30.0, 'female_weight_max': 130.0, 'female_weight_mean': 67.0, 'female_weight_std_dev': 11.0, 'wheel_width_min': 2.0, 'wheel_width_max': 20.0, 'wheel_width_mean': 6.0, 'wheel_width_std_dev': 0.5, 'total_length_min': 100.0, 'total_length_max': 200.0, 'total_length_mean': 142.0, 'total_length_std_dev': 5.0, 'handlebar_length_min': 30.0, 'handlebar_length_max': 90.0, 'handlebar_length_mean': 45.0, 'handlebar_length_std_dev': 5.0, 'top_tube_length_min': 40.0, 'top_tube_length_max': 90.0, 'top_tube_length_mean': 61.0, 'top_tube_length_std_dev': 5.0, 'bike_weight_min': 10.0, 'bike_weight_max': 100.0, 'bike_weight_mean': 30.0, 'bike_weight_std_dev': 5.0})
Immutable dictionary containing default statistical data for crowd generation.
- class configuration.utils.constants.MaterialNames(*values)[source]
Bases:
EnumEnum for material names.
- concrete = 1
- human_clothes = 2
- human_naked = 3
functions
Contains utility functions for data processing and manipulation.
- configuration.utils.functions.load_pickle(file_path)[source]
Load data from a pickle file.
- Parameters:
file_path (str) -- A string object representing the path to the pickle file to be loaded.
- Returns:
The deserialized data loaded from the pickle file. The type of the returned object depends on what was serialized into the pickle file (e.g. list[float], NDArray[np.float64] etc.).
- Return type:
Any
- Raises:
TypeError -- If file_path is not a Path object.
FileNotFoundError -- If the specified file does not exist.
- configuration.utils.functions.save_pickle(data, file_path)[source]
Save data to a pickle file.
- Parameters:
data (Any) -- The data to be serialized and saved. This can be any Python object that is supported by the pickle module.
file_path (Path) -- A Path object representing the path where the pickle file will be saved.
- Raises:
TypeError -- If file_path is not a Path object.
FileNotFoundError -- If the directory for file_path does not exist.
- Return type:
- configuration.utils.functions.load_csv(filename)[source]
Load data from a CSV file into a pandas DataFrame.
- Parameters:
filename (Path) -- A Path object representing the path to the CSV file to be loaded.
- Returns:
A pandas DataFrame containing the data from the CSV file.
- Return type:
pd.DataFrame
- Raises:
TypeError -- If filename is not a Path object.
FileNotFoundError -- If the specified file does not exist.
ValueError -- If the file does not have a .csv extension.
- configuration.utils.functions.get_csv_buffer(data_dict)[source]
Generate CSV content from a dictionary for download (in memory).
- configuration.utils.functions.draw_from_trunc_normal(mean, std_dev, min_val, max_val)[source]
Draw a sample from a truncated normal distribution.
This function generates a random sample from a normal distribution that is truncated within the range [min_val, max_val]. The truncation ensures that the sample lies within the specified bounds.
- Parameters:
- Returns:
A sample drawn from the truncated normal distribution.
- Return type:
- Raises:
ValueError -- If std_dev is less than or equal to zero, or if min_val is greater than or equal to max_val.
- configuration.utils.functions.draw_sex(p)[source]
Randomly draw a sex (male or female) based on the input proportion of male.
- Parameters:
p (float) -- A proportion value in [0,1], representing the probability of selecting male.
- Returns:
male if a randomly generated number is less than p; otherwise, female.
- Return type:
- Raises:
ValueError -- If the probability p is not in [0,1].
- configuration.utils.functions.cross2d(Pn, Pn1)[source]
Compute the 2D cross product of two vectors defined as Pn[0] * Pn1[1] - Pn[1] * Pn1[0].
- Parameters:
Pn (NDArray[np.float64]) -- A 1D NumPy array of shape (2,) representing the first 2D vector in the form [x, y].
Pn1 (NDArray[np.float64]) -- A 1D NumPy array of shape (2,) representing the second 2D vector in the form [x, y].
- Returns:
The magnitude of the resulting perpendicular vector to the plane formed by the input vectors.
- Return type:
- configuration.utils.functions.compute_moment_of_inertia(geometric_shape, weight)[source]
Compute the moment of inertia for a 2D Polygon or MultiPolygon.
This function calculates the moment of inertia (I_z) for a 2D shape represented as a polygon based on its vertices and weight. The calculation is performed using the second moment of area formula, assuming the polygon is in the XY-plane. For more details on the second moment of area, refer to: https://en.wikipedia.org/wiki/Second_moment_of_area.
- Parameters:
geometric_shape (Polygon | MultiPolygon) -- The geometrical representation as a shapely Polygon or MultiPolygon object (cm).
weight (float) -- The agent weight (kg).
- Returns:
The computed moment of inertia for the shape (kg·m²).
- Return type:
Notes
For the MultiPolygon case, it computes the moment of inertia for each polygon and sums them up, weighted by their respective areas.
- configuration.utils.functions.validate_material(material)[source]
Validate if the given material is in MaterialNames.
- configuration.utils.functions.rotate_vectors(vector_dict, theta)[source]
Rotate 2D vectors in a dictionary by a given angle.
- Parameters:
- Returns:
A dictionary with the same keys, where each vector has been rotated by the given angle.
- Return type:
- configuration.utils.functions.compute_bideltoid_breadth_from_multipolygon(multi_polygon)[source]
Compute the largest horizontal distance (bideltoid breadth) between points in a MultiPolygon object.
- Parameters:
multi_polygon (MultiPolygon) -- A MultiPolygon object.
- Returns:
The largest horizontal distance (bideltoid breadth).
- Return type:
Notes
To accelerate that function, only pairs of points with almost the same y-coordinate are considered. Therefore it is assumed that the input is a MultiPolygon object coming from the body3D of a pedestrian that has not been rotated.
- configuration.utils.functions.compute_chest_depth_from_multipolygon(multi_polygon)[source]
Compute the largest vertical distance (chest depth) in a MultiPolygon object.
- Parameters:
multi_polygon (MultiPolygon) -- A MultiPolygon object.
- Returns:
The largest vertical distance (chest depth).
- Return type:
Notes
To accelerate that function, only pairs of points with almost the same x-coordinate are considered. Therefore it is assumed that the input is a MultiPolygon object coming from the body3D of a pedestrian that has not been rotated.
- configuration.utils.functions.from_string_to_tuple(string)[source]
Convert a string representation of a tuple to an actual tuple of two floats.
- Parameters:
string (str) -- The string representation of the tuple, e.g., "1.0, 2.0" or "(1.0, 2.0)".
- Returns:
The converted tuple of floats, e.g., (1.0, 2.0).
- Return type:
- Raises:
ValueError -- If string is not in the expected format.
- configuration.utils.functions.sigmoid(x, smoothing)[source]
Compute the numerically stable sigmoid function.
- configuration.utils.functions.rectangular_function(height, scale_xy, sex)[source]
Compute the value of a door function evaluated in height, based on scale, and sex parameters.
- Parameters:
- Returns:
The value of the rectangular function.
- Return type:
- Raises:
ValueError -- If an invalid sex is provided.
- configuration.utils.functions.direction_of_longest_side(polygon)[source]
Compute the direction (in degrees) of the longest side of a 4-vertex polygon.
The direction is measured from the first vertex of the side to the second, relative to the positive x-axis.
- configuration.utils.functions.filter_dict_by_not_None_values(input_dict)[source]
Filter a dictionary to remove keys with None values.
- configuration.utils.functions.k_from_EG(E1, G1, E2, G2)[source]
Compute
k_perpandk_parfromE1,G1,E2,G2.The spring constants are given by:
\[\begin{split}k^{\perp} = \left(\frac{4G_1 - E_1}{4G_1^2} + \frac{4G_2 - E_2}{4G_2^2}\right)^{-1}, \\ k^{\parallel} = \left(\frac{6G_1 - E_1}{8G_1^2} + \frac{6G_2 - E_2}{8G_2^2}\right)^{-1}.\end{split}\]- Parameters:
- Return type:
- Returns:
k_perp (float) -- Spring constant for the direction orthogonal to the surface contact (N/m).
k_par (float) -- Spring constant for the direction parallel to the surface contact (N/m).
Notes
The elastic moduli are assumed to be for 2D systems and thus have units of N/m.
- configuration.utils.functions.EG_from_k(k_perp, k_par)[source]
Compute
EandGfromk_perpandk_par, assuming both materials in contact are identical.The moduli are given by:
\[\begin{split}G = \frac{k^{\parallel} k^{\perp}}{2 k^{\perp} - k^{\parallel}}, \\ E = \frac{2 k^{\parallel} k^{\perp} (4 k^{\perp} - 3 k^{\parallel})}{(k^{\parallel} - 2 k^{\perp})^2}.\end{split}\]- Parameters:
- Return type:
- Returns:
E (float) -- Young's modulus (N/m).
G (float) -- Shear modulus (N/m).
Notes
The elastic moduli are assumed to be for 2D systems and thus have units of N/m.
typing_custom
Custom type definitions.
- configuration.utils.typing_custom.Sex
Represents biological sex categories.
alias of
Literal['male', 'female']
- configuration.utils.typing_custom.AgentType
Represents different types of agents in the system.
alias of
Literal['pedestrian', 'bike', 'custom']
- configuration.utils.typing_custom.AgentPart
Represents the parts of an agent (e.g., physical dimensions).
alias of
Literal['chest_depth', 'bideltoid_breadth', 'height', 'sex', 'wheel_width', 'total_length', 'handlebar_length', 'top_tube_length']
- configuration.utils.typing_custom.ShapeType
Represents different types of shapes used in geometry.
alias of
Literal['disk', 'rectangle', 'polygon']
- configuration.utils.typing_custom.MaterialType
Represents common materials used in crowd simulations.
alias of
Literal['concrete', 'human_naked', 'human_clothes']
- configuration.utils.typing_custom.BackupDataType
Represents supported backup data formats.
alias of
Literal['pickle', 'xml']
- configuration.utils.typing_custom.ShapeDataType: TypeAlias = dict[str, dict[str, typing.Union[typing.Literal['disk', 'rectangle', 'polygon'], typing.Literal['concrete', 'human_naked', 'human_clothes'], float]]] | dict[str, dict[str, typing.Union[typing.Literal['disk', 'rectangle', 'polygon'], typing.Literal['concrete', 'human_naked', 'human_clothes'], float, shapely.geometry.polygon.Polygon, shapely.geometry.multipolygon.MultiPolygon]]]
Represents the structure of shape-related data.
- configuration.utils.typing_custom.StaticCrowdDataType
Represents the structure of a crowd-related data.
alias of
dict[str,dict[str,dict[str,Literal['pedestrian', 'bike', 'custom'] |float|int|dict[str,dict[str,Literal['disk', 'rectangle', 'polygon'] |Literal['concrete', 'human_naked', 'human_clothes'] |float]] |dict[str,dict[str,Literal['disk', 'rectangle', 'polygon'] |Literal['concrete', 'human_naked', 'human_clothes'] |float|Polygon|MultiPolygon]]]]]
- configuration.utils.typing_custom.DynamicCrowdDataType
Represents the structure of dynamic crowd-related data.
alias of
dict[str,dict[str,dict[str,int|dict[str,float]]]]
- configuration.utils.typing_custom.GeometryDataType
Represents the structure of geometry-related data.
alias of
dict[str,dict[str,dict[str,float] |dict[str,dict[str,int|Literal['concrete', 'human_naked', 'human_clothes'] |dict[str,dict[str,float]]]]]]
- configuration.utils.typing_custom.IntrinsicMaterialDataType
Represents the intrinsic properties of each material.
- configuration.utils.typing_custom.PairMaterialsDataType
Represents the properties associated with each pair of material.