period Module

average_rectified_sections(data)

Returns a slice of an oscillating data vector based on the max and min of the mean of the sections created by retifiying the data.

Parameters:
datandarray, shape(n,)
Returns:
datandarray, shape(m,)

A slice where m is typically less than n.

Notes

This is a function to try to handle the fact that some of the data from the torsional pendulum had a beating like phenomena and we only want to select a section of the data that doesn’t seem to exhibit the phenomena.

calc_periods_for_files(directory, filenames, forkIsSplit)

Calculates the period for all filenames in directory.

Parameters:
directorystring

This is the path to the RawData directory.

filenameslist

List of all the mat file names in the RawData directory.

forkIsSplitboolean

True if the fork is broken into a handlebar and fork and false if the fork and handlebar was measured together.

Returns:
periodsdictionary

Contains all the periods for the mat files in the RawData directory.

check_for_period(mp, forkIsSplit)

Returns whether the fork is split into two pieces and whether the period calculations need to happen again.

Parameters:
mpdictionary

Dictionary the measured parameters.

forkIsSplitboolean

True if the fork is broken into a handlebar and fork and false if the fork and handlebar was measured together.

Returns:
forcePeriodCalcboolean

True if there wasn’t enough period data in mp, false if there was.

forkIsSplitboolean

True if the fork is broken into a handlebar and fork and false if the fork and handlebar was measured together.

fit_goodness(ym, yp)

Calculate the goodness of fit.

Parameters:
ymndarray, shape(n,)

The vector of measured values.

ypndarry, shape(n,)

The vector of predicted values.

Returns:
rsqfloat

The r squared value of the fit.

SSEfloat

The error sum of squares.

SSTfloat

The total sum of squares.

SSRfloat

The regression sum of squares.

get_period(data, sample_rate_or_time, pathToPlotFile)

Returns the period and uncertainty for data resembling a decaying oscillation.

Parameters:
dataarray_like, shape(n,)

A time series that resembles a decaying oscillation.

sample_rate_or_timeint or array_like, shape(n,)

Either the frequency in Hertz that data was sampled at or a time array that corresponds to data.

pathToPlotFilestring

A path to the file to print the plots.

Returns:
Tufloat

The period of oscillation and its uncertainty.

get_period_from_truncated(data, sampleRate, pathToPlotFile)
get_period_key(matData, forkIsSplit)

Returns a dictionary key for the period entries.

Parameters:
matDatadictionary

The data imported from a pendulum mat file.

forkIsSplitboolean

True if the fork is broken into a handlebar and fork and false if the fork and handlebar was measured together.

Returns:
keystring

A key of the form ‘T[pendulum][part][orientation]’. For example, if it is the frame that was hung as a torsional pendulum at the second orientation angle then the key would be ‘TtB2’.

get_sample_rate(matData)

Returns the sample rate for the data.

jac_fitfunc(p, t)

Calculate the Jacobian of a decaying oscillation function.

Uses the analytical formulations of the partial derivatives.

Parameters:
pthe five parameters of the equation
ttime vector
Returns:
jacThe jacobian, the partial of the vector function with respect to the
parameters vector. A 5 x N matrix where N is the number of time steps.
make_guess(data, sampleRate)

Returns a decent starting point for fitting the decaying oscillation function.

plot_osfit(t, ym, yf, p, rsq, T, m=None, fig=None)

Plot fitted data over the measured

Parameters:
tndarray (n,)

Measurement time in seconds

ymndarray (n,)

The measured voltage

yfndarray (n,)
pndarray (5,)

The fit parameters for the decaying oscillation function.

rsqfloat

The r squared value of y (the fit)

Tfloat

The period

mfloat

The maximum value to plot

Returns:
figthe figure
select_good_data(data, percent)

Returns a slice of the data from the index at maximum value to the index at a percent of the maximum value.

Parameters:
datandarray, shape(n,)

This should be a decaying function.

percentfloat

The percent of the maximum to clip.

This basically snips of the beginning and end of the data so that the super
damped tails are gone and also any weirdness at the beginning.