util module

pub

class pysmurf.client.util.pub.Publisher(script_id=None, options={}, env_root=None)[source]
log_start()[source]

Publishes start message

log_stop()[source]

Publishes stop message

register_file(path, type, format='', timestamp=None, plot=False)[source]

Publishes file info so it can be picked up by the pysmurf-archiver.

Parameters
  • path (str) – Full path to file.

  • type (str) – Type of data file, e.g. “tuning” or “config_snapshot”.

  • format (str) – File extension. E.g. “npy” or “txt”.

  • timestamp (float or None, optional, default None) – Unix timestamp when file was created.

  • plot (bool, optional, default False) – True if file is a plot

smurf_util

class pysmurf.client.util.smurf_util.SmurfUtilMixin(log=None, epics_root=None, offline=False, pub_root=None, script_id=None, **kwargs)[source]
all_off()[source]

Turns off everything. Does band off, flux ramp off, then TES bias off.

att_to_band(att)[source]

500 MHz band associated with this attenuator number.

Parameters

att (int) – Attenuator number.

Returns

band – The 500 MHz band associated with the attenuator.

Return type

int

band_off(band, **kwargs)[source]

Turns off all tones in a band

Parameters

band (int) – The band that is to be turned off.

band_to_att(band)[source]

Attenuator number associated with this 500 MHz band.

Parameters

band (int) – 500 MHz band number.

Returns

att – The attenuator number associated with the band.

Return type

int

bias_bump(bias_group, wait_time=0.5, step_size=0.001, duration=5.0, start_bias=None, make_plot=False, skip_samp_start=10, high_current_mode=True, skip_samp_end=10, plot_channels=None, gcp_mode=False, gcp_wait=0.5, gcp_between=1.0, dat_file=None, offset_percentile=2)[source]

Toggles the TES bias high and back to its original state. From this, it calculates the electrical responsivity (sib), the optical responsivity (siq), and resistance.

This is optimized for high_current_mode. For low current mode, you will need to step much slower. Try wait_time=1, step_size=.015, duration=10, skip_samp_start=50, skip_samp_end=50.

Note that only the resistance is well defined now because the phase response has an un-set factor of -1. We will need to calibrate this out.

Parameters
  • bias_group (int of int array) – The bias groups to toggle. The response will return every detector that is on.

  • wait_time (float, optional, default 0.5) – The time to wait between steps

  • step_size (float, optional, default 0.001) – The voltage to step up and down in volts (for low current mode).

  • duration (float, optional, default 5.0) – The total time of observation.

  • start_bias (float or None, optional, default None) – The TES bias to start at. If None, uses the current TES bias.

  • make_plot (bool, optional, default False) – Whether to make plots. Must set some channels in plot_channels.

  • skip_samp_start (int, optional, default 10) – The number of samples to skip before calculating a DC level.

  • high_current_mode (bool, optional, default True) – Whether to observe in high or low current mode.

  • skip_samp_end (int, optional, default 10) – The number of samples to skip after calculating a DC level.

  • plot_channels (int array or None, optional, default None) – The channels to plot.

  • dat_file (str or None, optional, default None) – Filename to read bias-bump data from; if provided, data is read from file instead of being measured live.

  • offset_percentile (float, optional, default 2.0) – Number between 0 and 100. Determines the percentile used to calculate the DC level of the TES data.

Returns

  • bands (int array) – The bands.

  • channels (int array) – The channels.

  • resistance (float array) – The inferred resistance of the TESs in Ohms.

  • sib (float array) – The electrical responsivity. This may be incorrect until we define a phase convention. This is dimensionless.

  • siq (float array) – The power responsivity. This may be incorrect until we define a phase convention. This is in uA/pW

channel_off(band, channel, **kwargs)[source]

Turns off the tone for a single channel by setting the amplitude to zero and disabling feedback.

Parameters
  • band (int) – The band that is to be turned off.

  • channel (int) – The channel to turn off.

channel_to_freq(band, channel=None, yml=None)[source]

Gives the frequency of the channel.

Parameters
  • band (int) – The band the channel is in.

  • channel (int, None, or array, optional, default None) – If None, will return the channel freqs of all enabled channels

Returns

freq – The channel frequency in MHz or an array of values if channel is None. In the array format, the freq list is aligned with self.which_on(band).

Return type

float

check_adc_saturation(band)[source]

Reads data directly off the ADC. Checks for input saturation.

Parameters

band (int) – Which band. Assumes adc number is band%4.

Returns

saturated – True if ADC is saturated, otherwise False.

Return type

bool

check_dac_saturation(band)[source]

Reads data directly off the DAC. Checks for input saturation.

Parameters

band (int) – Which band. Assumes dac number is band%4.

Returns

saturated – Flag if DAC is saturated.

Return type

bool

check_full_band_resp(n_scan_per_band=5, amc_auto_detect=True, make_plot=True, save_plot=True, show_plot=False, save_results=True, **kwargs)[source]

Measures RF transfer function for all configured AMCs. This function is based on scratch/shawn/full_band_response.py. Usually we run this function with the AMCs connected in loopback with a short RF cable to verify that they are working.

Parameters
  • n_scan (int, optional, default 5) – The number of times to measure each band using full_band_resp.

  • amc_auto_detect (bool, optional, default True) – If True, determines AMC RF bands from serial number. Otherwise, uses get_band_center_mhz.

  • make_plot (bool, optional, default True) – Whether to make a plot.

  • save_plot (bool, optional, default True) – Whether to save the plot.

  • show_plot (bool, optional, default False) – Whether to show the plot

  • save_results (bool, optional, default True) – Whether or not to save the results.

  • **kwargs – Arbitrary keyword arguments. Passed directly to the full_band_resp call.

Returns

results – Dictionary with results.

Return type

dict

check_jesd(bay, silent_if_valid=False, max_timeout_sec=60, get_timeout_sec=5)[source]

Checks JESD status for requested bay.

Queries the Jesd tx and rx and compares the data_valid and enable bits. If newer Rogue AppTop.JesdHealth method is available, returns its status.

Parameters
  • bay (int) – Which bay (0 or 1).

  • silent_if_valid (bool, optional, default False) – If True, does not print anything if things are working.

  • max_timeout_sec (float, optional, default 60.0) – Seconds to wait for JESD health check to complete before giving up. Passed to set_check_jesd()

  • caget_timeout_sec (float, optional, default 5.0) – Seconds to wait for each poll of the JESD health check status register (see get_jesd_status()). Passed to set_check_jesd()

Returns

  • jesd_tx (bool) – True if DataValid = Enable for this bay’s JesdTx, otherwise False.

  • jesd_rx (bool) – True if DataValid = Enable for this bay’s JesdRx, otherwise False.

  • jesd_status (str or None) – System (all bays) JESD health status (see get_jesd_status() for a description of the possible statuses).

See also

set_check_jesd()

Gets the status of the Rogue AppTop.JesdHealth method.

config_cryo_channel(band, channel, frequencyMHz, amplitude, feedback_enable, eta_phase, eta_mag)[source]

Set parameters on a single cryo channel

Parameters
  • band (int) – The band for the channel.

  • channel (int) – Which channel to configure.

  • frequencyMHz (float) – The frequency offset from the subband center in MHz.

  • amplitude (int) – Amplitude scale to set for the channel (0..15).

  • feedback_enable (bool) – Whether to enable feedback for the channel.

  • eta_phase (float) – Feedback eta phase, in degrees (-180..180).

  • eta_mag (float) – Feedback eta magnitude.

decode_data(filename, swapFdF=False, recast=True, truncate=True)[source]

Take a dataset from take_debug_data and spit out results.

Parameters
  • filename (str) – Path to file.

  • swapFdF (bool, optional, default False) – Whether the F and dF (or I/Q) streams are flipped.

  • recast (bool, optional, default True) – Whether to recast from size n_channels_processed to n_channels.

  • truncate (bool, optional, default True) – Truncates the data if the number of elements returned is not an integer multiple of the sample rate.

Returns

  • f (numpy.ndarray) – If iqStreamEnable = 0. f is the tracking frequency. Otherwise if iqStreamEnable = 1. f is the demodulated in-phase tracking component.

  • df (numpy.ndarray) – If iqStreamEnable = 0. df is the tracking frequency error. Otherwise if iqStreamEnable = 1. f is the demodulated quadrature tracking component.

  • flux_ramp_strobe (numpy.ndarray) – The synchronizing pulse.

decode_single_channel(filename, swapFdF=False)[source]

decode take_debug_data file if in singlechannel mode

Parameters
  • filename (str) – Path to file to decode.

  • swapFdF (bool, optional, default False) – Whether to swap f and df streams.

Returns

[f, df, sync] if iq_stream_enable = False [I, Q, sync] if iq_stream_enable = True

Return type

list

estimate_phase_delay(band, nsamp=524288, make_plot=True, show_plot=True, save_plot=True, save_data=True, n_scan=5, timestamp=None, uc_att=None, dc_att=None, freq_min=- 2400000.0, freq_max=2400000.0)[source]

Estimates total system latency for requested band.

Measures the analog and digital (=processing) phase delay (or latency) by sweeping the [freq_min, freq_max] interval of the requested 500 MHz band. Estimates the best values for the refPhaseDelay and refPhaseDelayFine firmware registers to compensate for the measured delay. Three steps:

  1. Measures the analog latency using the [freq_min, freq_max] sub-interval of data taken using the full_band_resp() routine.

  2. Measures the total latency using the find_freq() routine.

  3. Sets the refPhaseDelay and refPhaseDelayFine registers to the values computed to best compensate for the total measured latency and re-measures the total latency again using the find_freq() routine.

On completion, the refPhaseDelay and refPhaseDelayFine registers are set to the estimated optimal values.

Parameters
  • band (int) – The band to estimate phase delay on.

  • nsamp (int, optional, default 2**19) – The number of samples to take.

  • make_plot (bool, optional, default True) – Whether or not to make plots.

  • show_plot (bool, optional, default True) – Whether or not to show plots.

  • save_plot (bool, optional, default True) – Whether or not to save plot to file.

  • save_data (bool, optional, default True) – Whether or not to save data to file.

  • n_scan (int, optional, default 5) – Number of scans to do to estimate analog phase delay, passed to full_band_resp().

  • timestamp (str or None, optional, default None) – ctime to timestamp the plot and data with (if saved to file). If None, it gets the time stamp right before acquiring data.

  • uc_att (int or None, optional, default None) – UC attenuator setting to use during measurements. If None, uses currently programmed setting.

  • dc_att (int or None, optional, default None) – DC attenuator setting to use during measurements. If None, uses currently programmed setting.

  • freq_min (float, optional, default -2.4E6) – Lower bound of the frequency interval used to estimate the phase delay, in Hz. From the center of the 500 MHz band.

  • freq_max (float, optional, default 2.4E6) – Upper bound of the frequency interval used to estimate the phase delay, in Hz. From the center of the 500 MHz band.

Returns

  • processing_delay_us (float) – Estimated processing phase delay, in microseconds.

  • dsp_corr_delay_us (float) – Residual total phase delay, for estimated refPhaseDelay and refPhaseDelayFine.

find_probe_tone_gap(band, n_tone=2, n_scan=5, make_plot=True, save_plot=True, show_plot=False)[source]

This finds the larges n_tone gaps in the band. These are used for finding gaps to put probe tones for checking JESD skips.

Parameters
  • band (int) – The 500 MHz frequency band to find gaps.

  • n_tone (int, optional) – The number of probe tones. Or the number of gaps to find.

  • n_scan (int, optional) – The number of times to measure the band using full_band_resp.

  • make_plot (bool, optional, default True) – Whether to make a plot.

  • save_plot (bool, optional, default True) – Whether to save the plot.

  • show_plot (bool, optional, default False) – Whether to show the plot

Returns

gaps – An array of size [n_tone, 2], indicating the start and end of the gap. recomment using the middle value between the two edges. You can calulate this quickly with np.mean(gaps, axis=1).

Return type

float array

flux_ramp_PV_to_rate(val)[source]

Convert between PV number in timing triggers and output flux ramp reset rate

Returns: reset_rate (int): the flux ramp reset rate, in kHz

flux_ramp_rate_to_PV(val)[source]

Convert between the desired flux ramp reset rate and the PV number for the timing triggers.

Hardcoded somewhere that we can’t access; this is just a lookup table Allowed reset rates (kHz): 1, 2, 3, 4, 5, 6, 8, 10, 12, 15

Returns: rate_sel (int): the rate sel PV for the timing trigger

freq_to_subband(band, freq)[source]

Look up subband number of a channel frequency, and its subband frequency offset.

Parameters
  • band (float) – The band to place the resonator.

  • freq (float) – Frequency in MHz.

Returns

  • subband_no (int) – Subband (0..n_subbands-1) of the frequency within the band.

  • offset (float) – Offset from subband center.

gcp_num_to_mask_num(gcp_num)[source]

Goes from a GCP number to the smurf2mce index. Inverse of mask_num_to_gcp_num

Parameters

gcp_num (int) – The gcp index.

Returns

mask_num – The index in the mask.

Return type

int

gcp_num_to_smurf_channel(gcp_num)[source]

Converts from gcp number to smurf channel (band and channel).

Parameters

gcp_num (int) – The GCP number.

Returns

  • band (int) – The smurf band number.

  • channel (int) – The smurf channel number.

get_channel_order(band=None, channel_orderfile=None)[source]

produces order of channels from a user-supplied input file

Parameters
  • band (int or None, optional, default None) – Which band. If None, assumes all bands have the same number of channels, and pulls the number of channels from the first band in the list of bands specified in the experiment.cfg.

  • channelorderfile (str or None, optional, default None) – Path to a file that contains one channel per line.

Returns

channel_order – An array of channel orders.

Return type

int array

get_channels_in_subband(band, subband, channelorderfile=None)[source]

Returns channels in subband

Parameters
  • band (int) – Which band.

  • subband (int) – Subband number, ranges from 0..127.

  • channelorderfile (str or None, optional, default None) – Path to file specifying channel order.

Returns

subband_chans – The channels in the subband.

Return type

int array

get_filter_params()[source]

Get the downsample filter parameters: filter order, filter gain, num averages, and the actual filter parameters.

If filter order is -1, the downsampler is using a rectangula integrator. This will set filter_a, filter_b to None.

Returns

filter_params – A dictionary with the filter parameters.

Return type

dict

get_fpga_status()[source]

Loads FPGA status checks if JESD is ok.

Returns

ret – A dictionary containing uptime, fpga_version, git_hash, build_stamp, jesd_tx_enable, and jesd_tx_valid

Return type

dict

get_gradient_descent_params(band)[source]

Convenience function for getting all the serial gradient descent parameters

Parameters

band (int) – The band to query.

Returns

params – A dictionary with all the gradient descent parameters

Return type

dict

get_hardware_log_entry()[source]

Returns hardware log file header and data.

Returns

  • hdr (str) – Header for hardware log file.

  • row (str) – One row of data for hardware log file. Measured values are polled once each time function is called.

See also

start_hardware_logging

Starts hardware logging thread.

get_hardware_log_file()[source]

Returns path to current hardware log file.

Returns

Path on disk to current hardware log file. If not currently hardware logging, returns None.

Return type

str or None

See also

start_hardware_logging

Starts hardware logging thread.

get_processed_channels(channel_orderfile=None)[source]

take_debug_data, which is called by many functions including tracking_setup only returns data for the processed channels. Therefore every channel is not returned.

Parameters

channelorderfile (str or None, optional, default None) – Path to a file that contains one channel per line.

get_sample_frequency()[source]

Gives the data rate.

Returns

sample_frequency – The data sample rate in Hz.

Return type

float

get_subband_centers(band, as_offset=True, hardcode=False, yml=None)[source]

returns frequency in MHz of subband centers

Parameters
  • band (int) – Which band.

  • as_offset (bool, optional, default True) – Whether to return as offset from band center.

get_subband_from_channel(band, channel, channelorderfile=None, yml=None)[source]

Returns subband number given a channel number

Parameters
  • band (int) – Which band we’re working in.

  • channel (int) – Ranges 0..(n_channels-1), cryo channel number.

  • channelorderfile (str or None, optional, default None) – Path to file containing order of channels.

Returns

subband – The subband the channel lives in.

Return type

int

get_tes_bias_bipolar(bias_group, return_raw=False, **kwargs)[source]

Returns the bias voltage in units of Volts for the requested TES bias group.

Parameters
  • bias_group (int) – The number of the bias group. Asserts if bias_group requested is not defined in the pysmurf configuration file.

  • return_raw (bool, optional, default False) – If True, returns pos and neg terminal values.

Returns

val – The bipolar output TES bias voltage for the requested bias group. If return_raw=True, then returns a two element float array containing the output voltages of the two DACs assigned to the requested TES bias group.

Return type

float

get_tes_bias_bipolar_array(return_raw=False, **kwargs)[source]

Returns array of bias voltages per bias group in units of volts.

Parameters

return_raw (bool, optional, default False) – If True, returns +/- terminal vals as separate arrays (pos, then negative)

Returns

bias_vals – If return_raw is False, returns an array of size n_bias_group with the TES bias in units of volts. If return_raw is True, returns two arrays of size n_bias_group. The first is the positive bias DAC and the second is the negative bias DAC.

Return type

float, array

get_tes_bias_high_current(bias_group)[source]

Returns 1 if requested bias_group is in high_current_mode and 0 otherwise.

Parameters

bias_group (int) – The bias group to query

get_timing_mode()[source]

Determines timing mode configuration.

Returns the current timing mode configuration, or None if the system is not in one of these three known configurations:

  • “ext_ref” : locked to an external reference, or free running if an external reference is absent.

  • “backplane” : locked to external timing signals distributed over the crate backplane by a carrier in slot 2 of this carrier’s crate receiving timing on its RTM’s timing input. Only carriers in slot 2 of typical crates can distribute timing to other carriers through the crate backplane, so carriers configured in “backplane” timing mode must be in slots 3 or higher.

  • “fiber” : locked to external timing input from the carrier’s RTM timing input and if the carrier is in slot 2 of a crate with a dual-start backplane, distributing the timing signals to all other carriers in the crate’s backplane.

The timing mode configuration is determined by polling the configuration of the timing crossbar, LMKs, triggers, and RTM.

For systems configured in “fiber” or “backplane” modes, a warning is printed if no external timing data is being received.

Returns

mode – Current timing mode configuration. Returns None if system not in one of the three recognized configurations : “ext_ref”, “backplane”, or “fiber”.

Return type

str or None

See also

set_timing_mode()

Can be used to set the timing mode.

get_timing_link_up()

Is external timing data being received?

header_to_tes_bias(header, as_volt=True, n_tes_bias=15)[source]

