Classes used to build the computational domain

Destination class used to build a destination

class cromosim.domain.Destination(name, colors, excluded_colors=[], desired_velocity_from_color=[], fmm_speed=None, velocity_scale=1, next_destination=None, next_domain=None, next_transit_box=None)[source]

Bases: object

A Destination object contains all the information necessary to direct people to a goal, for example a door, a staircase or another floor.

Examples

  • Examples with one destination:

    cromosim/examples/domain/domain_room.py cromosim/examples/domain/domain_stadium.py

  • Example with several destinations:

    cromosim/examples/domain/domain_shibuya_crossing.py

  • Example with a destination described in a json file

    cromosim/examples/domain/domain_from_json.py

Attributes
name: string

name of the destination

colors: list

List of colors [ [r,g,b],... ] drawing the destination. For example, a door can be represented by a red line.

excluded_colors: list

List of colors [ [r,g,b],... ] representing obstacles that cannot be crossed for someone wishing to go to this destination: the walls of course, but possibly another objects only visible to the people concerned by this destination.

desired_velocity_from_color: list

Allows you to associate a desired velocity (vx, vy) with a color (r, g, b):

[ [r,g,b, vx,vy],... ].

fmm_speed: numpy array

To automatically calculate the desired velocity leading to this destination, a Fast-Marching method is used to calculate the travel time to this destination. The opposite of the gradient of this time gives the desired velocity. This method solves the Eikonal equation |grad D| = 1/fmm_speed. By changing the fmm_speed (1 everywhere by default) you can make certain areas slower and thus modify the desired velocity to divert people

velocity_scale: float

Multiplying coefficient used in front of the desired velocity vector (which is renormalized). For example on a staircase one may wish to reduce the speed of people.

next_destination: string

Name of the next destination. Useful for linking destinations one after the other

next_domain: string

Name of the next domain where is the next_destination

next_transit_box: list

The people in the current domain present in this box will be duplicated in the next_domain. A box is defined by four points:

[x0, y0, x1, y1, x2, y2, x3, y3]

distance: numpy array

Distance (if fmm_speed == 1) or travel time (if fmm_speed != 1) to the destination

desired_velocity_X: numpy array

First component of the desired velocity

desired_velocity_Y: numpy array

Second component of the desired velocity

Domain class used to build the computational domain

class cromosim.domain.Domain(name='Domain', background='White', pixel_size=1.0, xmin=0.0, width=100, ymin=0.0, height=100, wall_colors=[[0, 0, 0]], npzfile=None)[source]

Bases: object

To define the computational domain:
  • a background: empty (white) or a PNG image which only contains the colors white, red (for the doors) and black (for the walls)

  • supplementary doors represented by matplotlib shapes:

    line2D

  • supplementary walls represented by matplotlib shapes:

    line2D, circle, ellipse, rectangle or polygon

To compute the obstacle distances and the desired velocities

Examples

  • A simple room

    cromosim/examples/domain/domain_room.py

  • A circular domain

    cromosim/examples/domain/domain_stadium.py

  • A domain with several destinations

    cromosim/examples/domain/domain_shibuya_crossing.py

  • A domain built from json file (where is its description)

    cromosim/examples/domain/domain_from_json.py

Attributes
pixel_size: float

size of a pixel in meters

width: int

width of the background image (number of pixels)

height: int

height of the background image (number of pixels)

xmin: float

x coordinate of the origin (bottom left corner)

xmax: float

xmax = xmin + width*pixel_size

ymin: float

y coordinate of the origin (bottom left corner)

ymax: float

ymax = ymin + height*pixel_size

X: numpy array

x coordinates (meshgrid)

Y: numpy array

y coordinates (meshgrid)

image: numpy array

pixel array (r,g,b,a) The Pillow image is converted to a numpy arrays, then using flipud the origin of the image is put it down left instead the top left

image_red: numpy array

red values of the image (r,g,b,a)

image_green: numpy array

green values of the image (r,g,b,a)

image_blue: numpy array

blue values of the image (r,g,b,a)

wall_mask: numpy array

boolean array: true for wall pixels

wall_mask_id: numpy array

wall pixel indices

wall_distance: numpy array

distance (m) to the wall

wall_grad_X: numpy array

gradient of the distance to the wall (first component)

wall_grad_Y: numpy array

gradient of the distance to the wall (second component)

door_distance: numpy array

distance (m) to the door

desired_velocity_X: numpy array
opposite of the gradient of the distance to the door: desired velocity

