Python and its libraries, Scipy and Pygame, are used to translate urban system models to programming libraries and geographic maps to surface objects in order to simulate a spatial organization in cities. Three modules were designed and written from scratch in order to make spatial simulation based on cellular automata and agent-based models.
The first module is designed for translating georeferenced maps, i.e. vector maps, to polygon objects. Taking the structure of an urban space, for example a metropolitan area formed by different shapes of small tracts of land, this module has a polygon class that receives the information of each tract, for example name, id, and coordinates, as attributes, and computes spatial features, for example return a list of local neighbors and the total area of its neighborhood, in order to create a list of tracts that updates its attributes every time step in the simulation.
The second module is formed by several functions that define and compute different types of transitional and behavioral rules of each tract, for example rules based on the number and area of local neighbors. Furthermore, wrapping Scipy libraries, such a module has functions that plot the dynamics and results of the simulation, for example histograms and line plots.
Based on the above modules and the Pygame library, the third module displays the simulation as a map or surface object where the attributes of each tract can change depending on the goal of the analysis, for example colors related to each tract can change depending on its local neighborhood simulating a modification in the preferences of others.
As a result, the advantage of using Python is its flexibility of translating geographical maps to objects and its well performance running spatial simulation.
Finally, taking the empirical case of textile firms related to the manufacture sector at Mexico City and the Schelling’s segregation model as a framework, the spatial localization of firms are simulated by local mechanisms based on competitive and cooperative behaviors between different sizes of firms, i.e. number of workers. The purpose of the simulation is to understand how such mechanisms between different sizes, in particular small, medium, and big, affect their localization decision in a city. Furthermore, the simulation evaluates whether the spatial distribution of such firms is systematically or randomly localized and explores the influence of the firm size and its local interaction with others to produce a spatial organization characterized by clusters.