Takes the SmurfHeader returned from read_stream_data and turns it to a TES bias. The header is a 20 field, and each DAC is 18 bits signed. So the output of the data in the header is (dac_b - dac_a)/2. This function also takes care of the factor of 2 in the denominator.

Parameters
  • header (dict) – The header dictionary from read_stream_data. This includes all the tes_byte data.

  • as_volt (bool, optional, default True) – Whether to return the data as voltage. If False, returns as DAC units.

  • n_tes_bias (int, optional, default 15) – The number of TES bias pairs.

Returns

bias – The tes bias data. (dac_b - dac_a) in voltage or DAC units depending on the as_volt opt arg.

Return type

numpy.ndarray

hex_string_to_int(s)[source]

Converts hex string, which is an array of characters, into an int.

Parameters

s (character array) – An array of chars to be turned into a single int.

Returns

i – The 64 bit int.

Return type

numpy.int64

identify_bias_groups(bias_groups=None, probe_freq=2.5, probe_time=3, probe_amp=0.1, make_plot=False, show_plot=False, save_plot=True, cutoff_frac=0.05, update_channel_assignment=True, high_current_mode=True)[source]

Identify bias groups of all the channels that are on. Plays a sine wave on a bias group and looks for a response. Does this with the TESs superconducting so it can look for an response is exactly the same amplitude as the input.

Parameters
  • bias_groups (int array or None, optional, default None) – The bias groups to search. If None, does the first 8 bias groups.

  • probe_freq (float, optional, default 2.5) – The frequency of the probe tone.

  • probe_time (float, optional, default 3) – The length of time to probe each bias group in seconds.

  • probe_amp (float, optional, default 0.1) – Amplitude of the probe signal in volts.

  • make_plot (bool, optional, default False) – Whether to make the plot.

  • show_plot (bool, optional, default False) – Whether to show the plot.

  • save_plot (bool, optional, default True) – Whether to save the plot.

  • cutoff_frac (float, optional, default 0.05) – The fraction difference the response can be away from the expected amplitude.

  • update_channel_assignment (bool, optional, default True) – Whether to update the master channels assignment to contain the new bias group information.

  • high_current_mode (bool, optional, default True) – Whether to use high or low current mode.

Returns

channels_dict – A dictionary where the first key is the bias group that is being probed. In each is the band, channnel pairs, and frequency of the channels.

Return type

dict of {int : dict of {str : numpy.ndarray} }

int_to_hex_string(i)[source]

Converts an int into a string of characters.

Parameters

i (int) – A 64 bit int to convert into hex.

Returns

s – A character array representing the int.

Return type

char array

iq_to_phase(i, q)[source]

Changes IQ to phase

make_channel_mask(band=None, smurf_chans=None)[source]

Makes the channel mask. Only the channels in the mask will be streamed or written to disk.

If no optional arguments are given, mask will contain all channels that are on. If both band and smurf_chans are supplied, a mask in the input order is created.

Parameters
  • band (int array or None, optional, default None) – An array of band numbers. Must be the same length as smurf_chans

  • smurf_chans (int_array or None, optional, default None) – An array of SMuRF channel numbers. Must be the same length as band.

Returns

output_chans – The output channels.

Return type

int array

make_freq_mask(mask)[source]

Makes the frequency mask. These are the frequencies associated with the channels in the channel mask.

Parameters

mask (int array) – The channel mask file.

Returns

freqs – An array with frequencies associated with the mask file.

Return type

float array

make_gcp_mask(band=None, smurf_chans=None, gcp_chans=None, read_gcp_mask=True)[source]

THIS FUNCTION WAS USED FOR BKUMUX DATA ACQUISITION. IT’S COMPLETELY BROKEN NOW, POST ROGUE4 MIGRATION.

Makes the gcp mask. Only the channels in this mask will be stored by GCP.

If no optional arguments are given, mask will contain all channels that are on. If both band and smurf_chans are supplied, a mask in the input order is created.

Parameters
  • band (int array or None, optional, default None) – An array of band numbers. Must be the same length as smurf_chans

  • smurf_chans (int_array or None, optional, default None) – An array of SMuRF channel numbers. Must be the same length as band.

  • gcp_chans (int_array or None, optional, default None) – A list of smurf numbers to be passed on as GCP channels.

  • read_gcp_mask (bool, optional, default True) – Whether to read in the new GCP mask file. If not read in, it will take no effect.

make_mask_lookup(mask_file, make_freq_mask=False)[source]

Makes an n_band x n_channel array where the elements correspond to the smurf_to_mce mask number. In other words, mask[band, channel] returns the GCP index in the mask that corresonds to band, channel.

Parameters
  • mask_file (str) – The full path the a mask file.

  • make_freq_mask (bool, optional, default False) – Whether to write a text file with resonator frequencies.

Returns

mask_lookup – An array with the GCP numbers.

Return type

int array

mask_num_to_gcp_num(mask_num)[source]

Goes from the smurf2mce mask file to a gcp number. Inverse of gcp_num_to_mask_num.

Parameters

mask_num (int) – The index in the mask file.

Returns

gcp_num – The index of the channel in GCP.

Return type

int

overbias_tes(bias_group, overbias_voltage=19.9, overbias_wait=1.0, tes_bias=19.9, cool_wait=20.0, high_current_mode=False, flip_polarity=False, actually_overbias=True)[source]

Overbiases requested bias group at overbias_voltage in high current mode for overbias_wait seconds. If high_current_mode=False, returns to low current mode, after which it biases the TESs at tes_bias. Then waits cool_wait seconds before returning control.

Parameters
  • bias_group (int) – The bias group to overbias. Asserts if not a valid bias group.

  • overbias_voltage (float, optional, default 19.9) – The value of the TES bias in the high current mode.

  • overbias_wait (float, optional, default 1.0) – The time to stay in high current mode in seconds.

  • tes_bias (float, optional, default 19.9) – The value of the TES bias when put back in low current mode.

  • cool_wait (float, optional, default 20.0) – The time to wait after setting the TES bias for transients to die off.

  • high_current_mode (bool, optional, default False) – Whether to keep the TES bias in high current mode after the kick.

  • flip_polarity (bool, optional, default False) – Whether to flip the TES bias bipolar DAC polarity.

  • actually_overbias (bool, optional, default True) – Whether to actaully do the overbias.

overbias_tes_all(bias_groups=None, overbias_voltage=19.9, overbias_wait=1.0, tes_bias=19.9, cool_wait=20.0, high_current_mode=False, actually_overbias=True)[source]

