nqrduck.helpers.functions#

A module that contains functions that can be used in various modules. This used to be part of the nqrduck-spectrometer module.

Classes

CustomFunction()

A custom function.

Function(expr)

A function that can be used as a pulse parameter.

GaussianFunction()

The Gaussian function.

RectFunction()

The rectangular function.

SincFunction()

The sinc function.

class nqrduck.helpers.functions.CustomFunction#

A custom function.

class nqrduck.helpers.functions.Function(expr)#

A function that can be used as a pulse parameter.

This class is the base class for all functions that can be used as pulse parameters. Functions can be used for pulse shapes, for example.

Parameters:

expr (str | sympy.Expr) – The expression of the function.

name#

The name of the function.

Type:

str

parameters#

The parameters of the function.

Type:

list

expr#

The sympy expression of the function.

Type:

sympy.Expr

resolution#

The resolution of the function in seconds.

Type:

float

start_x#

The x value where the evalution of the function starts.

Type:

float

end_x#

The x value where the evalution of the function ends.

Type:

float

class Parameter(name: str, symbol: str, value: float)#

A parameter of a function.

This can be for example the standard deviation of a Gaussian function.

Parameters:
  • name (str) – The name of the parameter.

  • symbol (str) – The symbol of the parameter.

  • value (float) – The value of the parameter.

name#

The name of the parameter.

Type:

str

symbol#

The symbol of the parameter.

Type:

str

value#

The value of the parameter.

Type:

float

default#

The default value of the parameter.

Type:

float

classmethod from_json(data)#

Creates a parameter from a json representation.

Parameters:

data (dict) – The json representation of the parameter.

Returns:

The parameter.

Return type:

Function.Parameter

set_value(value: float) None#

Sets the value of the parameter.

Parameters:

value (float) – The new value of the parameter.

to_json() dict#

Returns a json representation of the parameter.

Returns:

The json representation of the parameter.

Return type:

dict

add_parameter(parameter: Parameter) None#

Adds a parameter to the function.

Args: parameter (Function.Parameter): The parameter to add.

property end_x#

The x value where the evalution of the function ends.

evaluate(pulse_length: float, resolution: float = None) ndarray#

Evaluates the function for the given pulse length.

Parameters:
  • pulse_length (float) – The pulse length in seconds.

  • resolution (float, optional) – The resolution of the function in seconds. Defaults to None.

Returns:

The evaluated function.

Return type:

np.ndarray

property expr#

The sympy expression of the function.

frequency_domain_plot(pulse_length: float) MplWidget#

Plots the frequency domain of the function for the given pulse length.

Parameters:

pulse_length (float) – The pulse length in seconds.

Returns:

The matplotlib widget containing the plot.

Return type:

MplWidget

classmethod from_json(data: dict) Function#

Creates a function from a json representation.

Parameters:

data (dict) – The json representation of the function.

Returns:

The function.

Return type:

Function

get_pulse_amplitude(pulse_length: float, resolution: float = None) array#

Returns the pulse amplitude in the time domain.

Parameters:
  • pulse_length (Float) – The pulse length in seconds.

  • resolution (float, optional) – The resolution of the function in seconds. Defaults to None.

Returns:

The pulse amplitude.

Return type:

np.array

get_tdx(pulse_length: float) ndarray#

Returns the time domain points and the evaluated function for the given pulse length.

Parameters:

pulse_length (float) – The pulse length in seconds.

Returns:

The time domain points.

Return type:

np.ndarray

get_time_points(pulse_length: float) ndarray#

Returns the time domain points for the function with the given pulse length.

Parameters:

pulse_length (float) – The pulse length in seconds.

Returns:

The time domain points.

Return type:

np.ndarray

property resolution#

The resolution of the function in seconds.

property start_x#

The x value where the evalution of the function starts.

time_domain_plot(pulse_length: float) MplWidget#

Plots the time domain of the function for the given pulse length.

Parameters:

pulse_length (float) – The pulse length in seconds.

Returns:

The matplotlib widget containing the plot.

Return type:

MplWidget

to_json() dict#

Returns a json representation of the function.

Returns:

The json representation of the function.

Return type:

dict

class nqrduck.helpers.functions.GaussianFunction#

The Gaussian function.

The Gaussian function is defined as exp(-0.5 * ((x - mu) / sigma)**2). The parameters are the mean and the standard deviation.

class nqrduck.helpers.functions.RectFunction#

The rectangular function.

class nqrduck.helpers.functions.SincFunction#

The sinc function.

The sinc function is defined as sin(x * l) / (x * l). The parameter is the scale factor l.