# pymatgen.core.spectrum module¶

This module defines classes to represent any type of spectrum, essentially any x y value pairs.

class Spectrum(x: Union[Sequence[float], Sequence[Sequence[float]], Sequence[numpy.ndarray], numpy.ndarray], y: Union[Sequence[float], Sequence[Sequence[float]], Sequence[numpy.ndarray], numpy.ndarray], *args, **kwargs)[source]

Bases: monty.json.MSONable

Base class for any type of xas, essentially just x, y values. Examples include XRD patterns, XANES, EXAFS, NMR, DOS, etc.

Implements basic tools like application of smearing, normalization, addition multiplication, etc.

Subclasses should extend this object and ensure that super is called with ALL args and kwargs. That ensures subsequent things like add and mult work properly.

Parameters
• x (ndarray) – A ndarray of N values.

• y (ndarray) – A ndarray of N x k values. The first dimension must be the same as that of x. Each of the k values are interpreted as separate.

• *args – All subclasses should provide args other than x and y when calling super, e.g., super().__init__( x, y, arg1, arg2, kwarg1=val1, ..). This guarantees the +, -, *, etc. operators work properly.

• **kwargs – Same as that for *args.

XLABEL = 'x'[source]
YLABEL = 'y'[source]
copy()[source]
Returns

Copy of Spectrum object.

get_interpolated_value(x: float) → List[float][source]

Returns an interpolated y value for a particular x value.

Parameters

x – x value to return the y value for

Returns

Value of y at x

normalize(mode: str = 'max', value: float = 1.0)[source]

Normalize the spectrum with respect to the sum of intensity

Parameters
• mode (str) – Normalization mode. Supported modes are “max” (set the max y value to value, e.g., in XRD patterns), “sum” (set the sum of y to a value, i.e., like a probability density).

• value (float) – Value to normalize to. Defaults to 1.

smear(sigma: float = 0.0, func: Union[str, Callable] = 'gaussian')[source]

Apply Gaussian/Lorentzian smearing to spectrum y value.

Parameters
• sigma – Std dev for Gaussian smear function

• func – “gaussian” or “lorentzian” or a callable. If this is a callable, the sigma value is ignored. The callable should only take a single argument (a numpy array) and return a set of weights.

lorentzian(x, x_0: float = 0, sigma: float = 1.0)[source]
Parameters
• x – x values

• x_0 – Center

• sigma – FWHM

Returns

Value of lorentzian at x.