xfel.cxi.cspad_ana package

Submodules

xfel.cxi.cspad_ana.average_tbx module

class xfel.cxi.cspad_ana.average_tbx.average_mixin(address, avg_dirname=None, avg_basename=None, stddev_dirname=None, stddev_basename=None, max_dirname=None, max_basename=None, background_path=None, flags=None, hot_threshold=None, gain_threshold=None, noise_threshold=7, elastic_threshold=9, symnoise_threshold=4, **kwds)

Bases: common_mode_correction

beginjob(evt, env)

The beginjob() function does one-time initialisation from event- or environment data. It is called at an XTC configure transition.

@param evt Event data object, a configure object @param env Environment object

endjob(obj1, obj2=None)

The endjob() function finalises the mean and standard deviation images. The distance and wavelength in all images is actually the mean distance and wavelength, since standard deviations or maximum values of those quantities do not make much sense in visualisation.

@param evt Event object (psana only) @param env Environment object @return A dictionary object with accumulated statistics or @c

none if the contribution from the worker process is accounted for elsewhere

event(evt, env)

The event() function is called for every L1Accept transition.

@param evt Event data object, a configure object @param env Environment object

xfel.cxi.cspad_ana.common_mode module

Base class for dark subtraction and common-mode correction

XXX Better named cspad_base?

class xfel.cxi.cspad_ana.common_mode.common_mode_correction(address, calib_dir=None, common_mode_correction='none', photon_threshold=None, two_photon_threshold=None, dark_path=None, dark_stddev=None, mask_path=None, gain_map_path=None, gain_map_level=None, cache_image=True, roi=None, laser_1_status=None, laser_4_status=None, laser_wait_time=None, override_beam_x=None, override_beam_y=None, bin_size=None, crop_rayonix=False, **kwds)

Bases: mod_event_info

Dark subtraction and alternate implementation of common mode substituting for cspad_tbx.

Known problems: the algorithm relies on a substantial part of the sensor having no signal, which is not the case if a water ring crosses the sensor.

beginjob(evt, env)

The beginjob() function does one-time initialisation from event- or environment data. It is called at an XTC configure transition.

@param evt Event data object, a configure object @param env Environment object

chebyshev_common_mode(imgs, masks)
chebyshev_fit(x_obs, y_obs, w_obs, n_terms=None)
common_mode(img, stddev, mask)

The common_mode() function returns the mode of image stored in the array pointed to by @p img. @p mask must be such that the @p stddev at the selected pixels is greater than zero.

@param img 2D integer array of the image @param stddev 2D integer array of the standard deviation of each

pixel in @p img

@param mask 2D Boolean array, @c True if the pixel is to be

included, @c False otherwise

@return Mode of the image, as a real number

do_photon_counting()
do_sigma_scaling()
endjob(obj1, obj2=None)
event(evt, env)

The event() function is called for every L1Accept transition.

@param evt Event data object, a configure object @param env Environment object

xfel.cxi.cspad_ana.cspad_tbx module

Toolbox for images from the Cornell SLAC Pixel Array Detector (CSpad).

XXX Better named cspad_common?

XXX Read out detector temperature (see Hart et al., 2012)?

xfel.cxi.cspad_ana.cspad_tbx.CsPad2x2Image(data, config, sections)

The CsPad2x2Image() function assembles a two-dimensional image from the Sc1 detector readout in @p data.

@param data Detector readout from XTC stream @param config XXX @param sections XXX Directory with calibration information @return Assembled detector image

xfel.cxi.cspad_ana.cspad_tbx.CsPadDetector(address, evt, env, sections, right=True, quads=None)

The CsPadDetector() function assembles a two-dimensional image from the Ds1 detector readout in @p data3d and the calibration information in @p sections. XXX General question: do variable/function names make sense?

@param address Full data source address of the DAQ device @param evt Event data object, a configure object @param env Environment object @param sections XXX Directory with calibration information @param right @c True to restrict rotations to right angles @return Assembled detector image

xfel.cxi.cspad_ana.cspad_tbx.CsPadElement(data3d, qn, config)

Construct one image for each quadrant, each with 8 sections from a data3d = 3 x 2*194 x 185 data array. This function was originally written by Ingrid Ofte for pyana’s XtcExplorer module. XXX Documentation!

xfel.cxi.cspad_ana.cspad_tbx.cbcaa(config, sections)

