reborn.external package

Submodules

reborn.external.cheetah module

Utilities for working with data created by Cheetah. I make no promises that any of this will work as expected; Cheetahs are wild animals.

reborn.external.cheetah.reshape_psana_cspad_array_to_cheetah_array(psana_array)[source]

Transform a native psana cspad numpy array of shape (32,185,388) into a “Cheetah array” of shape (1480, 1552). Conversion to Cheetah format requires a re-write of the data in memory, and each detector panel is no longer stored contiguously in memory.

Parameters:

psana_array (numpy array) – A numpy array of shape (32,185,388) produced by the psana module

Returns:

A numpy array of shape (1480, 1552); same data as the psana array but mangled as done within Cheetah

Return type:

cheetah_array (numpy array)

reborn.external.cheetah.cheetah_cspad_array_to_pad_list(psana_array, geom_dict)[source]

This function is helpful if you have a CrystFEL geom file that refers to Cheetah output, but you wish to work with data in the native psana format. First you should create a crystfel geometry dictionary using the function geometry_file_to_pad_geometry_list().

Parameters:
  • psana_array (numpy array) – A numpy array of shape (32,185,388) produced by the psana module.

  • geom_dict (dict) – A CrystFEL geometry dictionary produced by external.crystfel.geom_to_dict() .

Returns:

A list containing data from each pixel array

Return type:

pad_list (list)

reborn.external.cheetah.reshape_psana_pnccd_array_to_cheetah_array(psana_array)[source]

Transform a native psana pnccd numpy array of shape (???) into a “Cheetah array” of shape (1024,1024). Conversion to Cheetah format requires a re-write of the data in memory. Panels might not be contiguous in memory.

Parameters:

psana_array (numpy array) – A numpy array of shape (???) produced by the psana module

Returns:

A numpy array of shape (1024, 1024); same data as the psana array but mangled as done within Cheetah

Return type:

cheetah_array (numpy array)

reborn.external.cheetah.cheetah_pnccd_array_to_pad_list(psana_array, geom_dict)[source]

This function is helpful if you have a CrystFEL geom file that refers to Cheetah output, but you wish to work with data in the native psana format. First you should create a crystfel geometry dictionary using the function geometry_file_to_pad_geometry_list().

Parameters:
  • psana_array (numpy array) – A numpy array of shape (32,185,388) produced by the psana module.

  • geom_dict (dict) – A CrystFEL geometry dictionary produced by external.crystfel.geom_to_dict() .

Returns:

A list containing data from each pixel array

Return type:

pad_list (list)

class reborn.external.cheetah.CheetahFrameGetter(*args, **kwargs)[source]

Bases: FrameGetter

A frame getter that attempts to read the CXIDB variants that are written by Cheetah.

When overriding the __init__ method, you should be sure to set the self.n_frames property. Do not use any positional or keyword arguments that cannot be serialized, such as file handlers (instead, provide a file path and create the handler within the __init__ method). If you pass in objects that cannot be serialized, your subclass will still work, but it will not be possible to pass your subclass into any of the parallelized processors that utilize FrameGetters

skip_peaks = False
fs_min = 0
fs_max = 0
ss_min = 0
ss_max = 0
load_cxidb_file(cxi_file_name)[source]
get_peaks(h5file, frame_number)[source]
get_data(frame_number=0)[source]

You must overrider this when making a subclass. You can do anything you want here, but you must return a valid DataFrame instance. Do not attempt to modify any private attributes of the abstract base class. Any property prefixed with an underscore is off-limits.

reborn.external.crystfel module

Utilities for working with CrystFEL files. Most of the functions below wrap around the functions in the crystfel_utils module within the cfelpyutils package, which is maintained by CFEL. The crystfel_utils module is included in reborn so that you do not need to install it with pip.

reborn.external.crystfel.load_crystfel_geometry(geometry_file: str) dict[source]

Given a CrystFEL geometry file, create a python dictionary object. The structure of this dictionary is defined by the cfelpyutils.crystfel_utils module, which is (was?) maintained by CFEL and included in reborn for convenience.

Parameters:

geometry_file (str) – Path to geometry file

Returns:

dict

