clophfit.utils#

General utility helpers for clophfit.

Functions#

weights_from_sigma(sigma)

Convert standard deviations to ODR weights (1 / sigma**2).

read_xls(path)

Read first sheet of an xls file.

lookup_listoflines(…)

Lookup line numbers (row index) where given pattern occurs.

strip_lines(lines)

Remove empty fields/cells from lines read from a csv file.

Module Contents#

clophfit.utils.weights_from_sigma(sigma)#

Convert standard deviations to ODR weights (1 / sigma**2).

Returns None when sigma is empty to use odrpack defaults.

Parameters:

sigma (numpy.ndarray)

Return type:

numpy.ndarray | None

clophfit.utils.read_xls(path)#

Read first sheet of an xls file.

Parameters:

path (Path) – Path to .xls file.

Returns:

Lines as list_of_lines.

Return type:

list[list[str | int | float]]

clophfit.utils.lookup_listoflines(csvl: list[list[str]], pattern: str, col: int) list[int]#
clophfit.utils.lookup_listoflines(csvl: list[list[str | int | float]], pattern: str = 'Label: Label', col: int = 0) list[int]

Lookup line numbers (row index) where given pattern occurs.

Parameters:
  • csvl (list[list[str | int | float]] | list[list[str]]) – Lines (list_of_lines) of a csv/xls file.

  • pattern (str) – Pattern to be searched (default=”Label: Label”).

  • col (int) – Column to search (default=0).

Returns:

Row/line index for all occurrences of pattern. Empty list for no occurrences.

Return type:

list[int]

clophfit.utils.strip_lines(lines)#

Remove empty fields/cells from lines read from a csv file.

Parameters:

lines (list[list[str | int | float]]) – Lines (list_of_lines) that are a list of fields, typically from a csv/xls file.

Returns:

Lines (list_of_lines) removed from blank cells.

Return type:

list[list[str | int | float]]

Examples

>>> lines = [
...     ["Shaking (Linear) Amplitude:", "", "", "", 2, "mm", "", "", "", "", ""]
... ]
>>> strip_lines(lines)
[['Shaking (Linear) Amplitude:', 2, 'mm']]