The cbcaa() function uses on-disk calibration data to estimate the beam centre and the active detector areas. The beam centre is approximated as the average of the four ASIC corners closest to the detector centre. That is the first corner of the section 1 in every quadrant. Note that first corner index is vertical coordinate, second index is the horizontal coordinate. XXX Construct the active areas in “spotfinder format”, i.e. opposing corners. XXX This is a really bad function name! XXX The beam centre may be extracted from the ebeam object?

@param config XXX @param sections XXX Directory with calibration information @return Tuple of 2D beam centre, and active areas in

“spotfinder format”

xfel.cxi.cspad_ana.cspad_tbx.dpack(*kwargs)

thin wrapper

xfel.cxi.cspad_ana.cspad_tbx.dwritef(d, dirname=None, basename=None)

The dwritef() function pickles the dictionary pointed to by @p d to the file whose directory and filename portions are pointed to by @p dirname and @p basename, respectively. The directory at @p dirname, as well as any intermediate directories, are recursively created if they do not already exist. The name of the written file is the concatenation of the @p basename parameter and a sequence number derived from the timestamp in the dictionary, @p d.

@param d Dictionary, as created by e.g. dpack() @param dirname Directory portion of output file @param basename Filename prefix of output file @return Path of output file

xfel.cxi.cspad_ana.cspad_tbx.dwritef2(obj, path)

The dwritef2() function writes the object @p obj to the Python pickle file whose path is pointed to by @p path. Non-existent directories of @p path are created as necessary.

@param obj Object to write, as created by e.g. dpack() @param path Path of output file @return Path of output file

xfel.cxi.cspad_ana.cspad_tbx.env_distance(*kwargs)

thin wrapper

xfel.cxi.cspad_ana.cspad_tbx.env_injector_xyz(env)

Returns the coordinates of the sample injector. XXX units unknown?

xfel.cxi.cspad_ana.cspad_tbx.env_laser_status(env, laser_id)

The return value is a bool that indicates whether the laser in question was on for that particular shot. Bear in mind that sample hit by the laser will only encounter the X-rays some time after, depending on the flow rate.

xfel.cxi.cspad_ana.cspad_tbx.env_sifoil(env)

The env_sifoil() function returns the total thickness of Si-foil, in um, that attenuates the beam. According to an e-mail from Garth Williams, the centres of the attenuators are in the beam at around 0 mm, and leave the beam at something like -7 mm. The “out” position is at approximately -15 mm.

@param env Environment object @return Total thickness of attenuating Si-foil

xfel.cxi.cspad_ana.cspad_tbx.env_wavelength_sxr(evt, env)

The env_wavelength_sxr() function returns the wavelength in Ångström of the environment pointed to by @p env at the time of the event @p evt. The function returns a positive value or @c None if no wavelength is available for the event. See Heimann et al. (2011) Rev. Sci. Instrum. 82, 093104.

@note The wavelength in eV is 12398.4187 divided by the value

returned from env_wavelength_sxr().

@param evt Event data object, a configure object @param env Environment object @return Wavelength, in Ångström

xfel.cxi.cspad_ana.cspad_tbx.evt_beam_charge(evt)

The evt_beam_charge() function returns the charge of the pulse in nC.

@param evt Event data object, a configure object @return Pulse charge, in nC

xfel.cxi.cspad_ana.cspad_tbx.evt_get_quads(address, evt, env)
xfel.cxi.cspad_ana.cspad_tbx.evt_pulse_energy(evt)

The evt_pulse_energy() function returns the energy, or the intensity, of the pulse in arbitrary units. The returned value should be proportional to the number of photons in the pulse, and may be negative due to noise.

@note An absolute, but less accurate, estimate of the number of

photons in the pulse may be obtained from the gas monitor detector’s fMilliJoulesPerPulse value.

@param evt Event data object, a configure object @return Pulse intensity, in arbitrary units

xfel.cxi.cspad_ana.cspad_tbx.evt_pulse_length(evt)

The evt_pulse_length() function returns the pulse length in fs. It is calculated as the ratio of the charge (in nC) and the peak current (in A).

@param evt Event data object, a configure object @return Pulse length, in fs

xfel.cxi.cspad_ana.cspad_tbx.evt_repetition_rate(evt, address='*')

The evt_repetition_rate() function returns the repetition rate of the instrument in Hz. See https://confluence.slac.stanford.edu/display/PCDS/EVR+Event+Codes

@param evt Event data object, a configure object @param address Data source address of the DAQ device @return Integer repetition rate, in Hz

xfel.cxi.cspad_ana.cspad_tbx.evt_seqno(evt=None)