reborn.external.crystfel.geometry_dict_to_pad_geometry_list(geometry_dict: dict) PADGeometryList[source]

Given a CrystFEL geometry dictionary, create a list of :class:<reborn.geometry.PADGeometry objects. This will also append the name of the panel to the PADGeometry instance.

Parameters:

geometry_dict (str) – Path to geometry file

Returns: PADGeometryList

reborn.external.crystfel.fix_cspad_cheetah_indexing(pads)[source]

Correction for CSPAD parent data slicing. Hopefully you do not need to use this as it will be removed in the future.

reborn.external.crystfel.extract_geom_from_stream(stream_path: str, geom_path: str) None[source]

Extract geometry from a CrystFEL stream file and write to CrystFEL geom file.

Parameters:
  • stream_path – Path to input stream file.

  • geom_path – Path to output geom file.

Returns:

None

reborn.external.crystfel.geometry_file_to_pad_geometry_list(geometry_file: str) PADGeometryList[source]

Given a CrystFEL geometry file, create a list of :class:<reborn.geometry.PADGeometry objects. This will also append extra crystfel-specific items like fsx, max_fs, etc.

Parameters:

geometry_file (str) – Path to geometry file

Returns:

PADGeometryList

reborn.external.crystfel.split_data_block(data: ndarray, geom_dict: dict, frame_number: int = 0) list[source]

Split a chunk of contiguous data (usually 3D) into a list of 2D ndarray instances.

reborn.external.crystfel.split_image(data: ndarray, geom_dict: dict) list[source]

Split a 2D image into individual panels (useful for working with Cheetah output). If the input data is not a 2D image, then attempt to reshape it according to the expected shape as specified in the geometry dictionary.

Parameters:
  • data (ndarray) – Contiguous block of image data

  • geom_dict (dict) – Geometry dictionary

Returns:

list

reborn.external.crystfel.unsplit_image(data: list, geom_dict: dict) ndarray[source]

Undo the action of split_image

Parameters:
  • data (list of ndarray) – List of individual pads

  • geom_dict (dict) – Geometry dictionary

Returns:

ndarray

reborn.external.crystfel.write_geom_file_single_pad(file_path: str = None, beam: Beam = None, pad_geometry: PADGeometryList = None) None[source]

Simple geom file writer. Beware – the file may not fully adhere to the CrystFEL specifications, and we do not attempt to maintain compatibility…

reborn.external.crystfel.write_geom_file_from_template(pad_geometry: PADGeometryList = None, template_file: str = None, out_file: str = None) None[source]

Given a matching template, write a geom file with the geometry of a corresponding PADGeometryList

reborn.external.crystfel.convert_to_crystfel_format(pad_geometry, beam=None, adu_per_ev=None)[source]

CrystFEL format described here .

This is not guaranteed to support all CrystFEL features.

Parameters:
Returns:

list containing geometry with crystFEL entries

Return type:

cgeom (List)

reborn.external.crystfel.write_geom_file_from_pad_geometry_list(pad_geometry, file_path, beam=None)[source]
reborn.external.crystfel.readStreamfile_get_total_number_of_frames(stream_file)[source]

Get the total number of frames from a stream file.

Parameters:

stream_file (str) – Path to the stream file

Returns: int

reborn.external.crystfel.readStreamfile_get_nth_frame(streamfile_name, n)[source]

Get the A matrix, CXI file path and CXI frame number from the nth frame in a stream file.

class reborn.external.crystfel.StreamfileFrameGetter(*args, **kwargs)[source]

Bases: FrameGetter

A frame getter that reads a CrystFEL stream file along with CXI files.

Parameters:
  • stream_file (str) – Path to the stream file

  • geom_file (str) – Optional path to a geom file (else search the stream for geometry)

h5_file_path = None
h5_file = None
current_frame = 0
n_frames = 0
cxi_path_replace = None
get_frame(frame_number=0, **kwargs)[source]

Get the dataframe corresponding to a given index.

Parameters:

frame_number (int) – The raw frame number of the desired DataFrame

get_data(frame_number=0)[source]

