mycelyso.misc package

Submodules

mycelyso.misc.graphml module

The graphml module contains output routines to output GraphML structured data from internal graph representations.

mycelyso.misc.graphml.to_graphml_string(g)[source]

Converts a networkx graph to a GraphML representation.

Parameters:g – graph
Returns:graphml string
mycelyso.misc.graphml.to_graphml_writer(g)[source]

Takes a networkx graph and returns a GraphMLWriter containing the graph.

Parameters:g – graph
Returns:GraphMLWriter instance
mycelyso.misc.graphml.write_graphml(g, name)[source]

Writes a networkx graph in GraphML format to a file.

Parameters:
  • g – graph
  • name – filename
Returns:

mycelyso.misc.regression module

The regression modules contains some helpers to perform linear fits on data with non-linear begins or ends.

mycelyso.misc.regression.find_linear_window(x, y, begin=nan, end=nan, window=0.1, condition=('rvalue', 'gt', 0.95), return_begin_end=False, return_nan_if_impossible=True)[source]

Tries to find a continuous window in x/y which (mostly) follows a linear relation subject to condition.

If window is a float, it is seen as relative length of the input lists. Linear regressions will be performed on each window, then the windows will be filtered by the condition (eg that they have a rvalue better than 0.95). Then the range between the first and the last window to follow these conditions will be used to perform the overall regression.

See also scipy.stats.linregress()

Parameters:
  • x – Input data, independent value
  • y – Input data, dependent value
  • begin
  • end
  • window – Window, either
  • condition – Condition to check, a tuple of three. The first must be a key of a linear regression result object, the second either ‘gt’ or ‘lt’, and the third the value to compare.
  • return_begin_end – If true, return the found range as well
  • return_nan_if_impossible – If True, return NaN if no suitable region was found, otherwise throws RuntimeError
Returns:

mycelyso.misc.regression.prepare_optimized_regression(x, y)[source]

First finds an optimal window using find_linear_window(), than performs a linear regression.

Parameters:
  • x – independent variable
  • y – dependent variable
Returns:

>>> x = np.linspace(1, 100, 100)
>>> y = x * 5 + 10
>>> y[0:10] = 0  # break our nice linear curve
>>> prepare_optimized_regression(x, y)
OrderedDict([('slope', 5.0), ('intercept', 10.0), ('rvalue', 0.9999999999999999), ('pvalue', 0.0), ('stderr', 7.942345602646859e-09), ('begin_index', 10), ('end_index', 100), ('begin', 11.0), ('end', 100.0)])

mycelyso.misc.util module

mycelyso.misc.util.calculate_length(points, times=1, w=5)[source]

Calculates the length of a path.

Paths sampled from pixel grids may contain notable measuring error, if euclidean distances are calculated naively. This method uses an adapted approach from [Cornelisse1984], by repeatedly smoothing the coordinates with a moving average filter before calculating the euclidean distance.

[Cornelisse1984]Cornelisse and van den Berg (1984) Journal of Microscopy 10.1111/j.1365-2818.1984.tb00544.x
Parameters:
  • points – Input points, a numpy array (X, 2)
  • times – Times smoothing should be applied
  • w – window width of the moving average filter
Returns:

Length of the input path

>>> calculate_length(np.array([[1.0, 1.0],
...                            [5.0, 5.0]]))
5.656854249492381
mycelyso.misc.util.clean_by_radius(points, radius=15.0)[source]

Bins points by radius and returns only one per radius, removing duplicates.

Parameters:
  • points – Input points
  • radius – Radius
Returns:

Filtered points

>>> clean_by_radius(np.array([[1.0, 1.0],
...                           [1.1, 1.1],
...                           [9.0, 9.0]]), radius=1.5)
array([[1., 1.],
       [9., 9.]])
mycelyso.misc.util.pairwise(iterable)[source]

s -> (s0,s1), (s1,s2), (s2, s3), …

Module contents

The misc package contains various helper functions.