rwth_nb.misc

Feedback

class rwth_nb.misc.feedback.RWTHFeedbackCollector

RWTH Feedback Collector Class

Processes json feedback files in a folder or feedbacks from RWTHJupyter realm and creates dataframes for every

mentioned notebook.

Intended to be used with RWTHFeedbackEvaluator but also standalone possible as the collected feedbacks are stored

as pandas Dataframes.

Examples

>>> from rwth_nb.misc.feedback import RWTHFeedbackCollector
>>> path_to_folder = './Feedbacks' # path to folder with feedback json files
>>> collector = RWTHFeedbackCollector()
>>> data = collector.get_all_folder(path_to_folder) # get feedback for all notebooks from folder
>>> data = collector.get_all_jupyter(realm) # get feedback for all notebooks from RWTHJupyter realm
get_all_folder(folder_path: str) DataFrame

Collect all DataFrames for every notebook from every json file in a path

Parameters

folder_path: str

Folder in which json feedback files are stored

Returns

pd.DataFrame

pandas dataframe of all submitted feedback files in a folder

class rwth_nb.misc.feedback.RWTHFeedbackEvaluator

RWTH Feedback Evaluator Class

Processes pandas dataframes created with the collector class above into an evaluation interface. Likert scale like answers are plotted in different styles (bar only for now) Free text answers are collected and displayed into a list for readability

Examples

>>> from rwth_nb.misc.feedback import RWTHFeedbackEvaluator
>>> eva = RWTHFeedbackEvaluator()
>>> eva.evaluate(data, lang='de') # data: see rwth_nb.misc.feedback.RWTHFeedbackCollector
evaluate(data, lang='en')

Actual evaluation

Parameters

data: pandas.Dataframe or List[pandas.Dataframe]

dataframe created by collector class using json files multiple dataframes can be passed in a list (note that all must be in the same language)

lang: str, optional

language to be used; the likert scale is chosen accordingly from RWTHFeedback class

class rwth_nb.misc.feedback.RWTHFeedbackJupyter(feedback_name, questions, lang='en', realm=None)

RWTH Feedback submission with RWTHJupyters submission service

Parameters

feedback_name: str

the feedbacks name

questions: dict

feedback options to be filled out

lang: str, optional

feedback language, scales are shown in that language

realm: str, optional

jupyter submission realm in which the feedback should be stored, is set automatically if None

class rwth_nb.misc.feedback.RWTHFeedbackMail(feedback_name, questions, lang='en', feedback_path='feedback.json', mail_to=None, mail_from='feedback@jupyter.rwth-aachen.de', mail_subject=None, mail_smtp_host='smarthost.rwth-aachen.de')

RWTH Feedback submission with mail

Parameters

feedback_name: str

the feedbacks name

questions: dict

feedback options to be filled out

lang: str, optional

feedback language, scales are shown in that language

feedback_path: str, optional

path in which a feedback json file should be stored

mail_to: str, optional

mail adress to which the feedback should be sent when submitted

mail_from: str, optional

mail adress from which the feedback should be sent when submitted

mail_subject: str, optional

subject of the mail

mail_smtp_host: str, optional

smtp host

save_entries()

Save entries into json file.

Not used if user is in jupyter cluster.

send_mail()

Sends JSON file as attachment of a mail to predefined recipient

Sets self.is_submitted to True if mail was sent successfully. False otherwise.

Media

Signals

This module defines functionality related to signal processing.

rwth_nb.misc.signals.dft(s, fs, NFFT=0)

Calculate discrete Fourier transform of vector s Sampling frequency fs is used to calculate frequency vector f Number of frequency coefficients can be specified as well

rwth_nb.misc.signals.find_ind_least_diff(x, x0)

Find index of the value that’s nearest to x0

Parameters

xarray_like

Array to be inspected

x0float

Target value to be searched for

Returns

indexint or list

index(indices) of value(s) that is (are) nearest to x0

rwth_nb.misc.signals.find_intervals(s, t, thresh, delta)

Find intervals of signal s by searching for delta-functions in the second derivative of s

Parameters

sarray_like

The signal

tarray_like

Corresponding t-axis

threshfloat

Threshold for delta search

deltafloat

Sampling period

Returns

intervals_s, peaks, dd : intervals are the intervals, peaks the found peaks and dd the second derivative of s.

rwth_nb.misc.signals.idft(S, Ntime=0, NFFT=0)

Calculate discrete inverse Fourier transform of vector S Number of time bins is used to crop the output of NumPy’s ifft function Number of frequency coefficients can be specified as well

Filters

rwth_nb.misc.filters.butter(cutoff, fs, order=5, type='Tiefpass', fdelta=0)

