mock
A collection of functions for the generation of mock data. This module is intended for project development and writing code tests, but may otherwise be useful for demonstration and utility purposes.
mock_graph
Generate a NetworkX
MultiGraph
for testing or experimentation purposes.
Parameters
If set to True
, the x
and y
attributes will be in WGS84 geographic coordinates instead of a projected cartesion coordinate system.
Returns
A NetworkX
MultiGraph
with x
and y
node attributes.
Notes
from cityseer.tools import mock, plot
nx_multigraph = mock.mock_graph()
plot.plot_nx(nx_multigraph)
Mock graph.
get_graph_extents
Derive geographic bounds for a given networkX graph.
Parameters
A NetworkX
MultiGraph
with x
and y
node parameters.
Returns
mock_data_gdf
Generate a GeoDataFrame
containing mock data for testing or experimentation purposes.
Parameters
A NetworkX
graph with x
and y
attributes. This is used in order to determine the spatial extents of the network. The returned data will be within these extents.
The number of data elements to return in the GeoDataFrame
.
An optional random seed.
Returns
A GeoDataFrame
with data points for testing purposes.
mock_landuse_categorical_data
Generate a numpy
array containing mock categorical data for testing or experimentation purposes.
Parameters
A NetworkX
graph with x
and y
attributes. This is used in order to determine the spatial extents of the network. The returned data will be within these extents.
The number of categorical elements to return in the array.
The maximum number of unique classes to return in the randomly assigned categorical data. The classes are randomly generated from a pool of unique class labels of length num_classes
. The number of returned unique classes will be less than or equal to num_classes
.
An optional random seed.
Returns
A GeoDataFrame
with a “categorical_landuses” data column for testing purposes. The number of rows will match the length
parameter. The categorical data will consist of randomly selected characters from num_classes
.
mock_numerical_data
Generate a 2d numpy
array containing mock numerical data for testing or experimentation purposes.
Parameters
A NetworkX
graph with x
and y
attributes. This is used in order to determine the spatial extents of the network. The returned data will be within these extents.
The number of numerical elements to return in the array.
The (inclusive) minimum value in the val_min
, val_max
range of randomly generated integers.
The (exclusive) maximum value in the val_min
, val_max
range of randomly generated integers.
The number of arrays to nest in the returned 2d array.
The floating point precision
An optional random seed.
Returns
A GeoDataFrame
with a “mock_numerical_x” data columns for testing purposes. The number of rows will match the length
parameter. The numer of numerical columns will match the num_arrs
paramter.
mock_species_data
Generate a series of randomly generated counts and corresponding probabilities. This function is used for testing diversity measures. The data is generated in varying lengths from randomly assigned integers between 1 and 10. Matching integers are then collapsed into species “classes” with probabilities computed accordingly.
Parameters
An optional random seed.
Returns
The number of members for each species class.
The probability of encountering the respective species classes.
Notes
from cityseer.tools import mock
for counts, probs in mock.mock_species_data():
cs = [c for c in counts]
print(f"c = {cs}")
ps = [round(p, 3) for p in probs]
print(f"p = {ps}")
# c = [1]
# p = [1.0]
# c = [1, 1, 2, 2]
# p = [0.167, 0.167, 0.333, 0.333]
# c = [3, 2, 1, 1, 1, 3]
# p = [0.273, 0.182, 0.091, 0.091, 0.091, 0.273]
# c = [3, 3, 2, 2, 1, 1, 1, 2, 1]
# p = [0.188, 0.188, 0.125, 0.125, 0.062, 0.062, 0.062, 0.125, 0.062]
# etc.