Skip to content

compute_rset_map: float arange adds an extra column of cells #581

Description

@chraibi

compute_rset_map (PedPy 1.5.1, pedpy/methods/profile_calculator.py) builds its cell edges with a floating-point arange:

x_edges = np.arange(min_x, max_x + grid_size, grid_size)

When the extent is a whole multiple of grid_size, this can return one edge too many. For a 30 × 10 m room with grid_size=0.6:

>>> len(np.arange(0, 30 + 0.6, 0.6))   # expected 51 edges (50 cells)
52
>>> len(np.arange(0, 10 + 0.6, 0.6))   # 16.7 cells, rounded up: 18 edges, as intended
18

The map then has 51 columns. The last one, x = 30.0–30.6, lies entirely outside the walkable area, but points on the boundary x = 30 (for example agents at a door in that wall) fall into it, because binned_statistic_2d puts values on the last edge into the last bin.

Found while reproducing Schröder et al. 2020 (related: #580). A possible fix is to compute the number of cells as ceil((max - min) / grid_size - eps) and build the edges with min + grid_size * np.arange(n + 1). get_grid_cells should probably get the same treatment so that both stay consistent.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions