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
-
DCS(output_filename=
'DCS.npz'
, output_dir='.'
, plots_directory='../examples/DCS_plots'
)¶ DCS FIR filter generation
-
GDS(output_filename=
'GDS.npz'
, output_dir='.'
, plots_directory='../examples/GDS_plots'
)¶ GDS FIR filter generation
-
CALCS_corr(output_filename=
-
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:¶
- fNyq
int
, optional Nyquist frequency of FIR filter
- dur
float
, optional Duration in seconds of FIR filter
- highpass_fcut
float
, optional Cut off frequency for high-pass filter
- lowpass_fcut
float
, optional Cut off frequency for low-pass filter (relevant for inverse sensing filter)
- window_type
str
, 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
- fNyq
- 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
-
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.
-
pydarm.firtools.DolphChebyshev(N, alpha, return_double=
False
)¶ Dolph-Chebyshev window
-
pydarm.firtools.dft(td_data, exp_array=
None
, return_double=False
, inverse=False
)¶ First, a discrete Fourier transform, evaluated according to the definition
-
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.
-
pydarm.firtools.find_exp_array2(N, inverse=
False
)¶ A function to compute the array of exponentials for Bluestein’s algorithm.
- pydarm.firtools.find_prime_factors(N)¶
A function to find prime factors of N, the size of the input data.
-
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.
-
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
-
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.
-
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.
-
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]
-
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.
-
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.
-
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.
-
pydarm.firtools.resample(data, N_out, return_double=
False
)¶ A resampler
-
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.
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
- 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
- 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:¶
- frequencies
float
, array-like array of frequencies to compute the response
- frequencies
- 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
- uimdict,
-
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
- 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:¶
- frequencies
float
, array-like array of frequencies to compute the response
- frequencies
- Returns:¶
- uim_response
complex128
, array-like transfer function response of the UIM stage
- pum_response
complex128
, array-like transfer function response of the PUM stage
- tst_response
complex128
, array-like transfer function response of the TST stage
- uim_response
- 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:¶
- frequencies
float
, array-like array of frequencies to compute the response
- frequencies
- Returns:¶
- uim_response
complex128
, array-like transfer function response of the UIM stage
- pum_response
complex128
, array-like transfer function response of the PUM stage
- tst_response
complex128
, array-like transfer function response of the TST stage
- uim_response
- 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:¶
- frequencies
float
, array-like array of frequencies to compute the response
- frequencies
- Returns:¶
- uim_response
complex128
, array-like transfer function response of the UIM stage
- pum_response
complex128
, array-like transfer function response of the PUM stage
- tst_response
complex128
, array-like transfer function response of the TST stage
- uim_response
- 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:¶
- frequencies
float
, array-like array of frequencies to compute the response
- frequencies
- Returns:¶
- uim_response
complex128
, array-like transfer function response of the UIM stage, everything but N/ct
- pum_response
complex128
, array-like transfer function response of the PUM stage, everything but N/ct
- tst_response
complex128
, array-like transfer function response of the TST stage, everything but N/ct
- uim_response
- 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
- frequencies
float
, array-like array of frequencies to compute the response
- Returns:¶
- UIM_F2L_freqresp
complex128
, array-like transfer function response of the UIM stage
- PUM_F2L_freqresp
complex128
, array-like transfer function response of the PUM stage
- TST_F2L_freqresp
complex128
, array-like transfer function response of the TST stage
- UIM_F2L_freqresp
- 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>
- sus_digital_filters(frequencies)¶
The transfer function of the SUS digital filters
- Parameters:¶
- frequencies
float
, array-like array of frequencies to compute the response
- frequencies
- Returns:¶
- tst_isc_inf_filter_response
complex128
, array-like transfer function response of the ISC_INF digital filters in the TST path
- tst_lock_filter_response
complex128
, array-like transfer function response of the LOCK digital filters in the TST path
- tst_drive_align_filter_response
complex128
, array-like transfer function response of the DRIVEALIGN digital filters in the TST path
- pum_lock_filter_response
complex128
, array-like transfer function response of the LOCK digital filters in the PUM path
- pum_drive_align_filter_response
complex128
, array-like - transfer function response of the DRIVEALIGN digital filters in the
PUM path
- uim_lock_filter_response
complex128
, array-like transfer function response of the LOCK digital filters in the UIM path
- uim_drive_align_filter_response
complex128
, array-like transfer function response of the DRIVEALIGN digital filters in the UIM path
- tst_isc_inf_filter_response
- sus_digital_filters_response(frequencies)¶
The transfer function of the SUS digital filters
- Parameters:¶
- frequencies
float
, array-like array of frequencies to compute the response
- frequencies
- Returns:¶
- uim_digital_filter_response
complex128
, array-like transfer function response of the digital filters in the UIM path
- pum_digital_filter_response
complex128
, array-like transfer function response of the digital filters in the PUM path
- tst_digital_filter_response
complex128
, array-like transfer function response of the digital filters in the TST path
- uim_digital_filter_response
- 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
-
actuation_stage_residual(frequencies, stage=
- 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:¶
- frequencies
float
, array-like array of frequencies to compute the response
- arm
str
arm for the calculation, ‘x’ or ‘y’
- syserr_dict
dict
, optional dict of multiplicative values, ex.: {‘xarm’: {‘UIM’:
complex
, array-like}}
- frequencies
- Returns:¶
- super_actuation
complex128
, array-like transfer function response of the actuation function
- super_actuation
-
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.
- 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:¶
- frequencies
float
, array-like array of frequencies to compute the response
- stage
str
, optional SUS stage for the calculation, ‘UIM’, ‘PUM’, or ‘TST’
- syserr_dict
dict
, optional dict of multiplicative values, ex.: {‘xarm’: {‘UIM’:
complex
, array-like}}
- frequencies
- Returns:¶
- super_actuation
complex128
, array-like transfer function response of the actuation function
- super_actuation
-
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:¶
- frequencies
float
, array-like array of frequencies to compute the response
- stage
str
SUS stage for the calculation, ‘UIM’, ‘PUM’, or ‘TST’
- syserr_dict
dict
, optional dict of multiplicative values, ex.: {‘xarm’: {‘UIM’:
complex
, array-like}}
- frequencies
- Returns:¶
- super_actuation
complex128
, array-like transfer function response of the actuation function
- super_actuation
-
arm_super_actuator(frequencies, arm=
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?
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)
- 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
-
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.
- 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
-
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:¶
- frequencies
float
, array-like array of frequencies to compute the CAL_DELTAL_EXTERNAL DTT calibration
- include_whitening
bool
, 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_calib
bool
, 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_file
str
, optional Filename (ASCII) to save the data from this result. Note: the default file columns are <frequency> <magnitude (dB)> <phase (deg)>
- fmt
str
, 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
- frequencies
- Returns:¶
- tf
complex128
, array-like transfer function response of the calibration
- tf
- 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:¶
- frequencies
float
, array-like array of frequencies for the CALCS approximated DARM actuation
- arm
str
arm for the calculation, ‘x’ or ‘y’
- stage
str
SUS stage for the calculation, ‘UIM’, ‘PUM’, or ‘TST’
- frequencies
- Returns:¶
- calcs_stage_actuation
complex128
, array-like CALCS approximation of SUS model ISCINF input to DARM displacement transfer function
- calcs_stage_actuation
-
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_endstation
bool
, 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_endstation
bool
, 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_omc
bool
, 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
- exact
bool
, optional When True, the exact TDCF transfer function calculations are updated in the output dictionary. This will append new values to the output dictionary
- gds_pcal_endstation
- 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
- 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
- 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.
- 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:¶
- frequencies
float
, array-like array of frequencies for the CALCS approximated longitudinal actuation of the test mass from the given stage
- arm
str
arm for the calculation, ‘x’ or ‘y’
- stage
str
SUS stage for the calculation, ‘UIM’, ‘PUM’, or ‘TST’
- frequencies
- Returns:¶
- out_tf
complex128
, array-like CALCS approximation of the DRIVEALIGN output to displacement
- out_tf
-
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:¶
- frequencies
float
, array-like array of frequencies to compute the GDS sensing correction
- stage
str
SUS stage for the calculation, ‘UIM’, ‘PUM’, or ‘TST’
- daqdownsample
bool
, optional When True (default), the 16k-4k daqdownsample is applied in GDS actuation correction
- frequencies
- Returns:¶
- correction
complex128
, array-like transfer function response of the correction
- 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
- 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”
-
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:¶
- frequencies
float
, array-like array of frequencies to model the phase delay
- clock
boolean
, 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)
- frequencies
- 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.
- sus_response_ratio(frequencies, arm, stage)¶
This computes (sus resp) / (sus resp)_foton
See T1900169 definition of delta A_mn
-
A_corr(frequencies, daqdownsample=
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)
-
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:¶
- frequencies
float
, array-like array of frequencies to compute the response
- sensing_syserr
complex
, array-like, optional multiplicative factor to include relative sensing systematic error
- actuation_syserr_dict
dict
, optional dict of multiplicative values, ex.: {‘xarm’: {‘UIM’:
complex
, array-like}, ‘yarm’: {‘PUM’:complex
, array-like}}
- frequencies
- Returns:¶
- eta_R_c
complex128
, array-like multiplicative scaling factor for the response function, applying the sensing systematic errors only
- eta_R_a
complex128
, array-like multiplicative scaling factor for the response function, applying the actuation systematic errors only
- eta_R
complex128
, array-like multiplicative scaling factor for the response function, applying both sensing and actuation systematic errors
- eta_R_c
-
compute_response_function(frequencies, sensing_syserr=
None
, actuation_syserr_dict=None
)¶ Compute the entire DARM response transfer function (see G1501518)
- Parameters:¶
- frequencies
float
, array-like array of frequencies to compute the response
- sensing_syserr
complex
, array-like, optional multiplicative factor to include relative sensing systematic error
- actuation_syserr_dict
dict
, optional dict of multiplicative values, ex.: {‘xarm’: {‘UIM’:
complex
, array-like}}
- frequencies
- Returns:¶
- tf
complex128
, array-like transfer function of the DARM closed-loop response
- tf
-
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_selection
str
, optional Select plot type, one of: ‘all’ (default), ‘optical’, ‘actuation’, ‘clg’, ‘olg’, or ‘digital’
- freq_min
float
, optional start frequency
- freq_max
float
, optional end frequency
- filename
str
, optional if given, ALL generated graphs will be saved in one pdf
- ifo
str
, optional if given with a model to plot, it will appear in the graph titles
- label
str
list, optional FIXME: what should this be?
- style
str
, optional one of the styles matplotlib has or a user filename with style
- ugf_start
float
, optional start frequency used for the search
- ugf_end
float
, optional end frequency used for the search
- show
bool
, optional if true the plot(s) will show
- **kwargsoptional
Matplotlib values passed to plots
- plot_selection
- 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.
pydarm.digital module¶
- pydarm.digital.daqdownsamplingfilters(from_freq, to_freq, filter_method, rcg_ver)¶
Compute the transfer function for the DAQ downsampling filters
-
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_str
str
Number of samples per second input
- filter_calc_method
str
Filtering method. Choose between ‘biquad’ and ‘df2’
- rcg_ver
str
, optional RCG version. Choose between ‘v3’ (default) and ‘v2’ (only needed when also specifying ‘16k’ and ‘biquad’)
- model_sample_rate
int
, optional Model sampling rate. Default value is 2**16 = 65536
- sample_freq_str
- Returns:¶
- iopfilter
scipy.signal.StateSpace
State space object
- iopfilter
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.
-
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_file
str
This is the *.ini model file to be used to process the measurement data
- meas_type
str
This should be one of ‘actuation_x_arm’ or ‘actuation_y_arm’
- meas_sus_exc_to_darm
Measurement
This is the object that contains the data for the DARM_IN channel to suspension excitation response
- meas_pcal_to_darm
Measurement
This is the object that contains data for the PCAL to DARM TF
- meas_tup_1
str
, 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_2
str
, 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_cohThresh
float
, optional Coherence threshold that values in measurement 1 must be above to be included; valid values in the range [0,1]. (default = 0)
- meas2_cohThresh
float
, 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_file
str
, optional Filename of a JSON file when stacking measurements or running GPR
- config_file
- 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:¶
- frequencies
float
, array-like frequency values of the transfer function, in units of Hz
- processed_measurement_response
complex128
, 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_unc
float
, array-like relative uncertainty of processed measurement data
- frequencies
-
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:¶
- response
complex128
, array-like Transfer function of the optical response, having divided out the known quantities from the measured transfer functions
- kappa_Ai
float
, 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)
- response
-
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:¶
- frequencies
float
, array-like Frequencies at which to compute the GPR (Hz)
- measurement_list
ProcessSensingMeasurement
list a list of measurements to normalize
- fmin
float
, optional minimum frequency used for the MCMC of reference measurement
- fmax
float
, optional maximum frequency used for the MCMC of reference measurement
- fmin_list
float
list, optional list of minimum frequencies used for the MCMC or None
- fmax_list
float
list, optional list of maximum frequencies used for the MCMC or None
- RBF_length_scale
float
, 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_flim
tuple
, 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
- frequencies
- Returns:¶
- y_pred
complex128
, array-like Best fit curve using the GPR and covariance kernel
- sigma
float
, array-like Standard deviation for the GPR
- cov
float
, array-like Covariance matrix for the GPR
- stacked_meas
list
, 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
- y_pred
-
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:¶
- fmin
float
, optional Optional minimum frequency value for the MCMC fitting. Default is the minimum frequency of xdata (default = None)
- fmax
float
, 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_file
str
, optional Filename (JSON) to save the maximum a postiori values from this result
- save_chain_to_file
str
, optional Filename (HDF5) to save the postirior chain from this result
- kwargsoptional
other kwargs are passed to ProcessMeasurement._mcmc
- fmin
- Returns:¶
- chain
float
, 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
- chain
-
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 listAdditional kwargs parameters are unused but present in the definition of this method to serve as passthroughs. We need to clean this up.
- Parameters:¶
- measurement_list
ProcessSensingMeasurement
list a list of measurements to normalize
- fmin
float
, optional minimum frequency used for the MCMC
- fmax
float
, optional maximum frequency used for the MCMC
- fmin_list
float
list, optional list of minimum frequencies used for the MCMC or None
- fmax_list
float
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)
- measurement_list
- Returns:¶
- output
list
, 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
- output
-
class pydarm.measurement.ProcessDACDrivenSensingElectronicsMeasurement(config_file, meas_obj, meas_tup, meas_cohThresh=
0
)¶ Bases:
ProcessOneMeasurement
- Parameters:¶
- meas_obj_1
Measurement
This is the object that contains the data for DAC-Driven measurement electronics measurement
- meas_obj_2
Measurement
This is the object that contains the data for DAC-Driven measurement electronics measurement
- meas_tup_1
float
, 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_2
float
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_cohThresh
float
list, optional list of maximum frequencies used
- meas2_cohThresh
float
list, optional list of maximum frequencies used
- meas_obj_1
- Returns:¶
- DACDrivenActuation(frequencies)¶
Compute actuation part of the DAC-drive measuement 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
- frequencies
float
, array-like array of frequencies to compute DAC-driven measurement response
- Returns:¶
- tf
complex128
, array-like transfer function response
- tf
-
static compare_dac_driven_meas_response(frequencies, tf_meas1, tf_meas2, show_tf_plot=
None
, show_compare_plot=None
)¶ - Parameters:¶
- frequencies
float
, array-like frequency values of the transfer function, in units of Hz
- tf_meas1
complex128
, array-like the extracted transfer function from meas_tup_1, excluding frequency points below the meas1_cohThresh coherence threshold
- tf_meas2
complex128
, 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
- frequencies
- Returns:¶
- mag_comp
float
, array-like the ratio of magnitude between two measurements
- pha_comp
float
, array-like the ratio of phase between two measurements
- mag_comp
- 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
- frequencies
float
, array-like array of frequencies to compute DAC-driven measurement response
- Returns:¶
- tf
complex128
, array-like transfer function response
- tf
-
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_file
str
This is the *.ini model file to be used to process the measurement data
- meas_sensing_or_actuation
Measurement
This is the object that contains the data for either the closed loop gain (sensing measurement) or suspension measurement (actuation)
- meas_pcal_to_darm
Measurement
This is the object that contains data for the PCAL to DARM TF
- meas_tup_1
str
, tuple This should be (‘channel A’, ‘channel B’) for the first measurement
- meas_tup_2
str
, tuple This should be (‘channel A’, ‘channel B’) for the second measurement
- meas1_cohThresh
float
, optional Coherence threshold that values in measurement 1 must be above to be included; valid values in the range [0,1]. (default = 0)
- meas2_cohThresh
float
, 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_file
str
, optional Filename for a JSON file
- config_file
-
crop_data(xdata, ydata, yerr, fmin=
None
, fmax=None
)¶ Crop the data with optional minimum and maximum bounds
- Parameters:¶
- xdata
float
, array-like Original frequency data
- ydata
complex
, array-like Original transfer function data
- yerr
float
, array-like Original uncertainties computed from the coherence values
- fmin
float
, optional Optional minimum frequency value for the MCMC fitting. Default is the minimum frequency of xdata (default = None)
- fmax
float
, optional Optional maximum frequency value for the MCMC fitting. Default is the maximum frequency of xdata (default = None)
- xdata
- Returns:¶
- xdata
float
, array-like cropped frequencies
- ydata
complex
, array-like cropped transfer function data
- yerr
float
, array-like cropped uncertainties computed from the coherence values
- xdata
- 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:¶
- frequencies
float
, array-like frequency values of the transfer function, in units of Hz
- tf_meas1
complex128
, array-like the extracted transfer function from meas_tup_1, excluding frequency points below the meas1_cohThresh coherence threshold
- tf_meas2
complex128
, array-like the extracted transfer function from meas_tup_2, excluding frequency points below the meas2_cohThresh coherence threshold
- pcal_correction
complex128
, array-like the transfer function for the offline photon calibrator correction
- processed_measurement_response_unc
float
, array-like relative uncertainty of combined measurement data
- frequencies
-
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’
- fmin
float
, optional minimum frequency used for the MCMC
- fmax
float
, optional maximum frequency used for the MCMC
- match
str
, optional result to return; ‘first’, ‘latest’, ‘all’ or the date of measurement analysis ‘DD/MM/YYYY HH:MM:SS’
- strict
bool
, optional if True, return the first entry in the json file. Default is False.
- Returns:¶
- measurement analysis date
str
the date of processing measurement analysis in form of ‘DD/MM/YYYY HH:MM:SS’
- mcmc_map_vals
float
, 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)
- measurement analysis date
-
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_vals
float
, 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_file
str
This is the *.ini model file to be used to process the measurement data
- meas
Measurement
This is the object that contains the data for either the closed loop gain (sensing measurement) or suspension measurement (actuation)
- meas_tup
str
, tuple This should be (‘channel A’, ‘channel B’) for the first measurement
- meas_cohThresh
float
, optional Coherence threshold that values in measurement must be above to be included; valid values in the range [0,1]. (default = 0)
- config_file
- 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:¶
- frequencies
float
, array-like frequency values of the transfer function, in units of Hz
- tf_meas
complex128
, array-like the extracted transfer function from meas_tup_1, excluding frequency points below the meas1_cohThresh coherence threshold
- unc_meas
float
, array-like relative uncertainty of measurement data
- frequencies
-
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_file
str
This is the *.ini model file to be used to process the measurement data
- meas_clg
Measurement
This is the object that contains the data for the closed loop gain
- meas_pcal_to_darm
Measurement
This is the object that contains data for the PCAL to DARM TF
- meas_tup_1
str
, tuple This should be (‘channel A’, ‘channel B’) for the first measurement Ex.: (‘H1:LSC-DARM1_IN2’, ‘H1:LSC-DARM1_EXC’)
- meas_tup_2
str
, 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_cohThresh
float
, optional Coherence threshold that values in measurement 1 must be above to be included; valid values in the range [0,1]. (default = 0)
- meas2_cohThresh
float
, 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_file
str
, optional Filename of a JSON file when stacking measurements or running GPR
- config_file
- 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:¶
- frequencies
float
, array-like frequency values of the transfer function, in units of Hz
- processed_measurement_response
complex128
, array-like transfer function response of the actuation function in units of digital counts per meter of DARM
- processed_measurement_response_unc
float
, array-like relative uncertainty of processed measurement data
- frequencies
- 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_chain
float
, array-like The result from the run_mcmc() method
- mcmc_chain
-
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_chain
float
, array-like The result from the run_mcmc() method
- cftdboolean, optional
if True then omit the 7000 Hz pole, nominally for the CFTD path
- mcmc_chain
-
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:¶
- frequencies
float
, array-like Frequency values for the transfer functions
- response
complex128
, array-like Transfer function of the optical response, having divided out the known quantities from the measured transfer functions
- kappa_c
float
, 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_cc
float
, 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)
- frequencies
- Returns:¶
- response
complex128
, array-like The scaled transfer function of optical response
- 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:¶
- frequencies
float
, array-like Frequencies at which to compute the GPR (Hz)
- measurement_list
ProcessSensingMeasurement
list a list of measurements to normalize
- fmin
float
, optional minimum frequency used for the MCMC of reference measurement
- fmax
float
, optional maximum frequency used for the MCMC of reference measurement
- fmin_list
float
list, optional list of minimum frequencies used for the MCMC or None
- fmax_list
float
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_scale
float
, 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_flim
tuple
, 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
- frequencies
- Returns:¶
- y_pred
complex128
, array-like Best fit curve using the GPR and covariance kernel
- sigma
float
, array-like Standard deviation for the GPR
- cov
float
, array-like Covariance matrix for the GPR
- stacked_meas
list
, 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
- y_pred
-
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:¶
- fmin
float
, optional Optional minimum frequency value for the MCMC fitting. Default is the minimum frequency of xdata (default = None)
- fmax
float
, 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_file
str
, optional Filename (JSON) to save the maximum a postiori values from this result
- save_chain_to_file
str
, optional Filename (HDF5) to save the postirior chain from this result
- kwargsoptional
other kwargs are passed to ProcessMeasurement._mcmc
- fmin
- Returns:¶
- chain
float
, 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
- chain
-
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_list
ProcessSensingMeasurement
list a list of measurements to normalize
- fmin
float
, optional minimum frequency used for the MCMC
- fmax
float
, optional maximum frequency used for the MCMC
- fmin_list
float
list, optional list of minimum frequencies used for the MCMC or None
- fmax_list
float
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
- measurement_list
- Returns:¶
- output
list
, 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
- output
-
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.
- 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
- 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
- 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.
-
analog_aa_or_ai_filter_response(frequencies, idx=
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:¶
- frequencies
float
, array-like array of frequencies to compute the response
- endstation
bool
, 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_dewhitening
bool
, optional if the dewhitening filter is on (default), then the correction will include the two 1 Hz poles
- arm
str
, optional string to indicate which arm is used for this correction, ‘REF’ (default), ‘X’, or ‘Y’
- frequencies
- Returns:¶
- tf
complex128
, array-like transfer function response of the correction
- tf
- digital_filter_response(frequencies)¶
- Importing suspension filter from FOTON file which normalized by whitening
filter 2 1Hz poles (susnorm) and mpN_DC gain.
-
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
- newtons_per_watt()¶
Newtons per watt for the photon calibrator 2*cos(theta)/c
- pcal_dewhiten_response(frequencies)¶
Compute the dewhitening response
-
compute_pcal_correction(frequencies, endstation=
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:¶
- freq
array
,list
frequency array
- tf
array
,list
frequency response
- tf_error
array
,list
relative error of frequency response
- **kwargs
Text
properties Other miscellaneous text parameters for matplotlib
- freq
- 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_minor
bool
Determine the finer tick location for log axes
- more_minor
-
legend(labels=
None
, **kwargs)¶ add legend
- Parameters:¶
- labels
string
, Optional add string legend for the plot
- **kwargs
Text
properties Other miscellaneous text parameters for matplotlib
- labels
- plot(freq, tf, **kwargs)¶
add frequency response to plot
- Parameters:¶
- freq
array
,list
frequency array
- tf
array
,list
frequency response
- **kwargs
Text
properties Other miscellaneous text parameters for matplotlib
- freq
- save(path)¶
save bode plot to file
- Parameters:¶
- path
str
,path-like
orbinary file-like
path directory for saving the figure
- path
- show()¶
show interactive plot
- text(x, y, plot_text)¶
add text in plot
- Parameters:¶
- x
float
x-position to place the text
- y
float
y-position to place the text
- plot_text
str
The text
- x
-
vlines(vfreq, color=
'red'
, lw=1.0
, linestyle='--'
, label='_nolegend_'
)¶ add vertical line at specific frequency in both mag and phase plot
- Parameters:¶
- vfreq
float
frequency point for vertical line
- color
color
, Optional color for vertical line, default = ‘red’
- lw
float
line width, default = 1.0
- linestyle{‘-’, ‘–’, ‘-.’, ‘:’, ‘’, …}, Optional
style for vertical line, default = ‘–’
- label
str
legend string for the vertical line
- vfreq
- xlim(freq_min, freq_max)¶
set min max for frequency axis
- Parameters:¶
- freq_min
float
start frequency
- freq_max
float
end frequency
- freq_min
-
ylim(mag_min, mag_max, phase_min=
-185
, phase_max=185
)¶ set min max for the magnitude (and phase) axis
- Parameters:¶
- mag_min
float
minimum magnitude scale
- mag_max
float
maximum magnitude scale
- phase_min
float
, Optional minimum phase scale, default = -185
- phase_max
float
, Optional maximum phase scale, default = 185
- mag_min
-
static autoscale_axis(ax, xlim=
-
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_minor
bool
, 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]
- more_minor
-
legend(label=
None
, quadrant=['tl', 'bl', 'tr', 'br']
)¶ add legend
- Parameters:¶
- label
str
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)
- label
- plot(tuple_left, tuple_right, **kwargs)¶
- Add frequency response to plot with or without error
Note: Error should be relative.
- Parameters:¶
- tuple_left
tuple
,array-like
add frequency response for the left-side frequencies area
- tuple_right
tuple
,array-like
add frequency response for the right-side frequencies area
- **kwargs
Text
properties Other miscellaneous text parameters for matplotlib
- tuple_left
- save(path)¶
save bode plot to file
- Parameters:¶
- path
str
,path-like
path directory for saving the figure
- path
- show()¶
show interactive plot
-
text(x, y, plot_text, quadrant=
['tl', 'bl', 'tr', 'br']
)¶ add text in plot
- Parameters:¶
- x
float
x-position to place the text
- y
float
y-position to place the text
- plot_text
str
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]
- x
-
vlines(vfreq, quadrant=
['tl', 'bl', 'tr', 'br']
)¶ add vertical line at specific frequency in both mag and phase plot
- Parameters:¶
- vfreq
float
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]
- vfreq
-
xlim(freq_min, freq_max, quadrant=
['tl', 'bl', 'tr', 'br']
)¶ set min max for frequency axis
- Parameters:¶
- freq_min
float
, Optional start frequency
- freq_max
float
, 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]
- freq_min
-
xscale(scale=
'linear'
, quadrant=['tl', 'bl', 'tr', 'br']
)¶ change the y scale of plot at given quadrant, linear or log
- Parameters:¶
- scale
str
, 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]
- scale
-
ylim(y_min, y_max, quadrant=
['tl', 'bl', 'tr', 'br']
)¶ set min max for the magnitude (and phase) axis
- Parameters:¶
- freq_min
float
, Optional start frequency
- freq_max
float
, 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]
- freq_min
-
yscale(scale=
'linear'
, quadrant=['tl', 'bl', 'tr', 'br']
)¶ change the y scale of plot at given quadrant, linear or log
- Parameters:¶
- scale
str
, 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]
- scale
-
greed(more_minor=
-
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:¶
- args
pydarm.darm.DARMModel
object 1 or 2 darm models objects, if more than 1, this should be a list
- filename
str
, optional if given, ALL generated graphs will be saved in one pdf
- plot_selection
str
, optional Select plot type, one of: ‘all’ (default), ‘optical’, ‘actuation’, ‘clg’, ‘olg’, or ‘digital’
- ifo
str
, optional if given with a model to plot, it will appear in the graph titles
- show
bool
, optional if true the plot(s) will show
- label
str
list, optional a list of labels for legend
- freq_min
float
, optional start frequency
- freq_max
float
, optional final frequency
- freq_points
int
, optional Number of frequency points
- ugf_start
float
, optional start frequency used for the search
- ugf_end
float
, optional end frequency used for the search
- greed
bool
, optional - figsize
float
, tuple - **kwargsoptional
Matplotlib values passed to plots
- args
-
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:¶
- freq
float
,array
frequencie arrays corresponding to the given tf
- tf
complex
,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
- freq
- 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_min
float
, optional start frequency
- freq_max
float
, optional end frequency
- freq_points
int
, optional number of points to calculate
- filename
str
, optional if given, ALL generated graphs will be saved in one pdf.
- mag_min
float
, optional minimum magnitude scale
- mag_max
float
, optional maximum magnitude scale
- phase_min
float
, optional minimum phase scale
- phase_max
float
, optional maximum phase scale
- label
str
list, optional legend string for the data sets given e.g. [‘first data’, ‘second’]
- title
str
, optional title of the graph
- style
str
, optional one of the styles matplotlib has or a user filename with style
- show
bool
, optional if true the plot will show
- greed
bool
, optional if true a finer grid is drawn for all figs
- figsize
float
tuple, optional figure size
- **kwargs
matplotlib arguments passed to all plots
- Returns:¶
- bp
pydarm.plot.BodePlot
object
- bp
-
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_model
float
, array-like frequencies that the model transfer function is computed
- tf_model
complex
, array-like transfer function response values at the
freq_model
points- freq_data
float
, array-like frequencies that the measured transfer function data values are computed at
- tf_data
complex
, array-like measured transfer function response values at the
freq_daata
points- unc_data
float
, array-like relative uncertainty values, determined from the measurement coherence
- mag_min
float
, optional minimum magnitude scale
- mag_max
float
, optional maximum magnitude scale
- phase_min
float
, optional minimum phase scale
- phase_max
float
, optional maximum phase scale
- mag_major_tick
float
, optional major tick placement for the residual magnitude plot
- mag_minor_tick
float
, optional minor tick placement for the residual magnitude plot
- phase_major_tick
float
, optional major tick placement for the residual phase plot
- phase_minor_tick
float
, optional minor tick placement for the residual phase plot
- filename
str
, optional save the plot to this file
- show
bool
, optional if true the plot will show
- freq_model
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:¶
- filename
str
pdf file name for the figures
- figs
list
,dict
list of given figures to save
- filename
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
- frequencies
float
, array-like array of frequencies to compute the response
- Returns:¶
- delay
complex
, array-like frequency response of the ADC delay
- delay
- compute_sensing(frequencies)¶
Compute the entire sensing function transfer function (see G1501518)
- light_travel_time_delay_response(frequencies)¶
Compute the frequency response from the light travel time delay
- mean_arm_length()¶
Compute the mean arm length of the x and y arms
- Returns:¶
- mean_length
float
mean arm length in units of meters
- mean_length
- 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
- frequencies
float
, array-like array of frequencies to compute the response
- Returns:¶
- response
complex128
, array-like transfer function response of the analog electronics in path
name
- response
- 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
- 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
- frequencies
float
, array-like array of frequencies to compute the response
- Returns:¶
- response
complex128
, array-like transfer function response of the analog transimpedence amplifier in path
name
- response
- 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
- frequencies
float
, array-like array of frequencies to compute the response
- Returns:¶
- response
complex128
, array-like transfer function response of the analog whitening electronics in path
name
- response
- 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
- frequencies
float
, array-like array of frequencies to compute the response
- Returns:¶
- filter_response
complex128
, array-like transfer function response of the digital filters in the path labeled by
name
- filter_response
- 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
- frequencies
float
, array-like array of frequencies to compute the response
- Returns:¶
- path_response
complex128
, array-like transfer function response of the path labeled by
idx
- path_response
-
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
- sensing_residual(frequencies)¶
Compute the residual sensing function
This is everything in the sensing function except the optical gain and the optical response
- single_pole_approximation_delay_correction_response(frequencies)¶
Compute the frequency response from the time delay correction to the single pole approximation
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
- frequencies
float
, array-like array of frequencies to compute the response
- trials
int
, optional number of times to sample the response
- data
gwpy.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_tf
complex
, 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_h5
str
, optional Path to file for saving response curves and samples as HDF5 (.h5 or .hdf5)
- save_to_file_txt
str
, 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
- response_sampleslist of
-
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
- frequencies
float
, array-like array of frequencies to compute the response
- data
gwpy.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:¶
- tf
complex128
, array-like transfer function response of the sensing function
- data
gwpy.timeseries.TimeSeriesDict
object object containing the queried channel data
- tf
-
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:¶
- frequencies
float
, array-like - response_mag_quant
float
, array-like - response_pha_quant
float
, array-like - ifo
str
, H1 or L1 - y_mag
float
, optional Y-axis magnitude range, in percent (default is +/- 10%)
- y_pha
float
, 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
- frequencies
- Returns:¶
- fig:
matplotlib.figure.Figure
, figure of uncertainty
- fig:
-
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_samples
complex128
, list list of arrays of ration of sampled responses to nominal response
- quantiles
float
, list, optional list of quantiles desired to be computed
- response_samples
- Returns:¶
- response_mag_quant
float
, array-like 2-d array of length(quantiles) x length(response_samples) giving magnitude quantiles
- response_pha_quant
float
, array-like 2-d array of length(quantiles) x length(response_samples) giving phase quantiles in radians
- response_mag_quant
-
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_quant
float
, array-like 2-d array of length(quantiles) x length(response_samples) giving magnitude quantiles
- response_pha_quant
float
, 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_txt
str
, 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_mag
float
, array-like 2-d array of length(3) x length(response_samples) giving magnitude quantiles (16th, 50th, 84th)
- response_unc_mon_phase
float
, array-like 2-d array of length(3) x length(response_samples) giving phase quantiles (16th, 50th, 84th)
- response_unc_mon_mag
-
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
- frequencies
float
, 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_gpr
complex
, array-like sampled GPR function
- this_gpr
-
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)
- data
gwpy.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_x
float
, array-like - this_cal_sus_y
float
, array-like
-
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
- frequencies
float
, array-like array of frequencies to compute the response
- data
gwpy.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_gpr
str
, optional Path to file of an additional sensing function GPR to apply when sampling
- Returns:¶
- tf
complex128
, array-like transfer function response of the sensing function
- data
gwpy.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_syserr
complex128
, array-like sample for this sensing function GPR
- act_syserr_dictdict
dictionary of samples for this arm and stage for actuation GPR
- tf
- 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)
- data
gwpy.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:¶
- sensing
float
, array-like kappa_c and f_cc in that order; zero if no channel provided
- actuation_x_arm
float
, array-like kappa_uim, kappa_pum, kappa_tst in that order; zero if no channel provided
- actuation_y_arm
float
, array-like kappa_uim, kappa_pum, kappa_tst in that order; zero if no channel provided
- sensing
-
compute_response_uncertainty(gpstime, frequencies, trials=
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:¶
- tf
complex128
, array-like transfer function response of the digital SUS filter
- pfiltarray-like
The Foton file is stored in this array for later re-use
- tf
- 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:¶
- sys
scipy.signal.ZerosPolesGain
Filter object
- w
float
, array-like Angular frequencies at which to compute the filter response
- sys
- Returns:¶
- w
float
, array-like Angular frequencies at which to compute the filter response
- h
complex128
, array-like Filter response
- w
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
- pydarm.utils.freqrespZPK(sys, w)¶
Compute the frequency response of a continuous ZPK filter
- Parameters:¶
- sys
scipy.signal.ZerosPolesGain
Filter object
- w
float
, array-like Angular frequencies at which to compute the filter response
- sys
- Returns:¶
- g
complex128
, array-like Filter response
- g
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)
- pydarm.utils.parallelZPK(sys1, sys2)¶
Add two ZPK filters together as though they were in parallel paths and summed
- Parameters:¶
- sys1
scipy.signal.ZerosPolesGain
First filter object
- sys2
scipy.signal.ZerosPolesGain
Second filter object
- sys1
- Returns:¶
- sys
scipy.signal.ZerosPolesGain
Combined filter object
- sys
Examples
>>> out = parallelZPK(in1, in2)
-
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
- pydarm.utils.read_filter_file(filename)¶
Read a filter file and return all the SOS coefficients info for the filters
- 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:¶
- filename
str
Path and filename of FOTON filter file
- bank
str
Name of the filter bank
- module
int
, 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
- filename
- Returns:¶
- sysd
scipy.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
- sysd
- 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_pred
complex128
, array-like Best fit curve using the GPR and covariance kernel
- cov
float
, array-like Covariance matrix for the GPR
- frequencies
float
, 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
- 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_model
str
ordict
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’
- chain
float
, 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_pred
complex128
, array-like Best fit curve using the GPR and covariance kernel
- cov
float
, array-like Covariance matrix for the GPR
- frequencies
float
, 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:¶
- filename
str
Chosen output filename, needs to end in .txt
- frequencies
float
, 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)
- filename
- pydarm.utils.serielZPK(sys1, sys2)¶
Multiply two ZPK filters together as though they were in a seriel path
- Parameters:¶
- sys1
scipy.signal.ZerosPolesGain
First filter object
- sys2
scipy.signal.ZerosPolesGain
Second filter object
- sys1
- Returns:¶
- sys
scipy.signal.ZerosPolesGain
Combined filter object
- sys
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
-
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.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.
-
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:¶
- frequencies
float
, array-like array of frequencies for the transfer function
- transfer_function
complex128
, array-like array of transfer function response values
- filenamestr
Output filename
- name
str
, optional Optional extra name string printed to the header
- info
str
, optional Optional additional information string printed to the header
- frequencies