(first component)

desired_velocity_Y: numpy array

opposite of the gradient of the distance to the door: desired velocity (second component)

Methods

add_destination(self, dest)

To compute the desired velocities to this destination and then to add this Destination object to this domain.

add_shape(self, shape[, outline_color, …])

To add a matplotlib shape: line2D, circle, ellipse, rectangle or polygon

build_domain(self)

To build the domain: reads the background image (if supplied) and initializes all the color arrrays

compute_wall_distance(self)

To compute the geodesic distance to the walls in using a fast-marching method

people_desired_velocity(self, xyr, people_dest)

This function determines people desired velocities from the desired velocity array computed by Domain thanks to a fast-marching method.

people_target_distance(self, xyr, people_dest)

This function determines distances to the current target for all people

people_wall_distance(self, xyr[, I, J])

This function determines distances to the nearest wall for all people

plot(self[, id, title, savefig, filename, dpi])

To plot the computational domain

plot_desired_velocity(self, destination_name)

To plot the desired velocity

plot_wall_dist(self[, step, scale, …])

To plot the wall distances

save(self, outfile)

To save the content of the domain in a file

add_destination(self, dest)[source]

To compute the desired velocities to this destination and then to add this Destination object to this domain.

Parameters
dest: Destination

contains the Destination object which must be added to this domain

add_shape(self, shape, outline_color=[0, 0, 0], fill_color=[255, 255, 255])[source]

To add a matplotlib shape: line2D, circle, ellipse, rectangle or polygon

Parameters
shape: matplotlib shape

line2D, circle, ellipse, rectangle or polygon

outline_color: list

rgb color

fill_color: list

rgb color

build_domain(self)[source]

To build the domain: reads the background image (if supplied) and initializes all the color arrrays

compute_wall_distance(self)[source]

To compute the geodesic distance to the walls in using a fast-marching method

people_desired_velocity(self, xyr, people_dest, I=None, J=None)[source]

This function determines people desired velocities from the desired velocity array computed by Domain thanks to a fast-marching method.

Parameters
xyr: numpy array

people coordinates and radius: x,y,r

people_dest: list of string

destination for each individual

I: numpy array (None by default)

people index i

J: numpy array (None by default)

people index j

Returns
I: numpy array

people index i

J: numpy array

people index j

Vd: numpy array

people desired velocity

people_target_distance(self, xyr, people_dest, I=None, J=None)[source]

This function determines distances to the current target for all people

Parameters
xyr: numpy array

people coordinates and radius: x,y,r

people_dest: list of string

destination for each individual

I: numpy array (None by default)

people index i

J: numpy array (None by default)

people index j

Returns
——-
I: numpy array

people index i

J: numpy array

people index j

D: numpy array

distances to the current target

people_wall_distance(self, xyr, I=None, J=None)[source]

This function determines distances to the nearest wall for all people

Parameters
xyr: numpy array

people coordinates and radius: x,y,r

I: numpy array (None by default)

people index i

J: numpy array (None by default)

people index j

Returns
I: numpy array

people index i

J: numpy array

people index j

D: numpy array

distances to the nearest wall

plot(self, id=1, title='', savefig=False, filename='fig.png', dpi=150)[source]

To plot the computational domain

Parameters
id: integer

Figure id (number)

title: string

Figure title

savefig: boolean

writes the figure as a png file if true

filename: string

png filename used to write the figure

dpi: integer

number of pixel per inch for the saved figure

plot_desired_velocity(self, destination_name, step=10, scale=10, scale_units='inches', id=1, title='', savefig=False, filename='fig.png', dpi=150)[source]

To plot the desired velocity

Parameters
destination_name: string

name of the considered destination

step: integer

draw an arrow every step pixels

scale: integer

scaling for the quiver arrows

scale_units: string

unit name for quiver arrow scaling

id: integer

Figure id (number)

title: string

Figure title

savefig: boolean

writes the figure as a png file if true

filename: string

png filename used to write the figure

dpi: integer

number of pixel per inch for the saved figure

plot_wall_dist(self, step=10, scale=10, scale_units='inches', id=1, title='', savefig=False, filename='fig.png', dpi=150)[source]

To plot the wall distances

Parameters
id: integer

Figure id (number)

title: string

Figure title

savefig: boolean

writes the figure as a png file if true

filename: string

png filename used to write the figure

dpi: integer

number of pixel per inch for the saved figure

save(self, outfile)[source]

To save the content of the domain in a file

Parameters
outfile: string

output filename