The evt_seqno() function returns string representation of a sequence number. If @p evt is not @c None the return value reflects the time at which @p evt occurred, otherwise the current time is used. If @p evt does not contain a time, evt_seqno() returns @c None. XXX Should probably return an integer type instead?

@param evt Event data object, a configure object @return String representation of sequence number

xfel.cxi.cspad_ana.cspad_tbx.evt_time(evt=None)

The evt_time() function returns the time of the event @p evt since midnight, 1 January 1970 UTC (Unix time) to millisecond precision. If @p evt does not contain a time, evt_time() returns @c None. If @p evt is @c None the return value reflects current time is used.

@note Millisecond precision is sufficient, because at 120 Hz, shots

are taken at 8.3 ms intervals.

@param evt Event data object, a configure object @return Unix time as a tuple of seconds and milliseconds

xfel.cxi.cspad_ana.cspad_tbx.evt_timestamp(t=None)

The evt_timestamp() function returns a string representation of an extended human-readable ISO 8601 timestamp. If @p t is @c None the current time is used. The function returns @c None on failure.

@param t Tuple of the time in seconds and milliseconds @return Human-readable ISO 8601 timestamp in string representation

xfel.cxi.cspad_ana.cspad_tbx.evt_wavelength(*kwargs)

thin wrapper

xfel.cxi.cspad_ana.cspad_tbx.getOptBool(s)
xfel.cxi.cspad_ana.cspad_tbx.getOptEvalOrString(s)

Allow python code macros in the pyana configuration file, e.g. dark_path = “/location_of_darks/r%%04d/Ds1-avg.pickle”%%(max([{True:dark,False:0}[3 > dark] for dark in [1,2,6,9,12,14,17,19]]))

xfel.cxi.cspad_ana.cspad_tbx.getOptFloat(s)

Return a single float.

xfel.cxi.cspad_ana.cspad_tbx.getOptInteger(s)

XXX Return a single integer. This function was originally written by Ingrid Ofte for pyana’s XtcExplorer module. XXX What if conversion fails?

xfel.cxi.cspad_ana.cspad_tbx.getOptROI(s)

Return a tuple of the region of interest. Format: roi = fast_low:fast_high,slow_low:slow_high

xfel.cxi.cspad_ana.cspad_tbx.getOptString(s)

XXX Return the string, strip of any white space (make sure there are no newline characters here). This function was originally written by Ingrid Ofte for pyana’s XtcExplorer module.

xfel.cxi.cspad_ana.cspad_tbx.getOptStrings(s, default=None)

XXX Return a list of strings. This function was originally written by Ingrid Ofte for pyana’s XtcExplorer module.

xfel.cxi.cspad_ana.cspad_tbx.hdf5pack(hdf5_file, active_areas=None, address=None, attenuation=None, beam_center_x=None, beam_center_y=None, ccd_image_saturation=None, data=None, distance=None, pixel_size=None, pulse_length=None, saturated_value=None, timestamp=None, wavelength=None, xtal_target=None)

Similar but far from identical to the HDF5 output from CASS. XXX Poor diagnostics–we don’t know if it failed or not.

@note Does not include the deprecated SEQUENCE_NUMBER attribute.

While some redundant items are written in order to keep the HDF5 synchronised to the pickle format, neither SIZE1 nor SIZE2 are included.

xfel.cxi.cspad_ana.cspad_tbx.image(address, config, evt, env, sections=None)

Assemble the uint16 detector image, and sum it up as int32. Sum the image of squared intensities as uint64. XXX Documentation! XXX Would be nice to get rid of the constant string names. XXX Better named evt_image()?

@param address Full data source address of the DAQ device @param config XXX This should go–get up-to-date object on the fly! @param evt Event data object, a configure object @param env Environment object @param sections XXX @return XXX

xfel.cxi.cspad_ana.cspad_tbx.image_xpp(address, evt, env, aa, quads=None)

Assemble the uint16 detector image, see also cspad_tbx.CsPadDetector(). XXX Documentation! XXX Would be nice to get rid of the constant string names. XXX Better named evt_image()?

@param address Full data source address of the DAQ device @param evt Event data object, a configure object @param env Environment object @param aa Active areas, in lieu of full metrology object @param quads Data, if None get it from the event @return XXX

xfel.cxi.cspad_ana.cspad_tbx.iplace(dst, src, angle, center)

The iplace() function places @p src in @p dst centred on @p center after rotating it by @p angle degrees counter-clockwise. The source image is mapped onto the destination image by bilinear interpolation. While this may introduce interpolation artifacts it is significantly simpler than many other interpolation methods–and bog slow.

