Auto-setup

From MCEWiki
(Redirected from Auto setup)

The python-based auto-setup is the primary tool used to tune the TES array. It provides a modular, flexible approach to tuning. The actions of acquisition, analysis, and plotting have been carefully separated. Objects exist to manage the locations of data and outputs to provide flexibility. Tools are provided to assist with loading and analyzing existing tuning data.

Currently the python auto-setup relies on scripts such as ramp_sa_bias and the mux_lock C programs to acquire the tuning data. Inside the python environment, data is loaded and manipulated as numpy arrays.

Obtaining python auto_setup

Auto-setup is part of the MCE script project. See the python/auto_setup subdirectory. You can get MCE script from the GitHub.

Script-level support

Pass "-h" to any of the scripts below to get a usage message.

auto_setup

The executable script auto_setup can be used to tune SQUID arrays from the command line.

plot_tuning

The executable script plot_tuning can be used create plots from existing tuning data.


The "auto_setup" module

The following classes may be useful for off-line analysis of tuning data. Note that the *Ramp and *Servo classes all inherit from the RCData class, takes a slightly eccentric approach to indexing the data it contains.

class util.FileSet

The FileSet class can be used to locate and group tuning data files, so that they can be more easily loaded as *Ramp and *Servo objects. Use like this:

import auto_setup as ast
tuning_dir = '/data/cryo/current_data/1234560000'
fs = ast.util.FileSet(tuning_dir)
for stage in ['sa_ramp', 'sq2_servo', 'sq1_servo', 'sq1_ramp']:
  print fs.stage_all(stage)

This will print out the data files associated with each tuning stage. They can be loaded and combined using a join method, e.g.:

sa_ramps = [SARamp(f) for f in fs.stage_all('sa_ramp')]  # individual ramps per RC
sa_ramp = SARamp.join(sa_ramps)                          # single, coherent ramp data object

Note that this join procedure isn't necessary if there is only one data file per squid stage (the default in modern python auto_setup). Older code acquired tuning data on each readout card individually; so the join procedure outlined should permit convenient loading of legacy data.

class util.mas_path

The mas_path class can be used to simplify path look-up. In the past this was simply done using environmental variables. That method doesn't work that well with Multicard MAS; mas_path abstracts path look-up, hiding the details of how paths are determined from the caller. Use like this:

from auto_setup.util import mas_path
mp = mas_path()
print mp.data_dir()

mas_path figures out paths by performing the following tests:

  1. if mas_var is present, it is run to determine the path
  2. if that doesn't work, mas_path looks in the environment for an appropriately named MAS_<...> variable and reports its value
  3. if neither of the above work, mas_path produces a "sensible default value".

Directories are cached after the first look-up.

A fibre card number (ignored if not-running Multicard MAS), an alternate mas.cfg file (only used if mas_var is run) and an alternate mas_var program can be passed to mas_path:

from auto_setup.util import mas_path
mp = mas_path(fibre_card=1, mas_cfg="/etc/mce/mas-alternate.cfg", mas_var="/some/other/mas_var")
print mp.data_dir()

If no fibre_card is specified, the value of $MAS_MCE_DEV is used, if it exists, otherwise zero is used as a default fibre card number. If mas_var is not specified, the value of $MAS_VAR is tried, if it exists, otherwise the default path "/usr/mce/bin/mas_var" is tried. If mas_var can't be found, the first of the three tests is simply skipped without error.