Overbiases all requested bias groups (specified by the bias_groups array) at overbias_voltage in high current mode for overbias_wait seconds. If high_current_mode=False, returns to low current mode, after which it biases the TESs at tes_bias. Then waits cool_wait seconds before returning control.

Parameters
  • bias_groups (array or None, optional, default None) – Which bias groups to overbias. defaults to all_groups. Asserts if any of the bias groups listed is not a defined bias group.

  • overbias_voltage (float, optional, default 19.9) – The value of the TES bias in the high current mode.

  • overbias_wait (float, optional, default 1.0) – The time to stay in high current mode in seconds.

  • tes_bias (float, optional, default 19.9) – The value of the TES bias when put back in low current mode.

  • cool_wait (float, optional, default 20.0) – The time to wait after setting the TES bias for transients to die off.

  • high_current_mode (bool, optional, default False) – Whether to keep the TES bias in high current mode after the kick.

  • actually_overbias (bool, optional, default True) – Whether to actaully do the overbias.

pause_hardware_logging()[source]

Pauses hardware logging thread.

See also

resume_hardware_logging

Resumes hardware logging thread.

start_hardware_logging

Starts hardware logging thread.

stop_hardware_logging

Stops hardware logging thread.

play_sine_tes(bias_group, tone_amp, tone_freq, dc_amp=None)[source]

Play a sine wave on the bias group pair.

Tone file is in bias bit units. The bias is int20. The inputs of this function are in units of bias dac output voltage. The conversion from requested volts to bits is calculated in this function.

Parameters
  • bias_group (int) – The bias group to play a sine wave on.

  • tone_amp (float) – The amplitude of the sine wave in units of out TES bias in volts.

  • tone_freq (float) – The frequency of the tone in Hz.

  • dc_amp (float or None, optional, default None) – The amplitude of the DC term of the sine wave. If None, reads the current DC value and uses that.

play_tes_bipolar_waveform(bias_group, waveform, do_enable=False, continuous=True, **kwargs)[source]

Play a bipolar waveform on the bias group.

Parameters
  • bias_group (int) – The bias group

  • waveform (float array) – The waveform the play on the bias group.

  • do_enable (bool, optional, default True) – Whether to enable the DACs (similar to what is required for TES bias).

  • continuous (bool, optional, default True) – Whether to play the TES waveform continuously.

play_tone_file(band, tone_file=None, load_tone_file=True)[source]

Plays the specified tone file on this band. If no path provided for tone file, assumes the path to the correct tone file has already been loaded.

Parameters
  • band (int) – Which band to play tone file on.

  • tone_file (str or None, optional, default None) – Path (including csv file name) to tone file. If None, uses whatever’s already been loaded.

  • load_tone_file (bool, optional, default True) – Whether or not to load the tone file. The tone file is loaded per DAC, so if you already loaded the tone file for this DAC you don’t have to do it again.

process_data(filename, dtype=<class 'numpy.uint32'>)[source]

Reads a file taken with take_debug_data and processes it into data and header.

Parameters
  • filename (str) – Path to file

  • dtype (numpy.dtype, optional, default numpy.uint32) – datatype to cast to.

Returns

  • header (numpy.ndarray) – The header information.

  • data (numpy.ndarray) – The resonator data.

read_adc_data(band, data_length=524288, hw_trigger=False, make_plot=False, save_data=True, timestamp=None, show_plot=True, save_plot=True, plot_ylimits=[None, None])[source]

Reads data directly off the ADC.

Parameters
  • band (int) – Which band. Assumes adc number is band%4.

  • data_length (int, optional, default 2**19) – The number of samples.

  • hw_trigger (bool, optional, default False) – Whether to use the hardware trigger. If False, uses an internal trigger.

  • make_plot (bool, optional, default False) – Whether or not to plot.

  • save_data (bool, optional, default True) – Whether or not to save the data in a time stamped file.

  • timestamp (int or None, optional, default None) – ctime to timestamp the plot and data with (if saved to file). If None, it gets the time stamp right before acquiring data.

  • show_plot (bool, optional, default True) – Whether or not to show plots.

  • save_plot (bool, optional, default True) – Whether or not to save plot to file.

  • plot_ylimits ([float or None, float or None], optional, default [None,None]) – y-axis limit (amplitude) to restrict plotting over.

Returns

dat – The raw ADC data.

Return type

int array

read_dac_data(band, data_length=524288, hw_trigger=False, make_plot=False, save_data=True, timestamp=None, show_plot=True, save_plot=True, plot_ylimits=[None, None])[source]

Read the data directly off the DAC.

Parameters
  • band (int) – Which band. Assumes dac number is band%4.

  • data_length (int, optional, default 2**19) – The number of samples.

  • hw_trigger (bool, optional, default False) – Whether to use the hardware trigger. If False, uses an internal trigger.

  • make_plot (bool, optional, default False) – Whether or not to plot.

  • save_data (bool, optional, default True) – Whether or not to save the data in a time stamped file.

  • timestamp (int or None, optional, default None) – ctime to timestamp the plot and data with (if saved to file). If None, in which case it gets the time stamp right before acquiring data.

  • show_plot (bool, optional, default True) – If make_plot is True, whether or not to show the plot.

  • save_plot (bool, optional, default True) – Whether or not to save plot to file.

  • plot_ylimits (list of float or list of None, optional, default [None,None]) – 2-element list of y-axis limits (amplitude) to restrict plotting over.

Returns

dat – The raw DAC data.

Return type

int array

read_stream_data(datafile, channel=None, nsamp=None, array_size=None, return_header=False, return_tes_bias=False, write_log=True, n_max=2048, make_freq_mask=False, gcp_mode=False)[source]

Loads data taken with the function stream_data_on. Gives back the resonator data in units of phase. Also can optionally return the header (which has things like the TES bias).

Parameters
  • datafile (str) – The full path to the data to read.

  • channel (int or int array or None, optional, default None) – Channels to load.

  • nsamp (int or None, optional, default None) – The number of samples to read.

  • array_size (int or None, optional, default None) – The size of the output arrays. If 0, then the size will be the number of channels in the data file.

  • return_header (bool, optional, default False) – Whether to also read in the header and return the header data. Returning the full header is slow for large files. This overrides return_tes_bias.

  • return_tes_bias (bool, optional, default False) – Whether to return the TES bias.

  • write_log (bool, optional, default True) – Whether to write outputs to the log file.

  • n_max (int, optional, default 2048) – The number of elements to read in before appending the datafile. This is just for speed.

  • make_freq_mask (bool, optional, default False) – Whether to write a text file with resonator frequencies.

  • (bool) (gcp_mode) – is the legacy data mode which was depracatetd in Rogue 4.

  • Ret

  • ----

  • array) (m (int) –

  • array)

  • array)

  • (dict) (h) –