@p dst Destination image @p src Source image @p angle Rotation angle, in degrees @p center Centre of @p src in @p dst, after rotation

xfel.cxi.cspad_ana.cspad_tbx.pathsubst(format_string, evt, env, **kwargs)

The pathsubst() function provides variable substitution and value formatting as described in PEP 3101. The function returns a copy of the input string, @p format_string, with field names replaced by their appropriate values as determined by either @p evt, @p env, or the user-supplied keyworded arguments, @p kwargs.

chunk: Chunk number or -1 if unknown.

epoch: Time of the event, in number of seconds since midnight,

1 January 1970 UTC (Unix time), to millisecond precision.

experiment: Experiment name, or empty string if unknown.

expNum: Experiment number or -1 if unknown.

instrument: Instrument name, or empty string if unknown.

iso8601: The time of the event as an extended human-readable ISO

8601 timestamp, to millisecond precision, or the empty string if unknown. Not suitable for file names, because it contains characters that do not play well with certain file systems (e.g. NTFS).

jobName: Job name.

jobNameSub: Combination of job name and subprocess index as a string

which is unique for all subprocesses in a job.

run: Run number or -1 if unknown.

seqno: Sequence number or -1 if unknown.

stream: Stream number or -1 if unknown.

subprocess: Subprocess number. This is a non-negative integer in

the range [0, nproc) when multiprocessing, or -1 for a single-process job.

user: The “login name” of the user.

In addition to the standard conversion flags, the pathsubst() function implements the <code>!u</code> and <code>!l</code> flags for conversion to upper- and lower-case strings, respectively.

Literal braces can be escaped by doubling, i.e. <code>{</code> is written <code>{{</code>, and <code>}</code> as <code>}}</code>.

@note Chunk number, expNum, run number, and stream number are

determined from the input XTC file name. If a file does not adhere to the standard format, it may not be possible to determine these quantities.

@note String substitution requires PSDM pyana version 0.10.3 or

greater.

@param format_string String containing replacement fields @param evt Event data object, a configure object @param env Environment object @param kwargs User-supplied replacements, on the form

<code>field_name=value</code>

@return Copy of @p format_string, with replacement

fields substituted by their appropriate values

xfel.cxi.cspad_ana.cspad_tbx.rplace(dst, src, angle, center)

The rplace() function places @p src in @p dst centred on @p centre after rotating it by @p angle degrees counter-clockwise. The rotation angle is rounded to the nearest integer multiple of 90 degrees before transformation.

@p dst Destination image @p src Source image @p angle Rotation angle, in degrees @p center Centre of @p src in @p dst, after rotation

xfel.cxi.cspad_ana.cspad_tbx.write_tiff(d, dirname=None, basename=None)

The write an image tiff. Basic implementation no frills, no metadata

xfel.cxi.cspad_ana.display_calib module

xfel.cxi.cspad_ana.display_calib.display_calib(dirname, right, verbose)

XXX Docstring, in fact revise all the documentation

@param dirname Directory with calibration information @param right @c True to restrict rotations to right angles @param verbose @c True to print ASIC coordinates

xfel.cxi.cspad_ana.histogram_finalise module

class xfel.cxi.cspad_ana.histogram_finalise.finalise_one_run(scratch_dir, pickle_pattern=None)

Bases: object

class xfel.cxi.cspad_ana.histogram_finalise.histogram_finalise(output_dirname, runs, pickle_pattern=None)

Bases: object

xfel.cxi.cspad_ana.histogram_finalise.update_histograms(hist_dict1, hist_dict2)

xfel.cxi.cspad_ana.hitfinder_tbx module

class xfel.cxi.cspad_ana.hitfinder_tbx.distl_hitfinder

Bases: object

distl_filter(address, cspad_img, distance, timestamp, wavelength)
get_active_data(imgobj, phil)
set_up_hitfinder(env)

xfel.cxi.cspad_ana.mod_average module

First- and second-order statistics for CS-PAD images

The mod_average user analysis module computes the (arithmetic) mean and the standard deviation from the images in an XTC stream. On successful completion, the mean and standard deviation images are written to disk as pickled dictionaries.

class xfel.cxi.cspad_ana.mod_average.mod_average(address, max_out=None, mean_out=None, std_out=None, **kwds)

Bases: average_mixin

Class for generating first- and second-order statistics within the pyana framework

XXX Maybe this module should be renamed to mod_stat12, mod_sstat or some such?

beginjob(evt, env)

The beginjob() function does one-time initialisation from event- or environment data. It is called at an XTC configure transition.

@param evt Event data object, a configure object @param env Environment object

