grapa.curve.Curve

class grapa.curve.Curve(data, attributes: dict, silent: bool = True)

Bases: object

A Curve object, fundamental to grapa. Contains data (presumably 2x 1-D vectors), and metadata (can be thought as a dict of key, values). keys are lower-case.

__init__(data, attributes: dict, silent: bool = True)

Methods

__init__(data, attributes[, silent])

alterListGUI()

Determines the possible curve visualisations.

appendPoints(x_series, y_series)

Append datapoints.

attr(key[, default])

Get attribute value

attr_pop(key)

Deletes an attribute, return the value

castCurve(new_type_gui)

cast_as(new_type)

Returns a new Curve of the specified subtype, with same data and attributes as self.

cast_listpossibletypes([only_different])

Returns a list of Curve subclasses into which a curve can be cast

classNameGUI()

Provide base data, for the GUI to show what subclass of curve this is.

data_units([unit_x, unit_y])

Set/get units for x and y data series.

funcListGUI(**kwargs)

Fills in the Curve actions specific to the Curve type. Retuns a list, which elements are instances of FuncGUI, or (old style): ::.

getAttribute(key[, default])

getAttributes([keys_list])

getData()

Deprecated.

getDataCustomPickerXY(idx[, alter, ...])

Given an index in the Curve data, returns a modified data which has some sense to the user.

get_attributes([keys_list])

Returns all attributes, or a subset with keys given in keyList

get_data()

Returns the data as a np.array

get_muloffset()

equivalent to attr("muloffset"), with ensure formatting as 2-element list

has_attr(key)

True if attribute key is defined, False if not defined or default

isHidden()

is_attr_value_default(value)

True is value is default (or does not exist), False if defined

label_auto(formatter)

Update the curve label according to formatting using python string Template, with curve attributes as variables.

print_help()

Prints help for the Curve subclass, generated from docstrings.

print_help_func(func[, funclabel, nparammax])

prints the docstring of a function

selectData([xlim, ylim, alter, offsets, data])

Deprecated: Use 'select_data' instead.

select_data([xlim, ylim, alter, offsets, data])

Returns slices of the data self.x(), self.y() which satisfy xlim[0] <= x <= xlim[1], and ylim[0] <= y <= ylim[1].

setX(x[, index])

Deprecated.

setY(y[, index])

Deprecated.

set_data(data)

Set curve data.

set_x(x[, index])

Set new value for the x data.

set_y(y[, index])

Set new value for the y data.

shape([idx])

Returns the shape of the data array, or one of its dimension if idx is 0 or 1

swapShowHide()

update(attributes)

Updates attributes.

updateFitParam(*param[, func])

Update the curve y values of a fit curve.

updateFitParamFormatPopt(_f, param)

Format the input parameters to be stored in _popt, depending on the fit function f.

updateValuesDictkeys(*args, **kwargs)

Deprecated, use update_values_keys instead Performs update({key1: value1, key2: value2, ...}).

updateValuesDictkeysGraph(*args[, keys, ...])

Depreated, use update_values_keys_graph_conditional instead.

update_plotter_boxplot_addon(fun, kw)

set boxplot_addon keyword.

update_scatter_next_curves(*values[, graph, ...])

To receive update instructions for Curves following self in graph, when self "type" is "scatter".

update_values_keys(*values[, keys])

Performs update({key1: value1, key2: value2, ...}).

update_values_keys_graph_condition(*args[, ...])

Similar as update_values_keys, for all curves inside a provided graph.

visible([state])

Set/get state of visibility.

x([index, alter, xyValue, error_if_mix_xy])

Returns the x data over the range index.

x_offsets(**kwargs)

Calls y(), and apply the effects of offset and muloffset on output.

y([index, alter, xyValue, error_if_mix_xy])

Returns the y data over the range index.

y_offsets(**kwargs)

Calls y(), and apply the effects of offset and muloffset on output.

Attributes

ALTER_ABS

ALTER_ABS0

ALTER_LOG10ABS

ALTER_MCA_KEV

ALTER_NM_CM

ALTER_NM_EV

ALTER_NORMALIZED

ALTER_SIMS_DEPTH

