cristallina package

Submodules

cristallina.SEA_GraphClient module

client for SEA GraphServer

Usage:

# open a client to host ‘samenv’, port 8764 # the port number for the graph server may be retrived by # the command ‘sea list’ on the samenv machine

client = GraphClient(‘samenv:8764’)

# get one curve

tlist, vlist, period = client.get_curves(start, end, name)

or

# get all important curves curves = client.get_curves(start, end)

# where:

start, end: interval (unix time, as retrieved from time.time()) name: the name of a curve (if no name or a list of names

is given, the result is a curves dict)

curves: dict <name> of [tlist, vlist, period] tlist: time axis (unix time) vlist: values (y-axis) period: the expected resolution (a hint for graphic clients,

saying that for a time step t(n) - t(n-1) significantly bigger than period, an additional point should be added at t(n) - period)

class cristallina.SEA_GraphClient.GraphClient(hostport)[source]

Bases: object

close()[source]
get_curves(start, end, name=None, none_value=None, nmax=None)[source]

get curves

start, end: interval (unix time, as retrieved from time.time())

non positive values are taken relative to the current time

name: a single name or a list of names or None to get all curves (as shown in the SEA GUI) none_value: replacement when no value is defined nmax: max. number of points per curve

when name is a string, returns [tlist, vlist, period] when name is None or a list of strings (names) returns a dict <name> of [tlist, vlist, period]

tlist: time axis (unix time) vlist: values (y-axis) period: the expected resolution (a hint for graphic clients)

get_names(start, end=None)[source]

get names and properties of curves configured to be display on SEA GUI graphics

get_raw(start, end, *args)[source]

get raw curves (values as text)

cristallina.SEA_GraphClient.expect_reply(sock, expected)[source]
cristallina.SEA_GraphClient.raw_sics_client(hostport, login)[source]
cristallina.SEA_GraphClient.sics_client(hostport, command=None, login='Spy 007')[source]

cristallina.analysis module

cristallina.analysis.fit_2d_gaussian(image, roi: ROI | None = None)[source]

2D Gaussian fit using LMFit for a given image and an optional region of interest.

Returns the x, y coordinates of the center and the results object which contains further fit statistics.

cristallina.analysis.get_contrast_images(fileset, channel='JF16T03V01', alignment_channels=None, batch_size=10, roi: ROI | None = None, preview=False)[source]

See perform_image_calculations. Here calculates mean and standard deviation for a given set of images.

cristallina.analysis.setup_cachedirs(pgroup=None, cachedir=None)[source]

Sets the path to a persistent cache directory either from the given p-group (e.g. “p20841”) or an explicitly given directory.

If heuristics fail we use “/tmp” as a non-persistent alternative.

cristallina.config module

cristallina.plot module

cristallina.plot.axis_styling(ax, channel_name, description)[source]
cristallina.plot.ju_patch_less_verbose(ju_module)[source]

Quick monkey patch to suppress verbose messages from gain & pedestal file searcher.

cristallina.plot.plot_1d_channel(data: SFDataFiles, channel_name, ax=None)[source]

Plots channel data for a channel that contains a single numeric value per pulse.

cristallina.plot.plot_2d_channel(data: SFDataFiles, channel_name, ax=None)[source]

Plots channel data for a channel that contains a 1d array of numeric values per pulse.

cristallina.plot.plot_channel(data: SFDataFiles, channel_name, ax=None)[source]

Plots a given channel from an SFDataFiles object.

Optionally: a matplotlib axis to plot into

cristallina.plot.plot_correlation(x, y, ax=None, **ax_kwargs)[source]

Plots the correlation of x and y in a normalized scatterplot. If no axis is given a figure and axis are created.

Returns: The axis object and the correlation coefficient between

x and y.

cristallina.plot.plot_image_channel(data: SFDataFiles, channel_name, pulse=0, ax=None, rois=None, norms=None)[source]

Plots channel data for a channel that contains an image (2d array) of numeric values per pulse.

cristallina.plot.plot_spectrum_channel(data: SFDataFiles, channel_name_x, channel_name_y, average=True, pulse=0, ax=None)[source]

Plots channel data for two channels where the first is taken as the (constant) x-axis and the second as the y-axis (here we take by default the mean over the individual pulses).

cristallina.skeleton module

This is a skeleton file that can serve as a starting point for a Python console script. To run this script uncomment the following lines in the [options.entry_points] section in setup.cfg:

console_scripts =
     fibonacci = cristallina.skeleton:run