endjob(obj1, obj2=None)

The endjob() function writes the mean and standard deviation images to disk.

@param evt Event object (psana only) @param env Environment object

event(evt, env)

The event() function is called for every L1Accept transition.

@param evt Event data object, a configure object @param env Environment object

xfel.cxi.cspad_ana.mod_average_cbf module

xfel.cxi.cspad_ana.mod_cbf_hitfind module

xfel.cxi.cspad_ana.mod_cbf_index module

xfel.cxi.cspad_ana.mod_cspad_cbf module

xfel.cxi.cspad_ana.mod_cspad_cbf_dump module

xfel.cxi.cspad_ana.mod_daq_status module

class xfel.cxi.cspad_ana.mod_daq_status.StatusFrame_thread

Bases: Thread

The XrayFrame_thread class allows Run MainLoop() to be run as a thread, which is necessary because all calls to wxPython must be made from the same thread that originally imported wxPython.

This is all based on “Running MainLoop in a separate thread”, http://wiki.wxpython.org/MainLoopAsThread.

run()

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

start_local()

The start_local() function calls the run() function through self.start_orig, and exists only after self.lock has been released. This eliminates a race condition which could cause updates to be sent to non-existent frame.

class xfel.cxi.cspad_ana.mod_daq_status.mod_daq_status

Bases: object

beginjob(evt, env)
endjob(obj1, obj2=None)

@param evt Event object (psana only) @param env Environment object

event(evt, env)
initialize()
update_plot()

Post an update event with current plot values to redraw the window.

xfel.cxi.cspad_ana.mod_dump module

Output image to the file system.

class xfel.cxi.cspad_ana.mod_dump.mod_dump(address, out_dirname, out_basename, out_format='pickle', **kwds)

Bases: common_mode_correction

Class for outputting images to the file system within the pyana analysis framework. XXX This should eventually deprecate the ‘write_dict’ dispatch from mod_hitfind.

event(evt, env)

The event() function is called for every L1Accept transition. It outputs the detector image associated with the event @p evt to the file system.

@param evt Event data object, a configure object @param env Environment object

xfel.cxi.cspad_ana.mod_dump_bitmap module

Output image to the file system.

class xfel.cxi.cspad_ana.mod_dump_bitmap.mod_dump_bitmap(address, out_dirname, out_basename, binning=1, brightness=1.0, color_scheme=0, format='png', **kwds)

Bases: common_mode_correction

Class for outputting images to the file system within the pyana analysis framework. XXX This should eventually deprecate the ‘write_dict’ dispatch from mod_hitfind.

event(evt, env)

The event() function is called for every L1Accept transition. It outputs the detector image associated with the event @p evt to the file system.

@param evt Event data object, a configure object @param env Environment object

xfel.cxi.cspad_ana.mod_event_info module

class xfel.cxi.cspad_ana.mod_event_info.laser_status(laser_id, status=None)

Bases: object

ms_since_last_status_change(evt_time)
set_status(status, evt_time)
property status
status_change_timestamp = None
class xfel.cxi.cspad_ana.mod_event_info.mod_event_info(address, detz_offset=575, check_beam_status=True, verbose=False, delta_k=0.0, override_energy=None, **kwds)

Bases: object

Extract basic information from the evt and env objects for each event.

beginjob(evt, env)

The beginjob() function does one-time initialisation from event- or environment data. It is called at an XTC configure transition.

@param evt Event data object, a configure object @param env Environment object

endjob(obj1, obj2=None)
event(evt, env)

The event() function is called for every L1Accept transition.

@param evt Event data object, a configure object @param env Environment object

xfel.cxi.cspad_ana.mod_filter module

The mod_filter module extracts timestamps from a file and uses them to filter events. A single valid timestamp can be embedded anywhere in a word, where individual words must be separated by any amount of white space. Lines where the first non-white space character is a hash mark are ignored.

By default, only events whose timestamps match are passed through to downwind modules. If @c negate is @c True, mismatching events are selected instead. Events with missing timestamps are always skipped.

class xfel.cxi.cspad_ana.mod_filter.mod_filter(timestamps_path=None, timestamps_interval=None, negate='False')

Bases: object

beginjob(evt, env)
endjob(obj1, obj2=None)

@param evt Event object (psana only) @param env Environment object

event(evt, env)

The event() function puts a “skip_event” object with value @c True into the event if the shot is to be skipped.

@param evt Event data object, a configure object @param env Environment object

xfel.cxi.cspad_ana.mod_hdf5 module

