integrator.utils module#

class integrator.utils.PeriodicAction(interval, function, args=None, kwargs=None)#

Bases: object

start()#
stop()#
cancel()#
class integrator.utils.PatchLogLevel(prefix, loglevel)#

Bases: ContextDecorator

integrator.utils.make_azims(azim_min, azim_max, nb_slices)#
integrator.utils.parse_poni_file(poni_file)#
integrator.utils.check_poni_file_detector(poni_file, detector, force_replace=False)#

Check a poni file so that the detector is replaced with another (user-provided) detector. This is useful when the detector file name within the poni file does not exist, or cannot be accessed.

Parameters:
  • poni_file (str) – Path to the poni file

  • detector (str) – Name or path of the detector used to replace the one in the poni file

  • force_replace (bool, optional) – Whether to use the provided detector even if the one in the poni file can be accessed

integrator.utils.get_h5_config_from_pyfai(pyfai_config, ai_config, dataset)#
integrator.utils.create_output_masterfile(files, output_file, ai_config, do_stack_mean, h5_config, entry='/', process_name='azimuthal integration')#
integrator.utils.browse_virtual_sources(dataset, logger)#
integrator.utils.retry_create_masterfile(n_retries, logger)#
integrator.utils.retry_n_times(n_times, logger, func, *args, **kwargs)#
integrator.utils.walltime_to_seconds(walltime)#

Converts a “walltime” formated string to a number of seconds.

Parameters:

walltime (str) – Walltime, in the form “Hours:Minutes:Seconds”

Returns:

secs – Number of seconds corresponding to walltime

Return type:

int

Examples

walltime_to_seconds(“02:50:27”) gives 10227

integrator.utils.whoami()#
integrator.utils.get_identifier(use_date=True)#

Return a simple identifier in the form {whoami}_{date}

integrator.utils.partition_list(list_, n_sets)#
integrator.utils.files_relative_paths(files, reference_file)#

From a list of (absolute) files paths, return a list of relative paths. Each path is relative to ‘reference_file’.

integrator.utils.get_worker_threads_affinity(n_workers, n_threads_per_worker)#

Given a number of workers (processes) and number of threads per worker, returns the optimal affinity list for each worker.

Note that it likely won’t work properly if the current host is used through a task scheduler(eg. SLURM). In this case, one must ensure that at least one full socket is allocated.

integrator.utils.get_opencl_devices(device_type='gpu', excluded_platform=None)#
integrator.utils.safe_format(str_, **kwargs)#

Alternative to str.format(), but does not throw a KeyError when fields are missing.

integrator.utils.exec_shell_command(cmd)#
integrator.utils.get_number_of_available_gpus(on_error='ignore')#

Get the number of available GPUs.

Parameters:

on_error (str, optional) – What to do on error. Can be “ignore”, “print” or “raise”.

integrator.utils.file_mode_to_octal(file_mode, default=509)#

Convert a file mode provided as a “regular int” (base 10) to an octal number of os.chmod()

integrator.utils.get_additional_metadata(scan_number, h5abspath, axes, logger=None)#

scankey: e.g. “{paths[‘sample’]}_{paths[‘datasetshort’]}_{paths[‘scan’]}” h5abspath: e.g. /data/visitor/ch6066/id15/sample1/sample1_dataset4/sample1_dataset4.h5 axes: e.g. [hry, hrz, temperature, potential, tfy]