read_stream_data_daq(data_length, bay=0, hw_trigger=False, write_log=False)[source]

Reads the stream data from the DAQ.

Parameters
  • data_length (int) – The number of samples to process.

  • bay (int, optional, default 0) – The AMC bay number.

  • hw_trigger (bool, optional, default False) – Whether to trigger the start of the acquistion with a hardware trigger.

  • write_log (bool, optional, default False) – Whether to write outputs to log.

read_stream_data_gcp_save(datafile, channel=None, unwrap=True, downsample=1, nsamp=None)[source]

Reads the special data that is designed to be a copy of the GCP data. This was the most common data writing mode until the Rogue 4 update. Maintining this function for backwards compatibility.

Parameters
  • datafile (str) – The full path to the data made by stream_data_on.

  • channel (int or list of int or None, optional, default None) – Channels to load.

  • unwrap (bool, optional, default True) – Whether to unwrap units of 2pi.

  • downsample (int, optional, default 1) – The amount to downsample.

  • nsamp (int or None, optional, default None) – The number of samples to read.

Returns

  • t (numpy.ndarray) – The timestamp data.

  • d (numpy.ndarray) – The resonator data in units of phi0.

  • m (numpy.ndarray) – The maskfile that maps smurf num to gcp num.

recover_jesd(bay, recover_jesd_rx=True, recover_jesd_tx=True)[source]

Attempts to recover the JESDs

Parameters
  • bay (int) – The AMC bay to recover

  • recover_jesd_rx (bool, optional, default True) – Whether to attempt to recover the JESD RX

  • recover_jesd_tx (bool, optional, default True) – Whether to attempt to recover the JESD TX

resume_hardware_logging()[source]

Resumes hardware logging thread.

See also

pause_hardware_logging

Pauses hardware logging thread.

start_hardware_logging

Starts hardware logging thread.

stop_hardware_logging

Stops hardware logging thread.

set_buffer_size(bay, size, debug=False, write_log=False)[source]

Sets the buffer size for reading and writing DAQs

Parameters

size (int) – The buffer size in number of points.

set_downsample_filter(filter_order, cutoff_freq, write_log=False)[source]

Sets the downsample filter. This is anti-alias filter that filters data at the flux_ramp reset rate, which is before the downsampler.

Parameters
  • filter_order (int) – The number of poles in the filter.

  • cutoff_freq (float) – The filter cutoff frequency.

set_feedback_limit_khz(band, feedback_limit_khz, **kwargs)[source]

Sets the feedback limit

Parameters
  • band (int) – The band that is to be turned off.

  • feedback_limit_khz (float) – The feedback rate in units of kHz.

set_fixed_tone(freq_mhz, tone_power, write_log=False)[source]

Places a fixed tone at the requested frequency. Asserts without doing anything if the requested resonator frequency falls outside of the usable 500 MHz bands, or if there are no unassigned channels available in the subband the requested frequency falls into (where a channel is deemed “assigned” if it has non-zero amplitude).

Parameters
  • freq_mhz (float) – The frequency in MHz at which to place a fixed tone.

  • tone_power (int) – The amplitude for the fixed tone (0-15 in recent fw revisions).

  • write_log (bool, optional, default False) – Whether to write low-level commands to the log file.

Returns

  • band (int) – The band number in which a tone was turned on.

  • channel (int) – The band channel number that was used to turn on the tone.

set_mode_ac(write_log=False)[source]

Sets flux ramp to AC coupling

Parameters

write_log (bool, optional, default False) – Whether to write outputs to log.

set_mode_dc(write_log=False)[source]

Sets flux ramp to DC coupling

Parameters

write_log (bool, optional, default False) – Whether to write outputs to log.

set_tes_bias_bipolar(bias_group, volt, do_enable=False, flip_polarity=False, **kwargs)[source]

Set an individual TES bias group to the specified voltage, in volts. Asserts if the requested bias group is not defined in the pysmurf configuration file. The positive DAC in the bias group is set to +volt/2, while the negative DAC in the bias group is set to -volt/2.

Parameters
  • bias_group (int) – The bias group.

  • volt (float) – The TES bias to command in volts.

  • do_enable (bool, optional, default True) – Sets the enable bit. Only must be done once.

  • flip_polarity (bool, optional, default False) – Sets the voltage to volt*-1.

set_tes_bias_bipolar_array(bias_group_volt_array, do_enable=False, **kwargs)[source]

Set TES bipolar values for all DACs at once. Set using a pyrogue array write, so should be much more efficient than setting each TES bias one at a time (a single register transaction vs. many). Only DACs assigned to TES bias groups are touched by this function. The enable status and output voltage of all DACs not assigned to a TES bias group are maintained.

Parameters
  • bias_group_volt_array (float array) – The TES bias to command in voltage for each bipolar TES bias group. Should be (n_bias_groups,).

  • do_enable (bool, optional, default True) – Set the enable bit for both DACs for every TES bias group.

set_tes_bias_high_current(bias_group, write_log=False)[source]

Sets all bias groups to high current mode. Note that the bias group number is not the same as the relay number. It also does not matter, because Joe’s code secretly flips all the relays when you flip one.

Parameters

bias_group (int) – The bias group(s) to set to high current mode.

set_tes_bias_low_current(bias_group, write_log=False)[source]

Sets all bias groups to low current mode. Note that the bias group number is not the same as the relay number. It also does not matter, because Joe’s code secretly flips all the relays when you flip one

Parameters

bias_group (int) – The bias group to set to low current mode.

set_tes_bias_off(**kwargs)[source]

Turns off all of the DACs assigned to a TES bias group in the pysmurf configuration file.

set_timing_mode(mode, write_log=False)[source]

Sets timing mode.

