pydarm package

Submodules

pydarm.fir module

class pydarm.fir.FIRFilterFileGeneration(config, fir_config=None)

Bases: DARMModel

FIR filter file generation.

CALCS_corr(output_filename='CALCS_corr.h5', output_dir='.', plots_directory='../examples/CALCS_corr_plots')

CALCS correction FIR filter generation

Parameters:
output_filenamestr

Output filename base

output_dirstr

Directory to which to save FIR filters file

plots_directorystr

Directory to which to save diagnostic plots

Returns:
output_filename, diagnostic plots of filters
DCS(output_filename='DCS.npz', output_dir='.', plots_directory='../examples/DCS_plots')

DCS FIR filter generation

Parameters:
output_filenamestr

Output filename

output_directorystr

Directory to which to save FIR filters file

plots_directorystr

Directory to which to save diagnostic plots.

Returns:
output_filename, diagnostic plots of filters
GDS(output_filename='GDS.npz', output_dir='.', plots_directory='../examples/GDS_plots')

GDS FIR filter generation

Parameters:
output_filenamestr

Output filename

output_dirstr

Directory to which to save FIR filters file

plots_directorystr

Directory to which to save diagnostic plots.

Returns:
output_filename, diagnostic plots of filters
class pydarm.fir.FIRfilter(fNyq=8192, desired_dur=1.0, highpass_fcut=None, lowpass_fcut=None, window_type='dpss', freq_res=3.0)

Bases: object

Model parameters for FIR filter creation

Parameters:
fNyqint, optional

Nyquist frequency of FIR filter

durfloat, optional

Duration in seconds of FIR filter

highpass_fcutfloat, optional

Cut off frequency for high-pass filter

lowpass_fcutfloat, optional

Cut off frequency for low-pass filter (relevant for inverse sensing filter)

window_typestr, optional

Type of window function to use. Options are ‘dpss’, ‘kaiser’, ‘dolph_chebyshev’, and ‘hann’.

freq_res: `float`, optional

Frequency resolution of the FIR filter, computed as half the width of

Returns:
FIRfilterlist

List of model parameters for FIR filter creation parameters

check_td_vs_fd(tdfilt, fdmodel, filename='td_vs_fd.png', plot_title='Frequency Response', legend=['FIR filter', 'DARM model'], samples_per_lobe=8, ymax_increase=1)

Checking time-domain vs frequency-domain filters

Parameters:
tdfilt

array of time domain filter

fdmodel

array of frequency domain model

filename

str for filename for plot output

plot_title

str for title of plot

legend

str, array-like for plot legend titles

samples_per_lobe

int for factor to upsample by for finer frequency resolution

ymax_increase

int for factor above max y array value to display in plot

Returns:
plot of filter and model comparison
freq_array:

frequency array for comparison

mag_ratio:

array of magnitude comparison

phase_diff:

array of phase differences

create_fir_filter(static_model, save_to_file=None)

Generate an FIR filter based on provided frequency-domain model

Parameters:
static_modelarray-like

Transfer function of frequency domain model

save_to_filestr, optional

Filename (NPZ) to save the data from this result

Returns:
model_FIRfloat64, array-like

A time domain FIR filter model

double_modelfloat, array-like

An array of real doubles FIR filter model

pydarm.fir.check_td_vs_fd_response(invsens_filt, invsens_highpass, TST_filt, PUM_filt, UIM_filt, act_highpass, D, R, invsens_fNyq=8192, invsens_highpass_fNyq=1024, act_fNyq=1024, D_fNyq=8192, R_fNyq=8192, invsens_delay=None, invsens_highpass_delay=None, act_delay=None, act_highpass_delay=None, time_delay=6.103515625e-05, filename='td_vs_fd_response.png', plot_title='Response Function', legend=['FIR filters', 'DARM model'])

Checking time-domain vs frequency-domain responses

Parameters:
invsens_filtarray
invsens_highpassarray
TST_filtarray-like
PUM_filtarray-like
UIM_filtarray-like
act_highpassarray
Darray
Rarray
invsens_fNyqfloat, int
invsens_highpass_fNyqfloat, int
act_fNyqfloat, int
D_fNyqfloat, int
R_fNyqfloat, int
invsens_delayfloat, int
invsens_highpass_delayfloat, int
act_delayfloat, int
act_highpass_delayfloat, int
time_delayfloat, int
filenamestr
plot_titlestr
legendstr, array-like
Returns:
plot figure
pydarm.fir.correctFIRfilter(FIRpars, tdfilt, fdmodel, window_correction_range, save_to_file=None)

Correct FIR filter production errors induced by windowing, and return a compensated version of the frequency-domain model.

pydarm.firtools module

pydarm.firtools.DPSS(N, alpha, return_double=False, max_time=10)

DPSS window

Compute a discrete prolate spheroidal sequence (DPSS) window, which maximizes the energy concentration in the central lobe.

Parameters:
Nfloat

length

alphafloat

parameter

return_doublebool, optional

double or longdouble

max_timeint, optional

maximum

Returns:
outputlongdouble, array-like

the filter

pydarm.firtools.DolphChebyshev(N, alpha, return_double=False)

Dolph-Chebyshev window

