shapepipe.pipeline.str_handler

shapepipe.pipeline.str_handler

STRING HANDLER.

This module defines a class for handling string operations.

Author

Axel Guinot

class StrInterpreter(string, catalogue, make_compare=False, mask_dict=None)[source]

Bases: object

String Interpreter Class.

Class to handle operation/comparison in a string.

Parameters
  • string (str) – String to interpret

  • catralog (dict, recarray or str) – If type(catalogue) == str : assume a SExtractor fits catalogue and read parameter in it else : assume the catalogue is already open and look into it

  • make_compare (bool) – If true assume a comparison in the string

  • mask_dict (dict) – Dictionary containing mask usable for the operation

  • autorun (bool) – If true return directly the result

interpret(string, make_compare=False, make_func=True, make_operate=True)[source]

Interpret.

This function handles the different possible operations

Parameters
  • str (string) – string to interpret

  • make_compare (bool) – If true look for a comparison

  • make_func (bool) – If true look for a function

  • make_operate (bool) – If true look for an operation

Returns

Result of the current operation.

Return type

array or float

Notes

This is a recursive function.

_compare(string)[source]

Handle Comparison in a String.

This function transform condition in a string to real condition.

Parameters

string (str) – strind containing the comparison.

_apply_func(string)[source]

Parse Input String for Function Name and Apply Function.

Parameters

str (string) – input string

Returns

result of the function

Return type

float

_init_stat_function()[source]

Initialise Available Stat Functions.

Create a dictionary containing the functions.

_mean(input)[source]

Get Mean.

Compute the mean of a distribution.

Parameters

input (numpy.ndarray) – Numpy array containing the data.

Returns

mean, if input array has size > 0; -1, otherwise

Return type

float

_mode(input, eps=0.001, iter_max=1000)[source]

Get Mode.

Compute the mode, the most frequent value of a continuous distribution.

Parameters
  • input (numpy.ndarray) – Numpy array containing the data.

  • eps (float, optional) – Accuracy to achieve (default is 0.001)

  • iter_max (int, optional) – Maximum number of iterations

Returns

mode, if input array has 10 or more elements; median, if input array has >0 and <10 elements; -1, if input array has 0 elements

Return type

float

_sigma_mad(input)[source]

Get Mean Absolute Deviation.

Compute median absolute deviation (MAD).

Parameters

input (numpy.ndarray) – input data

Returns

MAD, if input size > 0; -1 if input size is 0

Return type

float

_test_homogeneity(*args)[source]

Test Homogeneity.

Test homogeneity on 1D or 2D space.

Parameters
  • param1 (numpy.ndarray) – Array on which the homogeneity test is performed

  • param2 (numpy.ndarray, optional) – Array on which the homogeneity test is performed

  • nb_cells (int) – Number of cells in the space. (note : has to be a square number)

Returns

Percentage of inhomogeneity compared to worse possible case (based on the standard deviation)

Return type

float

_operate(string, string_split)[source]

Handle Operation in a String.

Make operation between catalogue’s parameters and/or numbers.

Parameters
  • string (str) – Parameter or linear combination of parameters.

  • string_split (str) – String split option

Returns

Result of the operation

Return type

float

Notes

It’s used as a recursive function

_string_op_func(string_op, string_split, op, tmp)[source]

Perform a Specified Operation.

This function handle the posible operation between parameters.

Parameters
  • string_op (list) – List of parameters to operate.

  • string_split (list) – The different parameter splitted using ‘*|/|\-|+s*(?![^()]*))’ as delimiter.

  • op (func) – The kind of operation provided as an operator function (Example : operator.sub).

  • tmp (str or float) – Temporary result of the global operation or value to initiate operation.

Returns

Result of the operation or ‘pass’ if there are remaining operations

Return type

float or str

_get_value(string)[source]

Get Value.

Return the value of the corresponding parameter. Or return a float with a number as parameter.

Parameters

string (str) – Parameter of the catalogue.

Returns

Value of the parameter. Or float

Return type

float

Notes

You can’t perform operations here!