The mod_hdf5 module writes all events to a single HDF5 (hierarchical data format, version 5) file. XXX Not sure how this module will behave under multiprocessing.

class xfel.cxi.cspad_ana.mod_hdf5.mod_hdf5(address, path, **kwds)

Bases: common_mode_correction

event(evt, env)

The event() function creates a HDF5 group for the event, unless it contains a “skip_event” object with value @c True.

@param evt Event data object, a configure object @param env Environment object

xfel.cxi.cspad_ana.mod_hitfind module

Hitfinding for CSPad images

XXX

class xfel.cxi.cspad_ana.mod_hitfind.mod_hitfind(address, dispatch=None, integration_dirname=None, integration_basename=None, out_dirname=None, out_basename=None, roi=None, distl_min_peaks=None, distl_flags=None, threshold=None, xtal_target=None, negate_hits=False, trial_id=None, db_logging=False, progress_logging=False, sql_buffer_size=1, db_host=None, db_name=None, db_table_name=None, db_experiment_tag=None, db_user=None, db_password=None, db_tags=None, trial=None, rungroup_id=None, db_version='v1', **kwds)

Bases: common_mode_correction, distl_hitfinder

Class for hitfinding within the pyana framework

beginjob(evt, env)

The beginjob() function does one-time initialisation from event- or environment data. It is called at an XTC configure transition.

@param evt Event data object, a configure object @param env Environment object

commit_entries()
commit_progress_entries()
endjob(obj1, obj2=None)

The endjob() function logs the number of processed shots.

@param evt Event object (psana only) @param env Environment object

event(evt, env)

The event() function is called for every L1Accept transition. XXX more?

Previously, common-mode correction was applied only after initial threshold filtering. Since the common_mode class applies the (lengthy) common-mode correction immediately after reading the image from the stream, this optimisation is currently not (elegantly) doable.

@param evt Event data object, a configure object @param env Environment object

queue_entry(entry)
queue_progress_entry(entry)

xfel.cxi.cspad_ana.mod_illumination_filter module

The mod_illumination_filter module filter events by their illumination condition. When illumination conditions matter, laser 4 should always be off, and laser 1 must have had its state changed for least laser_wait_time ms before the event. Events with missing timestamps are always skipped.

class xfel.cxi.cspad_ana.mod_illumination_filter.mod_illumination_filter(illumination, laser_wait_time='2000')

Bases: object

beginjob(evt, env)
endjob(obj1, obj2=None)

@param evt Event object (psana only) @param env Environment object

event(evt, env)

The event() function puts a “skip_event” object with value @c True into the event if the shot is to be skipped.

@param evt Event data object, a configure object @param env Environment object

xfel.cxi.cspad_ana.mod_ledge module

xfel.cxi.cspad_ana.mod_mar module

class xfel.cxi.cspad_ana.mod_mar.mod_mar(address, directory, beam_x=None, beam_y=None, template=None)

Bases: object

begincalibcycle(evt, env)
beginjob(evt, env)
endjob(obj1, obj2=None)

@param evt Event object (psana only) @param env Environment object

event(evt, env)

xfel.cxi.cspad_ana.mod_param module

Simple analysis of per-shot parameters of a run

XXX mod_param must be run as a single process–guard against it!

class xfel.cxi.cspad_ana.mod_param.mod_param

Bases: object

Class for simple analysis of certain per-shot parameters of a run. Currently attenuation, sample-detector distance, and wavelength are considered. Since attenuation and distance is not expected to vary, their values are output only when changed. For the wavelength, the average and standard deviation is computed. Note that incompleteness due to lacking image data is not detected, because it may slow down this module considerably.

beginjob(evt, env)

The beginjob() function does one-time initialisation from event- or environment data. It is called at an XTC configure transition.

@param evt Event data object, a configure object @param env Environment object

endjob(obj1, obj2=None)

The endjob() function finalises the mean and standard deviation calculations, and reports on the total number of skipped shots.

@param evt Event object (psana only) @param env Environment object

event(evt, env)

The event() function is called for every L1Accept transition. The event() function does not log shots skipped due to incompleteness in order to keep the output streams clean. Instead, the number of skipped shots is reported by endjob().

@param evt Event data object, a configure object @param env Environment object

xfel.cxi.cspad_ana.mod_pickle2cbf_dump module

xfel.cxi.cspad_ana.mod_pulnix_dump module

XXX

class xfel.cxi.cspad_ana.mod_pulnix_dump.mod_pulnix_dump(address, out_dirname=None, out_basename=None)

Bases: object