ALTER_TAUC

ALTER_TAUCLN1MINUSEQE

ALTER_X

ALTER_Y

AXISLABELS_X

AXISLABELS_Y

CURVE

KEY_AXISLABEL_X

KEY_AXISLABEL_Y

LINESTYLEHIDE

OFFSET_0MAX

OFFSET_MINMAX

alterListGUI() list

Determines the possible curve visualisations. One element has the form: AlterListItem(‘Label GUI’, [‘alter_x’, ‘alter_y’], ‘semilogx’, “print help doc”) By default only neutral (i.e. raw data) is provided

appendPoints(x_series, y_series) bool

Append datapoints.

Parameters:
  • x_series – a list or np.array

  • y_series – a list or np.array. same length as x_series

Returns:

True if success, False otherwise.

attr(key: str, default: Any = '') Any

Get attribute value

attr_pop(key: str)

Deletes an attribute, return the value

cast_as(new_type: str) Curve

Returns a new Curve of the specified subtype, with same data and attributes as self.

cast_listpossibletypes(only_different: bool = True) List[Tuple[str, str, type]]

Returns a list of Curve subclasses into which a curve can be cast

Parameters:

only_different – if false, also returns the object own subclass

classmethod classNameGUI() str

Provide base data, for the GUI to show what subclass of curve this is. Can be overridden, see CurveArrhenius.

data_units(unit_x=None, unit_y=None)

Set/get units for x and y data series.

Parameters:
  • unit_x – new value for unit of data x

  • unit_y – new value for unit of data y

Returns:

list[str] as [“nm”, “%”], or [“V”, “nF cm-2”]

funcListGUI(**kwargs) list

Fills in the Curve actions specific to the Curve type. Retuns a list, which elements are instances of FuncGUI, or (old style):

[func,
 'Button text',
 ['label 1', 'label 2', ...],
 ['value 1', 'value 2', ...],
 {'hiddenvar1': 'value1', ...}, (optional)
 [dictFieldAttributes, {}, ...]] (optional)

By default, returns quick modifs for offset and muloffset (if already set), and a help for some plot types (errorbar, scatter).

Parameters:

kwargs – this function should be called specifying kwargs[‘graph’] the graph self is embedded in, and kwargs[‘graph_i’] as position of self in graph.

getDataCustomPickerXY(idx, alter: str | List[str] = '', strDescription=False)

Given an index in the Curve data, returns a modified data which has some sense to the user. Can be overridden in child classes, see e.g. CurveCf If strDescription is True, then returns a string which describes what this method is doing. For example, CurveCf: return temperature, omega instead of f, C

get_attributes(keys_list: list | None = None) dict

Returns all attributes, or a subset with keys given in keyList

get_data()

Returns the data as a np.array

get_muloffset() list

equivalent to attr(“muloffset”), with ensure formatting as 2-element list

has_attr(key: str) bool

True if attribute key is defined, False if not defined or default

is_attr_value_default(value) bool

True is value is default (or does not exist), False if defined

label_auto(formatter)

Update the curve label according to formatting using python string Template, with curve attributes as variables. Examples: “${sample} ${_simselement}”, “${sample} ${cell}”, “${temperature [k]:.0f} K”

print_help()

Prints help for the Curve subclass, generated from docstrings.

classmethod print_help_func(func, funclabel: str = '', nparammax: int = -1)

prints the docstring of a function

select_data(xlim=None, ylim=None, alter='', offsets=False, data=None)

Returns slices of the data self.x(), self.y() which satisfy xlim[0] <= x <= xlim[1], and ylim[0] <= y <= ylim[1].

Parameters:
  • xlim – [xmin, xmax], or None

  • ylim – [ymin, ymax], or None

  • alter – ‘’, or [‘’, ‘abs’]. Affect the test AND the output.

  • offsets – if True, calls to x and y are affected by offset and muloffset

  • data – [xSeries, ySeries] can be provided. If provided, alter and offsets are ignored.

Return (x, y):

as np.array

setX(x, index=None)

Deprecated. Use ‘set_x’ instead.

setY(y, index=None)

Deprecated. Use ‘set_y’ instead.

