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

mock_graph
(
wgs84_coords : bool = False
)

Generate a NetworkX MultiGraph for testing or experimentation purposes.

Parameters

wgs84_coords
bool

If set to True, the x and y attributes will be in WGS84 geographic coordinates instead of a projected cartesion coordinate system.

Returns

MultiGraph

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)

Example graph Mock graph.

get_graph_extents

get_graph_extents
(
nx_multigraph
)->[ float float float float ]

Derive geographic bounds for a given networkX graph.

Parameters

nx_multigraph
MultiGraph

A NetworkX MultiGraph with x and y node parameters.

Returns

min_x
float
min_y
float
max_x
float
max_y
float

mock_data_gdf

mock_data_gdf
(
nx_multigraph
length : int = 50
random_seed : int = 0
)->[ GeoDataFrame ]

Generate a GeoDataFrame containing mock data for testing or experimentation purposes.

Parameters

nx_multigraph
MultiGraph

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.

length
int

The number of data elements to return in the GeoDataFrame.

random_seed
int

An optional random seed.

Returns

GeoDataFrame

A GeoDataFrame with data points for testing purposes.

mock_landuse_categorical_data

mock_landuse_categorical_data
(
nx_multigraph
length : int = 50
num_classes : int = 10
random_seed : int = 0
)->[ GeoDataFrame ]

Generate a numpy array containing mock categorical data for testing or experimentation purposes.

Parameters

nx_multigraph
MultiGraph

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.

length
int

The number of categorical elements to return in the array.

num_classes
int

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.

random_seed
int

An optional random seed.

Returns

GeoDataFrame

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

mock_numerical_data
(
nx_multigraph
length : int = 50
val_min : int = 0
val_max : int = 100000
num_arrs : int = 1
floating_pt : int = 3
random_seed : int = 0
)->[ GeoDataFrame ]

Generate a 2d numpy array containing mock numerical data for testing or experimentation purposes.

Parameters

nx_multigraph
MultiGraph

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.

length
int

The number of numerical elements to return in the array.

val_min
int

The (inclusive) minimum value in the val_min, val_max range of randomly generated integers.

val_max
int

The (exclusive) maximum value in the val_min, val_max range of randomly generated integers.

num_arrs
int

The number of arrays to nest in the returned 2d array.

floating_pt
int

The floating point precision

random_seed
int

An optional random seed.

Returns

GeoDataFrame

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

mock_species_data
(
random_seed : int = 0
)->[ Generator[tuple[list[int] list[float]] ]

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

random_seed
int

An optional random seed.

Returns

counts
ndarray[int]

The number of members for each species class.

probs
ndarray[float]

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.