pixie16.control module¶
Python interface to controlling the pixie16.
Based on XIA’s C-library from their SDK, we try to provide a more pythonic interface, make use of a config file to store different configurations, and supply addtional functionality.
The config file (which is a requirement) stores some of the parameter for booting the pixie as well as the main output directory. Therefore, our boot and init commands take less parameters then their SDK version.
Once the init_system function was called, we also cache the list of modules. We then provide functions that don’t need the addtional input of curent modules.
We provide some functions to modify channel and module parameters directly on the pixie, as well as, setting the run time and sync mode or enabling taking traces. Furthermore, there we provide function to start/stop acquisition and get information on all modules and save this to a json file.
We also provide our own mechanism of changing settings by providing a dictionary with name of the settings as key in the dictioinary and the settings value only provided for the channels in use. Since the pixie16 provides many settings by manipulating bits in a 32bit integer, we provide functions that help with this and one can access bits by name (inspired by the names in the manual). We also provide the option to overwrite some of the calculated values such as PAFlength or have them calculated automatically.
At the moment pypixie16 only supports Windows, but other platforms should be easy to add.
- pixie16.control.adjust_offsets(modules: Iterable[int] | None = None) None ¶
Adjust offsets for all channels in the list of module”.
- Parameters:
modules – Iterable of slots with modules (e.g. [2, 3]), uses modules defined in init call otherwise
- pixie16.control.boot(section_name: str | None = 'default', modules: list[int] | None = None, boot_pattern: int = 127, verbose: bool = False) None ¶
Boot modules with boot_pattern.
- Parameters:
section_name – name for Firmware section in config file that defines the FPGA code, etc that should be used.
modules – Boot certain modules (module list given in positions, i.e. not slots), if None use modules defined in init call.
boot_pattern – Bit pattern defining what gets booted.
verbose – Print some extra information if True
- pixie16.control.change_raw_setting_from_dict(settings: dict, call_pixie: bool | None = True)¶
Modify the raw settings on the pixie.
Note: this bypasses any checks that are normally done in XIA’s C-libary. This can be used to, for example, modify Peaksample if needed. However, if you set parameters to invalid numbers, there will be no error and the binary stream can be invalid.
- Parameters:
settings – A dictionary with the settings names as key and the values for each channel (or a single value that will be applied to all channels). One key must be called channels and must be a list of (module, channel) tuples.
call_pixie – Can be set to False, in which case the pixie16 is not actually called (used for tests)
- pixie16.control.change_setting_from_dict(settings: dict, call_pixie: bool | None = True)¶
Update settings in the pixie16.
Takes a dictionary with setting names as keys and setting values
The dictionary must also contain an entry called ‘channels’ that list all channels that should be set. Channels should be pairs in the form (module, channel).
The values in the dictionary can either be a single value, in which case the value will be used for all channels or a list of the same length as channels in which case each (module, channel) combination will get its own value.
- pixie16.control.check_run_status() bool ¶
Checks the run status of all known modules.
- pixie16.control.empty_all_fifos() None ¶
Read data from all fifos and discard it.
Uses the module list defined in init.
- pixie16.control.empty_fifo(module: int) None ¶
Read all data in a fifo of a specific module and discard it.
- Parameters:
module – The module number (starting at 0)
- pixie16.control.enable_trace_settings(channels: Iterable[tuple[int, int]], disable_CFD: bool = True) None ¶
Enable traces, histograms, and sums.
Also turn CFD settings off (or optionally leave unchanged). These data are useful when trying to analyze traces and optimize settings offline by trying out different settings values in software, for example, using pypixie16’s binary-browser.
- Parameters:
channels – List of (modules, channel) tuples
disable_CFD – Option to disable CFD for the listed channels
- pixie16.control.end_run() None ¶
Calls end_run on all the modules.
- pixie16.control.exit_system() None ¶
Calls exit_system on all the modules.
- pixie16.control.init(modules: list[int], offline_mode: bool = False, verbose: bool = False) None ¶
Initialize the system.
Calls init_system in the XIA library and saves the list of modules, so that we can use it as a default in later XIA library calls.
- Parameters:
modules – list of modules (slot numbers, e.g. [2,3])
offline_mode – Run with the pixie present or not
verbose – print some extra information
- pixie16.control.init_and_boot(offline_mode: bool = False, section_name: str | None = 'default', modules: list[int] | None = None, boot_pattern: int = 127, verbose: bool = False) None ¶
Init and boot in one function call.
- Parameters:
modules – list of modules (slot numbers, e.g. [2,3])
offline_mode – Run with the pixie present or not
section_name – name for Firmware section in config file that defines the FPGA code, etc that should be used.
boot_pattern – Bit pattern defining what gets booted.
verbose – Print some extra information if True
- pixie16.control.read_dummy_settings(modules) CrateSettings ¶
Read the current setting into memory.
Reads settings from a given file to be used as dummy data. Needed, for example, for tests.
- Return type:
A dictonary of setting data
- pixie16.control.read_histograms(module_channels: Iterable[tuple[int, int]]) list[numpy.ndarray] ¶
Read histograms from several channels.
Uses (module, channel) tuples, e.g. [(0, 8), (0, 3)] to read histograms.
- Parameters:
module_channels – List of tuples of (module, channel) to define which histograms we want to read
- Returns:
List of numpy arrays with the histograms
- Return type:
List[np.ndarray]
- pixie16.control.read_list_mode_fifo(check: bool = True, threshold: int = 64, modules: Iterable[int] | None = None) list[numpy.ndarray] ¶
Reads data from pixies FIFO across all modules defined in pixie16.control.modules
- Parameters:
check – If True, check first if there is enough data that should be read. Otherwise always read all data.
threshold – Minimum number of data to read when check is active.
modules – List of modules (slot numbers, e.g. [2]). Uses modules defined in init if None.
- Returns:
List with data as a numpy array of 32 bit unsigned integers for each module.
- Return type:
List[np.ndarray]
- pixie16.control.read_settings() CrateSettings ¶
Read the current setting into memory.
Reads the setting into a temporary json file using XIA’s library and then parse that file.
- Return type:
A dictonary of setting data
- pixie16.control.read_settings_from_json(filename: Path)¶
Reads the settings from a new-style json settings file.
- pixie16.control.reset_coincidence_setting(channels: Iterable[tuple[int, int]]) None ¶
Reset all setting in regards to coincedence mode.
Also, unsets capturing traces, etc.
This is usefule before an MCA run for example to just get raw channel spectra.
- Parameters:
channels – List of (module, channel) tuples
- pixie16.control.run_list_mode(filename: str | None = None, runtime: int = 5) None ¶
Run the pixie16 in list mode.
Start and stop a list mode run. The module needs to be initialized. Data will be written to a file. If the filename doesn’t end with ‘.bin’ the ending will be added. We use the same dataformat as the pixie uses internally. We also add a ‘000’ or higher number before the ‘.bin’ file ending automatically to avoid overiding an existing file. The file gets placed in a the directory specified in the config file and within that directory in a subdirectory of the form YYYY-MM-DD, which gets created if it doesn’t exist.
- Parameters:
filename – the filename
runtime – The time to take data for in seconds
- pixie16.control.save_settings_to_json(filename: Path)¶
Save the current settings to a file.
- pixie16.control.save_stats_to_json(filename: Path) None ¶
Get statistics for all modules and save as json to file.
- Parameters:
filename – name to save the settings to
- pixie16.control.set_channel_parameter(name: str, value, module: int, channel: int)¶
Set and read back a parameter for a channel on the pixie16.
- Parameters:
name – The name of the parameter
value – The new value
module – The module number
channel – The channel number
- Return type:
The new setting
- pixie16.control.set_defaults_for_module(module: int, call_pixie: bool | None = True)¶
Sets defaults for all used module and channel parameters in a module.
- Parameters:
module – The module number (0, 1, …)
call_pixie – Can be set to False, in which case the pixie16 is not actually called (used for tests)
- pixie16.control.set_module_parameter(name: str, value, module: int)¶
Set and read back a parameter for a module on the pixie16.
- Parameters:
name – The setting name
value – The new settings value
module – The module number (starting with 0)
- Return type:
The new setting
- pixie16.control.set_run_time(runtime, module)¶
Sets the run time for the next run on the pixie16.
- Parameters:
runtime – time in seconds
module – module number starting at 0
- pixie16.control.set_sync_mode(modules: Iterable[int] | None = None) None ¶
Turn on sync mode for every module.
- Parameters:
modules – Iterable of slots with modules (e.g. [2, 3]), uses modules defined in init call otherwise
- pixie16.control.set_traces(module: int, channel: int, status: bool) None ¶
Turn on/off taking traces for a certain channel in a specific module on the pixie16.
- Parameters:
module – The module number (starting at 0)
channel – The channel number (0-15)
status – True: record traces, False: do not record traces
- pixie16.control.start_histogram_run() None ¶
Start a histogram run.
Uses the module list defined during init.
- pixie16.control.start_list_mode_run() None ¶
Start a list mode run.
Uses the module list defined during init.
- pixie16.control.take_MCA_spectra(channels: Iterable[tuple[int, int]], duration: float, verbose: bool = True, position: int = 0) list[numpy.ndarray] ¶
Takes MCA spectra for a certain time on the specified channels.
This does the data acquisition and returns the data.
- Parameters:
channels – list of (modules, channel number) tuples
duration – MCA time in seconds
- Returns:
List of numpy arrays. One for each channel.
- Return type:
list(nd.ndarray)
- pixie16.control.take_list_mode_data(duration: float, modules: Iterable[int] | None = None) list[numpy.ndarray] ¶
Take list mode data for a certain time.
It also stops at 1 Gb of raw data to avoid too much memory use. If you want to take mor data, you need to use another mechanism and write the data to disk more often.
- Parameters:
duration – Length in seconds of how long data is acquired for
modules – List of modules, use the ones defined during init if None.
- Returns:
Dictionary with the raw binary data in it. Each module gets is a key in the dictionary and the values are the bytestring.
- Return type:
dict[int, ByteString]
- pixie16.control.temporary_settings() None ¶
Making it easy to temporary change settings in the pixie16.
A context manager that will remember the current setting, execute some code that can change those settings, and then reset the setting back to the original.
It saves the settings of all modules defined in the init call.
- pixie16.control.unset_sync_mode(modules: Iterable[int] | None = None) None ¶
Turn off sync mode for every module.
- Parameters:
modules – Iterable of slots with modules (e.g. [2, 3]), uses modules defined in init call otherwise
- pixie16.control.write_settings(data: CrateSettings) None ¶
Writes a setting object to the pixie16.
- Parameters:
data – Object created by read_settings.
- pixie16.control.write_settings_from_file(filename: Path) None ¶
Loads a setting file into the pixie16.
- Parameters:
filename – settings file to load