Class for dumping simple intensity images into an uncompressed tarball. At 120 Hz it is inconvenient to dump every single image to its own file.

beginjob(evt, env)

The beginjob() function is called at an XTC configure transition. It opens per-process tar files to avoid clobbering while multiprocessing.

@param evt Event data object, a configure object @param env Environment object

endjob(obj1, obj2=None)

The endjob() function closes the tar file opened in beginjob().

@param evt Event object (psana only) @param env Environment object

event(evt, env)

The event() function is called for every L1Accept transition.

@param evt Event data object, a configure object @param env Environment object

xfel.cxi.cspad_ana.mod_radial_average module

Calculate the radial average of the images in a stream, for each image.

class xfel.cxi.cspad_ana.mod_radial_average.mod_radial_average(address, out_dirname=None, out_basename=None, xtal_target=None, two_theta_low=None, two_theta_high=None, **kwds)

Bases: common_mode_correction

Class for calulating radial average of images

beginjob(evt, env)

The beginjob() function does one-time initialisation from event- or environment data. It is called at an XTC configure transition.

@param evt Event data object, a configure object @param env Environment object

endjob(obj1, obj2=None)

The endjob() function logs the number of processed shots.

@param evt Event object (psana only) @param env Environment object

event(evt, env)

The event() function is called for every L1Accept transition. @param evt Event data object, a configure object @param env Environment object

xfel.cxi.cspad_ana.mod_spectra module

xfel.cxi.cspad_ana.mod_spectra_view module

xfel.cxi.cspad_ana.mod_view module

xfel.cxi.cspad_ana.mod_xes module

First- and second-order statistics for CS-PAD images

The mod_xes user analysis module performs the following sequence of analysis: dark correction (using average dark previously computed by mod_average); removal of inactive pixels; common mode correction; removal of pixels with high stddev (“hot pixels”); removal of noise < 5 ADUs; selection of scan rows known to contain the spectrum; summation-reduction so as to form a single spectrum.

XXX mod_xes must be run as a single process–guard against it!

class xfel.cxi.cspad_ana.mod_xes.mod_xes(address, pickle_dirname='.', pickle_basename='', roi=None, **kwds)

Bases: average_mixin

Class for generating first- and second-order statistics within the pyana framework

XXX Maybe this module should be renamed to mod_stat12, mod_sstat or some such?

endjob(obj1, obj2=None)

The endjob() function finalises the mean and standard deviation images and writes them to disk.

@param evt Event object (psana only) @param env Environment object

event(evt, env)

The event() function is called for every L1Accept transition.

@param evt Event data object, a configure object @param env Environment object

xfel.cxi.cspad_ana.parse_calib module

class xfel.cxi.cspad_ana.parse_calib.Section(angle=0, center=(0, 0))

Bases: object

Class for a section, or a pair of ASIC:s, or a two-by-one. A quadrant (and to some extent a section) is really an imaginary object–the detector only reads out the ASIC:s. The metrology should be accurate to +/- one pixel, usually better but occasionally worse. XXX Is it a section, a two-by-one, or a sensor?

This class adopts a matrix-oriented coordinate system. The origin is in the top left corner, the first coordinate increases downwards, the second coordinate increases to the right, and the third coordinate increases towards the viewer. In this right-handed coordinate system, a rotation by a positive angle is counter-clockwise in the plane of the two first coordinates.

@note There are a few hard coded numbers throughout this class.

corners(right=True)

The corners() function returns an array of the four corners of the section, in counter-clockwise order. Each vertex is a two-dimensional array of the plane components. XXX Maybe better named corners_section()?

@param right @c True to restrict rotations to right angles @return Coordinates of the four corners, in counter-clockwise

order

corners_asic()

The corners_asic() function returns a list of pixel indices which position the two ASIC:s on the detector, in order from top to bottom by the “standing up” convention. Each list of indices gives the coordinates of the top, left and bottom, right corners of the section’s ASIC:s in “spotfinder format”.

q_size = (850, 850)
qrotate(angle)

The qrotate() function rotates the section counter-clockwise by @p angle degrees around the centre of its quadrant. The rotation angle is rounded to an integer multiple of 90 degrees prior to transformation. Rotation around the quadrant centre changes the location and the orientation of the section.

@param angle Rotation angle, in degrees

srotate(angle)

The srotate() function rotates the section counter-clockwise by @p angle degrees around its centre. Rotation within the quadrant only changes the orientation of the section.

@param angle Rotation angle, in degrees

translate(displacement)

The translate() function displaces the section.

@param displacement Two-dimensional array of the additive

displacement