Parameters:
Nfloat, int
alphafloat, int
return_doubleTrue or False
Returns:
win / win[N // 2]array-like
pydarm.firtools.compute_Tn(x, n)

A function for Dolph-Chebyshev window

Parameters:
xfloat, int
nfloat, int
Returns:
+- np.cos or cosh(n * np. arccos or arcosh(+-x))float
pydarm.firtools.compute_W0_lagged(N, alpha)

A function for Dolph-Chebyshev window

Parameters:
Nfloat, int
alphafloat, int
Returns:
W0array-like
pydarm.firtools.dft(td_data, exp_array=None, return_double=False, inverse=False)

First, a discrete Fourier transform, evaluated according to the definition

Parameters:
td_dataarray
exp_array‘array-like’
return_doubleTrue or False
inverseTrue or False
Returns:
fd_dataarray
pydarm.firtools.fft(td_data, prime_factors=None, exp_array=None, return_double=False, inverse=False, M=None, M_prime_factors=None, M_exp_array2=None, M_exp_array=None)

A fast Fourier transform using the Cooley-Tukey algorithm, which factors the length N to break up the transform into smaller transforms.

Parameters:
td_dataarray
prime_factorsfloat, int
exp_array‘array-like’
return_doubleTrue or False
inverseTrue or False
M
M_prime_factors
M_exp_array2
M_exp_array
Returns:
fd_dataarray-like
pydarm.firtools.find_M(M_min)

For Bluestein’s algorithm. Find a good padded length.

Parameters:
M_minfloat
Returns:
tupleint of M and prime factors
pydarm.firtools.find_exp_array(N, inverse=False)

A function to compute the array of exponentials.

Parameters:
Nfloat
inverseTrue or False
Returns:
exp_arrayarray-like
pydarm.firtools.find_exp_array2(N, inverse=False)

A function to compute the array of exponentials for Bluestein’s algorithm.

Parameters:
Nfloat
inverseTrue or False
Returns:
exp_arrayarray-like
pydarm.firtools.find_prime_factors(N)

A function to find prime factors of N, the size of the input data.

Parameters:
Nfloat, ‘array-like’
Returns:
prime_factorsarray-like
pydarm.firtools.freqresp(filt, delay_samples=0, samples_per_lobe=8, return_double=False)

A function to get the frequency-responce of an FIR filter, showing the lobes.

Parameters:
filtarray
delay_samplesfloat, int
samples_per_lobefloat, int
return_doubleTrue or False
Returns:
rfft(filt_prime, return_double=return_double)array-like
pydarm.firtools.ifft(fd_data, prime_factors=None, exp_array=None, return_double=False, normalize=True)

An inverse fast Fourier transform that factors the length N to break up the transform into smaller transforms

Parameters:
fd_dataarray
prime_factorsfloat, int
exp_array‘array-like’
return_doubleTrue or False
normalizeTrue or False
Returns:
td_dataarray-like
pydarm.firtools.irdft(fd_data, exp_array=None, return_double=False, N=None, normalize=True)

Inverse of the above real-input DFT. So the output of this is real and the input is assumed to be shortened to N // 2 + 1 samples to avoid redundancy.

Parameters:
fd_dataarray
exp_arrayfloat, array-like, optional
return_doublebool, optional
Nint, optional
normalizebool, optional
Returns:
td_datafloat, array-like
pydarm.firtools.irfft(fd_data, prime_factors=None, exp_array=None, return_double=False, normalize=True, M_fft=None, M_fft_prime_factors=None, M_fft_exp_array2=None, M_fft_exp_array=None, M_irfft=None, M_irfft_prime_factors=None, M_irfft_exp_array2=None, M_irfft_exp_array=None)

Inverse of the above real-input FFT. So the output of this is real and the input is assumed to be shortened to N // 2 + 1 samples to avoid redundancy.

Parameters:
fd_dataarray
prime_factorsfloat, int
exp_array‘array-like’
return_doubleTrue or False
M_fftfloat
M_fft_prime_factorsfloat, int
M_fft_exp_array2‘array-like’
M_fft_exp_array‘array-like’
M_irfft :float, int
M_irfft_prime_factorsfloat, int
M_irfft_exp_array2‘array-like’
M_irfft_exp_array‘array-like’
Returns:
fd_dataarray-like
pydarm.firtools.mat_times_vec(mat, vec)

A function to multiply a symmetric Toeplitz matrix times a vector and normalize. Assume that only the first row of the matrix is stored, to save memory. Assume that only half of the vector is stored, due to symmetry.

Parameters:
matarray-like
vecarray-like
Returns:
outputarray-like
pydarm.firtools.prime_fft(td_data, return_double=False, inverse=False, exp_array2=None, M=None, prime_factors=None, exp_array=None)

Bluestein’s algorithm for FFTs of prime length, for which the Cooley-Tukey algorithm is ineffective. Make the replacement nk -> -(k - n)^2 / 2 + n^2 / 2 + k^2 / 2. Then X_k = sum_(n=0)^(N-1) x_n * exp(-2*pi*i*n*k/N) = exp(-pi*i*k^2/N) * sum_(n=0)^(N-1) x_n * exp(-pi*i*n^2/N) * exp(pi*i*(k-n)^2/N) This can be done as a cyclic convolution between the sequences a_n = x_n * exp(-pi*i*n^2/N) and b_n = exp(pi*i*n^2/N), with the output multiplied by conj(b_k). a_n and b_n can be padded with zeros to make their lengths a power of 2. The zero-padding for a_n is done simply by adding zeros at the end, but since the index k - n can be negative and b_{-n} = b_n, the padding has to be done differently. Since k - n can take on 2N - 1 values, it is necessary to make the new arrays a length N’ >= 2N - 1. The new arrays are

|– | a_n, 0 <= n < N

A_n = -|
0, N <= n < N’

|

|– | b_n, 0 <= n < N

B_n = -| 0, N <= n <= N’ - N
b_{N’-n}, N’ - N <= n < N’

|

The convolution of A_n and B_n can be evaluated using the convolution theorem and the Cooley-Tukey FFT algorithm: X_k = conj(b_k) * ifft(fft(A_n) * fft(B_n))[:N]

Parameters:
td_dataarray
return_doublebool, optional
inversebool, optional
exp_array2float, array-like, optional
Mfloat, optional
prime_factorsfloat, int
exp_arrayfloat, array-like, optional
Returns:
fd_datacomplex, array-like
pydarm.firtools.prime_irfft(fd_data, return_double=False, N=None, normalize=True, exp_array2=None, M=None, prime_factors=None, exp_array=None)

Inverse of the above real-input FFT. So the output of this is real and the input is assumed to be shortened to N // 2 + 1 samples to avoid redundancy.

Parameters:
fd_dataarray
prime_factorsfloat, int
exp_array‘array-like’
return_doubleTrue or False
normalizeTrue or False
Nfloat
Mfloat
exp_array2array-like
Returns:
td_dataarray-like
pydarm.firtools.prime_rfft(td_data, return_double=False, return_full=False, exp_array2=None, M=None, prime_factors=None, exp_array=None)

If the input is real, the output is conjugate-symmetric: fd_data[n] = conj(fd_data[N - n]) We can reduce the number of operations by a factor of ~2. Also, we have the option to only output half of the result, since the second half is redundant.

Parameters:
td_dataarray
prime_factorsfloat, int
exp_array‘array-like’
return_doubleTrue or False
return_fullTrue or False
Mfloat
exp_array2array-like
Returns:
fd_dataarray-like
pydarm.firtools.rdft(td_data, exp_array=None, return_double=False, return_full=False)

If the input is real, the output is conjugate-symmetric: fd_data[n] = conj(fd_data[N - n]). We can reduce the number of operations by a factor of ~2. Also, we have the option to only output half of the result, since the second half is redundant.

Parameters:
td_dataarray
exp_arrayfloat, array-like, optional
return_doublebool, optional
return_fullbool, optional
Returns:
fd_dataarray
pydarm.firtools.resample(data, N_out, return_double=False)

A resampler

Parameters:
dataarray
N_outfloat, int
return_doubleTrue or False
Returns:
resampledfloat, array-like
pydarm.firtools.rfft(td_data, prime_factors=None, exp_array=None, return_double=False, return_full=False, M=None, M_prime_factors=None, M_exp_array2=None, M_exp_array=None)

If the input is real, the output is conjugate-symmetric: fd_data[n] = conj(fd_data[N - n]) We can reduce the number of operations by a factor of ~2. Also, we have the option to only output half of the result, since the second half is redundant.

Parameters:
td_dataarray
prime_factorsfloat, int
exp_array‘array-like’
return_doubleTrue or False
return_fullTrue or False
Mfloat, int
M_exp_array2array-like
M_prime_factorsarray-like
Returns:
fd_dataarray-like
pydarm.firtools.two_tap_zero_filter_response(zeros, sr, freq)

Generating two-tap zero filter

Parameters:
zerosfloat, int
srfloat, int
freqarray
Returns:
two_taparray

pydarm.actuation module

class pydarm.actuation.ActuationModel(config, measurement)

Bases: Model

An arm actuation model object

This is a class to set up the model for the actuation function from a configuration file with all the information about where the data is stored

actuation_stage_residual(frequencies, stage='TST')

This is the actuation residual for a given stage on a given arm (this object), meaning it contains everything in the actuation except for the output matrix, the digital distribution filters, the actuator gain, and suspension dynamics.

See T1900169

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

stagestr, optional

UIM, PUM or TST (default = ‘TST’)

Returns:
A_mn_rescomplex128, array-like

transfer function response of the residual actuation function

analog_driver_response(frequencies)

The transfer function of the analog driver electronics. By default, the output will be a dictionary for UIM, PUM, and TST with dictionaries for each containing the quadrants UL, LL, UR, LR. Transfer functions are unity with zero phase unless the params file/string contains a <uim|pum|tst>_driver_meas_<z|p>_<ul|ll|ur|lr> for the particular quadrant and values

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
outdict, complex128, array-like

transfer function response of the uncompensated driver electronics

combine_sus_quadrants(frequencies)

Combine the digital and analog paths for the SUS quadrants on a per-stage and per-path basis. Meaning (0.25 x UIM UL digital x UIM UL analog + 0.25 x UIM LL digital x UIM LL analog + …) and so on for each stage

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
uimdict, complex128, array-like

transfer function response of the digital compensation filters in each path and quadrant for the UIM

pumdict, complex128, array-like

transfer function response of the digital compensation filters in each path and quadrant for the PUM

tstdict, complex128, array-like

transfer function response of the digital compensation filters in each path and quadrant for the TST

compute_actuation_single_stage(frequencies, stage='TST')

Compute the actuation function transfer function for a single stage (see G1501518). This transfer function is from the DARM control input at the SUS user model, or the input to the ISCINF bank, to DARM displacement.

This does not include the OMC to SUS model jump delay

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

stagestr, optional

UIM, PUM or TST (default = ‘TST’)

Returns:
tfcomplex128, array-like

transfer function response of the actuation function

digital_out_to_displacement(frequencies)

This computes the transfer function from the output of the DRIVEALIGN filter bank of each stage to displacement of the test mass

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
uim_responsecomplex128, array-like

transfer function response of the UIM stage

pum_responsecomplex128, array-like

transfer function response of the PUM stage

tst_responsecomplex128, array-like

transfer function response of the TST stage

drivealign_to_darm_displacement(frequencies)

This computes the transfer function from the input of the DRIVEALIGN filter bank of each action stage to DARM by accounting for how positive longitudinal drive for each actuation stage pushes the given test mass to creates DARM.

DARM displacement is defined by

\[+ DARM = + Delta L \ = (Delta L_X - Delta L_Y) \ = - (Delta L_EX + Delta L_IX) + (Delta L_EY + Delta L_IY)\]

This is particularly useful for computing EPICS records

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
uim_responsecomplex128, array-like

transfer function response of the UIM stage

pum_responsecomplex128, array-like

transfer function response of the PUM stage

tst_responsecomplex128, array-like

transfer function response of the TST stage

drivealign_to_longitudinal_displacement(frequencies)

This computes the transfer function from the input of the DRIVEALIGN filter bank of each stage to displacement of the test mass where “longitudinal” is defined as in the traditional SUS Euler Basis: positive longitudinal displacement is along a vector perpendicular to the plane of the HR surface (positive ETMX displacement is in the -X global IFO direction, positive ITMY displacement is in the +Y global IFO direction).

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
uim_responsecomplex128, array-like

transfer function response of the UIM stage

pum_responsecomplex128, array-like

transfer function response of the PUM stage

tst_responsecomplex128, array-like

transfer function response of the TST stage

known_actuation_terms_for_measurement(frequencies)

This method computes all known terms which are divided out of the DARM_ERR / SUS_EXC full IFO actuation measurement for each stage such that the remaining dimensional actuation strength, H_Ai, can be fit by MCMC.

This computes the transfer function from the input of the DRIVEALIGN filter bank (same as the SUS_EXC point) of each stage to DARM displacement from any test mass, including everything except the N/(drive unit); either amps or volts**2, for which the MCMC will fit. The DARM feedback sign of the arm the measurement is taken on since we read out the measurement with DARM_ERR.

This method is essentially computing drivealign_to_darm_displacement / dc_gain_Npct * dc_gain_?pct where ? is A or V2, but we write all of this out explicitly because we want to be able to compute the transfer function without knowing in advance anything about NpA or NpV2

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
uim_responsecomplex128, array-like

transfer function response of the UIM stage, everything but N/ct

pum_responsecomplex128, array-like

transfer function response of the PUM stage, everything but N/ct

tst_responsecomplex128, array-like

transfer function response of the TST stage, everything but N/ct

static matlab_force2length_response(suspension_file, frequencies)

Load the ZPK output from the matlab exported values and output a frequency response. This function expects variables in a .mat file to be UIMz, UIMp, UIMk, PUMz, PUMp, PUMk, TSTz, TSTp, and TSTk

Parameters:
suspension_file: `str`

path and filename to .mat file that has the ZPK arrays

frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
UIM_F2L_freqrespcomplex128, array-like

transfer function response of the UIM stage

PUM_F2L_freqrespcomplex128, array-like

transfer function response of the PUM stage

TST_F2L_freqrespcomplex128, array-like

transfer function response of the TST stage

pum_dc_gain_Apct()

This computes the PUM DC gain in units of amps / count

pum_dc_gain_Npct()

This computes the PUM DC gain in units of Newtons / count

sus_digital_compensation_response(frequencies)

The transfer function of the SUS compensation filters for driver electronics. By default, the output will be a dictionary for UIM, PUM, and TST with dictionaries for each containing the quadrants UL, LL, UR, LR. Transfer functions are unity with zero phase unless the params file/string contains: <uim|pum|tst>_compensation_filter_bank_<ul|ll|ur|lr> with a name; <uim|pum|tst>_compensation_filter_modules_in_use_<ul|ll|ur|lr> with list of modules turned on; and <uim|pum|tst>_compensation_filter_gain_<ul|ll|ur|lr>

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
outdict, complex128, array-like

transfer function response of the digital compensation filters in each path and quadrant

sus_digital_filters(frequencies)

The transfer function of the SUS digital filters

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
tst_isc_inf_filter_responsecomplex128, array-like

transfer function response of the ISC_INF digital filters in the TST path

tst_lock_filter_responsecomplex128, array-like

transfer function response of the LOCK digital filters in the TST path

tst_drive_align_filter_responsecomplex128, array-like

transfer function response of the DRIVEALIGN digital filters in the TST path

pum_lock_filter_responsecomplex128, array-like

transfer function response of the LOCK digital filters in the PUM path

pum_drive_align_filter_responsecomplex128, array-like
transfer function response of the DRIVEALIGN digital filters in the

PUM path

uim_lock_filter_responsecomplex128, array-like

transfer function response of the LOCK digital filters in the UIM path

uim_drive_align_filter_responsecomplex128, array-like

transfer function response of the DRIVEALIGN digital filters in the UIM path

sus_digital_filters_response(frequencies)

The transfer function of the SUS digital filters

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
uim_digital_filter_responsecomplex128, array-like

transfer function response of the digital filters in the UIM path

pum_digital_filter_responsecomplex128, array-like

transfer function response of the digital filters in the PUM path

tst_digital_filter_responsecomplex128, array-like

transfer function response of the digital filters in the TST path

tst_dc_gain_Npct()

This computes the TST DC gain in units of Newtons / count

tst_dc_gain_V2pct()

This computes the TST DC gain in units of volts**2 / count

uim_dc_gain_Apct()

This computes the UIM DC gain in units of amps / count

uim_dc_gain_Npct()

This computes the UIM DC gain in units of Newtons / count

class pydarm.actuation.DARMActuationModel(config)

Bases: Model

An DARM actuation model object

This is a class to set up the model for the DARM loop from a configuration file with all the information about where the data is stored

arm_super_actuator(frequencies, arm='x', syserr_dict=None)

Compute the super actuator transfer function for a specific arm. In this case, the “arm super actuator” is created by choosing a specific arm and then for each QUAD, the arm transfer function to DARM is summed together.

This transfer function is from DARM_CTRL to meters sensed by the IFO. Note that the sign of the DARM_ERR signal is dependent upon which arm is under control.

The OMC to SUS delay is included in this transfer function.

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

armstr

arm for the calculation, ‘x’ or ‘y’

syserr_dictdict, optional

dict of multiplicative values, ex.: {‘xarm’: {‘UIM’: complex, array-like}}

Returns:
super_actuationcomplex128, array-like

transfer function response of the actuation function

compute_actuation(frequencies, syserr_dict=None)

Compute the entire actuation function transfer function (see G1501518). This transfer function is from DARM_CTRL to meters sensed by the IFO. Note that the sign of the DARM_ERR signal is dependent upon which arm is under control.

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

syserr_dictdict, optional

dict of multiplicative values, ex.: {‘xarm’: {‘UIM’: complex, array-like}}

Returns:
tfcomplex128, array-like

transfer function response of the actuation function

darm_output_matrix_values()

Turns the output matrix values into an array for the QUAD SUS

stage_super_actuator(frequencies, stage='TST', syserr_dict=None)

Compute the super actuator transfer function for a specific stage. In this case, the “stage super actuator” is created by choosing a specific stage and then for each QUAD, the stage transfer function to DARM is summed together.

This transfer function is from DARM_CTRL to meters sensed by the IFO. Note that the sign of the DARM_ERR signal is dependent upon which arm is under control.

The OMC to SUS delay is included in this transfer function.

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

stagestr, optional

SUS stage for the calculation, ‘UIM’, ‘PUM’, or ‘TST’

syserr_dictdict, optional

dict of multiplicative values, ex.: {‘xarm’: {‘UIM’: complex, array-like}}

Returns:
super_actuationcomplex128, array-like

transfer function response of the actuation function

stage_super_actuator_drivealign(frequencies, stage='TST', syserr_dict=None)

Compute the super actuator transfer function for a specific stage. In this case, the “stage super actuator” is created by choosing a specific stage and then for each QUAD, the stage transfer function to DARM is summed together.

This transfer function is from the input of the DRIVEALIGN filter bank to meters sensed by the IFO. This method assumes that the signal feedback to a single stage would be positive, but if the signal is sent to both arms (like a DARM signal) then X and Y are 180 degrees out of phase.

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

stagestr

SUS stage for the calculation, ‘UIM’, ‘PUM’, or ‘TST’

syserr_dictdict, optional

dict of multiplicative values, ex.: {‘xarm’: {‘UIM’: complex, array-like}}

Returns:
super_actuationcomplex128, array-like

transfer function response of the actuation function

pydarm.analog module

pydarm.analog.analog_aa_or_ai_filter_response(mat_file, frequencies)

This comes from an export of a Matlab LTI object which was a fit of measurements made at LHO and LLO by JeffK, JoeB, et al. The object has zeros, poles, gain, and a delay, so the exported mat-file has the arrays of zeros and poles, gain, and delay in the file. Measurements were made around ER7. TODO: find alog entries?

Parameters:
mat_filestr

path and filename of the Matlab mat-file export

frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
tfcomplex128, array-like

transfer function response of the analog AA or AI filter

pydarm.calcs module

class pydarm.calcs.CALCSModel(config, calcs=None)

Bases: DARMModel

A_corr(frequencies, daqdownsample=True)

Compute total DARM actuator A_corr = A / A_foton (aka delta A), see T1900169.

This is more complicated than computing C_corr, since the GDS actuation correction is applied to each stage separately, so we cannot just sum the corrections and multiply by a common factor. Instead, we compute the modeled (true) DARM actuation, and divide by the CALCS (approximate) DARM actuation. We also account for the OMC to CALCS delay and the possibility for DAQ downsampling.

DAQ downsample is an option here because if you want to create delta L_ctrl from ${IFO}:CAL-DELTAL_CTRL_DBL_DQ, then we need to use daqdownsampling = True because the channel that is read has been downsampled. When computing the delay between CAL-DELTAL_CTRL and CAL-DELTAL_RESIDUAL to improve CAL-DELTAL_EXTERNAL, however, one does not need daqdownsampling (see discussion in sec III of T1900169).

Both products are using the CALCS copy of DARM_CTRL and therefore need the delay (OMC to CALCS)

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the GDS sensing correction

daqdownsamplebool, optional

When True (default), the 16k-4k daqdownsample is applied in A_corr

Returns:
A_corrcomplex128, array-like

transfer function response of the correction

C_corr(frequencies)

Compute delta C = delay*(opt resp)/(opt resp)_foton*C_r

The inverse of this transfer function is multiplied by DELTAL_RESIDUAL as the GDS correction.

We need to divide out the normalized optical response FOTON filter only and be sure to include 1 16k clock cycle delay from the model jump OMC to CAL-CS. There is an optical gain factor in the front end model, but it is fine to leave this in place. The output is basically C_pydarm / C_foton, and GDS will need to either divide the DELTAL_RESIDUAL data by this function or invert the output of this function and multiply by the DELTAL_RESIDUAL data.

This is delay*(opt resp)/(opt resp)_foton*C_r (see T1900169-v5 eq 33)

This is also known as C_corr or delta C in T1900169

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the GDS sensing correction

Returns:
tfcomplex128, array-like

transfer function response of the correction

arm_super_actuator(frequencies, arm='x')

Compute the super actuator transfer function for a specific arm. In this case, the “arm super actuator” is created by choosing a specific arm and then for each QUAD, the arm transfer function to DARM is summed together.

This transfer function is from DARM_CTRL to meters sensed by the IFO. Note that the sign of the DARM_ERR signal is dependent upon which arm is under control.

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

armstr, optional

SUS stage for the calculation, ‘UIM’, ‘PUM’, or ‘TST’

Returns:
super_actuationcomplex128, array-like

transfer function response of the actuation function

calcs_darm_actuation(frequencies)

Compute the CALCS approximated DARM actuation. This method implicitly assumes that the CALCS DARM output matrix and actuation digital filtering matches the installed in-loop DARM ouput matrix and actuation digital filtering.

See T1900169, definition of A_CALCS

Parameters:
frequenciesfloat, array-like

array of frequencies for the CALCS approximated DARM actuation

Returns:
calcs_actuationcomplex128, array-like

Residual phase after removing the simulated delay

calcs_dtt_calibration(frequencies, include_whitening=True, strain_calib=False, save_to_file=None, fmt=None)

Compute the calibration transfer function, dL_pyDARM / dL_CALCS for the main control room calibrated sensitivity curve. One can save this data to a file with the needed frequency, dB magnitude, and degrees phase columns, and apply it to a DTT template.

See T1900169 section IV

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the CAL_DELTAL_EXTERNAL DTT calibration

include_whiteningbool, optional

if the whitening filter is on (default), then we’d like to remove its effect so by default this divides out the whitening filter

strain_calibbool, optional

the output defaults to dL_pyDARM/dL_CALCS, so that we can recalibrate CAL-DELTAL_EXTERNAL. If this option is True, then the output is h_pyDARM/dL_CALCS

save_to_filestr, optional

Filename (ASCII) to save the data from this result. Note: the default file columns are <frequency> <magnitude (dB)> <phase (deg)>

fmtstr, optional

if save_to_file is used, then this is the output format. Options are ‘dB,deg’ (default), ‘mag,deg’, ‘dB,rad’, ‘mag,rad’, or ‘re,im’. If none is given, then the default is used

Returns:
tfcomplex128, array-like

transfer function response of the calibration

compute_actuation_single_stage(frequencies, arm, stage)

A_n,calcs

CALCS approximation of a specific arm, stage from input to SUS ISCINF to DARM (and therefore does not include the OMC to CALCS delay) displacement. See T1900169

Parameters:
frequenciesfloat, array-like

array of frequencies for the CALCS approximated DARM actuation

armstr

arm for the calculation, ‘x’ or ‘y’

stagestr

SUS stage for the calculation, ‘UIM’, ‘PUM’, or ‘TST’

Returns:
calcs_stage_actuationcomplex128, array-like

CALCS approximation of SUS model ISCINF input to DARM displacement transfer function

compute_epics_records(gds_pcal_endstation=False, gds_sus_endstation=False, gds_darm_omc=False, exact=False)

Generate EPICS values for CALCS front-end model time dependent correction factors

This is a LIGO specific function for generating front end calibration EPICS records. The GDS pipeline reads these EPICS records and together with channels read from frames computes TDCFs. If GDS reads channels from the end station or OMC models rather than CALCS, then the CALCS model will need to get phase values assigned to DEMODs in order to have the proper synchronization. The default assumes that GDS reads all channels from CALCS

See T1700106-v10 and G1601472 for additional details

Parameters:
gds_pcal_endstationbool, optional

When false (default), the correction is computed for CAL-CS PCAL channel, which includes 1 16k clock cycle delay that we must compensate (undo). Otherwise, when true, the correction is computed at the end station, which does not include 1 16k clock cycle delay

gds_sus_endstationbool, optional

When false (default), the correction is computed for CAL-CS SUS channel, which includes 1 16k clock cycle delay that we must compensate (undo). Otherwise, when true, the correction is computed at the end station, which does not include 1 16k clock cycle delay

gds_darm_omcbool, optional

When false (default), the correction is computed for CAL-CS DARM ERR channel, which includes 1 16k clock cycle delay that we must compensate (undo). Otherwise, when true, the correction is computed at the OMC, which does not include 1 16k clock cycle delay

exactbool, optional

When True, the exact TDCF transfer function calculations are updated in the output dictionary. This will append new values to the output dictionary

Returns:
outdict

Dictionary of EPICS records

deltal_ext_pcal_correction(frequencies, **kwargs)

Compute the calibration transfer function, dL_pyDARM / dL_Pcal for determining the response function systematic error

See T1900169 section V

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the CAL_DELTAL_EXTERNAL DTT calibration

kwargsoptional

values are passed to calcs.calcs_dtt_calibration() and pcal.compute_pcal_correction()

Returns:
tfcomplex128, array-like

transfer function resposne of the correction factor

deltal_ext_whitening(frequencies)

Compute the interpolated transfer function of the DELTAL_EXTERNAL export from FOTON

If no export file is provided in the configuration, this method will return an array of ones

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the interpolation

Returns:
whitening_interpcomplex128, array-like

transfer function response of the calibration

drivealign_out_to_darm_displacement(frequencies, arm, stage)

CALCS representation of the SUS_EXC DRIVEALIGN point to DARM displacement transfer function.

Units are m/ct = (N/ct) * (m/N)

The gain (N/ct) of the CALCS model is assumed to be exactly the same as what is in the reference model, so that is used.

If there is anything in the “coiloutf” key-value pair, then this transfer function is also used, but this would be used only in special circumstances.

Parameters:
frequenciesfloat, array-like

array of frequencies

armstr

arm for the calculation, ‘x’ or ‘y’

stagestr

SUS stage for the calculation, ‘UIM’, ‘PUM’, or ‘TST’

Returns:
tfcomplex128, array-like

CALCS approximation of the DRIVEALIGN output to DARM displacement

drivealign_out_to_longitudinal_displacement(frequencies, arm, stage)

CALCS representation of the transfer function from the DRIVEALIGN bank to longitudinal displacement of the test mass. Units are m/ct = (N/ct) * (m/N)

The gain (N/ct) of the CALCS model is assumed to be exactly the same as what is in the reference model, so that is used. If any digital gain is present as <arm>_<stage>_analog_gain, then it will be applied here.

If there is anything in the “coiloutf” key-value pair, then this transfer function is also used, but this would be used only in special circumstances.

Parameters:
frequenciesfloat, array-like

array of frequencies for the CALCS approximated longitudinal actuation of the test mass from the given stage

armstr

arm for the calculation, ‘x’ or ‘y’

stagestr

SUS stage for the calculation, ‘UIM’, ‘PUM’, or ‘TST’

Returns:
out_tfcomplex128, array-like

CALCS approximation of the DRIVEALIGN output to displacement

gds_actuation_correction(frequencies, stage, daqdownsample=True)

Compute the correction to the CAL-CS output for GDS. Note that this implicitly assumes that the front end digital filters in CALCS is the same as that in the SUS path!

This is also more complicated than sensing because there is a single channel for a given stage that accounts for BOTH arms; e.g., ${IFO}:CAL-DELTAL_CTRL_${STAGE}_DBL_DQ takes input from both x and y arms using an output matrix.

This is (A_{xn}+A_{yn})/(A_{xn,calcs}+A_{yn,calcs})/(F*delay) where n is the stage, calcs denotes FOTON implementation of an actuator F is the DAQ downsampling filter (on by default), and delay of the 1 16384 clock cycle delay going from OMC to CALCS

See T1900169, definition of delta A_n

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the GDS sensing correction

stagestr

SUS stage for the calculation, ‘UIM’, ‘PUM’, or ‘TST’

daqdownsamplebool, optional

When True (default), the 16k-4k daqdownsample is applied in GDS actuation correction

Returns:
correctioncomplex128, array-like

transfer function response of the correction

gds_sensing_correction(frequencies)

Compute 1 / C_corr = C_foton / C see T1900169.

For the sensing path, GDS sensing correction = 1 / C_corr. This is to be multiplied into DELTAL_RESIDUAL

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the GDS sensing correction

Returns:
tfcomplex128, array-like

transfer function response of the correction

optical_response_ratio(frequencies)

This computes (opt resp) / (opt resp)_foton

It is a bit confusing because the FOTON filter is the inverse sensing function, so we’ll be multiplying the true optical response from the model by the FOTON transfer function.

In T1900169, in the definition of C/C_CALCS, the last three terms are .. math :: (opt resp)/(opt resp)_foton * (LP_foton/LP) * LP and this method returns this combination since the export from FOTON gives the full combination of .. math :: LP_foton / (opt resp)_foton

Note that (LP_foton/LP) is the “IIR warping”

Parameters:
frequenciesfloat, array-like

array of frequencies for the optical response ratio

Returns:
foton_inv_sensing_interpcomplex128, array-like

ratio of interpolated values

sensing_actuation_delay(frequencies, clock=False)

Compute the delay based on the GDS sensing and actuation correction in units of seconds delay or (if clock=True) in units of 16384 samples/sec, i.e., 1 16384 Hz clock delay = 6.1035e-5 s. Positive indicates a delay, negative indicates an advance

See T1900169, sec III “method 1”

Parameters:
frequenciesfloat, array-like

array of frequencies to model the phase delay

clockboolean, optional

if clock is True, then the output delay_fit and residual will be computed and rounded to the nearest number of integer clock cycles (16384)

Returns:
delayfloat

Units of seconds or 16384 Hz clock cycles (if clock=True)

stage_super_actuator(frequencies, stage='TST')

Compute the super actuator transfer function for a specific stage as estimated by the CALCS model. In this case, the “stage super actuator” is created by choosing a specific stage and then for each QUAD, the stage transfer function to DARM is summed together.

This transfer function is from DARM_CTRL to meters sensed by the IFO. Note that the sign of the DARM_ERR signal is dependent upon which arm is under control.

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

stagestr, optional

SUS stage for the calculation, ‘UIM’, ‘PUM’, or ‘TST’

Returns:
tfcomplex128, array-like

transfer function response of the actuation function

sus_response_ratio(frequencies, arm, stage)

This computes (sus resp) / (sus resp)_foton

See T1900169 definition of delta A_mn

Parameters:
frequenciesfloat, array-like

array of frequencies for the optical response ratio

armstr, x or y
stagestr UIM, PUM, or TST
Returns:
response_ratiocomplex128, array-like

ratio of interpolated values

pydarm.darm module

class pydarm.darm.DARMModel(config, sensing=None, actuation=None, digital=None, pcal=None)

Bases: Model

DARM model object

This is a class to set up the model for the DARM loop from a configuration file with all the information about where the data is stored

compute_darm_olg(frequencies)

Compute the entire DARM open loop transfer function (see G1501518)

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
tfcomplex128, array-like

transfer function response of the sensing function

compute_etas(frequencies, sensing_syserr=None, actuation_syserr_dict=None)

Compute multiplicative scaling factor to the response function. This returns “eta_R_C”, applying sensing systematic error only; “eta_R_A”, applying actuation systematic error only; and “eta_R”, applying both sensing and systematic errors.

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

sensing_syserrcomplex, array-like, optional

multiplicative factor to include relative sensing systematic error

actuation_syserr_dictdict, optional

dict of multiplicative values, ex.: {‘xarm’: {‘UIM’: complex, array-like}, ‘yarm’: {‘PUM’: complex, array-like}}

Returns:
eta_R_ccomplex128, array-like

multiplicative scaling factor for the response function, applying the sensing systematic errors only

eta_R_acomplex128, array-like

multiplicative scaling factor for the response function, applying the actuation systematic errors only

eta_Rcomplex128, array-like

multiplicative scaling factor for the response function, applying both sensing and actuation systematic errors

compute_response_function(frequencies, sensing_syserr=None, actuation_syserr_dict=None)

Compute the entire DARM response transfer function (see G1501518)

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

sensing_syserrcomplex, array-like, optional

multiplicative factor to include relative sensing systematic error

actuation_syserr_dictdict, optional

dict of multiplicative values, ex.: {‘xarm’: {‘UIM’: complex, array-like}}

Returns:
tfcomplex128, array-like

transfer function of the DARM closed-loop response

plot(plot_selection='all', freq_min=0.1, freq_max=5000, filename=None, ifo='', label=None, style=None, ugf_start=10, ugf_end=1000, show=None, **kwargs)

Make DARM critique plots

This method produces critique models for 1 or 2 models.

Parameters:
plot_selectionstr, optional

Select plot type, one of: ‘all’ (default), ‘optical’, ‘actuation’, ‘clg’, ‘olg’, or ‘digital’

freq_minfloat, optional

start frequency

freq_maxfloat, optional

end frequency

filenamestr, optional

if given, ALL generated graphs will be saved in one pdf

ifostr, optional

if given with a model to plot, it will appear in the graph titles

labelstr list, optional

FIXME: what should this be?

stylestr, optional

one of the styles matplotlib has or a user filename with style

ugf_startfloat, optional

start frequency used for the search

ugf_endfloat, optional

end frequency used for the search

showbool, optional

if true the plot(s) will show

**kwargsoptional

Matplotlib values passed to plots

class pydarm.darm.DigitalModel(config)

Bases: Model

DARM digital filter model object

compute_response(frequencies)

Compute DARM digital controller frequency response

Uses filter ZPK transfer function response from Foton file.

Parameters:
frequencies
Returns:
tfcomplex128, array-like

transfer function response of the digital SUS filter

pydarm.digital module

pydarm.digital.daqdownsamplingfilters(from_freq, to_freq, filter_method, rcg_ver)

Compute the transfer function for the DAQ downsampling filters

Parameters:
from_freqint

Number of samples per second input

to_freqint

Number of samples per second output

filter_methodstr

Filtering method. Choose between ‘biquad’ and ‘df2’

rcg_verstr

RCG version. Choose between ‘v3’ and ‘v2’

Returns:
daq_filterscipy.signal.StateSpace

State space object

pydarm.digital.iopdownsamplingfilters(sample_freq_str, filter_calc_method, rcg_ver='v3', model_sample_rate=65536)

Compute the transfer function for the DAQ downsampling filters

Parameters:
sample_freq_strstr

Number of samples per second input

filter_calc_methodstr

Filtering method. Choose between ‘biquad’ and ‘df2’

rcg_verstr, optional

RCG version. Choose between ‘v3’ (default) and ‘v2’ (only needed when also specifying ‘16k’ and ‘biquad’)

model_sample_rateint, optional

Model sampling rate. Default value is 2**16 = 65536

Returns:
iopfilterscipy.signal.StateSpace

State space object

pydarm.measurement module

class pydarm.measurement.Measurement(meas_file)

Bases: object

This class is used to get measurement data from a dtt measurement. This class is used in conjuction with the ProcessSensingMeasurement and ProcessActuationMeasurement class to get the input for the MCMC and GPR analysis.

This class uses the dttxml module to import transfer functions and ASDs.

Parameters:
meas_file: string

String of the name of the xml/hdf5 file of the measurement.

Returns:
Methods (Quick reference)
get_raw_tf: Input two channels, get array of freq and TFs
get_raw_asd: Input one channel, get array of freq and ASD
get_set_of_channels: No input, get a set of the channels in meas_file.

Notes

If the file is not given, the class will complain.

property data_access
get_raw_asd(channelA)

It returns the ASD of channelA from the dtt file. This will only work for a FFT (aka broadband) type measurement.

Parameters:
channelA: string

ASD channel.

Returns:
Returns two float array:
Array 1: frequencies (frequencies of the data in Hz)
Array 2: asd (ASD of channelA)
get_raw_tf(channelA, channelB, cohThresh=0)

Given two channels it returns the transfer function from the input file. Note that it gives channelB/channelA. In addition it populates averages and gps_time, calculates the uncertainty from coherence, and rejects data with coherence lower than the given threshold.

Parameters:
channelA: string

Channel in the denominator of the TF

channelB: string

Channel in the numerator of the TF

cohThresh: float

Coherence threshold below which data from dtt are rejected

Returns:
Returns a 4 arrays N length arrays, where N is the number of data
points:
Array 1: frequencies (frequencies of the data in Hz)
Array 2: tf (transfer function of B/A)
Array 3: coh (coherence of B/A measurement)
Array 4: unc (the uncertainty from coherence)
get_set_of_channels()

Method to get the channels in the measurement file. Annoyingly, the channels are given in a set.

For the .hdf5, channels can be swapped around freely, returing the inverse as expected. Parameters ———-

Returns:
channels_A: A python set with all the A channels in the measurement
file of this object.
channels_B: A python set with all the B (NON-A) channels in the
measurement file of this object.
class pydarm.measurement.ProcessActuationMeasurement(config_file, meas_type, meas_sus_exc_to_darm, meas_pcal_to_darm, meas_tup_1, meas_tup_2, meas1_cohThresh=0, meas2_cohThresh=0, json_results_file=None)

Bases: ProcessMeasurement

This class is used in conjuction with measurement data and ouputs arrays used as input to MCMC and GPR routines. For reference, please see G1501518-v21 subway map, and specifically ‘MCMC input for A’.

Parameters:
config_filestr

This is the *.ini model file to be used to process the measurement data

meas_typestr

This should be one of ‘actuation_x_arm’ or ‘actuation_y_arm’

meas_sus_exc_to_darmMeasurement

This is the object that contains the data for the DARM_IN channel to suspension excitation response

meas_pcal_to_darmMeasurement

This is the object that contains data for the PCAL to DARM TF

meas_tup_1str, tuple

This should be (‘channel A’, ‘channel B’) for the first measurement Ex.: (‘H1:SUS-ETMX_L3_CAL_EXC’, ‘H1:LSC-DARM1_IN1_DQ’)

meas_tup_2str, tuple

This should be (‘channel A’, ‘channel B’) for the second measurement Ex.: (‘H1:CAL-PCALY_RX_PD_OUT_DQ’, ‘H1:LSC-DARM_IN1_DQ’)

meas1_cohThreshfloat, optional

Coherence threshold that values in measurement 1 must be above to be included; valid values in the range [0,1]. (default = 0)

meas2_cohThreshfloat, optional

Coherence threshold that values in measurement 2 must be above to be included; valid values in the range [0,1]. (default = 0)

json_results_filestr, optional

Filename of a JSON file when stacking measurements or running GPR

get_processed_measurement_response()

This method extracts the transfer function data using the channel names from the DTT files specified in the object and computes the measurement response by removing known parameters (see G1501518-v21).

Returns:
frequenciesfloat, array-like

frequency values of the transfer function, in units of Hz

processed_measurement_responsecomplex128, array-like

transfer function response of the actuation function, in units of newtons per driver output (amps or volts**2). For example, for TST the units will be in N/V**2

processed_measurement_response_uncfloat, array-like

relative uncertainty of processed measurement data

rescale_actuation_by_tdcf_val(response, kappa_Ai=1.0, **kwargs)

This method rescales the response function by dividing out the kappa_Ai value

Parameters:
responsecomplex128, array-like

Transfer function of the optical response, having divided out the known quantities from the measured transfer functions

kappa_Aifloat, optional

The time dependent correction factor for actuator gain for this measurement. The data is divided by this number, so if anything other than the default value is provided, the data will be scaled differently (default = 1)

run_gpr(frequencies, measurement_list, fmin=None, fmax=None, fmin_list=None, fmax_list=None, RBF_length_scale=1.0, RBF_length_scale_limits=(0.5, 1.5), gpr_flim=None, save_to_file=None, strict_stack=False)

Run a Gaussian Process Regression on a set of actuation function measurements

Parameters:
frequenciesfloat, array-like

Frequencies at which to compute the GPR (Hz)

measurement_listProcessSensingMeasurement list

a list of measurements to normalize

fminfloat, optional

minimum frequency used for the MCMC of reference measurement

fmaxfloat, optional

maximum frequency used for the MCMC of reference measurement

fmin_listfloat list, optional

list of minimum frequencies used for the MCMC or None

fmax_listfloat list, optional

list of maximum frequencies used for the MCMC or None

RBF_length_scalefloat, optional

Initial length scale guess for the RBF term of the GPR fit (in logarithmic frequency)

RBF_length_scale_limitspair of floats >= 0, optional

The lower and upper bound on RBF_length_scale

gpr_flimtuple, optional

Minimum and maximum frequency points to include in the GPR, (fmin, fmax)

save_to_filestr, optional

Filename (HDF5) to save the data from this result

strict_stackboolean, optional

stack measurements strictly checking for matching MCMC executions

Returns:
y_predcomplex128, array-like

Best fit curve using the GPR and covariance kernel

sigmafloat, array-like

Standard deviation for the GPR

covfloat, array-like

Covariance matrix for the GPR

stacked_measlist, array-like

list of stacked measurement frequencies, transfer functions, rescaled transfer functions (to reference), uncertainties, and residuals

tdcfslist

list of time dependent correction factors for each measurement

run_mcmc(fmin=None, fmax=None, priors_bound=None, save_map_to_file=None, save_chain_to_file=None, **kwargs)

This method is what is used to process the actuation function measurement data

Parameters:
fminfloat, optional

Optional minimum frequency value for the MCMC fitting. Default is the minimum frequency of xdata (default = None)

fmaxfloat, optional

Optional maximum frequency value for the MCMC fitting. Default is the maximum frequency of xdata (default = None)

priors_bound: `float`, array-like, optional

User-specified boundary of prior distribution. Default boundary is only for gain, gain must be larger or equal to 0.0. If choosing a different set of boundaries, then this argument should be in form of a 2D array, 2X2. First (second) element of each row corresponds to the lower (upper) bound of each parameters: gain, residual delay.

save_map_to_filestr, optional

Filename (JSON) to save the maximum a postiori values from this result

save_chain_to_filestr, optional

Filename (HDF5) to save the postirior chain from this result

kwargsoptional

other kwargs are passed to ProcessMeasurement._mcmc

Returns:
chainfloat, array-like

The MCMC chain where index: - 0 is the gain in units of newtons per driver output (amps or volts**2). For example, for TST the units will be in N/V**2. - 1 is the residual time delay in units of seconds

stack_measurements(measurement_list, fmin=None, fmax=None, fmin_list=None, fmax_list=None, use_ini_reference=True, strict=False, **kwargs)

Stack measurements together where each measurement’s model for known filtering and digital filters is removed and the time dependence is removed. This makes it appear as though the measurements are taken at the same time. Only unknown variations or low frequency sensing spring variations remain.

This object and all objects in the measurement list need to have their maximum a postiori values saved to the JSON file because this method will query the JSON file provided in each ProcessSensingMeasurement object in the list

Additional kwargs parameters are unused but present in the definition of this method to serve as passthroughs. We need to clean this up.

Parameters:
measurement_listProcessSensingMeasurement list

a list of measurements to normalize

fminfloat, optional

minimum frequency used for the MCMC

fmaxfloat, optional

maximum frequency used for the MCMC

fmin_listfloat list, optional

list of minimum frequencies used for the MCMC or None

fmax_listfloat list, optional

list of maximum frequencies used for the MCMC or None

use_ini_reference`boolean’

flag to use the parameters for the reference model from the ini (default = True)

Returns:
outputlist, array-like

list of stacked measurement frequencies, transfer functions, rescaled transfer functions (to reference), uncertainties, and residuals

tdcfslist

list of time dependent correction factors for each measurement

class pydarm.measurement.ProcessDACDrivenSensingElectronicsMeasurement(config_file, meas_obj, meas_tup, meas_cohThresh=0)

Bases: ProcessOneMeasurement

Parameters:
meas_obj_1Measurement

This is the object that contains the data for DAC-Driven measurement electronics measurement

meas_obj_2Measurement

This is the object that contains the data for DAC-Driven measurement electronics measurement

meas_tup_1float, optional

This should be (‘channel A’, ‘channel B’) for the first measurement Ex.: (‘H1:OMC-TEST_DCPD_EXC’, ‘H1:OMC-DCPD_A_OUT_DQ’)

meas_tup_2float list, optional

This should be (‘channel A’, ‘channel B’) for the second measurement Ex.: (‘H1:OMC-TEST_DCPD_EXC’, ‘H1:OMC-DCPD_A_OUT_DQ’)

meas1_cohThreshfloat list, optional

list of maximum frequencies used

meas2_cohThreshfloat list, optional

list of maximum frequencies used

Returns:
DACDrivenActuation(frequencies)

Compute actuation part of the DAC-drive measuement response

Parameters:
frequenciesfloat, array-like

array of frequencies to compute DAC-driven measurement response

Returns:
tfcomplex128, array-like

transfer function response

DACDrivenSensingElectronic(name, frequencies)

Compute the DAC-drive measuement response only sensing part as shown in Part IV of G2200551

# TODO: current model disagrees with measurement. Need investigation. See LHO:63453

Parameters:
namestr

a string (e.g., ‘A’ or ‘A_A’) indicating the OMC path name to be evaluated. This string should be listed in SensingModel.omc_path_names variable

frequenciesfloat, array-like

array of frequencies to compute DAC-driven measurement response

Returns:
tfcomplex128, array-like

transfer function response

static compare_dac_driven_meas_response(frequencies, tf_meas1, tf_meas2, show_tf_plot=None, show_compare_plot=None)
Parameters:
frequenciesfloat , array-like

frequency values of the transfer function, in units of Hz

tf_meas1complex128, array-like

the extracted transfer function from meas_tup_1, excluding frequency points below the meas1_cohThresh coherence threshold

tf_meas2complex128, array-like

the extracted transfer function from meas_tup_2, excluding frequency points below the meas2_cohThresh coherence threshold

show_tf_plotoptional

the plot for each transfer function

show_compare_plotoptional

the plot for two transfer function comparsion

Returns:
mag_compfloat , array-like

the ratio of magnitude between two measurements

pha_compfloat , array-like

the ratio of phase between two measurements

fullDACDrivenMeasModel(name, frequencies)

Compute the full response of DAC-driven measurement model

Parameters:
namestr

a string (e.g., ‘A’ or ‘A_A’) indicating the OMC path name to be evaluated. This string should be listed in SensingModel.omc_path_names variable

frequenciesfloat, array-like

array of frequencies to compute DAC-driven measurement response

Returns:
tfcomplex128, array-like

transfer function response

get_processed_measurement_response()
Returns:
frequenciesfloat , array-like

list of normalized measurements

tf_meas1complex128 , array-like
tf_meas2complex128 , array-like
unc_meas1float , array-like
unc_meas1float , array-like
class pydarm.measurement.ProcessMeasurement(config_file, meas_sensing_or_actuation, meas_pcal_to_darm, meas_tup_1, meas_tup_2, meas1_cohThresh=0, meas2_cohThresh=0, json_results_file=None)

Bases: object

This class is used in conjuction with measurement data and ouputs arrays used as input to MCMC and GPR routines. For reference, please see G1501518-v21 subway map, and specifically ‘MCMC input for C’ or ‘MCMC input for A’.

Parameters:
config_filestr

This is the *.ini model file to be used to process the measurement data

meas_sensing_or_actuationMeasurement

This is the object that contains the data for either the closed loop gain (sensing measurement) or suspension measurement (actuation)

meas_pcal_to_darmMeasurement

This is the object that contains data for the PCAL to DARM TF

meas_tup_1str, tuple

This should be (‘channel A’, ‘channel B’) for the first measurement

meas_tup_2str, tuple

This should be (‘channel A’, ‘channel B’) for the second measurement

meas1_cohThreshfloat, optional

Coherence threshold that values in measurement 1 must be above to be included; valid values in the range [0,1]. (default = 0)

meas2_cohThreshfloat, optional

Coherence threshold that values in measurement 2 must be above to be included; valid values in the range [0,1]. (default = 0)

json_results_filestr, optional

Filename for a JSON file

crop_data(xdata, ydata, yerr, fmin=None, fmax=None)

Crop the data with optional minimum and maximum bounds

Parameters:
xdatafloat, array-like

Original frequency data

ydatacomplex, array-like

Original transfer function data

yerrfloat, array-like

Original uncertainties computed from the coherence values

fminfloat, optional

Optional minimum frequency value for the MCMC fitting. Default is the minimum frequency of xdata (default = None)

fmaxfloat, optional

Optional maximum frequency value for the MCMC fitting. Default is the maximum frequency of xdata (default = None)

Returns:
xdatafloat, array-like

cropped frequencies

ydatacomplex, array-like

cropped transfer function data

yerrfloat, array-like

cropped uncertainties computed from the coherence values

pre_process_transfer_functions()

This method extracts the transfer function data using the channel names from the DTT files specified in the object and computes the intermediate data products by removing known parameters (see G1501518-v21).

Returns:
frequenciesfloat, array-like

frequency values of the transfer function, in units of Hz

tf_meas1complex128, array-like

the extracted transfer function from meas_tup_1, excluding frequency points below the meas1_cohThresh coherence threshold

tf_meas2complex128, array-like

the extracted transfer function from meas_tup_2, excluding frequency points below the meas2_cohThresh coherence threshold

pcal_correctioncomplex128, array-like

the transfer function for the offline photon calibrator correction

processed_measurement_response_uncfloat, array-like

relative uncertainty of combined measurement data

query_results_from_json(measurement, fmin=None, fmax=None, match='latest', strict=False)

Query the JSON file for MCMC results. The query looks in the JSON file for a matching set of measurement files, configuration, coherence thresholds, and–optionally–the minimum and maximum frequency of the fit. match will determine what to return. It can be ‘first’ for the first matched, ‘latest’ for the last matched, ‘all’ for all matched or specify which result to return by providing the date of measurement analysis ‘DD/MM/YYYY HH:MM:SS’

Parameters:
measurementstr

measurement type; one of ‘sensing’ or ‘actuation’

fminfloat, optional

minimum frequency used for the MCMC

fmaxfloat, optional

maximum frequency used for the MCMC

matchstr, optional

result to return; ‘first’, ‘latest’, ‘all’ or the date of measurement analysis ‘DD/MM/YYYY HH:MM:SS’

strictbool, optional

if True, return the first entry in the json file. Default is False.

Returns:
measurement analysis datestr

the date of processing measurement analysis in form of ‘DD/MM/YYYY HH:MM:SS’

mcmc_map_valsfloat, array-like

array of maximum a postiori values found from the MCMC

is_pro_springbool

parameter for whether the fit assumed anti-spring (False) or pro-spring (True)

save_results_to_json(filename, fmin, fmax, mcmc_map_vals, measurement, append=False)

Save the model, input DTT filenames, coherence threshold values, minimum and maximum frequencies used in the MCMC, and the resulting MCMC MAP values

Parameters:
filenamestr

path and file name to JSON file

fminfloat

minimum frequency used for the MCMC

fmaxfloat

maximum frequency used for the MCMC

mcmc_map_valsfloat, array-like

array of maximum a postiori values found from the MCMC

measurementstr

measurement type; one of ‘sensing’, ‘actuation_x_arm’, or ‘actuation_y_arm’

appendbool

if True, append results to existing JSON file, otherwise overwrite

stack_measurements()

This method is meant to be overloaded by inherited classes

class pydarm.measurement.ProcessOneMeasurement(config_file, meas, meas_tup, meas_cohThresh=0)

Bases: object

This class is used in conjuction with measurement data and ouputs arrays used in general use

Parameters:
config_filestr

This is the *.ini model file to be used to process the measurement data

measMeasurement

This is the object that contains the data for either the closed loop gain (sensing measurement) or suspension measurement (actuation)

meas_tupstr, tuple

This should be (‘channel A’, ‘channel B’) for the first measurement

meas_cohThreshfloat, optional

Coherence threshold that values in measurement must be above to be included; valid values in the range [0,1]. (default = 0)

pre_process_transfer_functions()

This method extracts the transfer function data using the channel names from the DTT files specified in the object and computes the intermediate data products by removing known parameters (see G1501518-v21).

Returns:
frequenciesfloat, array-like

frequency values of the transfer function, in units of Hz

tf_meascomplex128, array-like

the extracted transfer function from meas_tup_1, excluding frequency points below the meas1_cohThresh coherence threshold

unc_measfloat, array-like

relative uncertainty of measurement data

class pydarm.measurement.ProcessSensingMeasurement(config_file, meas_clg, meas_pcal_to_darm, meas_tup_1, meas_tup_2, meas1_cohThresh=0, meas2_cohThresh=0, json_results_file=None)

Bases: ProcessMeasurement

This class is used in conjuction with measurement data and ouputs arrays used as input to MCMC and GPR routines. For reference, please see G1501518-v21 subway map, and specifically ‘MCMC input for C’.

Parameters:
config_filestr

This is the *.ini model file to be used to process the measurement data

meas_clgMeasurement

This is the object that contains the data for the closed loop gain

meas_pcal_to_darmMeasurement

This is the object that contains data for the PCAL to DARM TF

meas_tup_1str, tuple

This should be (‘channel A’, ‘channel B’) for the first measurement Ex.: (‘H1:LSC-DARM1_IN2’, ‘H1:LSC-DARM1_EXC’)

meas_tup_2str, tuple

This should be (‘channel A’, ‘channel B’) for the second measurement Ex.: (‘H1:CAL-PCALY_RX_PD_OUT_DQ’, ‘H1:LSC-DARM_IN1_DQ’)

meas1_cohThreshfloat, optional

Coherence threshold that values in measurement 1 must be above to be included; valid values in the range [0,1]. (default = 0)

meas2_cohThreshfloat, optional

Coherence threshold that values in measurement 2 must be above to be included; valid values in the range [0,1]. (default = 0)

json_results_filestr, optional

Filename of a JSON file when stacking measurements or running GPR

get_processed_measurement_response()

This method extracts the transfer function data using the channel names from the DTT files specified in the object and computes the measurement response by removing known parameters (see G1501518-v21).

Returns:
frequenciesfloat, array-like

frequency values of the transfer function, in units of Hz

processed_measurement_responsecomplex128, array-like

transfer function response of the actuation function in units of digital counts per meter of DARM

processed_measurement_response_uncfloat, array-like

relative uncertainty of processed measurement data

inverse_sensing_foton_filter(mcmc_chain)

Prints the FOTON filter string to the terminal. Would be preferable at some point if this could be automatically put in to the correct FOTON filter file, but at present this capability is not available

Parameters:
mcmc_chainfloat, array-like

The result from the run_mcmc() method

inverse_sensing_srcd2n_foton_filter_zpk(mcmc_chain, cftd=False)

Prints the FOTON filter string to the terminal. Would be preferable at some point if this could be automatically put in to the correct FOTON filter file, but at present this capability is not available

Parameters:
mcmc_chainfloat, array-like

The result from the run_mcmc() method

cftdboolean, optional

if True then omit the 7000 Hz pole, nominally for the CFTD path

rescale_sensing_by_tdcf_vals(frequencies, response, kappa_c=1.0, f_cc=None, **kwargs)

This method rescales the response function by dividing out the kappa_c and frequency response of the f_cc value and multiplying in the reference values given in the configuration file

Parameters:
frequenciesfloat, array-like

Frequency values for the transfer functions

responsecomplex128, array-like

Transfer function of the optical response, having divided out the known quantities from the measured transfer functions

kappa_cfloat, optional

The time dependent correction factor for optical gain for this measurement. The data is divided by this number, so if anything other than the default value is provided, the data will be scaled differently (default = 1)

f_ccfloat, optional

If provided, this coupled-cavity pole frequency transfer function will be divided out from the data and the reference value provided in the configuration file will be multiplied in (default = None)

Returns:
responsecomplex128, array-like

The scaled transfer function of optical response

run_gpr(frequencies, measurement_list, fmin=None, fmax=None, fmin_list=None, fmax_list=None, roaming_measurement_list_x=None, roaming_measurement_list_y=None, RBF_length_scale=1.0, RBF_length_scale_limits=(0.5, 1.5), gpr_flim=None, save_to_file=None, strict_stack=False)

Run a Gaussian Process Regression on a set of sensing function measurements

Parameters:
frequenciesfloat, array-like

Frequencies at which to compute the GPR (Hz)

measurement_listProcessSensingMeasurement list

a list of measurements to normalize

fminfloat, optional

minimum frequency used for the MCMC of reference measurement

fmaxfloat, optional

maximum frequency used for the MCMC of reference measurement

fmin_listfloat list, optional

list of minimum frequencies used for the MCMC or None

fmax_listfloat list, optional

list of maximum frequencies used for the MCMC or None

roaming_measurement_list_xtuple (model string, Measurement) list

a list of measurements from the roaming lines analysis for x-arm

roaming_measurement_list_ytuple (model string, Measurement) list

a list of measurements from the roaming lines analysis for y-arm

RBF_length_scalefloat, optional

Initial length scale guess for the RBF term of the GPR fit (in logarithmic frequency)

RBF_length_scale_limitspair of floats >= 0, optional

The lower and upper bound on RBF_length_scale

gpr_flimtuple, optional

Minimum and maximum frequency points to include in the GPR, (fmin, fmax)

save_to_filestr, optional

Filename (HDF5) to save the data from this result

strict_stackboolean, optional

stack measurements strictly checking for matching MCMC executions

Returns:
y_predcomplex128, array-like

Best fit curve using the GPR and covariance kernel

sigmafloat, array-like

Standard deviation for the GPR

covfloat, array-like

Covariance matrix for the GPR

stacked_measlist, array-like

list of stacked measurement frequencies, transfer functions, rescaled transfer functions (to reference), uncertainties, and residuals

tdcfslist

list of time dependent correction factors for each measurement

run_mcmc(fmin=None, fmax=None, priors_bound=None, save_map_to_file=None, save_chain_to_file=None, **kwargs)

This method is what is used to process the sensing function measurement data

Parameters:
fminfloat, optional

Optional minimum frequency value for the MCMC fitting. Default is the minimum frequency of xdata (default = None)

fmaxfloat, optional

Optional maximum frequency value for the MCMC fitting. Default is the maximum frequency of xdata (default = None)

priors_bound: `float`, array-like, optional

User-specified boundary of prior distribution. Default boundaries are only for spring freq (must be within this range 0.0<spring freq<20.0) and inv Q (must be within this range 1.e-2<inv Q<1.0). If choosing a different set of boundaries, then this argument should be in form of a 2D array, 5X2. First (second) element of each row corresponds to the lower (upper) bound of each parameters: gain, pole freq, spring freq, inv Q, residual delay.

save_map_to_filestr, optional

Filename (JSON) to save the maximum a postiori values from this result

save_chain_to_filestr, optional

Filename (HDF5) to save the postirior chain from this result

kwargsoptional

other kwargs are passed to ProcessMeasurement._mcmc

Returns:
chainfloat, array-like

The MCMC chain where index: - 0 is the gain in units of counts per meter of DARM - 1 is the coupled cavity pole frequency in units of Hz - 2 is the optical spring frequency in units of Hz - 3 is the quality factor of the optical spring (Q, unitless) - 4 is the residual time delay in units of seconds

stack_measurements(measurement_list, fmin=None, fmax=None, fmin_list=None, fmax_list=None, strict=False, roaming_measurement_list_x=None, roaming_measurement_list_y=None)

Stack measurements together where each measurement’s model for known filtering and digital filters is removed and the time dependence is removed. This makes it appear as though the measurements are taken at the same time. Only unknown variations or low frequency sensing spring variations remain.

This object and all objects in the measurement list need to have their maximum a postiori values saved to the JSON file because this method will query the JSON file provided in each ProcessSensingMeasurement object in the list

Parameters:
measurement_listProcessSensingMeasurement list

a list of measurements to normalize

fminfloat, optional

minimum frequency used for the MCMC

fmaxfloat, optional

maximum frequency used for the MCMC

fmin_listfloat list, optional

list of minimum frequencies used for the MCMC or None

fmax_listfloat list, optional

list of maximum frequencies used for the MCMC or None

strictboolean, optional

stack measurements strictly checking for matching MCMC executions

roaming_measurement_list_xtuple (model string, Measurement) list

a list of measurements from the roaming lines analysis for x-arm

roaming_measurement_list_ytuple (model string, Measurement) list

a list of measurements from the roaming lines analysis for y-arm

Returns:
outputlist, array-like

list of stacked measurement frequencies, transfer functions, rescaled transfer functions (to reference), uncertainties, and residuals

tdcfslist

list of time dependent correction factors for each measurement

class pydarm.measurement.RoamingLineMeasurementFile(meas_file, pcal_unc_corr_file=None)

Bases: object

property latest_measurement

Pass.

class pydarm.measurement.SingleRoamingLineMeasurement(freq, mag, phase, coh, navg, kappa_c, fcc, gps_start=None, gps_end=None, unc_corr_file_path=None)

Bases: object

property averages

Pass.

get_raw_tf(*args)

Return raw transfer function measurement values.

hf_unc_correction()

Return uncertainty adjustment due to deformation of ETM. See T2300381 and G2302160.

property unc

pydarm.model module

class pydarm.model.Model(config, measurement=None)

Bases: object

pyDARM Model class

Represents a transfer function.

analog_aa_or_ai_filter_response(frequencies, idx=0)

Compute the analog anti-aliasing or anti-imaging filter response

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

idxint, optional

if multiple files provided, use an index like 0, 1, or 2 to access the appropriate file (default = 0)

Returns:
tfcomplex128, array-like

transfer function response of the analog AA or AI filter

config_to_dict()

Return a nested dict of the model configuration. Sections are dict in of themselves

Returns:
outdict

dictionary of the model parameters

digital_aa_or_ai_filter_response(frequencies)

Compute the digital anti-aliasing or -imaging filter response

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
tfcomplex128, array-like

transfer function response of the digital filter

dpath(*args)

Return path to data file

Path should be relative to the directory specified in the cal_data_root configuration variable, which may be overridden with the CAL_DATA_ROOT environment variable. If not specified, paths will be assumed to be relative to the current working directory.

if os.path.join(*args) is a full path then return that.

pydarm.model.isfloat(value)

pydarm.pcal module

class pydarm.pcal.PcalModel(config)

Bases: Model

A photon calibrator (pcal) model object

The class serves to return transfer functions that are important to the pcal system, be it corrections to the response when pulling the PCAL channels from the frames, or establishing force coefficients.

compute_pcal_correction(frequencies, endstation=False, include_dewhitening=True, arm='REF')

Compute the Pcal correction for the offline analysis See G1501518 NOTE: This also includes the Pcal arm sign, so be aware!

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

endstationbool, optional

When false (default), the correction is computed for CAL-CS PCAL channel, which includes 1 16k clock cycle delay that we must compensate (undo). Otherwise, when true, the correction is computed at the end station, which does not include 1 16k clock cycle delay

include_dewhiteningbool, optional

if the dewhitening filter is on (default), then the correction will include the two 1 Hz poles

armstr, optional

string to indicate which arm is used for this correction, ‘REF’ (default), ‘X’, or ‘Y’

Returns:
tfcomplex128, array-like

transfer function response of the correction

digital_filter_response(frequencies)
Importing suspension filter from FOTON file which normalized by whitening

filter 2 1Hz poles (susnorm) and mpN_DC gain.

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
tfcomplex128, array-like

transfer function response of the correction

hwinj_calibration_newtons_per_ct(frequencies, arm='X')

Calibration of the hardware injection path, consisting of the photon calibrator components: N/ct, corner station to end station analog delay (2 16k clock cycles and 4 65k clock cycles), Pcal analog AI, and Pcal digital AI.

Note: this does not include the PCAL to DARM sign

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

armstr, optional

string to indicate which arm is used for this correction, ‘REF’ ‘X’ (default), or ‘Y’

Returns:
tfcomplex128, array-like

transfer function response of the correction

newtons_per_ct(arm='X')

Newtons per count for the photon calibrator

newtons_per_watt()

Newtons per watt for the photon calibrator 2*cos(theta)/c

pcal_dewhiten_response(frequencies)

Compute the dewhitening response

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
tfcomplex128, array-like

transfer function response of the Pcal dewhitening filter

pydarm.plot module

class pydarm.plot.BodePlot(fig=None, title=None, figsize=(12, 8), only='', spspec=[211, 212])

Bases: object

bode plotting object

static autoscale_axis(ax, xlim=None, log=False)

This function rescales a figure’s y-axis.

Scaling takes place based on the data that is visible given the current xlim of the axis, by default. If provided, the data within the provided xlim list is used instead.

Parameters:
xlimlist

data boundary to consider in stead of the entire visible range

logbool

use logarithmic (base 10) scale. Default is False.

autoscale_mag_y(**kwargs)

Rescale the mag plot’s y-axis.

See BodePlot.autoscale_axis() for keyword arguments.

autoscale_phase_y(**kwargs)

Rescale the mag plot.

See BodePlot.autoscale_axis() for keyword arguments.

error(freq, tf, tf_error, **kwargs)
add frequency response to plot with error

Note: Error should be relative.

Parameters:
freqarray, list

frequency array

tfarray, list

frequency response

tf_errorarray, list

relative error of frequency response

**kwargsText properties

Other miscellaneous text parameters for matplotlib

static get_ax_index_from_spspec(spec: int) int

Get index of axes object from the spec.

Assumes a three-digit spec (e.g. 212).

greed(more_minor=True)

add a finer grid than the default

Parameters:
more_minorbool

Determine the finer tick location for log axes

legend(labels=None, **kwargs)

add legend

Parameters:
labelsstring, Optional

add string legend for the plot

**kwargsText properties

Other miscellaneous text parameters for matplotlib

plot(freq, tf, **kwargs)

add frequency response to plot

Parameters:
freqarray, list

frequency array

tfarray, list

frequency response

**kwargsText properties

Other miscellaneous text parameters for matplotlib

save(path)

save bode plot to file

Parameters:
pathstr, path-like or binary file-like

path directory for saving the figure

show()

show interactive plot

text(x, y, plot_text)

add text in plot

Parameters:
xfloat

x-position to place the text

yfloat

y-position to place the text

plot_textstr

The text

vlines(vfreq, color='red', lw=1.0, linestyle='--', label='_nolegend_')

add vertical line at specific frequency in both mag and phase plot

Parameters:
vfreqfloat

frequency point for vertical line

colorcolor, Optional

color for vertical line, default = ‘red’

lwfloat

line width, default = 1.0

linestyle{‘-’, ‘–’, ‘-.’, ‘:’, ‘’, …}, Optional

style for vertical line, default = ‘–’

labelstr

legend string for the vertical line

xlim(freq_min, freq_max)

set min max for frequency axis

Parameters:
freq_minfloat

start frequency

freq_maxfloat

end frequency

ylim(mag_min, mag_max, phase_min=-185, phase_max=185)

set min max for the magnitude (and phase) axis

Parameters:
mag_minfloat

minimum magnitude scale

mag_maxfloat

maximum magnitude scale

phase_minfloat, Optional

minimum phase scale, default = -185

phase_maxfloat, Optional

maximum phase scale, default = 185

class pydarm.plot.QuadPlot(fig=None, title=None, figsize=(12, 8))

Bases: object

quad bode plotting object This is essentially a copy of the BodePlot class but plots two bode plots side by side

greed(more_minor=True, quadrant=['tl', 'bl', 'tr', 'br'])

add a finer grid than the default

Parameters:
more_minorbool, Optional

set a finer grid on the plot, default=True

quadrant[‘tl’, ‘bl’, ‘tr’, or ‘br’]

select specific plot to set finer grid alternatively you can use a list of numbers quadrant : [1, 3, 2, or 4]

legend(label=None, quadrant=['tl', 'bl', 'tr', 'br'])

add legend

Parameters:
labelstr

add text label for legend

quadrant[‘tl’, ‘bl’, ‘tr’, or ‘br’]

select position for legend on specific quadrant ‘tl’ : top-left (magnitude left) ‘bl’ : bottom-left (phase left) ‘tr’ : top-right (magnitude right) ‘br’ : bottom-right (phase right) alternatively you can use a list of numbers quadrant : [1, 3, 2, or 4] select position for legend on specific quadrant 1 : top-left (magnitude left) 3 : bottom-left (phase left) 2 : top-right (magnitude right) 4 : bottom-right (phase right)

plot(tuple_left, tuple_right, **kwargs)
Add frequency response to plot with or without error

Note: Error should be relative.

Parameters:
tuple_lefttuple, array-like

add frequency response for the left-side frequencies area

tuple_righttuple, array-like

add frequency response for the right-side frequencies area

**kwargsText properties

Other miscellaneous text parameters for matplotlib

save(path)

save bode plot to file

Parameters:
pathstr, path-like

path directory for saving the figure

show()

show interactive plot

text(x, y, plot_text, quadrant=['tl', 'bl', 'tr', 'br'])

add text in plot

Parameters:
xfloat

x-position to place the text

yfloat

y-position to place the text

plot_textstr

The text

quadrant[‘tl’, ‘bl’, ‘tr’, or ‘br’]

select specific plot to add the text alternatively you can use a list of numbers quadrant : [1, 3, 2, or 4]

vlines(vfreq, quadrant=['tl', 'bl', 'tr', 'br'])

add vertical line at specific frequency in both mag and phase plot

Parameters:
vfreqfloat

frequency position for vertical line

quadrant[‘tl’, ‘bl’, ‘tr’, or ‘br’]

select specific plot to add vertical line alternatively you can use a list of numbers quadrant : [1, 3, 2, or 4]

xlim(freq_min, freq_max, quadrant=['tl', 'bl', 'tr', 'br'])

set min max for frequency axis

Parameters:
freq_minfloat, Optional

start frequency

freq_maxfloat, Optional

final frequency

quadrant[‘tl’, ‘bl’, ‘tr’, or ‘br’]

select specific plot to setup xlim alternatively you can use a list of numbers quadrant : [1, 3, 2, or 4]

xscale(scale='linear', quadrant=['tl', 'bl', 'tr', 'br'])

change the y scale of plot at given quadrant, linear or log

Parameters:
scalestr, Optional

scale for x axis, default=’linear’

quadrant[‘tl’, ‘bl’, ‘tr’, or ‘br’]

select specific plot to set the xscale alternatively you can use a list of numbers quadrant : [1, 3, 2, or 4]

ylim(y_min, y_max, quadrant=['tl', 'bl', 'tr', 'br'])

set min max for the magnitude (and phase) axis

Parameters:
freq_minfloat, Optional

start frequency

freq_maxfloat, Optional

final frequency

quadrant[‘tl’, ‘bl’, ‘tr’, or ‘br’]

select specific plot to setup ylim alternatively you can use a list of numbers quadrant : [1, 3, 2, or 4]

yscale(scale='linear', quadrant=['tl', 'bl', 'tr', 'br'])

change the y scale of plot at given quadrant, linear or log

Parameters:
scalestr, Optional

scale for y axis, default=’linear’

quadrant[‘tl’, ‘bl’, ‘tr’, or ‘br’]

select specific plot to set the yscale alternatively you can use a list of numbers quadrant : [1, 3, 2, or 4]

pydarm.plot.critique(*args, filename=None, plot_selection='all', ifo='', show=None, label=None, freq_min=0.1, freq_max=5000, freq_points=1001, ugf_start=10, ugf_end=1000, greed=True, figsize=(12, 8), **kwargs)

This method produces critique models for 1 or 2 models.

Parameters:
argspydarm.darm.DARMModel object

1 or 2 darm models objects, if more than 1, this should be a list

filenamestr, optional

if given, ALL generated graphs will be saved in one pdf

plot_selectionstr, optional

Select plot type, one of: ‘all’ (default), ‘optical’, ‘actuation’, ‘clg’, ‘olg’, or ‘digital’

ifostr, optional

if given with a model to plot, it will appear in the graph titles

showbool, optional

if true the plot(s) will show

labelstr list, optional

a list of labels for legend

freq_minfloat, optional

start frequency

freq_maxfloat, optional

final frequency

freq_pointsint, optional

Number of frequency points

ugf_startfloat, optional

start frequency used for the search

ugf_endfloat, optional

end frequency used for the search

greedbool, optional
figsizefloat, tuple
**kwargsoptional

Matplotlib values passed to plots

pydarm.plot.get_ugf(freq, tf, search_start=5.0, search_end=1000.0, n_points=10000)

Very non-fancy function for easily finding UGF in the simplest of cases.

Parameters:
freqfloat, array

frequencie arrays corresponding to the given tf

tfcomplex, array

transfer function you want the ugf of

search_start: `float`

frequency to start UGF search

search_end: `float`

frequency to end UGF search

n_points: `int`

N point number for increased accuracy of UGF frequency

Returns:
floats: ugf frequency, ugf phase, ugf gain, ugf index of original array
pydarm.plot.plot(*args, freq_min=0.1, freq_max=5000, freq_points=1001, filename=None, mag_min=None, mag_max=None, phase_min=-185, phase_max=185, label=None, title=None, style=None, show=None, greed=False, figsize=(12, 8), **kwargs)

This method provides a simple way to plot quickly anything you want.

Parameters:
argstuple, lists

Here you can input any kind of transfer function related data. It accepts multiple sets in multiple formats. FORMATS: - 2-tuple (freq,transfer function) - 3-tuple (freq,transfer function, rel unc) - 4-tuple (freq,transfer function, coherence, rel unc) - freq, transfer function (two lists or 1d arrays separated by comma) - method that returns a transfer function e.g. D.compute_darm_olg (assuming D is a darm model object)

freq_minfloat, optional

start frequency

freq_maxfloat, optional

end frequency

freq_pointsint, optional

number of points to calculate

filenamestr, optional

if given, ALL generated graphs will be saved in one pdf.

mag_minfloat, optional

minimum magnitude scale

mag_maxfloat, optional

maximum magnitude scale

phase_minfloat, optional

minimum phase scale

phase_maxfloat, optional

maximum phase scale

labelstr list, optional

legend string for the data sets given e.g. [‘first data’, ‘second’]

titlestr, optional

title of the graph

stylestr, optional

one of the styles matplotlib has or a user filename with style

showbool, optional

if true the plot will show

greedbool, optional

if true a finer grid is drawn for all figs

figsizefloat tuple, optional

figure size

**kwargs

matplotlib arguments passed to all plots

Returns:
bppydarm.plot.BodePlot object
pydarm.plot.residuals(freq_model, tf_model, freq_data, tf_data, unc_data, mag_min=0.8, mag_max=1.2, phase_min=-5, phase_max=5, mag_major_tick=0.05, mag_minor_tick=0.01, phase_major_tick=2, phase_minor_tick=0.5, filename=None, show=None, title='')

This method provides a simple way to plot quickly anything you want.

Parameters:
freq_modelfloat, array-like

frequencies that the model transfer function is computed

tf_modelcomplex, array-like

transfer function response values at the freq_model points

freq_datafloat, array-like

frequencies that the measured transfer function data values are computed at

tf_datacomplex, array-like

measured transfer function response values at the freq_daata points

unc_datafloat, array-like

relative uncertainty values, determined from the measurement coherence

mag_minfloat, optional

minimum magnitude scale

mag_maxfloat, optional

maximum magnitude scale

phase_minfloat, optional

minimum phase scale

phase_maxfloat, optional

maximum phase scale

mag_major_tickfloat, optional

major tick placement for the residual magnitude plot

mag_minor_tickfloat, optional

minor tick placement for the residual magnitude plot

phase_major_tickfloat, optional

major tick placement for the residual phase plot

phase_minor_tickfloat, optional

minor tick placement for the residual phase plot

filenamestr, optional

save the plot to this file

showbool, optional

if true the plot will show

Notes

Example usage: >>> residuals(freq_model, tf_model, … freq_data, tf_data, unc_data, title=’Measurement vs Model’)

pydarm.plot.save_multifig(filename, figs=None)

method to save all existing (or list of given) figures in one pdf file

Parameters:
filenamestr

pdf file name for the figures

figslist, dict

list of given figures to save

pydarm.sensing module

class pydarm.sensing.SensingModel(config)

Bases: Model

A sensing function model object This is a class to set up the model for the sensing function from a configuration file with all the information about where the data is stored

adc_delay_response(name, frequencies)

Compute the ADC delay response

Parameters:
namestr

a string (e.g., ‘A’ or ‘A_A’) indicating the OMC path name to be evaluated. This string should be listed in SensingModel.omc_path_names variable

frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
delaycomplex, array-like

frequency response of the ADC delay

compute_sensing(frequencies)

Compute the entire sensing function transfer function (see G1501518)

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
tfcomplex128, array-like

transfer function response of the sensing function

light_travel_time_delay_response(frequencies)

Compute the frequency response from the light travel time delay

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
tfcomplex128, array-like

transfer function response

mean_arm_length()

Compute the mean arm length of the x and y arms

Returns:
mean_lengthfloat

mean arm length in units of meters

omc_analog_dcpd_readout_response(name, frequencies)

The transfer function of the analog OMC DCPD readout electronics

Parameters:
namestr

a string (e.g., ‘A’ or ‘A_A’) indicating the OMC path name to be evaluated. This string should be listed in SensingModel.omc_path_names variable

frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
responsecomplex128, array-like

transfer function response of the analog electronics in path name

omc_combine_path_responses(frequencies)

Compute the frequency response from the OMC DCPD electronics as shown in G1501518-v21 (the bracketed term directly below “O4 Calibration”)

Note however, that this is the WEIGHTED MEAN! Meaning that for N paths, we would sum the paths and divide by N if they were perfectly balanced

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
combined_pathscomplex128, array-like

transfer function response

omc_dcpd_transimpedence_amplifier_response(name, frequencies)

The transfer function of the analog OMC DCPD transimpedence amplifier electronics

Parameters:
namestr

a string (e.g., ‘A’ or ‘A_A’) indicating the OMC path name to be evaluated. This string should be listed in SensingModel.omc_path_names variable

frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
responsecomplex128, array-like

transfer function response of the analog transimpedence amplifier in path name

omc_dcpd_whitening_response(name, frequencies)

The transfer function of the analog OMC DCPD whitening electronics

Parameters:
namestr

a string (e.g., ‘A’ or ‘A_A’) indicating the OMC path name to be evaluated. This string should be listed in SensingModel.omc_path_names variable

frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
responsecomplex128, array-like

transfer function response of the analog whitening electronics in path name

omc_digital_filters_response(name, frequencies)

The transfer function of the OMC digital compensation filters

Parameters:
namestr

a string (e.g., ‘A’ or ‘A_A’) indicating the OMC path name to be evaluated. This string should be listed in SensingModel.omc_path_names variable

frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
filter_responsecomplex128, array-like

transfer function response of the digital filters in the path labeled by name

omc_path_response(name, frequencies)

Compute the frequency response for a single OMC DCPD readout as shown in G1501518-v21 (the bracketed term directly below “O4 Calibration”). This includes the gain ratio (= path idx / ref path, usually path A) and the balance matrix coefficient for path idx.

The reference path (usually path A) should have gain ratio = 1.

Parameters:
namestr

a string (e.g., ‘A’ or ‘A_A’) indicating the OMC path name to be evaluated. This string should be listed in SensingModel.omc_path_names variable

frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
path_responsecomplex128, array-like

transfer function response of the path labeled by idx

static optical_response(pole_frequency, detune_spring_frequency, detune_spring_Q, pro_spring=False)

Compute the coupled cavity response approximated by a single cavity pole and a detuned spring frequency and Q

Parameters:
pole_frequencyfloat

Coupled cavity pole frequency in Hz

detune_spring_frequencyfloat

Detuning spring frequency in Hz

detune_spring_Qfloat

Unitless Q

pro_springboolean, optional

logic flag to indicate pro-spring

Returns:
optical_responseLTI object

coupled cavity optical response

sensing_residual(frequencies)

Compute the residual sensing function

This is everything in the sensing function except the optical gain and the optical response

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the residual sensing function

Returns:
C_rescomplex128, array-like

transfer function response

single_pole_approximation_delay_correction_response(frequencies)

Compute the frequency response from the time delay correction to the single pole approximation

Parameters:
frequenciesfloat, array-like

array of frequencies to compute the response

Returns:
tfcomplex128, array-like

transfer function response

pydarm.uncertainty module

class pydarm.uncertainty.DARMUncertainty(config, uncertainty_config=None, sensing_mcmc_file=None, sensing_gpr_file=None, actuation_mcmc_files_dict=None, actuation_gpr_files_dict=None, response_curve_file=None)

Bases: object

compute_response_uncertainty(gpstime, frequencies, trials=1000, data=None, shift_sample_tf=None, save_to_file_h5=None, save_to_file_txt=None, seed=None, **kwargs)

This method samples the response function uncertainty a number of times in order to obtain an estimate of the systematic error and associated uncertainty. This is often referred to as the “error budget”

The values are R_sample / R_nominal, meaning they are a multiplicative correction factor to the calibrated data in order to obtain the “true” response

Parameters:
gpstimeint

GPS time

frequenciesfloat, array-like

array of frequencies to compute the response

trialsint, optional

number of times to sample the response

datagwpy.timeseries.TimeSeriesDict object, optional

This is the time series data of the TDCF channels (nominal values and uncertainty) computed either in the CAL-CS, GDS, or DCS pipeline. If this is not provided, or it does not match the GPS time and duration, then it will be queried. A LIGO.ORG credential will be required

shift_sample_tfcomplex, array-like, optional

Multiply sampled responses by a transfer function. The transfer function needs to be computed from the same frequenices as this method uses otherwise results are unpredictable

save_to_file_h5str, optional

Path to file for saving response curves and samples as HDF5 (.h5 or .hdf5)

save_to_file_txtstr, optional

Path to file for saving uncertainty envelope as ASCII (.txt)

seed: `int`, optional

Seed for the random generation of the uncertainty envelope samples. The default value (None) will mean results are not reproducible, whereas an integer value will return reproducible results.

**kwargs

keyword arguments to pass to sample_response method; ex.: supplemental_sensing_gpr for an additional GPR to apply to sensing samples

Returns:
response_sampleslist of complex128, array-like

list of response transfer function samples

static get_model_pars(model)

Extract the main fitted parameters from MCMCs into structures

Parameters:
modelpydarm.darm.DARMModel object
Returns:
sensing_parsdict

dictionary of the sensing parameters that the MCMC posteriors would impact

act_parsdict

dictionary of the actuation parameters that the MCMC posteriors would impact

nominal_response(gpstime, frequencies, data=None)

This method computes the response function of a model at a specified GPS time, and, depending on whether the time-dependent correction factors were applied at the time, applies those TDCFs to the model so that the response function is corrected for those changes at a specific GPS time

Parameters:
gpstimeint

GPS time

frequenciesfloat, array-like

array of frequencies to compute the response

datagwpy.timeseries.TimeSeriesDict object, optional

This is the time series data of the TDCF channels (nominal values and uncertainty) computed either in the CAL-CS, GDS, or DCS pipeline. If this is not provided, or it does not match the GPS time and duration, then it will be queried. A LIGO.ORG credential will be required

Returns:
tfcomplex128, array-like

transfer function response of the sensing function

datagwpy.timeseries.TimeSeriesDict object

object containing the queried channel data

static plot_response_samples(frequencies, response_mag_quant, response_pha_quant, ifo, y_mag=10, y_pha=10, filename=None, monitor_line_data=None)
Parameters:
frequenciesfloat, array-like
response_mag_quantfloat, array-like
response_pha_quantfloat, array-like
ifostr, H1 or L1
y_magfloat, optional

Y-axis magnitude range, in percent (default is +/- 10%)

y_phafloat, optional

Y-axis phase range, in degree (default is +/- 10 degrees)

monitor_line_datadict

dictionary of monitoring line data taken ~30min before and after the reference time of the modelled response. The dictionary must contain keys: {‘oscillator_frequency’, ‘TF_mag’, ‘TF_phase’} with values being float, array-like for each

Returns:
fig: matplotlib.figure.Figure, figure of uncertainty
static plot_response_samples_compare(frequencies, RRMag, RRPha, response_mag_quants, response_pha_quants, ifo, y_mag=10, y_pha=10, filename=None, monitor_line_data=None)
static response_quantiles(response_samples, quantiles=(16, 50, 84))

Calculate the quantiles of response uncertainty samples

Parameters:
response_samplescomplex128, list

list of arrays of ration of sampled responses to nominal response

quantilesfloat, list, optional

list of quantiles desired to be computed

Returns:
response_mag_quantfloat, array-like

2-d array of length(quantiles) x length(response_samples) giving magnitude quantiles

response_pha_quantfloat, array-like

2-d array of length(quantiles) x length(response_samples) giving phase quantiles in radians

response_uncertainty_combine_with_mon_line_data(freq, response_unc_mag, response_unc_phase, monitor_line_data, output_dir_diagnostics='.', save_to_file_txt=None, save_GP_models=False, seed=None)

Combine monitor lines to modelled response uncertainty

This method combines samples from the modelled response uncertainty to the monitoring line response measurements via a single GPR, to generate a more informed fit.

Parameters:
freq: `float` array-like

frequencies used for modelling the response uncertainty, these must correspond to the values of response_unc_mag, response_unc_phase

response_mag_quantfloat, array-like

2-d array of length(quantiles) x length(response_samples) giving magnitude quantiles

response_pha_quantfloat, array-like

2-d array of length(quantiles) x length(response_samples) giving phase quantiles in radians

monitor_line_datadict

dictionary of monitoring line data taken ~30min before and after the reference time of the modelled response. The dictionary must contain keys: {‘oscillator_frequency’, ‘TF_mag’, ‘TF_phase’} with values being float, array-like for each

output_dir_diagnostics: `str`, default ‘.’

Output directory (path) where the GPR training logging plots will be saved.

save_to_file_txtstr, optional

Path to file for saving uncertainty envelope as ASCII (.txt)

save_GP_modelsbool, default False

If True, the GPR TensorFlow checkpointed model will be saved in a folder names gp_model_mag/ or gp_model_phase. See https://www.tensorflow.org/guide/checkpoint

seed: `int`, optional

Seed for the random generation of the uncertainty envelope samples. The default value (None) will mean results are not reproducible, whereas an integer value will return reproducible results.

Returns:
response_unc_mon_magfloat, array-like

2-d array of length(3) x length(response_samples) giving magnitude quantiles (16th, 50th, 84th)

response_unc_mon_phasefloat, array-like

2-d array of length(3) x length(response_samples) giving phase quantiles (16th, 50th, 84th)

static sample_gpr(gpr, frequencies, n_trials=1)

Sample from the GPR instance where there are 4 parameters: - model configuration string (str) - best fit curve of the data (complex, array-like) - covariance matrix (float, array-like) - frequencies (float, array-like)

Parameters:
gprlist

GPR list instance as described above

frequenciesfloat, array-like

list of frequencies to sample the GPR; if this is different than what the GPR was computed on, then this method will interpolate to the new values using linear interpolation

Returns:
this_gprcomplex, array-like

sampled GPR function

sample_line_uncertainty(gpstime, data=None)

Sample the calibration line uncertainty

Parameters:
gpstimeint

GPS time at the point of interest. queried data will be [gpstime-duration/2, gpstime+duration/2)

datagwpy.timeseries.TimeSeriesDict object, optional

This is the time series data of the TDCF channels (nominal values and uncertainty) computed either in the CAL-CS, GDS, or DCS pipeline. If this is not provided, or it does not match the GPS time and duration, then it will be queried. A LIGO.ORG credential will be required

Returns:
this_cal_sensingfloat
this_cal_sus_xfloat, array-like
this_cal_sus_yfloat, array-like
static sample_pcal_unc(err=1, unc=0.005)

Sample PCAL uncertainty

Parameters:
errfloat, optional
uncfloat, optional
Returns:
float
sample_response(gpstime, frequencies, n_trials=1, data=None, supplemental_sensing_gpr=None)

This method samples the response function at a specific GPS time one at a time. Call this method multiple times in order to get an estimate of the overall error and uncertainty

Parameters:
gpstimeint

GPS time

frequenciesfloat, array-like

array of frequencies to compute the response

datagwpy.timeseries.TimeSeriesDict object, optional

This is the time series data of the TDCF channels (nominal values and uncertainty) computed either in the CAL-CS, GDS, or DCS pipeline. If this is not provided, or it does not match the GPS time and duration, then it will be queried. A LIGO.ORG credential will be required

supplemental_sensing_gprstr, optional

Path to file of an additional sensing function GPR to apply when sampling

Returns:
tfcomplex128, array-like

transfer function response of the sensing function

datagwpy.timeseries.TimeSeriesDict object

object containing the queried channel data

sensing_parsdict

dictionary of sesing parameters for this sample (gain, f_cc, f_s, Q, and tau_c (the residual delay)

act_parsdict

dictionary of actuation parameters for this sample. Each entry for an arm and stage is a list of: gain, tau_i (the residual delay)

this_sensing_syserrcomplex128, array-like

sample for this sensing function GPR

act_syserr_dictdict

dictionary of samples for this arm and stage for actuation GPR

tdcf_channel_list()

return the TDCF channel list, with <IFO>: prefix

tdcf_mean_values(gpstime, data=None)

Compute the mean values of the TDCF channels

Parameters:
gpstimeint

GPS time at the point of interest. queried data will be [gpstime-duration/2, gpstime+duration/2)

datagwpy.timeseries.TimeSeriesDict object, optional

This is the time series data of the TDCF channels (nominal values and uncertainty) computed either in the CAL-CS, GDS, or DCS pipeline. If this is not provided, or it does not match the GPS time and duration, then it will be queried. A LIGO.ORG credential will be required

Returns:
sensingfloat, array-like

kappa_c and f_cc in that order; zero if no channel provided

actuation_x_armfloat, array-like

kappa_uim, kappa_pum, kappa_tst in that order; zero if no channel provided

actuation_y_armfloat, array-like

kappa_uim, kappa_pum, kappa_tst in that order; zero if no channel provided

pydarm.utils module

class pydarm.utils.cds_filter(name, soscoef, fs, design)

Bases: tuple

design

Alias for field number 3

fs

Alias for field number 2

name

Alias for field number 0

soscoef

Alias for field number 1

class pydarm.utils.cds_filter_bank(name, filters, headerAndBody)

Bases: tuple

filters

Alias for field number 1

headerAndBody

Alias for field number 2

name

Alias for field number 0

pydarm.utils.clear_filter_module(foton_file, filterbank, mod_idx, verbose=False)

Clear foton filterbank module

Parameters:
foton_filefoton.FilterFile

foton file object for file that will be modified.

filterbankstr

the filterbank that is being written to (e.g. CS_DARM_ERR). Each filterbank contains 10 filter module “slots”

mod_idxint

filter module slot. based at zero. i.e. a bank in slot 5 as seen on MEDM should have mod_idx=4.

pydarm.utils.compute_digital_filter_response(filter_filename, filter_bank_name, filter_bank_modules, filter_bank_gain, frequencies, pfilt=None)

Compute a digital filter ZPK transfer function response from a Foton file

Parameters:
filter_filenamestr

Path to file and filename of Foton filter file

filter_bank_namestr

Name of the filter bank

filter_bank_modulesint, array-like

filter modules requested from the bank, from 1 .. 10

filter_bank_gainfloat

Digital gain of the filter bank

frequenciesfloat, array-like

Array of frequencies (in Hz) for the transfer function

pfiltarray-like (optional)

Use this as input when reading from the same Foton filter file multiple times. pfilt can be passed back in because it has all the file stored in the namedtuple

Returns:
tfcomplex128, array-like

transfer function response of the digital SUS filter

pfiltarray-like

The Foton file is stored in this array for later re-use

pydarm.utils.dfreqrespZPK(sys, w)

Compute the frequency response of a discrete ZPK filter

Note that control room computers don’t have the latest scipy so this is brought from scipy>=0.19.0. It basically does the same as freqz_zpk():

Parameters:
sysscipy.signal.ZerosPolesGain

Filter object

wfloat, array-like

Angular frequencies at which to compute the filter response

Returns:
wfloat, array-like

Angular frequencies at which to compute the filter response

hcomplex128, array-like

Filter response

Examples

>>> filt = signal.ZerosPolesGain(-2.0*np.pi*np.asarray([1.]),
               -2.0*np.pi*np.asarray([20.]), 20.0/1.0, 1.0/16384)
>>> out = dfreqrespZPK(filt, 2.0*np.pi*np.logspace(0, 3, 100))
pydarm.utils.digital_delay_filter(clock_cycles, sample_frequency)

Compute a digital delay filter

Parameters:
clock_cyclesint

Number of cycles delay with sample_frequency

sample_frequencyint

Sampling frequency

Returns:
filterscipy.signal.ZerosPolesGain

Zeros poles gain object

pydarm.utils.freqrespZPK(sys, w)

Compute the frequency response of a continuous ZPK filter

Parameters:
sysscipy.signal.ZerosPolesGain

Filter object

wfloat, array-like

Angular frequencies at which to compute the filter response

Returns:
gcomplex128, array-like

Filter response

Examples

>>> filt = signal.ZerosPolesGain(-2.0*np.pi*np.asarray([1.]),
               -2.0*np.pi*np.asarray([20.]), 20.0/1.0)
>>> out = freqrespZPK(filt, 2.0*np.pi*np.logspace(0, 3, 100))
pydarm.utils.freqresp_to_mag_db_phase_str(f, fr, include_header=False)

Convert frequency response to magnitude (dB) and phase string.

Parameters:
f: np.ndarray

Frequency array in Hertz.

fr: np.ndarray, complex

Complex frequency response.

include_header: bool, optional

If True, include a header line at the beginning of the string that indicates the purpose and unit of each column. This line will be preceded by a ‘#’ character to mark it as a comment.

Returns:
out: str

String containing three columns: frequency (Hz), magnitude (dB), and phase (degrees). Each row is separated by a newline character. Columns are delimited by a single space.

pydarm.utils.load_foton_export_tf(filename)

This function is designed to take a filename and load the data. The filename must be an ASCII file with three columns: frequency, real term, imaginary term (I think this is the default export behavior of FOTON)

Parameters:
filenamestr

full path and filename to the ASCII export of FOTON data

Returns:
file_data_freqfloat, array-like

frequency array of the data in the file in units of Hz

file_data_responsecomplex128, array-like

transfer function data of the FOTON filter

pydarm.utils.normalize(b, a)
pydarm.utils.parallelZPK(sys1, sys2)

Add two ZPK filters together as though they were in parallel paths and summed

Parameters:
sys1scipy.signal.ZerosPolesGain

First filter object

sys2scipy.signal.ZerosPolesGain

Second filter object

Returns:
sysscipy.signal.ZerosPolesGain

Combined filter object

Examples

>>> out = parallelZPK(in1, in2)
pydarm.utils.read_chain_from_hdf5(filename)

Read the MCMC chain from an HDF5 file

Parameters:
filenamestr

HDF5 filename

Returns:
meas_modelstr

Configuration string for the model

fminfloat

Minimum frequency used in the MCMC fit

fmaxfloat

Maximum frequency used in the MCMC fit

measurementstr

Either ‘sensing’ or ‘actuation’

chainfloat, array-like

The MCMC chain

pydarm.utils.read_eta_or_syserr_from_hdf5(filename, measurement=None, sensing=False, actuation=False)

Read eta results(See aLOG:62621) or sensing and actuation systematic error defined by user from an HDF5 file

Parameters:
filenamestr

Output filename

measurementstr

Either ‘sensing’ or ‘actuation’ or ‘filename’

sensingboolen
actuationboolen
Returns:
frequenciesfloat, array-like

Array of frequencies the eta result is valid for

syserrdict

dictionary of systematic error for this arm and stage

pydarm.utils.read_filter_file(filename)

Read a filter file and return all the SOS coefficients info for the filters

Parameters:
filenamestr

Path and filename of FOTON filter file

Returns:
outarray-like

Data from the FOTON filter file

pydarm.utils.read_filter_sys(filename, bank, module, **kwargs)

Read a filter system from a file and return a ZPK filter and pfilt (a structure containing the filter info from the file)

Parameters:
filenamestr

Path and filename of FOTON filter file

bankstr

Name of the filter bank

moduleint, array-like

Module numers ranging from 1 to 10

dataarray-like, optional

Array containing [filename, filter .. filter]. This is passed as an optional argument in case the file has already been read once and you don’t want to spend more I/O time re-reading this again

Returns:
sysdscipy.signal.ZerosPolesGain

ZPK object of the requested FOTON filters

pfiltarray-like

Data from the FOTON filter file. Passing this back to the same function speeds up searching more filters in the file

pydarm.utils.read_gpr_from_hdf5(filename, measurement)

Read GPR results from an HDF5 file

Parameters:
filenamestr

Output filename

measurementstr

Either ‘sensing’ or ‘actuation’

Returns:
meas_modelstr

Configuration string for the model

y_predcomplex128, array-like

Best fit curve using the GPR and covariance kernel

covfloat, array-like

Covariance matrix for the GPR

frequenciesfloat, array-like

Array of frequencies the GPR is valid for

pydarm.utils.read_response_curves_from_hdf5(filename)

Read the residual response curves from the response curve uncertainty envelope calculation

Parameters:
filenamestr

Response curve file

Returns:
frequencies`float’, array-like

Array of frequencies for the response curves

response_curves`complex’, array-like

Array of individual residual response function curves

pydarm.utils.save_chain_to_hdf5(filename, meas_model, fmin, fmax, measurement, chain)

Save the MCMC chain to an HDF5 file

Parameters:
filenamestr

Output filename

meas_modelstr or dict

Configuration string or dictionary for the model

fminfloat

Minimum frequency used in the MCMC fit

fmaxfloat

Maximum frequency used in the MCMC fit

measurementstr

Either ‘sensing’ or ‘actuation’

chainfloat, array-like

The MCMC chain

pydarm.utils.save_gpr_to_hdf5(filename, meas_model, measurement, y_pred, cov, frequencies)

Save GPR results to an HDF5 file

Parameters:
filenamestr

Output filename

meas_modelstr

Configuration string for the model

measurementstr

Either ‘sensing’ or ‘actuation’

y_predcomplex128, array-like

Best fit curve using the GPR and covariance kernel

covfloat, array-like

Covariance matrix for the GPR

frequenciesfloat, array-like

Array of frequencies the GPR is valid for

pydarm.utils.save_samples_to_txt(filename, frequencies, response_mag_quant, response_pha_quant)

This method saves frequencies and response uncertainty quantiles into a txt file, given a specified filename.

Parameters:
filenamestr

Chosen output filename, needs to end in .txt

frequenciesfloat, array-like

frequencies corresponding to the values of the response uncertainty

response_mag_quanttuple of arrays

response magnitude quantiles (float array-like for the 16th percentile,

float array-like for the 50th percentile, float array-like for the 84th percentile)

response_pha_quanttuple of arrays

response phase quantiles (float array-like for the 16th percentile,

float array-like for the 50th percentile, float array-like for the 84th percentile)

pydarm.utils.serielZPK(sys1, sys2)

Multiply two ZPK filters together as though they were in a seriel path

Parameters:
sys1scipy.signal.ZerosPolesGain

First filter object

sys2scipy.signal.ZerosPolesGain

Second filter object

Returns:
sysscipy.signal.ZerosPolesGain

Combined filter object

Examples

>>> out = serielZPK(in1, in2)
pydarm.utils.sos2zp(sos)

Replicate the MATLAB version of sos2zp because the scipy version is not like the MATLAB version

Parameters:
sosfloat, array-like

Second order sections

Returns:
zfloat

Zeros of the ZPK filter

pfloat, array-like
pydarm.utils.tf2zp(b, a)
pydarm.utils.tf_from_foton_zpk(zpk_params, fstart, fstop, n_points, rate=16384)

Use Foton Python bindings to compute a transfer function from ZPK params.

Parameters:
zpk_paramstuple

Tuple containing a transfer function’s zeros, poles, and gain. The tuple is expected to be of the form ([zeros], [poles], k).

fstartfloat

Start frequency

fstopfloat

Stop frequency

n_pointsint

Number of points to generate.

ratefloat, optional

Sampling rate to passed to Foton.

Returns:
freqsnp.array, float

Frequency array returned by the Foton binding

tfnp.array, complex

Complex transfer function generated by Foton

pydarm.utils.thiran_delay_filter(tau, Ts)

Create a frequency response Thiran Delay Filter

Parameters:
taufloat

time delay(secod)

Tsfloat

sample time(second)

Returns:
sysscipy.signal.TransferFunction
pydarm.utils.tuple_from_foton_zp_format(s)

Takes a list of zeros or poles in foton format and returns tuple.

Foton design strings contain lists of zeros and poles in the following format: ‘[6.2699;-6.4297]’. This function converts that string into a tuple of floats.

Parameters:
sstr

Foton formatted list of zeros or poles.

Returns:
tuple of zeros or poles as floats
pydarm.utils.write_dict_epics(dictionary, dry_run=True, IFO=None, save_file=None, as_float=True)

Write dictionary of key/value pairs to EPICS records (keys are channel names)

Parameters:
dictionarydict

the dictionary of values to write

dry_runboolean

actually write to EPICS if value is False

IFOstr

optional IFO string for IFO channel prefix if needed

save_file: path

optional file to save written record values

as_float: boolean, optional

convert all values to float before caput

pydarm.utils.write_filter_module(foton_file, filterbank, mod_idx, filter_name, zpk_params, verbose=False)

Write zpk string to foton module.

TODO: write pure gains using the gain() foton string rather than zpk()

Parameters:
foton_filefoton.FilterFile

foton file that the new values will be written to.

filterbankstr

the filterbank that is being written to (e.g. CS_DARM_ERR). Each filterbank contains 10 filter module “slots”

mod_idxint

filter module slot. based at zero. i.e. a bank in slot 5 as seen on MEDM should have mod_idx=4.

filter_namestr

the name given to the filter being installed. This is the name that appears above the toggle switch in MEDM.

zpk_paramsiterable

zpk parameters to be fed directly into foton. Format is (zs, ps, gain). the value written to the foton file will be ‘zpk({zs}, {ps}, {gain})’.

pydarm.utils.write_hwinj_data(frequencies, transfer_function, filename, name='', info='')

Write an ASCII file for the hardware injection transfer function

Parameters:
frequenciesfloat, array-like

array of frequencies for the transfer function

transfer_functioncomplex128, array-like

array of transfer function response values

filenamestr

Output filename

namestr, optional

Optional extra name string printed to the header

infostr, optional

Optional additional information string printed to the header

Module contents