The following methods are defined in this class:

  • bin_dir(): returns the location of the MAS binaries (ie. $MAS_BIN, if defined); "/usr/mce/bin" is the default.
  • config_dir(): returns the location of the MCE script configuration (ie. $MAS_CONFIG, if defined); "/usr/mce/config" is the default.
  • data_root(): returns the root data directory ($MAS_DATA_ROOT, if defined); the default is "/data/mceN" where N is the fibre card number. However, for backwards compatibility, if the "/data/mceN" directory doesn't exist, "/data/cryo" will be returned instead.
  • data_dir(): returns the current data directory ($MAS_DATA, if defined); the default is the value returned by data_root() with "/current_data" appended.
  • etc_dir(): returns the location of the MAS configuration files ($MAS_ETC, if defined); "/etc/mce" is the default.
  • experiment_file(): returns the location of the experiment config file (no corresponding environmental variable); the default is the value returned by data_dir() with "/experiment.cfg" appended.
  • hardware_file(): returns the location of the hardware config file (no corresponding environmental variable); the default is the value returned by etc_dir() with "/mceN.cfg" appended, where N is the fibre card number. However, for backwards compatibility, if the "mceN.cfg" file doesn't exist, plain "mce.cfg" will be used instead.
  • mas_prefix(): returns the location of the installed MAS tree (ie. $MAS_PREFIX, if defined); "/usr/mce" is the default.
  • temp_dir(): returns the location of the MAS/MCE script temp directory ($MAS_TEMP, if defined); "/tmp" is the default.
  • mas_root(): returns the location of the MCE script tree (ie. $MAS_ROOT, if defined); "/usr/mce/mce_script" is the default.
  • idl_dir(): returns the location of the MCE script IDL directory (ie. $MAS_IDL, if defined); the default is the value returned by mas_root() with "/idl_pro" appended.
  • python_dir(): returns the location of the MCE script Python directory (ie. $MAS_PYTHON, if defined); the default is the value returned by mas_root() with "/python" appended.
  • script_dir(): returns the location of the MCE script shell script directory (ie. $MAS_SCRIPT, if defined); the default is the value returned by mas_root() with "/script" appended.
  • template_dir(): returns the location of the MCE script template directory (ie. $MAS_TEMPLATE, if defined); the default is the value returned by mas_root() with "/template" appended.
  • test_suite_dir(): returns the location of the MCE script test suite directory (ie. $MAS_TEST_SUITE, if defined); the default is the value returned by mas_root() with "/test_suite" appended.

These functions are all implemented through calls to the low-level method:

 __get_path__(name, env, default)

where:

  • name is the name of a mas_var parameter to check, excluding the initial "--", or None
  • env is the name of an environmental variable to check, or None
  • default is the default value to return if other look-up methods fail.

Ie., the mas_path().bin_dir() method is implemented using the call:

mas_path().__get_path__('bin-dir', 'MAS_BIN', '/usr/mce/bin')

class SARamp

class SQ2Servo

class SQ1Servo

class SQ1Ramp

class RCData

This class stores time-ordered data for some set of detectors. Tuning data sets can be quite complex (consider a multi-bias, all-row SQ1 Servo for example) and so a certain convention has been adopted to indicate different structuring of the data. In all cases, the data themselves are stored in a 2-d numpy array, with the second index representing the time index and the first index encapsulating all other degrees of freedom (row, column, bias index,...). The underlying data shape is contained in the attribute data_shape. This is not to be confused with data.shape, which is the actual numpy dimensionality of the data array.

Form of data data_shape data.shape gridded rows cols
One time-stream per channel (n_row, n_col, n_time) (n_row*n_col, n_time) True list of rows (size n_row) list of columns (size n_col)
Multi-bias data; n_bias time-stream per channel (n_bias, n_row, n_col, n_time) (n_bias*n_row*n_col, n_time) True list of rows (size n_chan) list of columns (size n_chan)
One time stream for some set of row, column pairs (1, n_chan, n_time) (n_chan, n_time) False list of rows (size n_chan) list of columns (size n_chan)
Multi-bias data; for some set of row, column pairs (n_bias, 1, n_chan, n_time) (n_bias*n_chan, n_time) False list of rows (size n_chan) list of columns (size n_chan)

class config.configFile

This is a class for reading and modifying simple libconfig configuration files, such as experiment.cfg. The class extends the python "dict" class; keys from the configuration file become the keys of the dictionary. The class calls mas_param to decode the specified config file, including type information. Array data are stored as numpy arrays.

Typical usage in a script, to obtain access to experiment.cfg parameters, is done like this:

from auto_setup.config import configFile
cfg = configFile('/data/cryo/current_data/experiment.cfg')

print cfg['default_num_rows']
print cfg['sa_bias']

Output:

33
[42000 15000 16500 15000 15000 15000 15000 15000     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0]

Updating values

There are two ways to update values in the target configuration file. The first is to use "set_param":

cfg.set_param('sa_bias', [65535] * 32)    # write 65535 to all 32 entries of SA bias

This will immediately update the target configuration file, with a single call to mas_param to set the 'sa_bias' key.

The second way may be more convenient when modifying a large number of parameters. One updates the dict with new values and then calls the .write() method:

cfg['sa_bias'] = [65535] * 32
cfg['sa_offset'] = [1000] * 32
cfg['sq2_bias'] = [0] * 32
cfg.write()

Note that cfg.write() will rewrite *all* of the keys, not just the ones you have changed. This will make it somewhat slower and potentially more confusing than using cfg.set_param. So you might just want to stick with set_param.