xfel.cxi.cspad_ana.parse_calib.calib2sections(dirname)

The calib2sections() function reads calibration information stored in the directory tree beneath @p dirname and returns a two-dimensional array of Section objects. The first index in the returned array identifies the quadrant, and the second index identifies the section within the quadrant.

@param dirname Directory with calibration information @return Section objects

xfel.cxi.cspad_ana.parse_calib.calib2tensor3(dirname, component)

The calib2tensor3() function reads the latest calibration tensor for @p component from @p dirname. Any obsoleted calibration data is ignored. The function returns the tensor as a numpy array on successful completion.

@param dirname Directory with calibration information @param component Kind of calibration data sought @return Tensor as numpy array

xfel.cxi.cspad_ana.parse_calib.fread_matrix(stream)

The fread_matrix() function reads a vector or matrix from the stream pointed to by @p stream and returns it as a numpy array.

@param stream Stream object @return Tensor as numpy array

xfel.cxi.cspad_ana.parse_calib.fread_tensor3(stream)

The fread_tensor3() function reads a tensor of rank no greater than 3 from the stream pointed to by @p stream and returns it as a numpy array.

@param stream Stream object @return Tensor as numpy array

xfel.cxi.cspad_ana.parse_calib.fread_vector(stream)

The fread_vector() function reads a vector from the stream pointed to by @p stream and returns it as a numpy array.

@param stream Stream object @return Tensor as numpy array

xfel.cxi.cspad_ana.parse_calib.v2calib2sections(filename)

The v2calib2sections() function reads calibration information stored in new style SLAC calibration file and returns a two-dimensional array of Section objects. The first index in the returned array identifies the quadrant, and the second index identifies the section within the quadrant.

@param dirname Directory with calibration information @return Section objects

xfel.cxi.cspad_ana.pixel_histograms module

class xfel.cxi.cspad_ana.pixel_histograms.pixel_histograms(address, pickle_dirname='.', pickle_basename='hist', roi=None, hist_min=None, hist_max=None, n_slots=None, **kwds)

Bases: common_mode_correction

beginjob(evt, env)

The beginjob() function does one-time initialisation from event- or environment data. It is called at an XTC configure transition.

@param evt Event data object, a configure object @param env Environment object

endjob(obj1, obj2=None)

The endjob() function finalises the mean and standard deviation images and writes them to disk. @param evt Event object (psana only) @param env Environment object

event(evt, env)

The event() function is called for every L1Accept transition. Once self.nshots shots are accumulated, this function turns into a nop.

@param evt Event data object, a configure object @param env Environment object

xfel.cxi.cspad_ana.xes_finalise module

xfel.cxi.cspad_ana.xes_finalise.cspad2x2_bad_pixel_mask_cxi_run7()
xfel.cxi.cspad_ana.xes_finalise.cspad_unbound_pixel_mask()
xfel.cxi.cspad_ana.xes_finalise.filter_outlying_pixels(spectrum_focus, mask_focus)
class xfel.cxi.cspad_ana.xes_finalise.finalise_one_run(scratch_dir)

Bases: object

class xfel.cxi.cspad_ana.xes_finalise.first_moment_analysis(x, y)

Bases: object

as_trace()
calculate()
xfel.cxi.cspad_ana.xes_finalise.get_spectrum(spectrum_focus, mask_focus=None)
xfel.cxi.cspad_ana.xes_finalise.output_image(flex_img, filename, invert=False, scale=False)
xfel.cxi.cspad_ana.xes_finalise.output_matlab_form(flex_matrix, filename)
xfel.cxi.cspad_ana.xes_finalise.output_spectrum(spectrum_focus, mask_focus=None, output_dirname='.', run=None)
xfel.cxi.cspad_ana.xes_finalise.plot_energy(plot_x)
xfel.cxi.cspad_ana.xes_finalise.spec_plot(x, y, img, file_name, figure_size=(10, 5), transparent=False)
class xfel.cxi.cspad_ana.xes_finalise.xes_finalise(runs, output_dirname='.', roi=None)

Bases: object

xfel.cxi.cspad_ana.xes_histograms module

xfel.cxi.cspad_ana.xes_histograms.run(args)
class xfel.cxi.cspad_ana.xes_histograms.xes_from_histograms(pixel_histograms, output_dirname='.', gain_map_path=None, gain_map=None, method='photon_counting', estimated_gain=30, nproc=None, photon_threshold=0.6666666666666666, roi=None, run=None)

Bases: object

Module contents

xfel.cxi.cspad_ana.skip_event_flag()