set_data(data: ndarray)

Set curve data. Raise IncorrectInputError if failed.

set_x(x, index=None)

Set new value for the x data. Index can be provided (self.data[0,index] = x).

set_y(y, index=None)

Set new value for the y data. Index can be provided (self.data[1,index] = y).

shape(idx=':')

Returns the shape of the data array, or one of its dimension if idx is 0 or 1

update(attributes: dict) None

Updates attributes. a dict must be provided

updateFitParam(*param, func: Callable | None = None)

Update the curve y values of a fit curve. Raise IncorrectInputError if problem with input.

Parameters:
  • param – the new parameters to consider for the fit formula. Will be placed into _popt.

  • func – if provided, will call func(…) instead of getattr(self, self.attr(“_fitfunc”))(…) Used for example in curveMCA for fit

updateFitParamFormatPopt(_f, param)

Format the input parameters to be stored in _popt, depending on the fit function f. This is useful when the fit function has some fixed parameters, or when the input needs to be reshaped.

updateValuesDictkeysGraph(*args, keys: list | None = None, graph: Graph = None, also_attr: list | None = None, also_vals: list | None = None)

Depreated, use update_values_keys_graph_conditional instead. :meta private:

update_plotter_boxplot_addon(fun, kw: dict) bool

set boxplot_addon keyword.

update_scatter_next_curves(*values, graph=None, graph_i=None) bool

To receive update instructions for Curves following self in graph, when self “type” is “scatter”.

Parameters:
  • values – values for keyword “type”, to apply on the Curves following self in graph.

  • graph – the Graph object self is part of

  • graph_i – index of self within graph (NB: graph may contain self >1x)

Returns:

True if success, False otherwise

update_values_keys(*values, keys: List[str] | None = None)

Performs update({key1: value1, key2: value2, …}). Handy to call from GUI

Parameters:
  • values – value1, value2, …

  • list_keys – keys=[‘key1’, ‘key2’, …]. Same length as args. Not optional.

Returns:

True if success, False otherwise

update_values_keys_graph_condition(*args, keys: list | None = None, graph: Graph = None, also_attr: list | None = None, also_vals: list | None = None)

Similar as update_values_keys, for all curves inside a provided graph. Implemented as curve method for easier integration into GUI.

Parameters:
  • args – value1, value2, …

  • keys – [‘key1’, ‘key2’, …]

  • graph – Graph object, will apply to all Curves within

  • also_attr – list of attribute keys.

  • also_vals – list, same len as also_attr. Test each curve in graph, only perfom modifications if for all i in range, curve.attr(also_attr[i]) == also_vals[i].

visible(state: bool | None = None)

Set/get state of visibility. Replaces .isHidden(), with added setter functionality.

Parameters:

state – True to show the Curve, False to hide. None: unchanged state.

Returns:

True if shown (visible), False if hidden

x(index: int | slice | range | None = None, alter='', xyValue=None, error_if_mix_xy=False) ndarray

Returns the x data over the range index.

Parameters:
  • index – range to the data.

  • alter – requested alteration to the data (i.e. ‘’, ‘nmeV’)

  • xyValue – provide [x, y] values pair to be alter-ed. x, y can be np.array In that case, the curve x values are ignored.

  • error_if_mix_xy – throw ValueError exception if alter value calculation requires both x and y components. Useful for transforming xlim and ylim, where x do not know y in advance.

Returns:

a nd.array of x values

x_offsets(**kwargs)

Calls y(), and apply the effects of offset and muloffset on output.

y(index: int | slice | range | None = None, alter='', xyValue=None, error_if_mix_xy=False) ndarray

Returns the y data over the range index.

Parameters:
  • index – range to the data.

  • alter – requested alteration to the data (i.e. ‘’, ‘nmeV’)

  • xyValue – provide [x, y] values pair to be alter-ed. x, y can be np.array In that case, the curve x values are ignored.

  • error_if_mix_xy – raise ValueError if alter value calculation requires both x and y components. Used for transforming xlim and ylim, where y do not know x in advance.

Returns:

a nd.array of y values

y_offsets(**kwargs)

Calls y(), and apply the effects of offset and muloffset on output.