Butterworth Filter of order n

Parameters

cutofffloat

cutoff frequency

fsfloat

sampling frequency, is used to calculate nyquist frequency

orderfloat, optional

order of filter

type: {‘Tiefpass’, ‘Bandpass’, ‘Hochpass’}, optional

type of filter.

fdelta: float, optional

bandwith of filter

Returns

bndarray

numerator polynomial of the IIR filter

andarray

denominator polynomial of the IIR filter

rwth_nb.misc.filters.butter_bandpass(f0, fdelta, fs, order=5)

Bandpass Butterworth Filter

This filter is set as a bandpass filter with f0, fdelta, fs and order set by user.

See Also

butter : Filter design using order and critical points

rwth_nb.misc.filters.butter_highpass(cutoff, fs, order=5)

Highpass Butterworth Filter

This filter is set as a highpass filter with cutoff, fs and order set by user.

See Also

butter : Filter design using order and critical points

rwth_nb.misc.filters.butter_lowpass(cutoff, fs, order=5)

Lowpass Butterworth Filter

This filter is set as a lowpass filter with cutoff, fs and order set by user.

See Also

butter : Filter design using order and critical points

rwth_nb.misc.filters.filter(s, b, a)

Digital Filter

Filter s(n) in z-Domain with filter coefficients a and b:
-1

-M

b[0] + b[1]z + … + b[M] z

G(z) = ——————————– S(z)
-1

-N

a[0] + a[1]z + … + a[N] z

Parameters

sarray_like

n-dimensional input array

barray_like

numerator coefficient vector in a 1-D sequence.

aarray_like

denominator coefficient vector in a 1-D sequence.

Returns

garray

output of digital filter.

Transforms

rwth_nb.misc.transforms.dft(s, fs, NFFT=0)

Calculate discrete fourier transform of vector s

Parameters

sarray_like

vector to be transformed

fsfloat

sampling frequency, is used to calculate frequency vector f

NFFTfloat, optional

number of frequency coefficients

Returns

Sndarray

resulting discrete fourier transform

fndarray

frequency vector

Examples

For examples see primer at rwth_nb/RWTH Transforms.ipynb

rwth_nb.misc.transforms.idft(S, Ntime=0, NFFT=0)

Calculate inverse discrete fourier transform of vector S

Parameters

Sarray_like

vector to be transformed

Ntimefloat, optional

number of time bins, is used to crop the output of NumPy’s ifft function

NFFTfloat, optional

number of frequency coefficients

Returns

sndarray

resulting inverse discrete fourier transform

Examples

For examples see primer at rwth_nb/RWTH Transforms.ipynb

rwth_nb.misc.transforms.ilaplace_Hf(f=array([-6., -5.98826979, -5.97653959, ..., 5.97653959, 5.98826979, 6.]), H0=1, pp=array([], dtype=float64), pz=array([], dtype=float64), ord_p=array([], dtype=float64), ord_z=array([], dtype=float64), dB=False)

Calculate frequency response H(f) of H(p) defined by its gain factor, poles and zeroes

Parameters

farray_like

array of f-domain to be transformed to

H0float

gain factor

pparray_like

poles on pz-plane (exclude conjugated poles)

pzarray_like

zeroes on pz-plane (exclude conjugated zeroes)

ord_parray_like

poles’ orders

ord_zarray_like

zeroes’ orders

dBbool

return frq response in dB if true

Returns

_ndarray

calculated frequency response (in dB if parameter dB is true)

Examples

Calculate frequency response of H(p) with gain H0 = 1
poles:

p_p1 = +j, -j (order 1) Note: Exclude conjugated poles!

zeroes:

p_n1 = 0 (order 1)

and return in dB

>>> from rwth_nb.misc.transforms import ilaplace_Hf
>>>
>>> f = numpy.linspace(-6, 6, 1024)
>>> H0 = 1
>>> poles = [1j]  # Exclude conjugated pole
>>> poles_order = [1]
>>> zeroes = [0]
>>> zeroes_order = [1]
>>> dB = True
>>>
>>> H_f = ilaplace_Hf(f, H0, poles, zeroes, poles_order, zeroes_order, dB)

For more examples see primer at rwth_nb/RWTH Transforms.ipynb

rwth_nb.misc.transforms.ilaplace_ht(t=array([-6., -5.98826979, -5.97653959, ..., 5.97653959, 5.98826979, 6.]), H0=1, pp=array([], dtype=float64), pz=array([], dtype=float64), ord_p=array([], dtype=float64), ord_z=array([], dtype=float64), roc=[-12, 12])