You must overrider this when making a subclass. You can do anything you want here, but you must return a valid DataFrame instance. Do not attempt to modify any private attributes of the abstract base class. Any property prefixed with an underscore is off-limits.

reborn.external.denss module

reborn.external.denss.get_crystal_structure(pdb_file, cell=1e-07, create_bio_assembly=True, ignore_waters=False) CrystalStructure[source]

Retrieve the crystal structure from a given PDB file.

Parameters:
  • pdb_file (str) – The PBD ID. Ex: “1jfp”.

  • cell (float, optional) – Default cell size. Defaults to 100e-9.

  • create_bio_assembly (bool, optional) – Whether to create a bio assembly. Defaults to True.

Returns:

An instance of CrystalStructure.

Return type:

object

reborn.external.denss.get_denss_pdb(pdb_file, create_bio_assembly=True, ignore_waters=False)[source]

This is a hack to add the biomolecular assembly to DENSS PDB format. Get the PDB file to be used with DENSS.

Parameters:
  • pdb_file (str) – The PBD ID. Ex: “1jfp”.

  • create_bio_assembly (bool, optional) – Whether to create a bio assembly. Defaults to True.

  • ignore_waters (bool, optional) – Ignore water molecules. Defaults to False.

Returns:

DENSS PDB object with bio assembly partners (if requested).

reborn.external.denss.get_scattering_profile(pdb_file, create_bio_assembly=True, q_mags=None, ignore_waters=False)[source]

Retrieve the scattering profile from a given PDB file.

Parameters:
  • pdb_file (str) – Path to the PDB file.

  • create_bio_assembly (bool, optional) – Whether to create a bio assembly. Defaults to True.

  • ignore_waters (bool, optional) – Ignore water molecules. Defaults to False.

Returns:

A tuple containing the qbin and I(q) values.

Return type:

tuple

reborn.external.denss.create_density_map(pdb_file, solvent_contrast=True, create_bio_assembly=True, map_resolution=1e-10, map_oversampling=3, ignore_waters=False)[source]

Create a density map from a given PDB file.

Parameters:
  • pdb_file (str) – The PBD ID. Ex: “1jfp”.

  • solvent_contrast (bool, optional) – If true, adds solvent contrast. Defaults to True.

  • create_bio_assembly (bool, optional) – Whether to create a bio assembly. Defaults to True.

  • map_resolution (float, optional) – Resolution of the map. Defaults to 0.2e-9.

  • map_oversampling (int, optional) – The map oversampling factor. Defaults to 2.

  • ignore_waters (bool, optional) – Ignore water molecules. Defaults to False.

Returns:

A tuple containing the density map [e-], side of the map [m], and extra info.

Return type:

tuple

reborn.external.denss.get_pad_pdb_scattering_intensity(pdb_file: str, create_bio_assembly: bool = True, ignore_waters: bool = False, beam: Beam = None, pad_geometry: PADGeometryList = None, mass_density: float = None, sample_thickness: float = None, as_list: bool = True)[source]

Produce biomolecule scattering intensity from a PDB file.

Parameters:
  • pdb_file (str) – Path to the PBD file or PDB ID (Ex: “1jfp”).

  • create_bio_assembly (bool) – Whether to create a bio assembly. Defaults to True.

  • ignore_waters (bool, optional) – Ignore water molecules. Defaults to False.

  • beam (Beam) – X-ray beam info.

  • pad_geometry (PADGeometryList) – PAD geometry info.

  • mass_density (float) – Concentration of protein in kg/m^3 (numerically equivalent to mg/ml).

  • sample_thickness (float) – Thickness of the sample, assumed to be uniform across the x-ray beam.

  • as_list (bool) – Choose if you want the output to be a list of 2D PAD arrays, or a flat 1D array. Default is True.

Returns:

reborn.external.euxfel module

Utilities for working with EuXFEL data. Uses EuXFEL’s extra_data package. Documentation:

Source Code: https://github.com/European-XFEL/EXtra-data

reborn.external.euxfel.find_proposal(propnum)[source]

Find proposal directory given proposal number.

reborn.external.euxfel.check_extra_data()[source]

Check if the extra_data package is installed.

reborn.external.euxfel.debug_message(*args, caller=True, **kwargs)[source]

