Table of Contents
- Package pyimgalgos
- Module pyimgalgos.AngularIntegrator
- Function pyimgalgos.AngularIntegrator.divideArraysSafely
- Function pyimgalgos.AngularIntegrator.drawGraph
- Function pyimgalgos.AngularIntegrator.drawImage
- Function pyimgalgos.AngularIntegrator.mainTest
- Function pyimgalgos.AngularIntegrator.MakeImage
- Function pyimgalgos.AngularIntegrator.valueToIndexProtected
- Module pyimgalgos.centroid_smoother
- Module pyimgalgos.cm_epix
- Module pyimgalgos.cspad_arr_producer
- Module pyimgalgos.cspad_gainmap
- Module pyimgalgos.EventViewer
- Module pyimgalgos.ex_peaks_nda
- Module pyimgalgos.FastArrayTransformation
- Function pyimgalgos.FastArrayTransformation.applyRadialNormalizationToPolarArray
- Function pyimgalgos.FastArrayTransformation.cart2polar
- Function pyimgalgos.FastArrayTransformation.coordinateToIndex
- Function pyimgalgos.FastArrayTransformation.coordinateToIndexOpenEnd
- Function pyimgalgos.FastArrayTransformation.coordinateToIndexProtected
- Function pyimgalgos.FastArrayTransformation.draw2DImage
- Function pyimgalgos.FastArrayTransformation.drawHistogram
- Function pyimgalgos.FastArrayTransformation.drawImage
- Function pyimgalgos.FastArrayTransformation.drawImageAndSpectrum
- Function pyimgalgos.FastArrayTransformation.drawOrShow
- Function pyimgalgos.FastArrayTransformation.gaussian
- Function pyimgalgos.FastArrayTransformation.getCartesianArray1Ring
- Function pyimgalgos.FastArrayTransformation.getCartesianArray3Rings
- Function pyimgalgos.FastArrayTransformation.getGainCorrectionArrayFromAverage
- Function pyimgalgos.FastArrayTransformation.mainTest1Ring
- Function pyimgalgos.FastArrayTransformation.mainTest3Rings
- Function pyimgalgos.FastArrayTransformation.polar2cart
- Function pyimgalgos.FastArrayTransformation.printArrForTest
- Function pyimgalgos.FastArrayTransformation.printMeanAndStandardDeviation
- Function pyimgalgos.FastArrayTransformation.rebinArray
- Function pyimgalgos.FastArrayTransformation.transformCartToPolarArray
- Module pyimgalgos.FiberAngles
- Function pyimgalgos.FiberAngles.calc_beta
- Function pyimgalgos.FiberAngles.calc_phi
- Function pyimgalgos.FiberAngles.fraser
- Function pyimgalgos.FiberAngles.fraser_xyz
- Function pyimgalgos.FiberAngles.funcy
- Function pyimgalgos.FiberAngles.funcy2
- Function pyimgalgos.FiberAngles.funcy_l0
- Function pyimgalgos.FiberAngles.funcy_l1_v0
- Function pyimgalgos.FiberAngles.funcy_l1_v1
- Function pyimgalgos.FiberAngles.funcy_v0
- Function pyimgalgos.FiberAngles.qh_to_xy
- Function pyimgalgos.FiberAngles.recipnorm
- Function pyimgalgos.FiberAngles.rotation
- Function pyimgalgos.FiberAngles.rotation_cs
- Function pyimgalgos.FiberAngles.rotation_phi_beta
- Function pyimgalgos.FiberAngles.test_fraser
- Function pyimgalgos.FiberAngles.test_plot_beta
- Function pyimgalgos.FiberAngles.test_plot_beta_l0
- Function pyimgalgos.FiberAngles.test_plot_beta_l1
- Function pyimgalgos.FiberAngles.test_plot_beta_l1_zoom
- Function pyimgalgos.FiberAngles.test_plot_phi
- Module pyimgalgos.FiberIndexing
- Function pyimgalgos.FiberIndexing.fill_row
- Function pyimgalgos.FiberIndexing.lattice
- Function pyimgalgos.FiberIndexing.lattice_node_radius
- Function pyimgalgos.FiberIndexing.make_index_table
- Function pyimgalgos.FiberIndexing.make_lookup_table
- Function pyimgalgos.FiberIndexing.make_lookup_table_v2
- Function pyimgalgos.FiberIndexing.plot_lattice
- Function pyimgalgos.FiberIndexing.print_nda
- Function pyimgalgos.FiberIndexing.print_omega_dr
- Function pyimgalgos.FiberIndexing.radial_distance
- Function pyimgalgos.FiberIndexing.reciprocal_from_bravias
- Function pyimgalgos.FiberIndexing.rotation
- Function pyimgalgos.FiberIndexing.rotation_cs
- Function pyimgalgos.FiberIndexing.round_vzeros
- Function pyimgalgos.FiberIndexing.str_omega_drhkl
- Function pyimgalgos.FiberIndexing.test_lattice
- Function pyimgalgos.FiberIndexing.triclinic_primitive_vectors
- Function pyimgalgos.FiberIndexing.wavelength_nm_from_energy_ev
- Function pyimgalgos.FiberIndexing.wave_vector_value
- Module pyimgalgos.GlobalGraphics
- Function pyimgalgos.GlobalGraphics.drawCenter
- Function pyimgalgos.GlobalGraphics.drawCircle
- Function pyimgalgos.GlobalGraphics.drawLine
- Function pyimgalgos.GlobalGraphics.drawRectangle
- Function pyimgalgos.GlobalGraphics.fig_axes
- Function pyimgalgos.GlobalGraphics.fig_axim_axcb_imsh
- Function pyimgalgos.GlobalGraphics.getArrangedImage
- Function pyimgalgos.GlobalGraphics.getImageAs2DHist
- Function pyimgalgos.GlobalGraphics.getImageFromIndexArrays
- Function pyimgalgos.GlobalGraphics.getRandomImage
- Function pyimgalgos.GlobalGraphics.hist1d
- Function pyimgalgos.GlobalGraphics.main
- Function pyimgalgos.GlobalGraphics.move
- Function pyimgalgos.GlobalGraphics.move_fig
- Function pyimgalgos.GlobalGraphics.plotGraph
- Function pyimgalgos.GlobalGraphics.plotHistogram
- Function pyimgalgos.GlobalGraphics.plotImage
- Function pyimgalgos.GlobalGraphics.plotImageAndSpectrum
- Function pyimgalgos.GlobalGraphics.plotImageLarge
- Function pyimgalgos.GlobalGraphics.plot_img
- Function pyimgalgos.GlobalGraphics.plot_imgcb
- Function pyimgalgos.GlobalGraphics.plot_peaks_on_img
- Function pyimgalgos.GlobalGraphics.plotSpectrum
- Function pyimgalgos.GlobalGraphics.save
- Function pyimgalgos.GlobalGraphics.savefig
- Function pyimgalgos.GlobalGraphics.save_fig
- Function pyimgalgos.GlobalGraphics.show
- Function pyimgalgos.GlobalGraphics.size_of_shape
- Module pyimgalgos.GlobalUtils
- Function pyimgalgos.GlobalUtils.convertCheetahEventName
- Function pyimgalgos.GlobalUtils.create_directory
- Function pyimgalgos.GlobalUtils.cspad_ndarr_from_table
- Function pyimgalgos.GlobalUtils.cspad_ndarr_from_table8x8
- Function pyimgalgos.GlobalUtils.divide_protected
- Function pyimgalgos.GlobalUtils.list_of_windarr
- Function pyimgalgos.GlobalUtils.locxymax
- Function pyimgalgos.GlobalUtils.main
- Function pyimgalgos.GlobalUtils.mask_2darr_edges
- Function pyimgalgos.GlobalUtils.mask_3darr_edges
- Function pyimgalgos.GlobalUtils.mask_from_windows
- Function pyimgalgos.GlobalUtils.mean_of_listwarr
- Function pyimgalgos.GlobalUtils.print_ndarr
- Function pyimgalgos.GlobalUtils.reshape_to_2d
- Function pyimgalgos.GlobalUtils.reshape_to_3d
- Function pyimgalgos.GlobalUtils.save_image_file
- Function pyimgalgos.GlobalUtils.save_image_tiff
- Function pyimgalgos.GlobalUtils.shape_as_2d
- Function pyimgalgos.GlobalUtils.shape_as_3d
- Function pyimgalgos.GlobalUtils.size_from_shape
- Function pyimgalgos.GlobalUtils.src_from_rc8x8
- Function pyimgalgos.GlobalUtils.str_tstamp
- Function pyimgalgos.GlobalUtils.subtract_bkgd
- Function pyimgalgos.GlobalUtils.table8x8_from_cspad_ndarr
- Function pyimgalgos.GlobalUtils.table_from_cspad_ndarr
- Function pyimgalgos.GlobalUtils.test_01
- Function pyimgalgos.GlobalUtils.test_02
- Function pyimgalgos.GlobalUtils.test_03
- Function pyimgalgos.GlobalUtils.test_04
- Function pyimgalgos.GlobalUtils.test_05
- Function pyimgalgos.GlobalUtils.test_06
- Function pyimgalgos.GlobalUtils.test_07
- Function pyimgalgos.GlobalUtils.test_08
- Function pyimgalgos.GlobalUtils.test_09
- Function pyimgalgos.GlobalUtils.test_10
- Function pyimgalgos.GlobalUtils.test_11
- Function pyimgalgos.GlobalUtils.usage
- Module pyimgalgos.Graphics
- Function pyimgalgos.Graphics.add_axes
- Function pyimgalgos.Graphics.add_title_labels_to_axes
- Function pyimgalgos.Graphics.colorbar
- Function pyimgalgos.Graphics.draw
- Function pyimgalgos.Graphics.draw_fig
- Function pyimgalgos.Graphics.figure
- Function pyimgalgos.Graphics.hist
- Function pyimgalgos.Graphics.imshow
- Function pyimgalgos.Graphics.imshow_cbar
- Function pyimgalgos.Graphics.move
- Function pyimgalgos.Graphics.move_fig
- Function pyimgalgos.Graphics.save_fig
- Function pyimgalgos.Graphics.save_plt
- Function pyimgalgos.Graphics.set_win_title
- Function pyimgalgos.Graphics.show
- Function pyimgalgos.Graphics.test01
- Function pyimgalgos.Graphics.test02
- Function pyimgalgos.Graphics.test03
- Function pyimgalgos.Graphics.test04
- Function pyimgalgos.Graphics.test_all
- Function pyimgalgos.Graphics.test_selected
- Module pyimgalgos.HBins
- Module pyimgalgos.HPolar
- Function pyimgalgos.HPolar.bincount
- Function pyimgalgos.HPolar.cart2polar
- Function pyimgalgos.HPolar.data_geo
- Function pyimgalgos.HPolar.divide_protected
- Function pyimgalgos.HPolar.polar2cart
- Function pyimgalgos.HPolar.polarization_factor
- Function pyimgalgos.HPolar.test01
- Function pyimgalgos.HPolar.test02
- Function pyimgalgos.HPolar.test03
- Module pyimgalgos.HSpectrum
- Module pyimgalgos.image_crop
- Module pyimgalgos.image_save_in_file
- Module pyimgalgos.MedianFilter
- Function pyimgalgos.MedianFilter.example01
- Function pyimgalgos.MedianFilter.example02
- Function pyimgalgos.MedianFilter.example03
- Function pyimgalgos.MedianFilter.footprint_ring
- Function pyimgalgos.MedianFilter.main
- Function pyimgalgos.MedianFilter.median_filter_ndarr
- Function pyimgalgos.MedianFilter.random_standard_ndarr
- Function pyimgalgos.MedianFilter.reshape_nda_to_3d
- Function pyimgalgos.MedianFilter.slope_2darr
- Function pyimgalgos.MedianFilter.usage
- Module pyimgalgos.NDArrGenerators
- Function pyimgalgos.NDArrGenerators.add_random_peaks
- Function pyimgalgos.NDArrGenerators.add_ring
- Function pyimgalgos.NDArrGenerators.aranged_array
- Function pyimgalgos.NDArrGenerators.print_ndarr
- Function pyimgalgos.NDArrGenerators.prod_of_elements
- Function pyimgalgos.NDArrGenerators.random_1
- Function pyimgalgos.NDArrGenerators.random_256
- Function pyimgalgos.NDArrGenerators.random_exponential
- Function pyimgalgos.NDArrGenerators.random_one
- Function pyimgalgos.NDArrGenerators.random_standard
- Function pyimgalgos.NDArrGenerators.random_xffffffff
- Function pyimgalgos.NDArrGenerators.reshape_to_2d
- Function pyimgalgos.NDArrGenerators.reshape_to_3d
- Function pyimgalgos.NDArrGenerators.ring_intensity
- Function pyimgalgos.NDArrGenerators.shape_as_2d
- Function pyimgalgos.NDArrGenerators.shape_as_3d
- Function pyimgalgos.NDArrGenerators.size_from_shape
- Module pyimgalgos.NDArrSpectrum
- Module pyimgalgos.NDArrSpectrumV0
- Function pyimgalgos.NDArrSpectrumV0.arr_bin_indexes
- Function pyimgalgos.NDArrSpectrumV0.arr_varbin_indexes
- Function pyimgalgos.NDArrSpectrumV0.example_equidistant
- Function pyimgalgos.NDArrSpectrumV0.example_varsize
- Function pyimgalgos.NDArrSpectrumV0.main
- Function pyimgalgos.NDArrSpectrumV0.random_standard_array
- Function pyimgalgos.NDArrSpectrumV0.usage
- Module pyimgalgos.NDArrSpectrumV1
- Module pyimgalgos.PeakData
- Module pyimgalgos.PeakStore
- Module pyimgalgos.RadialBkgd
- Module pyimgalgos.RadialBkgdV0
- Function pyimgalgos.RadialBkgdV0.bincount
- Function pyimgalgos.RadialBkgdV0.cart2polar
- Function pyimgalgos.RadialBkgdV0.data_geo
- Function pyimgalgos.RadialBkgdV0.divide_protected
- Function pyimgalgos.RadialBkgdV0.polar2cart
- Function pyimgalgos.RadialBkgdV0.polarization_factor
- Function pyimgalgos.RadialBkgdV0.test01
- Function pyimgalgos.RadialBkgdV0.test02
- Function pyimgalgos.RadialBkgdV0.test03
- Module pyimgalgos.SvnProps
- Module pyimgalgos.tahometer
- Module pyimgalgos.TDCheetahPeakRecord
- Module pyimgalgos.TDFileContainer
- Module pyimgalgos.TDGroup
- Module pyimgalgos.TDMatchRecord
- Module pyimgalgos.TDNodeRecord
- Module pyimgalgos.TDPeakRecord
- Module pyimgalgos.TestImageGenerator
- Function pyimgalgos.TestImageGenerator.cspad2x1_arr
- Function pyimgalgos.TestImageGenerator.cspad_nparr
- Function pyimgalgos.TestImageGenerator.gaussian
- Function pyimgalgos.TestImageGenerator.main
- Function pyimgalgos.TestImageGenerator.monotonicly_rising
- Function pyimgalgos.TestImageGenerator.peaks_on_ring
- Function pyimgalgos.TestImageGenerator.random_exponential
- Function pyimgalgos.TestImageGenerator.random_normal
- Function pyimgalgos.TestImageGenerator.rings_sinc
- Function pyimgalgos.TestImageGenerator.ring_xy_random
- Module pyimgalgos.AngularIntegrator
Package pyimgalgos¶
Module pyimgalgos.AngularIntegrator¶
AngularIntegrator
- Evaluate radial histogram for angle-integrated 2-d image
Usage:
# IMPORT
from pypsalg.AngularIntegrator import AngularIntegratorM
# Define test parameters
import numpy as np
img = np.ones((1200,1300), dtype=np.float32) # generate test image as numpy array of ones of size (rows,cols) = (1200,1300)
mask = np.ones_like(img) # generate test mask for all good pixels
rows, cols = img.shape # define shape parameters rows, cols - number of image rows, columns, respectively
rmin, rmax, nbins =100, 400, 50 # define radial histogram parameters - radial limits and number of equidistant bins
# Initialization of object and its parameters
ai = AngularIntegratorM()
ai.setParameters(rows, cols, xc=cols/2, yc=rows/2, rmin=rmin, rmax=rmax, nbins=nbins, mask=mask, phimin=-180, phimax=180)
# do angular integration for each input image and return array of bin centers and associated normalized intensities
bins, intensity = ai.getRadialHistogramArrays(img)
# test plot example
import matplotlib.pyplot as plt
plt.figure(figsize=(10,5), dpi=80, facecolor='w', edgecolor='w', frameon=True)
plt.hist(bins, bins=nbins, weights=intensity, color='b')
plt.show()
See also: pypsalg.AngularIntegratorM
This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.
Version: $Id: AngularIntegrator.py 10848 2015-10-14 16:14:43Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Function pyimgalgos.AngularIntegrator.valueToIndexProtected¶
-
pyimgalgos.AngularIntegrator.
valueToIndexProtected
(V, VRange)[source]¶ Returns array of indexes from array of values @param[in] V - numpy array of values, @param[in] VRange - Vmin, Vmax, contains the binning parameters Vmin, Vmax, and Nbins Output: Array of indexes from 0 to Nbins (Nbins+1 index) with shape of V. The last index Nbins is used for overflow and underflow.
Module pyimgalgos.centroid_smoother¶
Class pyimgalgos.centroid_smoother.CentroidSmoother¶
-
class
pyimgalgos.centroid_smoother.
CentroidSmoother
(ds, det, rNum)[source]¶ With the datasource, detector and run number, this object will fetch the relevant data as saved by the CentroidSmootherCalib object and read it in.
- Parameters: ds - datasource as obtained via psana.DataSource()
- det - detector used as obtained via psana.Detector() rNum - run number of data
-
getSmoothedCentroids
(offsets)[source]¶ - Parameters: An array of floats the rows and columns of peak centroids
- in the shape (x, 2) for x peaks.
- Output: An array of floats of the rows and columns of the smoothed
- centroids in the same shape as the input.
Given an array of centroids, this function smooths and returns them.
Class pyimgalgos.centroid_smoother.CentroidSmootherCalib¶
-
class
pyimgalgos.centroid_smoother.
CentroidSmootherCalib
(nBins=100)[source]¶ A calibration object that needs only to run once. Data and constants will be saved to be used by the CentroidSmoother object.
- Parameters: nBins - (Optional) The number of bins for the histogramming
- of the absolute distance from the center of the pixel for each centroid
-
add
(centroids)[source]¶ - Parameters: An array of floats of the rows and columns of peak
- centroids in the shape (x, 2) for x peaks.
Computes, for each centroid, the absolute distance from the center of the pixel that the centroid is in. The values range from 0 to 0.5.
-
save
(ds, det, rNumBegin, rNumEnd=None)[source]¶ - Parameters: ds - datasource as obtained via psana.DataSource()
det - detector used as obtained via psana.Detector() rNumBegin - run number that the saved data begins with rNumEnd - (Optional) run number that the saved data
ends with
From the given parameters, saves the data that has been added by add() along with the bins which are computed from the value for nBins.
Module pyimgalgos.cm_epix¶
Function pyimgalgos.cm_epix.cm_epix¶
-
pyimgalgos.cm_epix.
cm_epix
(img, rms, maxCorr=30, histoRange=30, colrow=3, minFrac=0.25, normAll=False)[source]¶ Parameters: img - image on which the common mode is applied rms - array of noise values for each pixel with same shape as img maxCorr - (optional) maximum correction applied. If common mode
correction is larger than this value, no correction will be appliedhistoRange - (optional) all pixels above this parameter are masked colrow - (optional) decides what is corrected. If 1, only the columns
are corrected. If 2, only the rows are corrected. And if 3, both are corrected- minFrac - (optional) the minimum fraction of pixels required to be
- left in a row or column after applying the mask and rejecting high pixels and their neighbors
- normAll - (optional) if true, will subtract the mean from the full
- image with the masked applied
Module pyimgalgos.cspad_arr_producer¶
User analysis module for pyana framework.
This software was developed for the LCLS project. If you use all or part of it, please give an appropriate acknowledgment.
Version: $Id: cspad_arr_producer.py 12470 2016-08-11 21:23:21Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Class pyimgalgos.cspad_arr_producer.cspad_arr_producer¶
-
class
pyimgalgos.cspad_arr_producer.
cspad_arr_producer
[source]¶ Produces from CSPAD data numpy array of shape=(4, 8, 185, 388) or (185, 388, 2) and specified data type.
Class constructor. Parameters are passed from pyana.cfg configuration file. All parameters are passed as strings
- source - string, address of Detector-Id|Device-ID
- dtype_type - string, output array data type
- key_out - string, unique keyword for output array identification
- val_miss - float, intensity value substituted for missing in data 2x1s
- print_bits - int, bit-word for verbosity control
-
beginjob
(evt, env)[source]¶ This method is called once at the beginning of the job. It should do a one-time initialization possible extracting values from event data (which is a Configure object) or environment.
- evt - event data object
- env - environment object
-
beginrun
(evt, env)[source]¶ This optional method is called if present at the beginning of the new run.
- evt - event data object
- env - environment object
-
event
(evt, env)[source]¶ This method is called for every L1Accept transition.
- evt - event data object
- env - environment object
-
dic_dtypes
= {'int32': <type 'numpy.int32'>, 'int16': <type 'numpy.int16'>, 'int': <type 'int'>, 'float': <type 'float'>, 'uint8': <type 'numpy.uint8'>, 'uint': <type 'numpy.uint64'>, 'int8': <type 'numpy.int8'>, 'double': <type 'numpy.float64'>, 'uint16': <type 'numpy.uint16'>, 'uint32': <type 'numpy.uint32'>, 'float32': <type 'numpy.float32'>}¶
Module pyimgalgos.cspad_gainmap¶
User analysis module
This software was developed for the LCLS project. If you use all or part of it, please give an appropriate acknowledgment.
Version: $Id: cspad_gainmap.py 8453 2014-06-20 22:38:14Z cpo@SLAC.STANFORD.EDU $
Author: Christopher O’Grady
Module pyimgalgos.EventViewer¶
Module pyimgalgos.ex_peaks_nda¶
User analysis module for pyana and psana frameworks.
This software was developed for the LCLS project. If you use all or part of it, please give an appropriate acknowledgment.
Version: $Id: ex_peaks_nda.py 8469 2014-06-24 22:55:21Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Class pyimgalgos.ex_peaks_nda.ex_peaks_nda¶
-
class
pyimgalgos.ex_peaks_nda.
ex_peaks_nda
[source]¶ Example module: gets peaks_nda produced by ImgAlgos.CSPadArrPeakFinder and prints its content
Class constructor. Parameters are passed from pyana.cfg configuration file. All parameters are passed as strings
@param source string, address of DetInfo(:Cspad.) @param key_in string, keyword for input image 2-d array @param print_bits int, bit-word for verbosity control
Module pyimgalgos.FastArrayTransformation¶
A set of methods for the fast array transformation based on NumPy and SciPy
This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.
@see
Version: $Id: FastArrayTransformation.py 8453 2014-06-20 22:38:14Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Module pyimgalgos.FiberAngles¶
A set of methods to evaluate angles in fiber diffraction experiments.
- Usage::
# Import from pyimgalgos.FiberAngles import fraser, calc_phi, calc_beta, funcy
# Fraser transformation: s12rot, s3rot, reciparr = fraser(arr, beta_deg, L, center=None, oshape=(1500,1500))
# Evaluation of fiber tilt angles beta phi (in the image plane) (in transverse to image plane). phi = calc_phi (x1, y1, x2, y2, dist) beta = calc_beta(x1, y1, phi, dist)
#Fit functions yarr = funcy(xarr, phi_deg, bet_deg)
yarr = funcy_l1_v0(xarr, phi_deg, bet_deg, DoR=0.4765, sgnrt=-1.) (depric.) yarr = funcy_l1_v1(xarr, phi_deg, bet_deg, DoR=0.4765, sgnrt=-1.)
yarr2 = funcy2(xarr, a, b, c)
# Conversion methods qx, qy, qz = recipnorm(x, y, z) # returns q/fabs(k) components for 3-d point along k^prime.
# Commands to test in the release directory: # python ./pyimgalgos/src/FiberAngles.py <test-id> # where # <test-id> = 1 - test of the Fraser transformation # <test-id> = 2 - test of the phi angle # <test-id> = 3 - test of the beta angle
This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.
Version: $Id: FiberAngles.py 11999 2016-06-01 21:16:06Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Function pyimgalgos.FiberAngles.calc_beta¶
-
pyimgalgos.FiberAngles.
calc_beta
(xpix, ypix, phi, dist)[source]¶ Evaluates fiber beta angle [rad] for two peaks in equatorial region - xpix - [in] x coordinate of the point - ypix - [in] y coordinate of the point - phi - [in] fiber tilt angle [rad] if the detector plane - dist - [in] distance from sample to detector
Function pyimgalgos.FiberAngles.calc_phi¶
-
pyimgalgos.FiberAngles.
calc_phi
(x1pix, y1pix, x2pix, y2pix, dist)[source]¶ Evaluates fiber phi angle [rad] for two peaks in equatorial region - x1pix - [in] x coordinate of the 1st point - y1pix - [in] y coordinate of the 1st point - x1pix - [in] x coordinate of the 2nd point - y1pix - [in] y coordinate of the 2nd point - dist - [in] distance from sample to detector
Function pyimgalgos.FiberAngles.fraser¶
-
pyimgalgos.FiberAngles.
fraser
(arr, beta_deg, L, center=None, oshape=(1500, 1500))[source]¶ Do fraser correction for an array at angle beta and distance L, given in number of pixels (109.92um), angle is in degrees. Example: fraser(array,10,909); (10 degrees at 100mm distance)
ASSUMPTION: 1. by default 2-d arr image center corresponds to (x,y) origin - arr - [in] 2-d image array - beta_deg - [in] angle beta in degrees - L - [in] distance from sample to detector given in units of pixels (110um) - center - [in] center (row,column) location on image, which will be used as (x,y) origin - oshape - [in] ouitput image shape
Function pyimgalgos.FiberAngles.fraser_xyz¶
-
pyimgalgos.FiberAngles.
fraser_xyz
(x, y, z, beta_deg, k=1.0)[source]¶ Do fraser transformation for of 3-d points given by x,y,z arrays for angle beta around x and returns horizontal and vertical components of the scattering vector in units of k (eV or 1/A). x,y-arrays representing image point coordinates, z-can be scalar - distance from sample to detector. x, y, and z should be in the same units; ex.: number of pixels (109.92um) or [um], angle is in degrees. Example: fraser_xy(x,y,909,10); (10 degrees at 909 pixel (100mm) distance)
ASSUMPTION: - x,y,z - [in] point coordinate arrays with originn in IP - beta_deg - [in] angle beta in degrees - k - [in] scale factor, ex.: wave number in units of (eV or 1/A).
Function pyimgalgos.FiberAngles.funcy_l1_v0¶
-
pyimgalgos.FiberAngles.
funcy_l1_v0
(x, phi_deg, bet_deg, DoR=0.474, sgnrt=-1.0)[source]¶ DEPRICATED: D/L - is not a constant as it should be Function for parameterization of y(x, phi, beta). v0: EQUATION FOR D/L=... of peaks in l=1 plane for fiber diffraction DoR = d/R ratio, where d is a distance between l=0 and l=1 on image, DoR = 433/913.27 - default constant R is sample to detector distance ATTENTION!: curve_fit assumes that x and returned y are numpy arrays.
Function pyimgalgos.FiberAngles.funcy_l1_v1¶
-
pyimgalgos.FiberAngles.
funcy_l1_v1
(x, phi_deg, bet_deg, DoR=0.4292, sgnrt=1.0)[source]¶ v0: EQUATION FOR D/R. Function for parameterization of y(x, phi, beta) of peaks in l=1 plane for fiber diffraction DoR = d/R ratio, where d is a distance between l=0 and l=1 on image, DoR = 392/913.27 - default R is sample to detector distance ATTENTION!: curve_fit assumes that x and returned y are numpy arrays.
Function pyimgalgos.FiberAngles.qh_to_xy¶
-
pyimgalgos.FiberAngles.
qh_to_xy
(qh, R)[source]¶ Returns reciprocal (xe,ye) coordinates of the qh projection on Evald sphere. qh - (numpy array) horizontal component of q values (1/A) R - (float scalar) Evald sphere radius (1/A) Assuming that center of the Evald sphere is in (-R,0); qh is oriented along y. NOTE: qh, L, sina, cosa, xe, ye - are the numpy arrays of the same shape as qh
Function pyimgalgos.FiberAngles.recipnorm¶
-
pyimgalgos.FiberAngles.
recipnorm
(x, y, z)[source]¶ Returns normalizd reciprocal space coordinates (qx,qy,qz) of the scattering vector q = (k^prime- k)/abs(k), and assuming that - scattering point is a 3-d space origin, also center of the Ewalds sphere - k points from 3-d space origin to the point with coordinates x, y, z (pixel coordinates relative to IP) - scattering is elastic, no energy lost or gained, abs(k^prime)=abs(k) - reciprocal space origin is in the intersection point of axes z and Ewald’s sphere.
Module pyimgalgos.FiberIndexing¶
Created on Oct 7, 2015
@author: Mikhail
Function pyimgalgos.FiberIndexing.fill_row¶
-
pyimgalgos.FiberIndexing.
fill_row
(dr, qv, qh, h, k, l, sigma_ql, sigma_qt, bpq)[source]¶ Returns histogram array (row) for horizontal q component filled by probability to see the peak, modulated by the Gaussian function of dr, where dr is a radial distance between the lattice node and Evald’s sphere.
Function pyimgalgos.FiberIndexing.make_lookup_table¶
-
pyimgalgos.FiberIndexing.
make_lookup_table
(b1=(1.0, 0.0, 0.0), b2=(0.0, 1.0, 0.0), b3=(0.0, 0.0, 1.0), hmax=3, kmax=2, lmax=1, cdtype=<type 'numpy.float32'>, evald_rad=3, sigma_q=0.001, fout=None, bpq=None, bpomega=None, bpbeta=None)[source]¶ Depricated, see make_lookup_table_v2 with sigma_ql, sigma_qt in stead of sigma_q
Function pyimgalgos.FiberIndexing.make_lookup_table_v2¶
-
pyimgalgos.FiberIndexing.
make_lookup_table_v2
(b1=(1.0, 0.0, 0.0), b2=(0.0, 1.0, 0.0), b3=(0.0, 0.0, 1.0), hmax=3, kmax=2, lmax=1, cdtype=<type 'numpy.float32'>, evald_rad=3, sigma_ql=0.001, sigma_qt=0.001, fout=None, bpq=None, bpomega=None, bpbeta=None)[source]¶ Makes lookup table - crystal lattice nodes information as a function of angle beta and omega, where beta [deg] - fiber axis tilt, omega [deg] - fiber rotation around axis, For each crysal orientation (beta, gamma) lookup table contains info about lattice nodes closest to the Evald’s sphere:
# beta 20.00 omega 178.50 degree # index beta omega h k l dr [1/A] R(h,k,l) qv [1/A] qh [1/A] P(omega) 1078 20.00 178.50 1 -5 0 0.000262 0.211944 -0.016779 0.211221 0.964192 1078 20.00 178.50 0 -1 0 0.002470 0.038484 0.000343 0.038306 0.038686 1078 20.00 178.50 0 1 0 0.000582 0.038484 -0.000344 -0.038455 0.834544
where: index - orientation index (just an unique integer number) beta, omega [deg] - crystal orientation angles, h, k, l - Miller indeces dr [1/A] - distance between lattice node and Evald’s sphere R(h,k,l) [1/A] - distance between nodes (h,k,l) and (0,0,0) qv, qh [1/A] - vertical and horizontal components of scattering vector q P(omega) - un-normalized probability (<1) evaluated for dr(omega) using sigma_ql.
File name is generated automatically with current time stamp like lut-cxif5315-r0169-2015-10-23T14:58:36.txt
Input parameters: b1, b2, b3 - reciprocal lattice primitive vectors, hmax, kmax, lmax - lattice node indeces cdtype - data type for lattice node coordinates, evald_rad - Evald’s sphere radius, sigma_ql - expected q resolution along k (due to crystal rotation), sigma_qt - expected qt resolution (in detector plane), fout - open output file object, bpq, bpomega, bpbeta - binning parameters for q, omega, and beta NOTE: Units of b1, b2, b3, evald_rad, and sigma_q should be the same, for example [1/A].
Returns 2-d numpy array for image; summed for all beta probobility(omega vs. q_horizontal).
Function pyimgalgos.FiberIndexing.plot_lattice¶
-
pyimgalgos.FiberIndexing.
plot_lattice
(b1=(1.0, 0.0, 0.0), b2=(0.0, 1.0, 0.0), b3=(0.0, 0.0, 1.0), hmax=3, kmax=2, lmax=1, cdtype=<type 'numpy.float32'>, evald_rad=0.5, qtol=0.01, prefix='', do_movie=False, delay=400)[source]¶ Plots 2-d reciprocal space lattice, evald sphere, generates series of plots for rotated lattice and movie from these plots.
- do_movie = True/False - on/off production of movie
- delay - is a time in msec between movie frames.
Function pyimgalgos.FiberIndexing.radial_distance¶
-
pyimgalgos.FiberIndexing.
radial_distance
(X, Y, Z, evald_rad=0.5)[source]¶ For all defined nodes of the lattice returns dr - distance from evald sphere to the reciprocal lattice node, qv, qh - vertical, horizontal components of the momentum transfer vector. NOTE: X, Y, Z, DX, L, dr, qv, qh, ql are the numpy arrays with shape=(2*hmax+1, 2*kmax+1, 2*lmax+1), evald_rad is a scalar
Function pyimgalgos.FiberIndexing.triclinic_primitive_vectors¶
-
pyimgalgos.FiberIndexing.
triclinic_primitive_vectors
(a=18.36, b=26.65, c=4.81, alpha=90, beta=90, gamma=102.83)[source]¶ Returns 3-d (Bravias) primitive vectors directed along crystal axes (edges) from lattice cell edge lengths [Angstrom or other prefered units] and angles [degree] for triclinic crystal cell parametes:
*----------* / \ / \ / \ / \ / \ gamma \ / *----------* / / / / /alpha / / / *-------/--* c \ / \ beta/ a / \ / \ / \ / *-----b----*
where a, b, c - crystal cell edge lengths, alpha, beta, gamma - interaxial angles around a, b, c edges, respectively’ By design, a1 vector for edge a is directed along x, a2 vector for edge b is in x-y plane, has (x,y,0) components only, a3 vector for edge c has (x,y,z) components.
Module pyimgalgos.GlobalGraphics¶
Collection of global graphical methods.
This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.
Version: $Id: GlobalGraphics.py 12839 2016-11-07 01:27:55Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Function pyimgalgos.GlobalGraphics.fig_axim_axcb_imsh¶
-
pyimgalgos.GlobalGraphics.
fig_axim_axcb_imsh
(figsize=(13, 12), title='Image', dpi=80, win_axim=(0.05, 0.03, 0.87, 0.93), win_axcb=(0.923, 0.03, 0.02, 0.93), arr2d=array([[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]]), origin='upper')[source]¶ Creates and returns figure, axes for image and color bar, imshow object
Function pyimgalgos.GlobalGraphics.hist1d¶
-
pyimgalgos.GlobalGraphics.
hist1d
(arr, bins=None, amp_range=None, weights=None, color=None, show_stat=True, log=False, figsize=(6, 5), axwin=(0.15, 0.12, 0.78, 0.8), title=None, xlabel=None, ylabel=None, titwin=None)[source]¶ Makes historgam from input array of values (arr), which are sorted in number of bins (bins) in the range (amp_range=(amin,amax))
Function pyimgalgos.GlobalGraphics.plot_peaks_on_img¶
-
pyimgalgos.GlobalGraphics.
plot_peaks_on_img
(peaks, axim, iX, iY, color='w', pbits=0, lw=2)[source]¶ Draws peaks on the top of image axes (axim) Plots peaks from array as circles in coordinates of image.
@param peaks - 2-d list/tuple of peaks; first 6 values in each peak record should be (s, r, c, amax, atot, npix) @param axim - image axes @param iX - array of x-coordinate indexes for all pixels addressed as [s, r, c] - segment, row, column @param iX - array of y-coordinate indexes for all pixels addressed as [s, r, c] - segment, row, column @param color - peak-ring color @param pbits - verbosity; print 0 - nothing, +1 - peak parameters, +2 - x, y peak coordinate indexes
Module pyimgalgos.GlobalUtils¶
GlobalUtils.py contains collection of global utilities with a single call algorithms.
Usage:
# Import
# ==============
from pyimgalgos.GlobalUtils import subtract_bkgd, mask_from_windows #, ...
from pyimgalgos.NDArrGenerators import random_standard_array
# Background subtraction
# ======================
# Example for cspad, assuming all nda_*.shape = (32,185,388)
winds_bkgd = [ (s, 10, 100, 270, 370) for s in (4,12,20,28)] # use part of segments 4,12,20, and 28 to subtract bkgd
nda = subtract_bkgd(nda_data, nda_bkgd, mask=nda_mask, winds=winds_bkgd, pbits=0)
# Operations with numpy array shape
# =================================
shape = (32,185,388)
size = size_from_shape(shape) # returns 32*185*388
shape_2d = shape_as_2d(shape) # returns (32*185,388)
arr_2d = reshape_to_2d(nda) # returns re-shaped ndarray
shape = (4,8,185,388)
shape_3d = shape_as_3d(shape) # returns (32,185,388)
arr_3d = reshape_to_3d(nda) # returns re-shaped ndarray
# Make mask n-d numpy array using shape and windows
# =================================================
shape = (2,185,388)
w = 1
winds = [(s, w, 185-w, w, 388-w) for s in (0,1)]
mask = mask_from_windows(shape, winds)
# Make mask as 2,3-d numpy array for a few(width) rows/cols of pixels
# ===================================================================
mask2d = mask_2darr_edges(shape=(185,388), width=2)
mask3d = mask_3darr_edges(shape=(32,185,388), width=5)
# Make mask of local maximal intensity pixels in x-y (ignoring diagonals)
# ===================================================================
# works for 2-d and 3-d arrays only - reshape if needed.
data = random_standard_array(shape=(32,185,388), mu=0, sigma=10)
mask_xy_max = locxymax(data, order=1, mode='clip')
# Get string with time stamp, ex: 2016-01-26T10:40:53
# ===================================================================
ts = str_tstamp(fmt='%Y-%m-%dT%H:%M:%S', time_sec=None)
# Converters for Cheetah
# ======================
runnum, tstamp, tsec, fid = convertCheetahEventName('LCLS_2015_Feb22_r0169_022047_197f7', fmtts='%Y-%m-%dT%H:%M:%S')
table8x8 = table_from_cspad_ndarr(nda_cspad)
nda_cspad = cspad_ndarr_from_table(table8x8)
# Save math
# =========
res = divide_protected(num, den, vsub_zero=0)
# Single line printed for np.array
# ================================
print_ndarr(nda, name='', first=0, last=5)
# Save image in file
# ==================
image = random_standard()
save_image_tiff(image, fname='image.tiff', verb=True) # 16-bit tiff
save_image_file(image, fname='image.png', verb=True) # gif, pdf, eps, png, jpg, jpeg, tiff (8-bit only)
# Create directory
# ==================
create_directory('work-dir')
# Test
# ======================
# is implemented for test numbers from 1 to 9. Command example
# python pyimgalgos/src/GlobalUtils.py 1
See also: pyimgalgos.GlobalUtils
This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.
Version: $Id: GlobalUtils.py 11969 2016-05-21 01:30:48Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Function pyimgalgos.GlobalUtils.cspad_ndarr_from_table8x8¶
-
pyimgalgos.GlobalUtils.
cspad_ndarr_from_table8x8
(table8x8)¶ returns cspad array with shape=(32,185,388) generated from table of 2x1s shaped as (8*185, 4*388) in style of Cheetah
Function pyimgalgos.GlobalUtils.locxymax¶
-
pyimgalgos.GlobalUtils.
locxymax
(nda, order=1, mode='clip')[source]¶ For 2-d or 3-d numpy array finds mask of local maxima in x and y axes (diagonals are ignored) using scipy.signal.argrelmax and return their product.
@param nda - input ndarray @param order - range to search for local maxima along each dimension @param mode - parameter of scipy.signal.argrelmax of how to treat the boarder
Function pyimgalgos.GlobalUtils.mask_from_windows¶
-
pyimgalgos.GlobalUtils.
mask_from_windows
(ashape=(32, 185, 388), winds=None)[source]¶ Makes mask as 2-d or 3-d numpy array defined by the shape with ones in windows. N-d shape for N>3 is converted to 3-d. @param shape - shape of the output numpy array with mask. @param winds - list of windows, each window is a sequence of 5 parameters (segment, rowmin, rowmax, colmin, colmax)
Function pyimgalgos.GlobalUtils.subtract_bkgd¶
-
pyimgalgos.GlobalUtils.
subtract_bkgd
(data, bkgd, mask=None, winds=None, pbits=0)[source]¶ Subtracts numpy array of bkgd from data using normalization in windows for good pixels in mask. Shapes of data, bkgd, and mask numpy arrays should be the same. Each window is specified by 5 parameters: (segment, rowmin, rowmax, colmin, colmax) For 2-d arrays segment index is not used, but still 5 parameters needs to be specified. @param data - numpy array for data. @param bkgd - numpy array for background. @param mask - numpy array for mask. @param winds - list of windows, each window is a sequence of 5 parameters. @param pbits - print control bits; =0 - print nothing, !=0 - normalization factor.
Function pyimgalgos.GlobalUtils.table8x8_from_cspad_ndarr¶
-
pyimgalgos.GlobalUtils.
table8x8_from_cspad_ndarr
(nda_cspad)¶ returns table of 2x1s shaped as (8*185, 4*388) in style of Cheetah generated from cspad array with size=(32*185*388) ordered as in data, shape does not matter.
Module pyimgalgos.Graphics¶
Module pyimgalgos.HBins¶
HBins.py histogram-style bin parameters holder
Usage:
from pyimgalgos.HBins import HBins
# Equal bins constructor
hb = HBins((1,6), nbins=5)
# Variable bins constructor
hb = HBins((1,2,4,6,10))
# Access methods
nbins = hb.nbins() # returns int input parameter - number of bins
edges = hb.edges() # returns np.array input list of bin edges
vmin = hb.vmin() # returns vtype minimal value of bin edges
vmax = hb.vmax() # returns vtype maximal value of bin edges
vtype = hb.vtype() # returns np.dtype - type of bin edge values
equalbins = hb.equalbins() # returns bool True/False for equal/variable size bins
limits = hb.limits() # returns np.array of limits (vmin, vmax)
binedges = hb.binedges() # returns np.array with bin edges of size nbins+1
binedgesleft = hb.binedgesleft() # returns np.array with bin left edges of size nbins
binedgesright = hb.binedgesright() # returns np.array with bin rignt edges of size nbins
bincenters = hb.bincenters() # returns np.array with bin centers of size nbins
binwidth = hb.binwidth() # returns np.array with bin widths of size nbins or scalar bin width for equal bins
halfbinw = hb.halfbinw() # returns np.array with half-bin widths of size nbins or scalar bin half-width for equal bins
strrange = hb.strrange(fmt) # returns str of formatted vmin, vmax, nbins ex: 1-6-5
ind = hb.bin_index(value, edgemode=0) # returns bin index [0,nbins) for value.
indarr = hb.bin_indexes(valarr, edgemode=0) # returns array of bin index [0,nbins) for array of values
# edgemode - defines what to do with underflow overflow indexes;
# = 0 - use indexes 0 and nbins-1 for underflow overflow, respectively
# = 1 - use extended indexes -1 and nbins for underflow overflow, respectively
# Print methods
hb.print_attrs_defined()
hb.print_attrs()
hb.print_attrs_and_methods()
See also: pyimgalgos.HPolar
,
pyimgalgos.HSpectrum
,
pyimgalgos.NDArrSpectrum
,
pyimgalgos.RadialBkgd
,
Radial background.
This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.
Version: $Id: HBins.py 11999 2016-06-01 21:16:06Z dubrovin@SLAC.STANFORD.EDU $
Created on 2016-01-15
Author: Mikhail S. Dubrovin
Module pyimgalgos.HPolar¶
HPolar
- makes 2-d histogram in polar (r-phi) coordinates for imaging detector n-d array data
Usage:
# Import
# ------
from pyimgalgos.HPolar import HPolar
# Initialization
# --------------
hp = HPolar(xarr, yarr, mask=None, radedges=None, nradbins=100, phiedges=(0,360), nphibins=32)
# Access methods
# --------------
orb = hp.obj_radbins() # returns HBins object for radial bins
opb = hp.obj_phibins() # returns HBins object for angular bins
rad = hp.pixel_rad()
irad = hp.pixel_irad()
phi0 = hp.pixel_phi0()
phi = hp.pixel_phi()
iphi = hp.pixel_iphi()
iseq = hp.pixel_iseq()
npix = hp.bin_number_of_pixels()
int = hp.bin_intensity(nda)
arr1d = hp.bin_avrg(nda)
arr2d = hp.bin_avrg_rad_phi(nda, do_transp=True)
pixav = hp.pixel_avrg(nda)
pixav = hp.pixel_avrg_interpol(nda, method='linear') # method='nearest' 'cubic'
# Print attributes and n-d arrays
# -------------------------------
hp.print_attrs()
hp.print_ndarrs()
# Global methods
# --------------
from pyimgalgos.HPolar import polarization_factor, divide_protected, cart2polar, polar2cart, bincount
polf = polarization_factor(rad, phi, z)
result = divide_protected(num, den, vsub_zero=0)
r, theta = cart2polar(x, y)
x, y = polar2cart(r, theta)
bin_values = bincount(map_bins, map_weights=None, length=None)
See also: pyimgalgos.HBins
,
pyimgalgos.RadialBkgd
Radial background.
pyimgalgos.HSpectrum
(pyimgalgos.NDArrSpectrum
),
This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.
Revision: $Revision: 12490 $
Version: $Id: HPolar.py 12490 2016-08-16 17:26:28Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Module pyimgalgos.HSpectrum¶
HSpectrum
- support creation of spectral histogram for arbitrary shaped numpy array.
Usage:
# Import
# ==============
from pyimgalgos.HSpectrum import HSpectrum
# Initialization
# ==============
# 1) for bins of equal size:
range = (vmin, vmax)
nbins = 100
spec = HSpectrum(range, nbins)
# 2) for variable size bins:
bins = (v0, v1, v2, v4, v5, vN) # any number of bin edges
spec = HSpectrum(bins)
# Fill spectrum
# ==============
# nda = ... (get it for each event somehow)
spec.fill(nda)
# Get spectrum
# ==============
histarr, edges, nbins = spec.spectrum()
# Optional
# ==============
spec.print_attrs()
See also: pyimgalgos.HBins
,
pyimgalgos.HPolar
This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.
Revision: $Revision: 11999 $
Version: $Id: HSpectrum.py 11999 2016-06-01 21:16:06Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Module pyimgalgos.image_crop¶
User analysis module for pyana and psana frameworks.
This software was developed for the LCLS project. If you use all or part of it, please give an appropriate acknowledgment.
Version: $Id: image_crop.py 8453 2014-06-20 22:38:14Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Class pyimgalgos.image_crop.image_crop¶
-
class
pyimgalgos.image_crop.
image_crop
[source]¶ Get image from the evt store crop it and put it back in the evt store
Class constructor. Parameters are passed from pyana.cfg configuration file. All parameters are passed as strings
@param source string, address of Detector.Id:Device.ID @param key_in string, keyword for input image 2-d array @param key_out string, unique keyword for output image array @param rowmin int, row minimal to crop image (dafault = 0 - for full size) @param rowmax int, row maximal to crop image (dafault = -1 - for full size) @param colmin int, column minimal to crop image (dafault = 0 - for full size) @param colmax int, column maximal to crop image (dafault = -1 - for full size) @param print_bits int, bit-word for verbosity control
Module pyimgalgos.image_save_in_file¶
User analysis module
This software was developed for the LCLS project. If you use all or part of it, please give an appropriate acknowledgment.
Version: $Id: image_save_in_file.py 11271 2016-01-30 00:02:41Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Class pyimgalgos.image_save_in_file.image_save_in_file¶
-
class
pyimgalgos.image_save_in_file.
image_save_in_file
[source]¶ Saves image array in file with specified in the name type.
Class constructor. Parameters are passed from pyana.cfg configuration file.
- source - string, address of Detector.Id:Device.ID
- key_in - string, keyword for input image array of variable shape
- ofname - string, output file name (type is selected by extention) supported formats: txt, tiff, gif, pdf, eps, png, jpg, jpeg, npy (default), npz
- mode - int, 0-save one event per event, >0-length of the ring buffer (or round robin) for event browser
- delay_sec - int, additional sleep time in sec between events for event browser
- print_bits - int, bit-word for verbosity control
Module pyimgalgos.MedianFilter¶
pyimgalgos.MedianFilter.py - contains method median_filter_ndarr and associated code for self test.
Usage:
# Import
# ======
from pyimgalgos.MedianFilter import median_filter_ndarr
#nda = ... should be defined somehow, for example nda = det.calib(evt)
rank=3
nda_med = median_filter_ndarr(nda, rank)
This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.
Command to test python pyimgalgos/src/MedianFilter.py 3
Also see for details: http://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.ndimage.filters.median_filter.html#scipy.ndimage.filters.median_filter
Revision: $Revision: 12470 $
Version: $Id: MedianFilter.py 12470 2016-08-11 21:23:21Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Function pyimgalgos.MedianFilter.median_filter_ndarr¶
-
pyimgalgos.MedianFilter.
median_filter_ndarr
(nda_in, rank=3)[source]¶ returns 2-d or 3-d array with number of merged photons per pixel.
Parameters - nda_in : numpy.array - n-dimensional numpy array - rank : int - radial parameter, pixels within radius less or equal rank will be used to evaluate the median.
use scipy.ndimage.filters.median_filter(input, size=None, footprint=None, output=None, mode=’reflect’, cval=0.0, origin=0) http://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.ndimage.filters.median_filter.html#scipy.ndimage.filters.median_filter
Module pyimgalgos.NDArrGenerators¶
Created on Nov 23, 2015
@author: Mikhail
Function pyimgalgos.NDArrGenerators.add_ring¶
-
pyimgalgos.NDArrGenerators.
add_ring
(arr2d, amp=100, row=4.3, col=5.8, rad=100, sigma=3)[source]¶ Adds peak Gaussian-shaped peak intensity to numpy array arr2d Parameters ———- arr2d : np.array - 2-d numpy array amp : float - ring intensity row : float - ring center row col : float - ring center col rad : float - ring mean radius sigma : float - width of the peak
Function pyimgalgos.NDArrGenerators.random_1¶
-
pyimgalgos.NDArrGenerators.
random_1
(shape=(40, 60), dtype=<type 'float'>)¶ Returns numpy array of requested shape and type filled with random numbers in the range [0,255].
Function pyimgalgos.NDArrGenerators.ring_intensity¶
-
pyimgalgos.NDArrGenerators.
ring_intensity
(r, r0, sigma)[source]¶ returns numpy array with ring intensity distribution modulated by Gaussian(r-r0,sigma). Parameters ———- r : np.array - numpy array of radius (i.e. radios for each pixel) r0 : float - radius of the ring sigma : float - width of the ring
Module pyimgalgos.NDArrSpectrum¶
NDArrSpectrum
- ALIAS FOR HSpectrum - support creation of spectral histogram for arbitrary shaped numpy array.
Usage:
# Import
# ==============
from pyimgalgos.NDArrSpectrum import NDArrSpectrum
# Initialization
# ==============
# 1) for bins of equal size:
range = (vmin, vmax)
nbins = 100
spec = NDArrSpectrum(range, nbins)
# 2) for variable size bins:
bins = (v0, v1, v2, v4, v5, vN) # any number of bin edges
spec = NDArrSpectrum(bins)
# Fill spectrum
# ==============
# nda = ... (get it for each event somehow)
spec.fill(nda)
# Get spectrum
# ==============
histarr, edges, nbins = spec.spectrum()
# Optional
# ==============
spec.print_attrs()
See also: pyimgalgos.HSpectrum
,
pyimgalgos.HBins
pyimgalgos.HPolar
This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.
Revision: $Revision: 11999 $
Version: $Id: NDArrSpectrum.py 11999 2016-06-01 21:16:06Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Module pyimgalgos.NDArrSpectrumV0¶
NDArrSpectrum
- support creation of spectral histogram for arbitrary shaped numpy array.
Usage:
# Import
# ==============
from pyimgalgos.NDArrSpectrum import NDArrSpectrum
# Initialization
# ==============
# 1) for bins of equal size:
range = (vmin, vmax)
nbins = 100
spec = NDArrSpectrum(range, nbins)
# 2) for variable size bins:
bins = (v0, v1, v2, ..., v<n-1>, n<n>)
spec = NDArrSpectrum(bins)
# Fill spectrum
# ==============
nda = ... (get it for each event somehow)
spec.fill(nda)
# Get spectrum
# ==============
histarr, edges, nbins = spec.spectrum()
# Optional
# ==============
spec.print_attrs()
See also: pyimgalgos.NDArrSpectrum
This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.
Revision: $Revision: 11959 $
Version: $Id: NDArrSpectrumV0.py 11959 2016-05-19 23:45:39Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Module pyimgalgos.NDArrSpectrumV1¶
NDArrSpectrum
- support creation of spectral histogram for arbitrary shaped numpy array.
Usage:
# Import
# ==============
from pyimgalgos.NDArrSpectrum import NDArrSpectrum
# Initialization
# ==============
# 1) for bins of equal size:
range = (vmin, vmax)
nbins = 100
spec = NDArrSpectrum(range, nbins)
# 2) for variable size bins:
bins = (v0, v1, v2, v4, v5, vN) # any number of bin edges
spec = NDArrSpectrum(bins)
# Fill spectrum
# ==============
# nda = ... (get it for each event somehow)
spec.fill(nda)
# Get spectrum
# ==============
histarr, edges, nbins = spec.spectrum()
# Optional
# ==============
spec.print_attrs()
See also: pyimgalgos.HBins
,
pyimgalgos.HPolar
This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.
Revision: $Revision: 11999 $
Version: $Id: NDArrSpectrumV1.py 11999 2016-06-01 21:16:06Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Module pyimgalgos.PeakStore¶
Class helps to save text file with information about peaks found in peak-finders.
Usage:
# Imports
from pyimgalgos.PeakStore import PeakStore
# Usage with psana types env and evt
pstore = PeakStore(env, 5, prefix='xxx', add_header='TitV1 TitV2 TitV3 ...', pbits=255)
for peak in peaks :
rec = '%s %d %f ...' % (peak[0], peak[5], peak[7],...)
pstore.save_peak(evt, rec)
pstore.close() # is done by default in destructor
# Usage without psana types
pstore = PeakStore('expNNNNN', 5, prefix='xxx', add_header='TitV1 TitV2 TitV3 ...', pbits=255)
for peak in peaks :
rec = '%s %d %f ...' % (peak[0], peak[5], peak[7],...)
pstore.save_peak(peak_rec=rec)
# Print methods
pstore.print_attrs()
This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.
Version: $Id: PeakStore.py 10975 2015-11-14 01:29:46Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Module pyimgalgos.RadialBkgd¶
RadialBkgd
- radial background subtraction for imaging detector n-d array data,- extension of the base class
HPolar
for methods subtract_bkgd and subtract_bkgd_interpol.
Usage:
# Import
# ------
from pyimgalgos.RadialBkgd import RadialBkgd
# Initialization
# --------------
rb = RadialBkgd(xarr, yarr, mask=None, radedges=None, nradbins=100, phiedges=(0,360), nphibins=32)
# Access methods
# --------------
orb = rb.obj_radbins() # returns HBins object for radial bins
opb = rb.obj_phibins() # returns HBins object for angular bins
rad = rb.pixel_rad()
irad = rb.pixel_irad()
phi0 = rb.pixel_phi0()
phi = rb.pixel_phi()
iphi = rb.pixel_iphi()
iseq = rb.pixel_iseq()
npix = rb.bin_number_of_pixels()
int = rb.bin_intensity(nda)
arr1d = rb.bin_avrg(nda)
arr2d = rb.bin_avrg_rad_phi(nda, do_transp=True)
pixav = rb.pixel_avrg(nda)
pixav = rb.pixel_avrg_interpol(nda, method='linear') # method='nearest' 'cubic'
cdata = rb.subtract_bkgd(nda)
cdata = rb.subtract_bkgd_interpol(nda, method='linear')
# Print attributes and n-d arrays
# -------------------------------
rb.print_attrs()
rb.print_ndarrs()
# Global methods
# --------------
from pyimgalgos.RadialBkgd import polarization_factor, divide_protected, cart2polar, polar2cart, bincount
polf = polarization_factor(rad, phi, z)
result = divide_protected(num, den, vsub_zero=0)
r, theta = cart2polar(x, y)
x, y = polar2cart(r, theta)
bin_values = bincount(map_bins, map_weights=None, length=None)
See also: pyimgalgos.HPolar
pyimgalgos.HBins
See Radial background.
pyimgalgos.HSpectrum
This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.
Revision: $Revision: 12490 $
Version: $Id: RadialBkgd.py 12490 2016-08-16 17:26:28Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Module pyimgalgos.RadialBkgdV0¶
RadialBkgd
- radial background subtraction for imaging detector n-d array data
Usage:
# Import
# ------
from pyimgalgos.RadialBkgd import RadialBkgd
# Initialization
# --------------
rb = RadialBkgd(xarr, yarr, mask=None, radedges=None, nradbins=100, phiedges=(0,360), nphibins=32)
# Access methods
# --------------
orb = rb.obj_radbins() # returns HBins object for radial bins
opb = rb.obj_phibins() # returns HBins object for angular bins
rad = rb.pixel_rad()
irad = rb.pixel_irad()
phi0 = rb.pixel_phi0()
phi = rb.pixel_phi()
iphi = rb.pixel_iphi()
iseq = rb.pixel_iseq()
npix = rb.npixels_per_bin()
int = rb.intensity_per_bin(nda)
arr = rb.average_per_bin(nda)
arr = rb.average_rad_phi(nda, do_transp=True)
bkgd = rb.bkgd_nda(nda)
bkgd = rb.bkgd_nda_interpol(nda, method='linear') # method='nearest' 'cubic'
cdata = rb.subtract_bkgd(nda)
cdata = rb.subtract_bkgd_interpol(nda, method='linear')
# Print attributes and n-d arrays
# -------------------------------
rb.print_attrs()
rb.print_ndarrs()
# Global methods
# --------------
from pyimgalgos.RadialBkgd import polarization_factor
polf = polarization_factor(rad, phi, z)
result = divide_protected(num, den, vsub_zero=0)
r, theta = cart2polar(x, y)
x, y = polar2cart(r, theta)
bin_values = bincount(map_bins, map_weights=None, length=None)
See also: pyimgalgos.RadialBkgd
See Radial background.
This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.
Revision: $Revision: 11999 $
Version: $Id: RadialBkgdV0.py 11999 2016-06-01 21:16:06Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Module pyimgalgos.SvnProps¶
Class SvnProps stores updated by svn properties.
NOTE: To update revision number in this file when revision changes, use command: psvn mktxtprop src/SvnProps.py or svn propset svn:keywords “Revision” src/SvnProps.py Also see: ~/.subversion/config
This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.
Version: $Id: SvnProps.py 8453 2014-06-20 22:38:14Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhai S. Dubrovin
Module pyimgalgos.tahometer¶
User analysis module
This software was developed for the LCLS project. If you use all or part of it, please give an appropriate acknowledgment.
Version: $Id: tahometer.py 8453 2014-06-20 22:38:14Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Class pyimgalgos.tahometer.tahometer¶
-
class
pyimgalgos.tahometer.
tahometer
[source]¶ Saves image array in file with specified in the name type.
Class constructor. Parameters are passed from pyana.cfg configuration file.
@param dn int, interval in number of events to print current statistics @param print_bits int, bit-word for verbosity control
Module pyimgalgos.TDCheetahPeakRecord¶
Class helps to retreive and use peak data in processing
Usage:
# Imports
from pyimgalgos.TDCheetahPeakRecord import TDCheetahPeakRecord
# Usage
# make object
rec = TDCheetahPeakRecord(line)
# access peak attributes
rec.line
rec.fields
rec.frameNumber
rec.runnum
rec.tstamp
rec.fid
rec.photonEnergyEv
rec.wavelengthA
rec.GMD
rec.peak_index
rec.peak_x_raw
rec.peak_y_raw
rec.peak_r_assembled
rec.peak_q
rec.peak_resA
rec.nPixels
rec.totalIntensity
rec.maxIntensity
rec.sigmaBG
rec.SNR
rec.tsec
# print attributes
rec.print_peak_data()
rec.print_peak_data_short()
rec.print_attrs()
This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.
Version: $Id: TDCheetahPeakRecord.py 11634 2016-04-05 18:47:50Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Module pyimgalgos.TDFileContainer¶
TDFileContainer - text/table data file container - load/hold/provide access to data from text file.
It is assumed that text data file contains records of the same format and occasionally record-header beginning with character # (hash in [0] position). Example of the file content:
# Exp Run Date Time time(sec) time(nsec) fiduc Evnum Reg Seg Row Col ...
cxif5315 169 2015-02-22 02:20:47 1424600447 486382070 104421 0 EQU 17 153 48 ...
cxif5315 169 2015-02-22 02:20:47 1424600447 494719789 104424 1 EQU 1 161 32 ...
cxif5315 169 2015-02-22 02:20:47 1424600447 494719789 104424 1 EQU 17 170 51 ...
cxif5315 169 2015-02-22 02:20:47 1424600447 503058551 104427 2 EQU 25 170 310 ...
cxif5315 169 2015-02-22 02:20:47 1424600447 503058551 104427 2 EQU 25 180 292 ...
cxif5315 169 2015-02-22 02:20:47 1424600447 511393301 104430 3 EQU 1 162 27 ...
cxif5315 169 2015-02-22 02:20:47 1424600447 536405573 104439 6 ARC 8 11 41 ...
cxif5315 169 2015-02-22 02:20:47 1424600447 536405573 104439 6 ARC 8 10 20 ...
...
Header (without #) should have the same as data number of literal fields separated by spaces. Records in the file should be grupped by unique group-id parameter, for example a group of records may have the same group number or some unique index.
Originaly it is designed to work with text file containing record data generated by peak-finder. It is adopted to work with any other object type beside peak data.
Usage:
# !!! NOTE: None is returned whenever requested information is missing.
# Import
from pyimgalgos.TDFileContainer import TDFileContainer
from pyimgalgos.TDPeakRecord import TDPeakRecord # use it by default in TDFileContainer
from pyimgalgos.TDNodeRecord import TDNodeRecord
from pyimgalgos.TDCheetahPeakRecord import TDCheetahPeakRecord
# Initialization
# for peakfinder records
fname = '/reg/neh/home1/dubrovin/LCLS/rel-mengning/work/pfv2-cxif5315-r0169-2015-09-14T14:28:04.txt'
fc = TDFileContainer(fname, indhdr='Evnum', objtype=TDPeakRecord, pbits=0)
# for index table:
fc = TDFileContainer(fname, indhdr='index', objtype=TDNodeRecord)
# for Cheetah file with peaks:
fc = TDFileContainer(fname, indhdr='frameNumber', objtype=TDCheetahPeakRecord)
gr_nums = fc.group_numbers()
ngrps = fc.number_of_groups()
grnum = fc.current_group_number()
gr_curr = fc.group(grpnum) # returns current or specified group
gr_next = fc.next() # returns next group
gr_prev = fc.previous() # returns previous group
hdr = fc.header()
# Print
fc.print_attrs()
fc.print_content(nlines=None) # prints nline (or all by default) lines from file conteiner
# ____________________________________
# Example of iterations over groups
for grnum in fc.group_num_iterator() :
group = fc.next()
group.print_attrs()
peaks = group.get_objs()
for pk in peaks :
pk.print_short()
# Information available through the TDPeakRecord object pk
# ________________________________________________________
# pk.exp, pk.run, pk.evnum, pk.reg
# pk.date, pk.time, pk.tsec, pk.tnsec, pk.fid
# pk.seg, pk.row, pk.col, pk.amax, pk.atot, pk.npix
# pk.rcent, pk.ccent, pk.rsigma, pk.csigma
# pk.rmin, pk.rmax, pk.cmin, pk.cmax
# pk.bkgd, pk.rms, pk.son
# pk.imrow, pk.imcol
# pk.x, pk.y, pk.r, pk.phi
# pk.sonc
# pk.dphi000
# pk.dphi180
# pk.line
# Example of direct access to group by its number
grpnum = 8 # but grpnum is not necessaraly conecutive number, it should be in fc.group_num_iterator() ...
group = fc.group(grpnum) # returns current or specified group
group.print_attrs()
This software was developed for the LCLS project. If you use all or part of it, please give an appropriate acknowledgment.
See also: classes
pyimgalgos.TDFileContainer
- file records container.
pyimgalgos.TDGroup
- holds a list of records associated with a single group.
pyimgalgos.TDPeakRecord
- provides access to the peak record.
pyimgalgos.TDNodeRecord
- provides access to the look-up table with crystal orientation record.
pyimgalgos.TDCheetahPeakRecord
- provides access to the Cheetah peak record.
Version: $Id: TDFileContainer.py 11634 2016-04-05 18:47:50Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Module pyimgalgos.TDGroup¶
TDGroup - text data event information holder/accessor class.
Works together with TDFileContainer and TDPeakRecord classes.
This software was developed for the LCLS project. If you use all or part of it, please give an appropriate acknowledgment.
See also: TDFileContainer - loads/holds text data from class and provides per-event-indexed access. See also: TDPeakRecord - holds a list of records associated with a single event.
Version: $Id: TDGroup.py 11634 2016-04-05 18:47:50Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Module pyimgalgos.TDMatchRecord¶
Class helps to retreive and use peak data in processing
Usage:
# import
from pyimgalgos.TDMatchRecord import TDMatchRecord
# make object
rec = TDMatchRecord(line)
# access record attributes
index, beta, omega, h, k, l, dr, R, qv, qh, P = rec.index, rec.beta, rec.omega, rec.h, rec.k, rec.l, rec.dr, rec.R, rec.qv, rec.qh, rec.P
line = rec.line
# print attributes
rec.print_short()
This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.
Version: $Id: TDMatchRecord.py 11902 2016-05-13 22:37:49Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Module pyimgalgos.TDNodeRecord¶
Class helps to retreive and use peak data in processing
Usage:
# Import
from pyimgalgos.TDNodeRecord import TDNodeRecord
# make object
rec = TDNodeRecord(line)
# access record attributes
index, beta, omega, h, k, l, dr, R, qv, qh, P = rec.index, rec.beta, rec.omega, rec.h, rec.k, rec.l, rec.dr, rec.R, rec.qv, rec.qh, rec.P
line = rec.line
# print attributes
rec.print_short()
This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.
Version: $Id: TDNodeRecord.py 11902 2016-05-13 22:37:49Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Module pyimgalgos.TDPeakRecord¶
Class helps to retreive and use peak data in processing
Usage:
# Imports
from pyimgalgos.TDPeakRecord import TDPeakRecord
# Usage
# make object
pk = TDPeakRecord(line)
# access peak attributes
exp = pk.exp # (str) experiment name
run = pk.run # (int) run number
son = pk.son # (float) S/N for pixel with maximal intensity
sonc = pk.sonc # (float) S/N for all pixels included in the peak
line = pk.line # (str) entire record with peak data
...
# Information available through the TDPeakRecord object pk
# ____________________________________________________
# pk.exp, pk.run, pk.evnum, pk.reg
# pk.date, pk.time, pk.tsec, pk.tnsec, pk.fid
# pk.seg, pk.row, pk.col, pk.amax, pk.atot, pk.npix
# pk.rcent, pk.ccent, pk.rsigma, pk.csigma
# pk.rmin, pk.rmax, pk.cmin, pk.cmax
# pk.bkgd, pk.rms, pk.son
# pk.imrow, pk.imcol
# pk.x, pk.y, pk.r, pk.phi
# pk.sonc
# pk.dphi000
# pk.dphi180
# pk.line
# get evaluated parameters
# pk.peak_signal()
# pk.peak_noise()
# pk.peak_son()
# for peak records with fit information:
# pk.fit_phi, pk.fit_beta
# pk.fit_phi_err, pk.fit_beta_err
# pk.fit_chi2, pk.fit_ndof, pk.fit_prob
# print attributes
pk.print_peak_data()
pk.print_peak_data_short()
pk.print_attrs()
This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.
Version: $Id: TDPeakRecord.py 11902 2016-05-13 22:37:49Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin
Module pyimgalgos.TestImageGenerator¶
TestImageGenerator - a set of methods to generate test images as numpy arrays
This software was developed for the SIT project. If you use all or part of it, please give an appropriate acknowledgment.
Version: $Id: TestImageGenerator.py 8800 2014-08-19 06:12:58Z dubrovin@SLAC.STANFORD.EDU $
Author: Mikhail S. Dubrovin