Use this function to configure the system’s timing mode. The currently supported configurations are:

  • “ext_ref” : lock system to an external reference, or free run if an external reference is absent.

  • “backplane” : lock system to external timing signals distributed over the crate backplane by a carrier receiving timing on its RTM’s timing input in slot 2 running in “fiber” timing mode. Only carriers in slots 3 or higher can lock to backplane distributed timing.

  • “fiber” : lock to external timing input from the carrier’s RTM timing input and if the carrier is in slot 2 of a crate with a dual-start backplane, distribute the timing signals to all other carriers in the crate’s backplane.

The timing mode configuration adjusts the configuration of the timing crossbar, LMKs, triggers, and RTM.

For systems configured in “fiber” or “backplane” modes, after configuration a warning is printed if no external timing data is being received after a one second wait after configuring the timing crossbar.

Before changing the timing configuration, the current configuration is polled via get_timing_mode() and if the system is already in the requested mode, the function prints a message and does nothing.

Warning

If “backplane” mode is requested for a slot 2 system, set_timing_mode instead configures the system for “fiber” timing. This may or may not be what was desired.

Parameters
  • mode (str) – The timing mode to configure the system with. Currently valid options are “ext_ref”, “backplane”, or “fiber”.

  • write_log (bool, optional, default False) – Whether or not to print all EPICS calls, for logging or debugging purposes. Passed through all register set calls to the underlying epics.caput calls.

See also

get_timing_mode()

Can be used to set the timing mode.

get_timing_link_up()

Is external timing data being received?

setup_daq_mux(converter, converter_number, data_length, band=0, debug=False, write_log=False)[source]

Sets up for either ADC or DAC data taking.

Parameters
  • converter (str) – Whether it is the ADC or DAC. choices are ‘adc’, ‘dac’, or ‘debug’. The last one takes data on a single band.

  • converter_number (int) – The ADC or DAC number to take data on.

  • data_length (int) – The amount of data to take.

  • band (int, optional, default 0) – which band to get data on.

smurf_channel_to_gcp_num(band, channel)[source]

Converts from smurf channel (band and channel) to a gcp number

Parameters
  • band (int) – The smurf band number.

  • channel (int) – The smurf channel number.

Returns

gcp_num – The GCP number.

Return type

int

start_hardware_logging(filename=None, wait_btw_sec=5.0)[source]

Starts hardware logging in external thread.

Parameters
  • filename (str or None, optional, default None) – Name of file on disk to write hardware logging to (including path). If None, file name is automatically generated as CTIME_hwlog.dat with CTIME the current unix epoch timestamp returned by get_timestamp(), and saved in the directory specified by the SmurfControl class attribute output_dir.

  • wait_btw_sec (float, optional, default 5.0 Time to wait, in) – seconds, between each poll of the hardware registers being logged.

See also

get_hardware_log_entry

Generates each row of hardware logging data written to file.

pause_hardware_logging

Pauses hardware logging thread.

resume_hardware_logging

Resumes hardware logging thread.

stop_hardware_logging

Stops hardware logging thread.

stop_hardware_logging()[source]

Stops and cleans up hardware logging thread.

See also

start_hardware_logging

Starts hardware logging thread.

stop_tes_bipolar_waveform(bias_group, **kwargs)[source]

Stop the bipolar waveform being played on a bias group.

Parameters

bias_group (int) – The bias group.

stop_tone_file(band)[source]

Stops playing tone file on the specified band and reverts to DSP.

Parameters

band (int) – Which band to play tone file on.

stream_data_cm(write_log=True, register_file=False, **stream_on_kwargs)[source]

Context manager for data streaming. If you intend to turn streaming on, do something, and then turn streaming off this is a safe way to make sure streaming is in fact stopped properly even if an error is raised.

Parameters
  • write_config (bool, optional, default False) – Whether to dump the entire config. Warning this can be slow.

  • data_filename (str or None, optional, default None) – The full path to store the data. If None, it uses the timestamp.

  • downsample_factor (int or None, optional, default None) – The number of fast samples to skip between sending.

  • write_log (bool, optional, default True) – Whether to write to the log file.

  • update_payload_size (bool, optional, default True) – Whether to update the payload size (the number of channels written to disk). If the number of channels on is greater than the payload size, then only the first N channels are written. This bool will update the payload size to be the same as the number of channels on across all bands)

  • reset_filter (bool, optional, default True) – Whether to reset the filter before taking data.

  • reset_unwrapper (bool, optional, default True) – Whether to reset the unwrapper before taking data.

  • make_freq_mask (bool, optional, default True) – Whether to write a text file with resonator frequencies.

  • register_file (bool, optional, default False) – If true, the stream data file will be registered through the publisher.

Yields

data_filename (str) – The fullpath to where the data is stored.

stream_data_off(write_log=True, register_file=False)[source]

Turns off streaming data.

Parameters
  • write_log (bool, optional, default True) – Whether to log the CA commands or not.

  • register_file (bool, optional, default False) – If true, the stream data file will be registered through the publisher.

stream_data_on(write_config=False, data_filename=None, downsample_factor=None, write_log=True, update_payload_size=True, reset_filter=True, reset_unwrapper=True, make_freq_mask=True, channel_mask=None, make_datafile=True, filter_wait_time=0.1)[source]

Turns on streaming data.

Parameters
  • write_config (bool, optional, default False) – Whether to dump the entire config. Warning this can be slow.

  • data_filename (str or None, optional, default None) – The full path to store the data. If None, it uses the timestamp.

  • downsample_factor (int or None, optional, default None) – The number of fast samples to skip between sending.

  • write_log (bool, optional, default True) – Whether to write to the log file.

  • update_payload_size (bool, optional, default True) – Whether to update the payload size (the number of channels written to disk). If this is True, will set the payload size to 0, which tells rogue to automatically adjust it based on the channel count.

  • reset_filter (bool, optional, default True) – Whether to reset the filter before taking data.

  • reset_unwrapper (bool, optional, default True) – Whether to reset the unwrapper before taking data.

  • make_freq_mask (bool, optional, default True) – Whether to write a text file with resonator frequencies.

  • channel_mask (list or None, optional, default None) – Channel mask to set before streamig data. This should be an array of absolute smurf channels between 0 and nbands * chans_per_band. If None will create the channel mask containing all channels with a non-zero tone amplitude.

  • make_datafile (bool, optional, default True) – Whether to create a datafile.

  • filter_wait_time (float, optional, default 0.1) – Time in seconds to wait after filter reset.

Returns

data_filename – The fullpath to where the data is stored.

Return type

str