Then run pip install . (or pip install -e . for editable mode) which will install the command fibonacci inside your current environment.

Besides console scripts, the header (i.e. until _logger…) of this file can also be used as template for Python modules.

Note

This file can be renamed depending on your needs or safely removed if not needed.

References

cristallina.skeleton.fib(n)[source]

Fibonacci example function

Parameters:

n (int) – integer

Returns:

n-th Fibonacci number

Return type:

int

cristallina.skeleton.main(args)[source]

Wrapper allowing fib() to be called with string arguments in a CLI fashion

Instead of returning the value from fib(), it prints the result to the stdout in a nicely formatted message.

Parameters:

args (List[str]) – command line parameters as list of strings (for example ["--verbose", "42"]).

cristallina.skeleton.parse_args(args)[source]

Parse command line parameters

Parameters:

args (List[str]) – command line parameters as list of strings (for example ["--help"]).

Returns:

command line parameters namespace

Return type:

argparse.Namespace

cristallina.skeleton.run()[source]

Calls main() passing the CLI arguments extracted from sys.argv

This function can be used as entry point to create console scripts with setuptools.

cristallina.skeleton.setup_logging(loglevel)[source]

Setup basic logging

Parameters:

loglevel (int) – minimum loglevel for emitting messages

cristallina.utils module

cristallina.utils.FWHM_to_sigma(FWHM)[source]

FWHM to gaussian sigma

class cristallina.utils.ROI(left: int | None = None, right: int | None = None, top: int | None = None, bottom: int | None = None, center_x: int | None = None, center_y: int | None = None, width: int | None = None, height: int | None = None, name: str | None = None)[source]

Bases: object

Definition of region of interest (ROI) in image coordinates.

Example: ROI(left=10, right=20, bottom=100, top=200).

Directions assume that lower left corner of image is at (x=0, y=0).

property LeftRightBottomTop
property cols
from_centers_widths(center_x, center_y, width, height)[source]
property height
property rows
property width
cristallina.utils.channel_names(run_number, verbose=False)[source]

Prints channel names for a given run_number or scan object

cristallina.utils.eV_to_joules(eV)[source]

Just a unit conversion

cristallina.utils.find_nearest(array, value)[source]

Finds an index in an array with a value that is nearest to given number

cristallina.utils.find_two_nearest(time_array, percentage)[source]

Finds indeces of the two values that are the nearest to the given value in an array

cristallina.utils.gauss(x, H, A, x0, sigma)[source]

Returns gauss function value

cristallina.utils.gauss_fit(x, y, fit_details=None, plot=None)[source]

Returns [baseline_offset, Amplitude, center, sigma, FWHM]

cristallina.utils.heuristic_extract_base_path()[source]

The function tries to guess the full path where the raw data is saved.

cristallina.utils.heuristic_extract_pgroup(path=None)[source]

The function tries to guess the current p-group from the current working directory (default) or the contents of the given path.

cristallina.utils.heuristic_extract_smalldata_path()[source]

The function tries to guess the full path where the small data is saved.

cristallina.utils.joules_to_eV(joules)[source]

Just a unit conversion

cristallina.utils.photon_energy_from_wavelength(wavelength)[source]

Returns photon energy in eV from wavelength in meters. Source https://www.kmlabs.com/en/wavelength-to-photon-energy-calculator

cristallina.utils.print_run_info(run_number=42, print_channels=True, extra_verbose=False, base_path=None)[source]

Prints overview of run information.

Extra verbose output contains all files and pids.

cristallina.utils.process_run(run_number, rois, detector='JF16T03V01', calculate=None, only_shots=slice(None, None, None), n_jobs=16)[source]

Process rois for a given detector. Save the results small data in the res/small_data/run… By default only sum of rois is calculated, [mean,std,img] can be added to the “calculate” optional parameter.

cristallina.utils.scan_info(run_number, base_path=None, small_data=True)[source]

Returns SFScanInfo object for a given run number. If there is are small data channels, they will be added (small_data=False to suppress their loading).

cristallina.utils.sigma_to_FWHM(sigma)[source]

Gaussian sigma to FWHM

cristallina.utils.wavelength_from_photon_energy(Eph)[source]

Returns wavelength in meters from photon energy in eV. Source https://www.kmlabs.com/en/wavelength-to-photon-energy-calculator

cristallina.utils.xray_transmission(energy, thickness, material='Si', density=[])[source]

Calculate x-ray tranmission for given energy, thickness and material. Default material is Si. Add material=element as a string for another material. Density as optional parameter

Module contents