Calculate inverse laplace transform h(t) of H(p) defined by its gain factor, poles and zeroes

Parameters

tarray_like

array of t-domain to be transformed to

H0float

gain factor

pparray_like

poles on pz-plane (exclude conjugated poles)

pzarray_like

zeroes on pz-plane (exclude conjugated zeroes)

ord_parray_like

poles’ orders

ord_zarray_like

zeroes’ orders

rocarray_like

region of convergence (range from -infinity to infinity)

Returns

hndarray

calculated inverse Laplace-transform according to t-domain

td: ndarray

dirac’s x coordinate if existing, empty otherwise

sd: ndarray

dirac’s gain factor if existing, empty otherwise

Examples

Calculate inverse Laplace-transform with gain H0 = 1
poles:

p_p1 = -3 (order 1) p_p2 = +1 (order 2)

zeroes:

p_n1 = 0 (order 1)

region of convergence:

1 to infinity

>>> from rwth_nb.misc.transforms import ilaplace_ht
>>>
>>> t = numpy.linspace(-5, 5, 1024)
>>> H0 = 1
>>> poles = [-3, 1]
>>> poles_order = [1, 2]
>>> zeroes = [0]
>>> zeroes_order = [1]
>>> roc = [1, numpy.inf]
>>>
>>> h_t, td, sd = ilaplace_ht(t, H0, poles, zeroes, poles_order, zeroes_order, roc)

For more examples see primer at rwth_nb/RWTH Transforms.ipynb

rwth_nb.misc.transforms.iz_Hf(f=array([-6., -5.98826979, -5.97653959, ..., 5.97653959, 5.98826979, 6.]), H0=1, pp=array([], dtype=float64), pz=array([], dtype=float64), ord_p=array([], dtype=float64), ord_z=array([], dtype=float64), dB=False)

Calculate frequency response H(f) of z-transformed H(z) defined by its gain factor, poles and zeroes

Parameters

farray_like

array of f-domain to be transformed to

H0float

gain factor

pparray_like

poles on pz-plane (exclude conjugated poles)

pzarray_like

zeroes on pz-plane (exclude conjugated zeroes)

ord_parray_like

poles’ orders

ord_zarray_like

zeroes’ orders

dBbool

return frq response in dB if true

Returns

_ndarray

calculated frequency response (in dB if parameter dB is true)

Examples

Calculate frequency response of H(z) with gain H0 = 1
poles:

z_p1/2 = +j, -j (order 1) Note: Exclude conjugated poles!

zeroes:

z_n1 = 0 (order 1)

and return in dB

>>> from rwth_nb.misc.transforms import iz_Hf
>>>
>>> f = numpy.linspace(-6, 6, 1024)
>>> H0 = 1
>>> poles = [1j]  # Exclude conjugated pole
>>> poles_order = [1]
>>> zeroes = [0]
>>> zeroes_order = [1]
>>> dB = True
>>>
>>> H_f = iz_Hf(f, H0, poles, zeroes, poles_order, zeroes_order, dB)

For more examples see primer at rwth_nb/RWTH Transforms.ipynb

rwth_nb.misc.transforms.iz_hn(n=array([-6., -5., -4., -3., -2., -1., 0., 1., 2., 3., 4., 5., 6.]), H0=1, pp=array([], dtype=float64), pz=array([], dtype=float64), ord_p=array([], dtype=float64), ord_z=array([], dtype=float64), roc=[0, 12])

Calculate inverse z-transform h(n) of H(z) defined by its gain factor, poles and zeroes

Parameters

narray_like

array of n-domain to be transformed to

H0float

gain factor

pparray_like

poles on pz-plane (exclude conjugated poles)

pzarray_like

zeroes on pz-plane (exclude conjugated zeroes)

ord_parray_like

poles’ orders

ord_zarray_like

zeroes’ orders

rocarray_like

region of convergence (range from 0 to infinity)

Returns

hndarray

calculated inverse z-transform according to n-domain

Examples

Calculate inverse z-transform with gain H0 = 1
poles:

z_p1 = +0.5 (order 1) z_p2 = +1 (order 2)

zeroes:

z_n1 = +2 (order 1)

region of convergence:

0.5 to 1

>>> from rwth_nb.misc.transforms import iz_hn
>>>
>>> n = [-3, -2, -1, 0, 1, 2, 3]
>>> H0 = 1
>>> poles = [0.5, 1]
>>> poles_order = [1, 2]
>>> zeroes = [2]
>>> zeroes_order = [1]
>>> roc = [0.5, 1]
>>>
>>> h_n = iz_hn(n, H0, poles, zeroes, poles_order, zeroes_order, roc)