c6.utils package

Submodules

c6.utils.encoding module

Encoding for JSON etc

c6.utils.encoding.CoreToNumpy(obj_to_encode)[source]

Convert lists back to numpy arrays

class c6.utils.encoding.JSONNumpyPandasEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: json.encoder.JSONEncoder

Based on RYMC’s version

Constructor for JSONEncoder, with sensible defaults.

If skipkeys is false, then it is a TypeError to attempt encoding of keys that are not str, int, float or None. If skipkeys is True, such items are simply skipped.

If ensure_ascii is true, the output is guaranteed to be str objects with all incoming non-ASCII characters escaped. If ensure_ascii is false, the output can contain non-ASCII characters.

If check_circular is true, then lists, dicts, and custom encoded objects will be checked for circular references during encoding to prevent an infinite recursion (which would cause an OverflowError). Otherwise, no such check takes place.

If allow_nan is true, then NaN, Infinity, and -Infinity will be encoded as such. This behavior is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a ValueError to encode such floats.

If sort_keys is true, then the output of dictionaries will be sorted by key; this is useful for regression tests to ensure that JSON serializations can be compared on a day-to-day basis.

If indent is a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation.

If specified, separators should be an (item_separator, key_separator) tuple. The default is (‘, ‘, ‘: ‘) if indent is None and (‘,’, ‘: ‘) otherwise. To get the most compact JSON representation, you should specify (‘,’, ‘:’) to eliminate whitespace.

If specified, default is a function that gets called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a TypeError.

default(obj_to_encode)[source]

Pandas and Numpy have some specific types that we coerce to core Python types, for JSON generation purposes. This attempts to do so where applicable.

c6.utils.encoding.NumpyToCore(obj_to_encode)[source]

Convert numpy objects to standard python objects

c6.utils.math module

c6.utils.math.clip(number, minimum, maximum)[source]

Clip a number to be between the minimum and maximum

c6.utils.math.norm(p)[source]

2 norm, distance from a point to the origin on the plane

c6.utils.nameing module

Generate random names from the numpy RNG

c6.utils.nameing.name(length=6)[source]

Generate a random name of length

We need our random names to be generated by numpy’s RNG, or they will be different even when taking the same seed so we need to roll our own truncated UUID generator to keep track of our cells.

Parameters

length (int) – number of hex chars in name

Returns

name – random name

Return type

str

c6.utils.serialize module

Provide (de)serialization for the space and its cells

class c6.utils.serialize.CSVLog(fn=None, header=None)[source]

Bases: object

Log the output of a run as we go in a tidy CSV

Parameters
  • fn (str) – filename to log output to, will have ‘.c6log’ appended if not present

  • header (list) – list of cell properties to log, will also log timestep from space default [“id”, “x”, “y”, “dir_x”, “dir_y”, “speed”, “radius”, “age”, “parent”]

close()[source]
log_space(space)[source]

Log cells in a space at a single timestep

class c6.utils.serialize.SimulariumLog(fn=None)[source]

Bases: object

Log the output of the run to a Simularium compatible JSON format

Parameters

fn (str) – filename to log output to, will have ‘.simularium’ appended if not present

close()[source]

Terminate the JSON and close the file

log_space(space)[source]

Log space at a timepoint

c6.utils.serialize.load_starting_conditions(conditions_filename)[source]

Load starting conditions into memory

c6.utils.serialize.write_starting_conditions(conditions_filename, space, extra_top_level={}, universal_keys=None, cell_keys=None)[source]

Write the current state of a space as a set of starting conditions

Module contents