Skip to content

SRW tools for image processing from beamlines

License

Notifications You must be signed in to change notification settings

NSLS-II-CHX/srw-image-tools

Repository files navigation

srw-image-tools

Retrieve data from CHX (NSLSII Hard X-ray beamline) BlueSky servers and edit images from the eiger detector.

Title: srw-image-tools
Author: Rebecca Coles
Updated on Aug 20, 2019

This notebook can be used on the CHX Jupyter Hub: https://notebook.nsls2.bnl.gov

Table of Contents

  1. Required Python Packages
  2. Functions
    1. save_hdf5
    2. plot_profile_horiz
    3. plot_profile_vert
    4. display_image_in_actual_size
    5. display_cropped_image
    6. plot_eiger_for_srw
  3. Example Output
    1. get_meta_data
    2. plot_eiger_for_srw

Required Python Packages

Required Python Packages:

External CHX package:

Functions

save_hdf5

Access BlueSky HDF5 binary data from CHX measurement.

def save_hdf5(data, filename='data.h5', dataset='dataset')

param data: HDF5 binary data from CHX measurement.
param filename='data.h5': HDF5 filename. Default is contained in the header file.
param dataset='dataset': Creates dataset type. Default is dataset.

return: string status of dataset creation.

plot_profile_horiz

Show plot of intensity versus horizontal position.

def plot_profile_horiz(data, uid, y_crd=1200, dpi=80, clim=(0, 200), cmap='afmhot', line_color='deepskyblue', linestyles=None)

param data: HDF5 binary data from CHX measurement.
param uid: unique ID automatically assigned to a CHX measurement.
param y_crd=1200: add a horizontal line across the axis at a given location on the image.
param dpi=80: dpi (dots per inch) for output image.
param clim=(0, 200): sets the color limits of the current image.
param cmap='afmhot': color map (https://matplotlib.org/examples/color/colormaps_reference.html)
param line_color='red': color of line that will show the cut location.

plot_profile_vert

Show plot of intensity versus vertical position.

def plot_profile_vert(data, uid, x_crd=1100, dpi=80, clim=(0, 200), cmap='afmhot', line_color='deepskyblue', linestyles=None)

param data: HDF5 binary data from CHX measurement.
param uid: unique ID automatically assigned to a CHX measurement.
param x_crd=1100: add a vertical line across the axis at a given location on the image.
param dpi=80: dpi (dots per inch) for output image.
param clim=(0, 200): sets the color limits of the current image.
param cmap='afmhot': color map (https://matplotlib.org/examples/color/colormaps_reference.html)
param line_color='red': color of line that will show the cut location.
param linestyles=None: custom linestyles.

display_image_in_actual_size

Display CHX Eiger image in full size and save the image as a TIFF with dual pixel and mm axis.

def display_image_in_actual_size(img, uid, dpi=80, eiger_size_per_pixel=0.075, clim=(0, 100), cmap='gist_stern')

param im: eiger detector image.
param uid: unique ID automatically assigned to a CHX measurement.
param dpi=80: dpi (dots per inch) for output image.
param eiger_size_per_pixel=0.075: eiger camera has 75 um per pixel.
param cmap='gist_stern': color map (https://matplotlib.org/examples/color/colormaps_reference.html)
param clim: sets the color limits of the current image.

display_cropped_image

Display CHX eiger image cropped to user specifications and save the image as a TIFF with dual pixel and mm axis.

def display_cropped_image(img, uid, x1=900, x2=1650, y1=750, y2=1400, dpi=80, eiger_size_per_pixel=0.075, clim=(0, 100), cmap='gist_stern')

param im: eiger detector image.
param uid: unique ID automatically assigned to a CHX measurement.
param x1=900: x-axis stating location (columns).
param x2=1650: x-axis final location (columns).
param y1=750: y-axis stating location (rows).
param y2: y-axis final location (rows).
param dpi=80: dpi (dots per inch) for output image.
param eiger_size_per_pixel=0.075: eiger camera has 75 um per pixel.
param cmap='gist_stern': color map (https://matplotlib.org/examples/color/colormaps_reference.html)
param clim: sets the color limits of the current image.

plot_eiger_for_srw

Display CHX eiger image: fullsize, cropped to user specifications, and with horizontal and vertical cuts, and save the plots and images as a TIFFs.

def plot_eiger_for_srw(uid, det='eiger4m_single_image', cmap='afmhot', clim=(0, 100), mean=False, frame_num=0, grid=False)

param uid: unique ID automatically assigned to a CHX measurement.
param det='eiger4m_single_image': which eiger dector.
param cmap='gist_stern': color map (https://matplotlib.org/examples/color/colormaps_reference.html)
param clim=(0, 200): sets the color limits of the current image.
param mean=False: mean of combined images along axis 0.
param frame_num=0: which image to use.
param grid=False: grid on the image.

Example Output

get_meta_data

Using the get_meta_data from the CHX package:

get_meta_data('1b9ff7',verbose=True)

where 1b9ff7 is the UID for the CHX measurement, gives the output:

 {'suid': '1b9ff7',
 'filename': '/XF11ID/data/2017/10/24/98e7508f-61f3-4c03-909a_4806_master.h5',
 'detector': 'eiger4m_single_image',
 'beam_center_x': 1098.0,
 'beam_center_y': 1225.0,
 'wavelength': 1.2846771478652954,
 'det_distance': 10.038560260000002,
 'cam_acquire_time': 60.0,
 'cam_acquire_period': 60.0000114440918,
 'cam_num_images': 1,
 'threshold_energy': 4825.5,
 'photon_energy': 9651.0,
 'detectors': ['eiger4m_single'],
 'num': 1,
 'time': 1508886690.4590404,
 'uid': '1b9ff785-e508-4438-875c-6d04123bd9b3',
 'scan_id': 8289,
 'hints': {'dimensions': [[['time'], 'primary']]},
 'run': '2017-3',
 'user': 'Chubar',
 'scatterer': 'R5',
 'Measurement': 'R5 - 60s exposure, MBS:0.05x0.4',
 'beamline_id': 'CHX',
 'MBS': '0.05x0.4',
 'plan_type': 'generator',
 'num_intervals': 0,
 'plan_name': 'count',
 'num_points': 1,
 'sample': 'Litho 4 - Julien',
 'owner': 'xf11id',
 'start_time': '2017-10-24 19:11:30',
 'stop_time': '2017-10-24 19:12:32',
 'img_shape': [2167, 2070],
 'verbose': True}

plot_eiger_for_srw

Using the plot_eiger_for_srw definition:

def plot_eiger_for_srw(uid, det='eiger4m_single_image', cmap='afmhot', clim=(0, 100), mean=False, frame_num=0, grid=False)

where if, for example, 1b9ff7 is the UID for the CHX measurement, gives the output:

{'eiger4m_single_stats4_total', 'eiger4m_single_stats2_total', 'eiger4m_single_image', 'eiger4m_single_stats3_total', 'eiger4m_single_stats1_total', 'eiger4m_single_stats5_total'}
(1, 1, 2167, 2070)
min: 0, max: 4294967295
<Figure size 432x288 with 0 Axes>



Horizontal cut at row 1200


Vertical cut at column 1100


[<Frames>
 Length: 1 frames
 Frame Shape: 2167 x 2070
 Pixel Datatype: uint32]

About

SRW tools for image processing from beamlines

Resources

Stars

Watchers

Forks