take_debug_data(band, channel=None, nsamp=524288, filename=None, IQstream=1, single_channel_readout=1, debug=False, rf_iq=False, write_log=True)[source]

Takes raw debugging data.

Parameters
  • band (int) – The band to take data on.

  • channel (int or None, optional, default None) – The channel to take debug data on in single_channel_mode.

  • nsamp (int, optional, default 2**19) – The number of samples to take.

  • filename (str or None, optional, default None) – The name of the file to save to.

  • IQstream (int, optional, default 1) – Whether to take the raw IQ stream.

  • single_channel_readout (int, optional, default 1) – Whether to look at one channel.

  • debug (bool, optional, default False) – Whether to take data in debug mode.

  • rf_iq (bool, optional, default False) – Return the RF IQ. Must provide channel.

  • write_log (bool, optional, default True) – Whether to write low-level commands to the log file.

Returns

  • f (float array) – The frequency response.

  • df (float array) – The frequency error.

  • sync (float array) – The sync count.

take_stream_data(meas_time, downsample_factor=None, write_log=True, update_payload_size=True, reset_unwrapper=True, reset_filter=True, return_data=False, make_freq_mask=True, register_file=False)[source]

Takes streaming data for a given amount of time

To do: move downsample_factor to config table

Parameters
  • meas_time (float) – The amount of time to observe for in seconds.

  • downsample_factor (int or None, optional, default None) – The number of fast sample (the flux ramp reset rate - typically 4kHz) to skip between reporting. If None, does not update.

  • write_log (bool, optional, default True) – Whether to write to the log file.

  • update_payload_size (bool, optional, default True) – Whether to update the payload size (the number of channels written to disk). If the number of channels on is greater than the payload size, then only the first N channels are written. This bool will update the payload size to be the same as the number of channels on across all bands)

  • reset_unwrapper (bool, optional, default True) – Whether to reset the unwrapper before taking data.

  • reset_filter (bool, optional, default True) – Whether to reset the filter before taking data.

  • return_data (bool, optional, default False) – Whether to return the data. If False, returns the full path to the data.

  • make_freq_mask (bool, optional, default True) – Whether to write a text file with resonator frequencies.

  • register_file (bool, optional, default False) – Whether to register the data file with the pysmurf publisher.

Returns

data_filename – The fullpath to where the data is stored.

Return type

str

toggle_feedback(band, **kwargs)[source]

Toggles feedbackEnable (->0->1) and lmsEnables1-3 (->0->1) for this band. Only toggles back to 1 if it was 1 when asked to toggle, otherwise leaves it zero.

Parameters

band (int) – The band whose feedback to toggle.

turn_off_fixed_tones(band)[source]

Turns off every channel which has nonzero amplitude but feedback set to zero.

Parameters

band (int) – The band to query.

which_bands()[source]

Which bands the carrier firmware was built for.

Returns

bands – Which bands the carrier firmware was built for.

Return type

list of int

which_bays()[source]

Which carrier AMC bays are enabled.

Returns which AMC bays were enabled on pysmurf server startup. Each SMuRF carrier has two AMC bays, indexed by an integer, either 0 or 1. If looking at an installed carrier from the front of a crate, bay 0 is on the right and bay 1 is on the left.

A bay is enabled if the –disable-bay# argument is not provided as a startup argument to the pysmurf server where # is the bay number, either 0 or 1. The pysmurf server startup arguments are returned by the get_smurf_startup_args() routine.

Returns

bays – Which bays were enabled on pysmurf server startup.

Return type

list of int

which_on(band)[source]

Finds all detectors that are on.

Parameters

band (int) – The band to search.

Returns

The channels that are on.

Return type

int array

why()[source]

Why not?

tools

pysmurf.client.util.tools.P_singleMode(f_center, bw, T)[source]

Optical power in a single mode in a bandwidth bw centered on frequency f_center from an optical load of temperature T. SI units.

Parameters
  • f_center (float) – The center frequency

  • bw (float) – The bandwidth in SI units

  • T (float) – The temperature

Returns

The optical power

Return type

float

pysmurf.client.util.tools.dPdT_singleMode(f_center, bw, T)[source]

Change in optical power per change in temperature (dP/dT) in a single mode in a bandwidth bw centered on frequency f_center from an optical load of temperature T. SI units.

pysmurf.client.util.tools.fit_skewed_lorentzian(f, mag)[source]

Fits frequency and magnitude data with a skewed lorentzian.

Parameters
  • f (float array) – The frequency array

  • mag (float array) – The resonator response array

Returns

fit_params – The fit parameters

Return type

float array

pysmurf.client.util.tools.limit_phase_deg(phase, minphase=- 180)[source]

Limits the phase in degrees

Brazenly stolen from https://stackoverflow.com/questions/2320986/easy-way-to-keeping-angles-between-179-and-180-degrees

Parameters
  • phase (float) – The input phase

  • minphase (float) – The minimum phase

Returns

phase_limited – The phase information with the limited phase

Return type

float

pysmurf.client.util.tools.load_yaml(filename)[source]

Load the yml yaml file

Parameters

filename (str) – Full path to the yaml file

Returns

The yaml file

Return type

yaml_file_object

pysmurf.client.util.tools.skewed_lorentzian(x, bkg, bkg_slp, skw, mintrans, res_f, Q)[source]

Skewed Lorentzian model.

Parameters
  • x (float) – The x-data to build the skewed Lorentzian

  • bkg (float) – The DC value of the skewed Lorentzian

  • bkg_slp (float) – The slope of the skewed Lorentzian

  • skw (float) – The skewness of the Lorentzian

  • mintrans (float) – The minimum of the trans. This is associated with the skewness term.

  • res_f (float) – The center frequency of the resonator (the center of the Lorentzian)

  • Q (float) – The Q of the resonator

Returns

The model of the Lorentzian

Return type

float

pysmurf.client.util.tools.utf8_to_str(d)[source]

Many of the rogue variables are returned as UTF8 formatted byte arrays by default. This function changes them from UTF8 to a string

Parameters

d (int array) – An integer array with each element equal to a character.

Returns

The string associated with input d.

Return type

str

pysmurf.client.util.tools.yaml_parse(yml, cmd)[source]

Gets the values out of the yaml file

Parameters
  • yml (yaml_file) – The input yaml file, loaded with load_yaml

  • cmd (str) – The full epics path in the yaml file

Returns

The value associated with the requested cmd

Return type

val