morphoclass.console.helpers module

Helper functions for morphoclass checkpoints.

morphoclass.console.helpers.convert(val)

Convert value from str to python type.

Parameters

val (str) – Input parameter to be converted to corresponding type, or leave it as a string as a last option.

Returns

Value converted to a corresponding type.

Return type

int, float, str, dict

morphoclass.console.helpers.ctx2dict(ctx)

Convert click context to dictionary.

Parameters

ctx (click.Context, list) – Context object with unspecified parameters (used as kwargs for models, etc.). E.g., [‘–a’, ‘1’, ‘–b’, ‘sth’, ‘–c’, ‘d=1 g=2’]

Returns

config_params – Context content as dictionary.

Return type

dict

Note

It won’t happen that the keys start with only one dash, since we didn’t specify these parameters explicitly with their shorter names.

morphoclass.console.helpers.params2dict(params)

Convert dictionary and nested dictionaries with string values to correct type.

Parameters

params (dict) – Dictionary of string values and/or nested dictionaries with string values.

Returns

config_params – Dictionary with correct value types.

Return type

dict

morphoclass.console.helpers.params_dict(value)

Covert string to dictionary.

This conversion is needed for converting method parameters given as string in the command line. E.g., random_state=113587 objective=”multi:softmax”.

Parameters

value (str) – Input parameter to be converted to corresponding type, or leave it as a string as a last option.

Returns

Value converted to a dictionary.

Return type

dict

Raises

ValueError – If any of the partitions is empty string, this is not the dict type.

morphoclass.console.helpers.validate_params(ctx, param, value)

Validate click input for method parameters.

Parameters
  • ctx (click.Context) – Click context.

  • param (str) – Parameter name.

  • value (str) – Value to check if it has the correct parameres from.

Returns

val – Converted value.

Return type

dict

Raises

ValueError – If format is not parsable to dictionary.