Standard debug message, which includes the function called.

reborn.external.euxfel.inspect_available_data(experiment_id, run_id, source=None)[source]

Prints out available data sources for a specific proposal & run. If given a data source, it will also print out the keys for that data source.

Parameters:
  • experiment_id (int) – Experiment proposal number.

  • run_id (int) – Experiment run number.

  • source (str) – data source (example=’SPB_XTD9_XGM/XGM/DOOCS’).

class reborn.external.euxfel.EuXFELFrameGetter(*args, **kwargs)[source]

Bases: FrameGetter

EuXFELFrameGetter to retrieve detector data from EuXFEL endstations in the standard way.

EuXFEL saves a series of exposures each corresponding to an individual x-ray pulse together, indexed by the pulse_train. This framegetter handles that for you so you can iterate directly through frames as if they were globally indexed as in (LCLS or SACLA). The trains are cached so the data is not reloaded if the next frame is within the same train.

Parameters:
  • experiment_id (int) – Experiment proposal number.

  • run_id (int) – Experiment run number.

  • pad_detectors (str) – pad detector data path in H5 (example=’SPB_DET_AGIPD1M-1/DET/*CH0:xtdf’,

  • default='*/DET/*').

  • geom (PADGeometryList) – reborn.detector.PADGeometryList instance with the experiment geometry.

  • max_events (int) – Maximum number of frames to retrieve.

  • beam (Beam) – reborn.source.Beam instance with the x-ray details for the run.

When overriding the __init__ method, you should be sure to set the self.n_frames property. Do not use any positional or keyword arguments that cannot be serialized, such as file handlers (instead, provide a file path and create the handler within the __init__ method). If you pass in objects that cannot be serialized, your subclass will still work, but it will not be possible to pass your subclass into any of the parallelized processors that utilize FrameGetters

current_train_stack = None
current_train_id = None
mask = None
n_trains = None
beam = None
update_detector_distance(vector=array([0., 0., 0.001]))[source]

Modify the PADGeometryList.

Parameters:

vector (ndarray) – This is the vector indicating the direction and step size. The stage offset and vector are added and set to the PADGeometry.t_vec

get_data(frame_number=0)[source]

You must overrider this when making a subclass. You can do anything you want here, but you must return a valid DataFrame instance. Do not attempt to modify any private attributes of the abstract base class. Any property prefixed with an underscore is off-limits.

reborn.external.hdf5 module

reborn.external.hdf5.all_keys_in_file(h5_file_path)[source]

Gather all keys an HDF5 file.

Parameters:

h5_file_path (str) – filename

reborn.external.hdf5.save_metadata_as_h5(h5_file_path, experiment_id, run_id, **meta)[source]

Save metadata in an HDF5 file in a standardized way.

Parameters:
  • h5_file_path (str) – filename

  • experiment_id (str) – experiment id

  • run_id (int) – experiment run id

  • meta – other metadata to save (format: key=value)

reborn.external.hdf5.load_metadata_from_h5(h5_file_path)[source]

Load metadata from an HDF5 file in a standardized way.

Parameters:

h5_file_path (str) – filename

Returns:

dictionary with everything stored in

hdf5 file under the ‘meta’ group.

Return type:

metadata (dict)

reborn.external.hdf5.save_pad_geometry_as_h5(h5_file_path, pad_geometry)[source]

Save PADGeometryList in an HDF5 file in a standardized way.

FIXME: Missing the parent_data_slice and parent_data_shape info.

Parameters:
reborn.external.hdf5.load_pad_geometry_from_h5(h5_file_path)[source]

Load PADGeometryList from HDF5 file in a standardized way.

Parameters:

h5_file_path (str) – filename

Returns:

pad geometry saved in hdf5 file

Return type:

pad_geometry (PADGeometryList)

reborn.external.hdf5.save_pad_data_as_h5(h5_file_path, data_key, data_list)[source]

Save data in an HDF5 file in a standardized way.

Parameters:
  • h5_file_path (str) – filename

  • data_key (str) – root key for data

  • data_list (list) – data to save

reborn.external.hdf5.load_pad_data_from_h5(h5_file_path, data_key)[source]
reborn.external.hdf5.save_beam_as_h5(h5_file_path, beam)[source]

Save Beam in an HDF5 file in a standardized way.

Parameters:
  • h5_file_path (str) – filename

  • beam (Beam) – beam to save

reborn.external.hdf5.load_beam_from_h5(h5_file_path)[source]

Load Beam from HDF5 file in a standardized way.

Parameters:

h5_file_path (str) – filename

Returns:

beam saved in hdf5 file

Return type:

beam (Beam)

reborn.external.hdf5.save_analysis_as_h5(h5_file_path, **analysis)[source]

Save analysis result in an HDF5 file format in a standardized way.

Parameters:
  • h5_file_path (str) – filename

  • analysis – data you would like to save (format: key=data)

reborn.external.hdf5.load_analysis_from_h5(h5_file_path)[source]

Load analysis results from an HDF5 file in a standardized way.

Parameters:

h5_file_path (str) – filename

Returns:

data stored in HDF5 file

Return type:

data (dict)

reborn.external.hdf5.load_analysis_key_from_h5(h5_file_path, *analysis_key)[source]

Load analysis results from a specific key in an HDF5 file in a standardized way.

Parameters:
  • h5_file_path (str) – filename

  • analysis_key (str) – analysis keys for data to retrieve

Returns:

data stored in HDF5 file

Return type:

data (dict)

reborn.external.hdf5.save_dataframe_as_h5(h5_base_path, dataframe, **kwargs)[source]

Save dataframe to HDF5 file in a standardized way.

Parameters:
  • h5_base_path (str) – path to where file will be saved

  • dataframe (DataFrame) – frame data

  • **kwargs – anything else to save (needs manual loading)

reborn.external.hdf5.load_dataframe_from_h5(h5_file_path)[source]

Load dataframe from an HDF5 file in a standardized way.

Parameters:

h5_file_path (str) – filename

Returns:

frame data

Return type:

dataframe (DataFrame)

reborn.external.lcls module

Utilities for working with LCLS data. Most of what you need is already in the psana package. I don’t know where the official psana documentation is but if you work with LCLS data you should at least skim through all of the material in the LCLS Data Analysis Confluence pages. Note that there is documentation on LCLS PAD geometry.

reborn.external.lcls.debug_message(*args, caller=True, **kwargs)[source]

Standard debug message, which includes the function called.

reborn.external.lcls.pad_to_asic_data_split(data, n, m)[source]

Split an array of shape (P, N, M) into a list of n*m*P arrays of shape (N/n, M/m).

For epix we split into 2x2

For cspad we split into 1x2 (?)

Parameters:
  • data (np.ndarray) – PAD data.

  • n (int) – Number of ASICS to split “vertically” with vsplit

  • m (int) – Number of ASICS to split “horizontally” with hsplit

Returns:

List of separated PADs.

Return type:

pads (list)

reborn.external.lcls.get_pad_pixel_coordinates(pad_det, run_number, splitter)[source]

This should work for any detector (except Rayonix, not implemented in psana) without modification so long as splitter is set up correctly.

Parameters:
  • pad_det (obj) – psana detector object

  • run_number (int) – run number of interest

  • splitter (func) – function to split the arrays returned by pad_det into individual asics

Returns:

x (list) y (list) z (list)

reborn.external.lcls.get_pad_geometry_from_psana(pad_det, run_number, splitter)[source]

Creates PADGeometryList from psana detector object.

This should work for any detector without modification so long as splitter is set up correctly.

Parameters:
  • pad_det (obj) – psana detector object

  • run_number (int) – run number of interest

  • splitter (func) – function to split the arrays returned by pad_det into individual asics

Returns:

PADGeometryList (list of reborn PADGeometry objects)

Notes

CSPAD: Has rows of pixels that are elongated

The nominal pixel size is 109.92 x 109.92 microns, but the central two columns (193 and 194) have pixels of size 274.80 x 109.92 microns. This is documented here: https://confluence.slac.stanford.edu/display/PSDM/Detector+Geometry https://confluence.slac.stanford.edu/display/PSDM/CSPAD+Geometry+and+Alignment

class reborn.external.lcls.EpicsTranslationStageMotion(epics_pv=None, vector=array([0., 0., 0.001]))[source]

Bases: object

A class that updates PADGeometry according to stages with positions specified by EPICS PVs.

Parameters:
  • epics_pv ('str') – The EPICS PV string.

  • vector (ndarray) – This is the vector indicating the direction and step size. The stage position will be multiplied by this vector and added to PADGeometry.t_vec

modify_geometry(pad_geometry, event)[source]

Modify the PADGeometryList.

Parameters:
  • pad_geometry (PADGeometryList) – PAD geometry.

  • event (psana.Event) – A psana event from which the stage position derives.

class reborn.external.lcls.TranslationMotion(vector=array([0., 0., 0.001]))[source]

Bases: object

A class that updates PADGeometry with a shift.

Parameters:

vector (ndarray) – The translation to apply to the PADGeometry

modify_geometry(pad_geometry, event)[source]

Modify the PADGeometryList.

Parameters:
  • pad_geometry (PADGeometryList) – PAD geometry.

  • event (psana.Event) – A psana event from which the stage position derives.

class reborn.external.lcls.AreaDetector(pad_id=None, geometry=None, mask=None, data_type='calib', motions=None, run_number=1, adu_per_photon=None, **kwargs)[source]

Bases: object

Thin wrapper for psana.Detector class. Adds methods to generate list of PADGeometry instances and to split the PAD data into a list of 2d arrays.

Instantiate with same arguments you would use to instantiate a psana.Detector instance. Usually this means to supply a psana.DataSource instance.

Parameters:
  • pad_id (str) – Example: DscCsPad

  • geometry (PADGeometryList) – Geometry, or a path to geometry file.

  • mask (ndarray) – Mask array, or path to mask file

  • data_type (str) – Default data type (‘calib’ or ‘raw’)

  • motions (dict) – Special dictionaries to describe motorized motions of the detector

splitter = None
motions = None
adu_per_photon = None
setup_motions(motions)[source]
get_detector_type()[source]

The psana detector fails to provide reliable information on detector type.

get_pad_geometry(event) PADGeometryList[source]

See documentation for the function get_pad_geometry().

split_pad(data)[source]

Split psana data block into a PAD list

get_data_split(event)[source]

Just like the calib data but split into a list of panels. Just like the raw data but split into a list of panels.

get_pixel_coordinates(run_number)[source]

Get pixel coordinates from psana. Returns None for rayonix.

get_mask(split=False)[source]
property n_pixels
reborn.external.lcls.get_event_ids(experiment_id, run_number, cachedir=None, psana_dir=None)[source]

Get the list of event IDs (3-tuples) and use caching if requested. Would be great if we didn’t need to do this… maybe there is a better way but we don’t know where to find it in the psana docs.

Parameters:
  • experiment_id (str) – Experiment ID (e.g. cxilu1817)

  • run_number (int) – Run number

  • cachedir (str or None) – Where to look for cached data or save data

  • psana_dir (str or None) – Use this if the XTC data is in a strange location. For advanced users…

class reborn.external.lcls.LCLSFrameGetter(*args, **kwargs)[source]

Bases: FrameGetter

Parameters:
  • experiment_id (str) – E.g. cxilu5617

  • run_number (int) – run number

  • () (pad_detectors) – TODO

  • max_events (int) – Truncate to max number of shots/events

  • psana_dir (str) – Use this if the XTC data is in a non-standard place

  • beam (Beam) – Beam info

  • idx (bool) – Set to false if no index files are available (email SLAC to create them)

  • cachedir (str) – Path to put a cache of event IDs for faster loading.

  • event_ids (list or ndarray) – If you want to pre-select event IDs, provide them here.

  • event_codes (dict) – Provide event codes to add to the returned DataFrame . Example: dict(xray_on=40, laser_on=41)

  • evr_id (str) – If you know the event reader to search for event codes (e.g. “evr0”)

  • photon_wavelength_pv (str)

mask = None
event = None
event_codes = None
event_ids = None
get_data(frame_number=0)[source]

You must overrider this when making a subclass. You can do anything you want here, but you must return a valid DataFrame instance. Do not attempt to modify any private attributes of the abstract base class. Any property prefixed with an underscore is off-limits.

reborn.external.pyqt module

reborn.external.pyqtgraph module

reborn.external.pyqtgraph.keep_open()[source]

Simple helper that keeps a pyqtgraph window open when you run a script from the terminal.

reborn.external.pyqtgraph.image(*args, **kargs)[source]

Create and return an ImageWindow class instance (this is just a window with an ImageView widget inside) and show image data. Will show 2D or 3D image data. Accepts a title argument to set the title of the window. All other arguments are used to show data. (see ImageView.setImage())

Note

This is a direct copy of the equivalent (undocumented?) function in pyqtgraph, except that it adds the view argument so that you can easily put your image in a plot axis.

reborn.external.pyqtgraph.imview(image, *args, hold=False, gradient='flame', aspect_locked=False, **kwargs)[source]

Makes an ImageView widget but adds some functionality that I commonly need. A PlotItem is used as the view so that there are axes, and by default the aspect ratio is unlocked so that the image is stretched to fill the view. The default colormap is set to “flame”. The hold option keeps the window open, so that your script will not exit and close your window a few milliseconds after opening it. A Qt application is created if need be, which avoids a common runtime error.

class reborn.external.pyqtgraph.ImView(*args, **kwargs)[source]

Bases: ImageView

A subclass of pyqtgraph.ImageView that adds helpful features when you need the image to be embedded in a plot axis. Lists of roi, plot, and line items are maintained. In addition to the usual positional and keyword arguments for the pyqtgraph.ImageView class, the following arguments are accepted:

Parameters:
  • gradient (str) – Set the colormap (‘thermal’, ‘flame’, ‘yellowy’, ‘bipolar’, ‘spectrum’, ‘cyclic’, ‘greyclip’, ‘grey’, ‘viridis’, ‘inferno’, ‘plasma’, ‘magma’)

  • show_histogram (bool) – Set to False if you don’t want the usual histogram to appear on the right.

  • aspect_locked (bool) – Set to False if you don’t want the aspect ratio of the plot/image to be fixed to 1.

  • title (str) – Plot title.

  • ss_label (str) – X (horizontal) axis label.

  • fs_label (str) – Y (vertical) axis label.

  • fs_lims (tuple of float) – The min and max values of pixel coordinates along fast-scan axis.

  • ss_lims (tuple of float) – The min and max values of pixel coordinates along slow-scan axis.

plots = []
lines = []
rois = []
setImage(*args, **kwargs)[source]

Override setImage so that the image is positioned properly on the plot. The default puts the corner of the first pixel at the position (0, 0) by default, which makes no sense; the center of the pixel should be located at (0, 0) for all the obvious reasons.

In addition to the usual positional and keyword arguments, the following keyword arguments are accepted:

Parameters:
  • fs_lims (list) – The minimum and maximum values of the pixel coordinates along the fast-scan direction.

  • ss_lims (list) – The minimum and maximum values of the pixel coordinates along the slow-scan direction.

add_plot(*args, **kwargs)[source]

TODO: Document.

add_line(*args, position=None, vertical=False, horizontal=False, **kwargs)[source]

Adds pyqtgraph.InfiniteLine. Accepts the InfiniteLine arguments: pos=None, angle=90, pen=None, movable=False, bounds=None, hoverPen=None, label=None, labelOpts=None, span=(0, 1), markers=None, name=None

Adds the following arguments:

horizontal (bool): Make the line horizontal (angle=) vertical (bool): Make the line vertical (angle=) position (str): Same as pos argument for InfiniteLine

add_roi(*args, **kwargs)[source]

TODO: Document.

get_roi(name=None)[source]
get_roi_slice(name=None)[source]
get_plot(name=None)[source]
get_line(name=None)[source]
set_mask(mask, color=None)[source]
class reborn.external.pyqtgraph.ImageWindow(*args, **kargs)[source]

Bases: ImageView

(deprecated; use ImageView instead)

Note

This is a direct copy of the equivalent (undocumented?) class in pyqtgraph, except that it adds the view argument so that you can easily put your image in a plot axis.

By default, this class creates an ImageItem to display image data and a ViewBox to contain the ImageItem.

Parameters:
  • parent (QWidget) – Specifies the parent widget to which this ImageView will belong. If None, then the ImageView is created with no parent.

  • name (str) – The name used to register both the internal ViewBox and the PlotItem used to display ROI data. See the name argument to ViewBox.__init__().

  • view (ViewBox or PlotItem) –

    If specified, this will be used as the display area that contains the displayed image. Any ViewBox, PlotItem, or other compatible object is acceptable. Note: to display axis ticks inside the ImageView, instantiate it with a PlotItem instance as its view:

    pg.ImageView(view=pg.PlotItem())
    

  • imageItem (ImageItem) – If specified, this object will be used to display the image. Must be an instance of ImageItem or other compatible object.

  • levelMode (str) – See the levelMode argument to HistogramLUTItem.__init__()

  • discreteTimeLine (bool) – Whether to snap to xvals / frame numbers when interacting with the timeline position.

  • roi (ROI) – If specified, this object is used as ROI for the plot feature. Must be an instance of ROI.

  • normRoi (ROI) – If specified, this object is used as ROI for the normalization feature. Must be an instance of ROI.

class reborn.external.pyqtgraph.MultiHistogramLUTWidget(parent=None, *args, **kargs)[source]

Bases: GraphicsView

This is the equivalent of pyqtgraph.HistogramLUTWidget, but wraps MultiHistogramLUTWidget instead of pyqtgraph.HistogramLUTItem.

Arguments:

parent

Optional parent widget

useOpenGL

If True, the GraphicsView will use OpenGL to do all of its rendering. This can improve performance on some systems, but may also introduce bugs (the combination of QGraphicsView and QOpenGLWidget is still an ‘experimental’ feature of Qt)

background

Set the background color of the GraphicsView. Accepts any single argument accepted by mkColor. By default, the background color is determined using the ‘backgroundColor’ configuration option (see setConfigOptions).

sizeHint()[source]

Undocumented pyqtgraph method.

class reborn.external.pyqtgraph.MultiHistogramLUTItem(*args, **kwargs)[source]

Bases: HistogramLUTItem

This is a reborn extension to the pyqtgraph.HistogramLUTItem that allows control over multiple images. The main feature is the addition of the setImageItems method.

This is a pyqtgraph.graphicsWidget which provides controls for adjusting the display of an image.

Includes:

  • Image histogram

  • Movable region over histogram to select black/white levels

  • Gradient editor to define color lookup table for single-channel images

Parameters:
  • image (ImageItem or None) – If image is provided, then the control will be automatically linked to the image and changes to the control will be immediately reflected in the image’s appearance.

  • fillHistogram (bool) – By default, the histogram is rendered with a fill. For performance, set fillHistogram = False.

  • rgbHistogram (bool) – Sets whether the histogram is computed once over all channels of the image, or once per channel.

  • levelMode ('mono' or 'rgba') – If ‘mono’, then only a single set of black/whilte level lines is drawn, and the levels apply to all channels in the image. If ‘rgba’, then one set of levels is drawn for each channel.

Undocumented pyqtgraph method.

setImageItems(imgs)[source]

Set a list of pyqtgraph.ImageItem instances that will have their levels and LUT automatically controlled by this HistogramLUTItem.

gradientChanged()[source]

Undocumented pyqtgraph method.

regionChanged()[source]

Undocumented pyqtgraph method.

regionChanging()[source]

Undocumented pyqtgraph method.

setLevelMode(mode)[source]

Set the method of controlling the image levels offered to the user. Options are ‘mono’ or ‘rgba’.

class reborn.external.pyqtgraph.ImageItemPlus(*args, **kwargs)[source]

Bases: ImageItem

See setOpts for further keyword arguments and and setImage for information on supported formats.

Parameters:

image (np.ndarray, optional) – Image data

render()[source]
reborn.external.pyqtgraph.downsample(data, n, axis=0, xvals='subsample', func=None)[source]

Downsample by averaging points together across axis. If multiple axes are specified, runs once per axis. If a metaArray is given, then the axis values can be either subsampled or downsampled to match.

Module contents