crystalpy.util package

Submodules

crystalpy.util.CalculationStrategy module

Numeric strategy for calculation. The exp, sin and cos functions are calculated using numpy, numpy with truncation of the arguments, or arbitrary precision using mpmath.

class crystalpy.util.CalculationStrategy.CalculationStrategy[source]

Bases: object

Abstract strategy for calculation. Can be plain python or arbitrary precision like mpmath.

cos(power)[source]

Cos to the power.

Parameters:

power – The power to raise to.

Raises:

Exception – Must override this method.

createVariable(initial_value)[source]

Factory method for calculation variable.

Parameters:

initial_value – Initial value of the variable.

Raises:

Exception – Must override this method.

exponentiate(power)[source]

Exponentiates to the power.

Parameters:

power – The power to raise to.

Raises:

Exception – Must override this method.

sin(power)[source]

Sin to the power.

Parameters:

power – The power to raise to.

Raises:

Exception – Must override this method.

toComplex(variable)[source]

Converts calculation variable to native python complex.

Parameters:

variable – Calculation variable to convert.

Raises:

Exception – Must override this method.

class crystalpy.util.CalculationStrategy.CalculationStrategyMPMath[source]

Bases: CalculationStrategy

Use mpmath for calculation.

cos(power)[source]

Cos function.

Parameters:

power (float or numpy array) – The arg of cos.

Returns:

Cos.

Return type:

mpmath variable

createVariable(initial_value)[source]

Factory method for calculation variable.

Parameters:

initial_value (float, complex or numpy array) – Initial value of the variable.

Returns:

variable.

Return type:

instance of CalculationStrategyMPMath

exponentiate(power)[source]

Exponentiates to the power.

Parameters:

power (float) – The power to raise to.

Returns:

Exponential.

Return type:

mpmath variable

sin(power)[source]

Sin function.

Parameters:

power (float or numpy array) – The arg of sin.

Returns:

Sin.

Return type:

mpmath variable

toComplex(variable)[source]

Converts calculation variable to native python complex.

Parameters:

variable – variable to convert.

Returns:

Native python complex variable.

Return type:

numpy array

class crystalpy.util.CalculationStrategy.CalculationStrategyNumpy[source]

Bases: CalculationStrategy

Use plain python for calculation.

cos(power)[source]

Cos function.

Parameters:

power – The coa argument.

Returns:

Cos.

Return type:

numpy array

createVariable(initial_value)[source]

Factory method for calculation variable.

Parameters:

initial_value – Initial value of the variable.

Returns:

variable.

Return type:

instance of CalculationStrategyNumpy

exponentiate(power)[source]

Exponentiates to the power.

Parameters:

power (float) – The power to raise to.

Returns:

Exponential.

Return type:

numpy array

sin(power)[source]

Sin function.

Parameters:

power – The sin argument.

Returns:

Sin.

Return type:

numpy array

toComplex(variable)[source]

Converts calculation variable to native python complex.

Parameters:

variable – Calculation variable to convert.

Returns:

Native python complex variable.

Return type:

numpy array (complex)

class crystalpy.util.CalculationStrategy.CalculationStrategyNumpyTruncated(limit=1000)[source]

Bases: CalculationStrategy

Use plain python for calculation.

cos(power)[source]

Cos function.

Parameters:

power – The coa argument.

Returns:

Cos.

Return type:

numpy array

createVariable(initial_value)[source]

Factory method for calculation variable.

Parameters:

initial_value – Initial value of the variable.

Returns:

variable.

Return type:

instance of CalculationStrategyNumpy

exponentiate(power)[source]

Exponentiates to the power.

Parameters:

power (float) – The power to raise to.

Returns:

Exponential.

Return type:

numpy array

sin(power)[source]

Sin function.

Parameters:

power – The sin argument.

Returns:

Sin.

Return type:

numpy array

toComplex(variable)[source]

Converts calculation variable to native python complex.

Parameters:

variable – Calculation variable to convert.

Returns:

Native python complex variable.

Return type:

numpy array (complex)

crystalpy.util.ComplexAmplitudePhoton module

Represents a photon defined by its energy, direction vector and pi and sigma complex amplitudes.

class crystalpy.util.ComplexAmplitudePhoton.ComplexAmplitudePhoton(energy_in_ev, direction_vector, Esigma=None, Epi=None)[source]

Bases: Photon

Constructor.

Parameters:
  • energy_in_ev (float) – Photon energy in eV.

  • direction_vector (Vector instance) – The direction of the photon (no need to be normalized).

  • Esigma (complex) – The sigma-amplitude.

  • Esigma – The pi-amplitude.

getComplexAmplitudeP()[source]

Gets the pi complex amplitude.

Returns:

Pi-complex amplitude.

Return type:

complex

getComplexAmplitudeS()[source]

Gets the sigma complex amplitude.

Returns:

Sigma-complex amplitude.

Return type:

complex

getIntensity()[source]

Gets the total (sigma plus pi) intensity.

Returns:

Intensity of photon.

Return type:

float

getIntensityP()[source]

Gets the pi intensity.

Returns:

Intensity (pi) of photon.

Return type:

float

getIntensityS()[source]

Gets the sigma intensity.

Returns:

Intensity (sigma) of photon.

Return type:

float

getPhaseP()[source]

Gets the pi phase.

Returns:

Pi-phase in radians.

Return type:

float

getPhaseS()[source]

Gets the sigma phase.

Returns:

Sigma-phase in radians.

Return type:

float

rescaleEpi(factor)[source]

Multiply the pi complex amplitude by a factor.

Parameters:

factor (float) – The multiplying factor.

rescaleEsigma(factor)[source]

Multiply the sigma complex amplitude by a factor.

Parameters:

factor (float) – The multiplying factor.

setComplexAmplitudeP(value)[source]

Sets the pi complex amplitude.

Parameters:

value (complex, numpy array) – the value (complex) or numpy array (dtype=complex)

setComplexAmplitudeS(value)[source]

Sets the sigma complex amplitude.

Parameters:

value (complex, numpy array) – the value (complex) or numpy array (dtype=complex)

crystalpy.util.ComplexAmplitudePhotonBunch module

A stack of “complex-amplitude” photons characterized by photon energy, direction vector and sigma and pi complex amplitudes.

class crystalpy.util.ComplexAmplitudePhotonBunch.ComplexAmplitudePhotonBunch(complex_amplitude_photons=None)[source]

Bases: ComplexAmplitudePhoton, ComplexAmplitudePhotonBunchDecorator

The ComplexAmplitudePhotonBunch is a ComplexAmplitudePhoton stack.

It inheritates from ComplexAmplitudePhoton and uses stacks for more efficient stockage. Additional methods useful for stacks or bunches are defined in ComplexAmplitudePhotonBunchDecorator.

Constructor.

Parameters:

complex_amplitude_photons (list, optional) – List of ComplexAmplitudePhoton instances.

classmethod initializeFromArrays(energy=[], vx=[], vy=[], vz=[], Esigma=[], Epi=[])[source]

Construct a complex amplitude photon bunch from arrays with photon energies, directions and amplitudes.

Parameters:
  • energies (list, numpy array) – the array with photon energy in eV.

  • vx (list, numpy array) – the array with X component of the direction vector.

  • vy (list, numpy array) – the array with Y component of the direction vector.

  • vz (list, numpy array) – the array with Z component of the direction vector.

  • Esigma (list, numpy array) – the array with S complex amplitude.

  • Epi (list, numpy array) – the array with P complex amplitude.

Return type:

ComplexAmplitudePhotonBunch instance

classmethod initializeFromComplexAmplitudePhoton(photon_stack)[source]

Construct a complex amplitude photon bunch from a complex amplitude photon stack.

Parameters:

photon_stack (instance of ComplexAmplitudePhoton) –

Return type:

ComplexAmplitudePhotonBunch instance

class crystalpy.util.ComplexAmplitudePhotonBunch.ComplexAmplitudePhotonBunchDecorator[source]

Bases: PhotonBunchDecorator

addPhoton(to_be_added)[source]

Adds a photon to the bunch.

Parameters:

to_be_added (Photon instance) –

getPhotonIndex(index)[source]

Returns the photon in the bunch with a given index.

Parameters:

index (int) – The photon index to be referenced.

Returns:

The photon (referenced, not copied).

Return type:

Photon instance

setPhotonIndex(index, polarized_photon)[source]

Sets the photon in the bunch with a given index.

Parameters:
  • index (int) – The photon index to be modified.

  • polarized_photon (Photon instance) – The photon to be stored.

toDictionary()[source]

Created a dictionary containing information about the bunch.

Returns:

Information in tags: “number of photons”, “energies”, “deviations”, “vx”, “vy”, “vz”, “intensityS”, “intensityP”, “intensity”, “phaseS”, “phaseP”, “complexAmplitudeS”,”complexAmplitudeP”

Return type:

dict

class crystalpy.util.ComplexAmplitudePhotonBunch.ComplexAmplitudePhotonBunchOld(complex_amplitude_photons=None)[source]

Bases: PhotonBunch

Constructor.

Parameters:

complex_amplitude_photons (list, optional) – List of ComplexAmplitudePhoton instances.

rescaleEpi(factor)[source]

Multiply the pi complex amplitudes by a factor array.

Parameters:

factor (list. numpy array) – The multiplying factor array.

rescaleEsigma(factor)[source]

Multiply the sigma complex amplitudes by a factor array.

Parameters:

factor (list. numpy array) – The multiplying factor array.

toDictionary()[source]

Created a dictionary containing information about the bunch.

Returns:

Information in tags: “number of photons”, “energies”, “deviations”, “vx”, “vy”, “vz”, “intensityS”, “intensityP”, “intensity”, “phaseS”, “phaseP”, “complexAmplitudeS”,”complexAmplitudeP”

Return type:

dict

toString()[source]

Returns a string containing the parameters characterizing each photon in the bunch.

crystalpy.util.Photon module

Represents a photon defined by its energy and direction vector

class crystalpy.util.Photon.Photon(energy_in_ev=1000.0, direction_vector=<crystalpy.util.Vector.Vector object>)[source]

Bases: object

Constructor.

Parameters:
  • energy_in_ev (float, optional) – Photon energy in eV.

  • direction_vector (Vector instance, optional) – The direction of the photon (no need to be normalized).

deviation()[source]

Returns the deviation angle (angle of the projection on YZ plane with Y axis)

Returns:

the deviation angle. The deviations are calculated supposing that the bunch moves along the y axis

Return type:

float

duplicate()[source]

Return a clone of the Photon instance.

Return type:

Photon instance

energy()[source]

Get the photon energy in eV.

Returns:

The photon energy.

Return type:

float

setEnergy(value)[source]
Parameters:

value (float) – The energy in eV to be set

setUnitDirectionVector(vector=<crystalpy.util.Vector.Vector object>)[source]

Sets the Photon direction.

Parameters:

vector (Vector instance) – The vector with the direction (may be not normalized).

unitDirectionVector()[source]

Returns the photon direction vector.

Returns:

the photon dicection.

Return type:

Vector instance

wavelength()[source]

Returns the photon wavelength in m.

Returns:

the photon wavelength

Return type:

float

wavenumber()[source]

Returns the photon wavenumber (2 pi / wavelength) in m^-1.

Returns:

the photon wavenumber

Return type:

float

wavevector()[source]

Returns the photon wavevector in m^-1.

Returns:

the photon wavevector

Return type:

Vector instance

crystalpy.util.PhotonBunch module

A stack of photons, each one characterized by energy and direction.

class crystalpy.util.PhotonBunch.PhotonBunch(photons=None)[source]

Bases: Photon, PhotonBunchDecorator

The PhotonBunch is a Photon stack.

It inheritates from Photon and uses stacks for more efficient stockage. Additional methods useful for stacks or bunches are defined in PhotonBunchDecorator.

Constructor.

Parameters:

photons (list) – List of Photon instances.

classmethod initializeFromArrays(energy=[], vx=[], vy=[], vz=[])[source]

Construct a bunch from arrays with photon energies and directions.

Parameters:
  • energies (list, numpy array) – the array with photon energy in eV.

  • vx (list, numpy array) – the array with X component of the direction vector.

  • vy (list, numpy array) – the array with Y component of the direction vector.

  • vz (list, numpy array) – the array with Z component of the direction vector.

Return type:

PhotonBunch instance

classmethod initializeFromPhoton(photon_stack)[source]

Construct a bunch from a photon stack.

Parameters:

photon_stack (instance of Photon) –

Return type:

PhotonBunch instance

class crystalpy.util.PhotonBunch.PhotonBunchDecorator[source]

Bases: object

addBunch(to_be_added)[source]

Adds photons in a PhotonBunch instance.

Parameters:

to_be_added (PhotonBunch instance) – Photons to be added.

addPhoton(to_be_added)[source]

Adds a photon to the bunch.

Parameters:

to_be_added (Photon instance) –

addPhotonsFromList(to_be_added)[source]

Adds a list of photons to the bunch.

Parameters:

to_be_added (list) – The photons to be added

energies()[source]

Return the energies of the photons.

Returns:

The energies of the photons (copied, not referenced).

Return type:

numpy array

getArrayByKey(key)[source]

Returns the array of a givem key in from toDictionary method

Parameters:

key – deviations’, ‘s0’, ‘s1’, ‘s2’, ‘s3’.

Return type:

numpy array

getListOfPhotons()[source]

Returns a list with the photons in the bunch.

Returns:

List with photons.

Return type:

list

getNumberOfPhotons()[source]

Returns the number of photons in the bunch.

Returns:

Number of photons.

Return type:

int

getPhotonIndex(index)[source]

Returns the photon in the bunch with a given index.

Parameters:

index (int) – The photon index to be referenced.

Returns:

The photon (referenced, not copied).

Return type:

Photon instance

isMonochromatic(places)[source]

Inquires about bunch monochromaticity.

Parameters:

places – number of decimal places to be taken into account for comparing energies.

Returns:

True if all photons in the bunch have the same energy.

Return type:

bool

isUnidirectional()[source]

Inquires if all photons in the bunch have the same direction.

Returns:

True if all photons have the same direction.

Return type:

bool

keys()[source]

return the keys of the dictionary resulting from toDictionary method

setPhotonIndex(index, polarized_photon)[source]

Sets the photon in the bunch with a given index.

Parameters:
  • index (int) – The photon index to be modified.

  • polarized_photon (Photon instance) – The photon to be stored.

toDictionary()[source]

Created a dictionary containing information about the bunch.

Returns:

Information in tags: “number of photons”, “energies”, “deviations”, “vx”, “vy” and “vz”.

Return type:

dict

toString()[source]

Returns a string table containing the energy and direction vector for each photon in the bunch.

class crystalpy.util.PhotonBunch.PhotonBunchOld(photons=None)[source]

Bases: object

The PhotonBunch is Photon stack instances, making up the photon bunch or beam.

Constructor.

Parameters:

photons (list) – List of Photon instances.

addBunch(to_be_added)[source]

Adds photons in a PhotonBunch instance.

Parameters:

to_be_added (PhotonBunch instance) – Photons to be added.

addPhoton(to_be_added)[source]

Adds a photon to the bunch.

Parameters:

to_be_added (Photon instance) –

addPhotonsFromList(to_be_added)[source]

Adds a list of photons to the bunch.

Parameters:

to_be_added (list) – The photons to be added

duplicate()[source]

Return a clone of the PhotonBunch instance.

Return type:

PhotonBunch instance

energies()[source]

Return the energies of the photons.

Returns:

The energies of the photons (copied, not referenced).

Return type:

numpy array

energy()[source]

Return the energies of the photons.

Returns:

The energies of the photons (copied, not referenced).

Return type:

numpy array

getArrayByKey(key)[source]

Returns the array of a givem key in from toDictionary method

Parameters:

key – deviations’, ‘s0’, ‘s1’, ‘s2’, ‘s3’.

Return type:

numpy array

getListOfPhotons()[source]

Returns a list with the photons in the bunch.

Returns:

List with photons.

Return type:

list

getNumberOfPhotons()[source]

Returns the number of photons in the bunch.

Returns:

Number of photons.

Return type:

int

getPhotonIndex(index)[source]

Returns the photon in the bunch with a given index.

Parameters:

index (int) – The photon index to be referenced.

Returns:

The photon (referenced, not copied).

Return type:

Photon instance

classmethod initialize_from_energies_and_directions(energies, V)[source]

Construct a bunch from arrays with photon energies and directions

Parameters:
  • energies (list, numpy array) –

  • V (Vector instance (with a tack of vectors)) –

Return type:

PhotonBunch instance

isMonochromatic(places)[source]

Inquires about bunch monochromaticity.

Parameters:

places – number of decimal places to be taken into account for comparing energies.

Returns:

True if all photons in the bunch have the same energy.

Return type:

bool

isUnidirectional()[source]

Inquires if all photons in the bunch have the same direction.

Returns:

True if all photons have the same direction.

Return type:

bool

keys()[source]

return the keys of the dictionary resulting from toDictionary method

setPhotonIndex(index, polarized_photon)[source]

Sets the photon in the bunch with a given index.

Parameters:
  • index (int) – The photon index to be modified.

  • polarized_photon (Photon instance) – The photon to be stored.

setUnitDirectionVector(vector)[source]

Sets the directions of the photons.

Parameters:

vector (Vector instance) – Stack of vectors with the directions.

toDictionary()[source]

Created a dictionary containing information about the bunch.

Returns:

Information in tags: “number of photons”, “energies”, “deviations”, “vx”, “vy” and “vz”.

Return type:

dict

toString()[source]

Returns a string containing the parameters characterizing each photon in the bunch.

unitDirectionVector()[source]

Return the directions of the photons.

Returns:

The directions in stacked vectors.

Return type:

Vector instance

wavelength()[source]

Return the wavelengths of the photons (in m).

Returns:

The wavelengths of the photons.

Return type:

numpy array

wavenumber()[source]

Return the wavenumbers of the photons (in m^-1).

Returns:

The wavenumbers of the photons.

Return type:

numpy array

wavevector()[source]

Return the wavevectors of the photons.

Returns:

The wavevectors in stacked vectors.

Return type:

Vector instance

crystalpy.util.PlotData1D module

—OK—

class crystalpy.util.PlotData1D.Interval(inf, sup)[source]

Bases: object

check_extrema()[source]

Returns True if inf <= sup. False if inf > sup. :return: bool

print()[source]

Prints the interval to video.

class crystalpy.util.PlotData1D.PlotData1D(title, title_x_axis, title_y_axis)[source]

Bases: object

Represents a 1D plot. The graph data together with related information.

add_plot_info(name, info)[source]

Adds a plot info. :param name: Name of the info. :param info: The info.

add_xy_point(x_point, y_point)[source]

Adds an x-y point. :param x_point: x coordinate. :param y_point: y coordinate.

plot_info()[source]

Returns the plot info copy. :return: The plot info.

set_x(x)[source]

Sets X data. :param x: x data.

set_x_max(x_max)[source]

Sets X range maximum. :param x_max: X range maximum.

set_x_min(x_min)[source]

Sets x range minimum. :param x_min: X range minimum.

set_y(y)[source]

Sets Y data. :param y: y data.

set_y_max(y_max)[source]

Sets Y range maximum. :param y_max: Y range maximum.

set_y_min(y_min)[source]

Sets Y range minimum. :param y_min: Y range minimum.

smart_unwrap(intervals, intervals_number, phase_limits, deg)[source]

Unwraps data correctly by avoiding discontinuities. :param intervals: list of pairs. Each element is a pair with the two extrema of the x interval. :param phase_limits: min and max tolerable values for the phase plot, [min, max]. :param intervals_number: number of intervals to set to zero. :param deg: True if values are in degrees. False if radians.

crystalpy.util.PolarizedPhoton module

This object represents a polarized photon, characterized by energy, direction vector and Stokes parameters.

class crystalpy.util.PolarizedPhoton.PolarizedPhoton(energy_in_ev, direction_vector, stokes_vector)[source]

Bases: Photon

Constructor.

Parameters:
  • energy_in_ev (float) – Photon energy in eV.

  • direction_vector (Vector instance) – The direction of the photon (no need to be normalized).

  • stokes_vector (StokesVector instance) – Stokes vector describing the polarization state.

applyMuellerMatrix(mueller_matrix=<crystalpy.polarization.MuellerMatrix.MuellerMatrix object>)[source]

Modify the stokes vector by a Muller matrix.

Parameters:

mueller_matrix (MuellerMatrix instance, optional) – The Mueller matrix

circularPolarizationDegree()[source]

Returns the degree of circular polarization.

Returns:

The polarization degree.

Return type:

float

setStokesVector(stokes_vector)[source]

Sets the stokes vector

Parameters:

stokes_vector (StokesVector instance) –

stokesVector()[source]

Returns the Stokes vector.

Returns:

The Stokes vector (referenced, not copied).

Return type:

StokesVector instance

crystalpy.util.PolarizedPhotonBunch module

A stack of polarized photons characterized by photon energy, direction vector and Stokes vector.

class crystalpy.util.PolarizedPhotonBunch.PolarizedPhotonBunch(polarized_photons=None)[source]

Bases: PolarizedPhoton, PolarizedPhotonBunchDecorator

The PolarizedPhotonBunch is a PolarizedPhoton stack.

It inheritates from PolarizedPhoton and uses stacks for more efficient stockage. Additional methods useful for stacks or bunches are defined in PolarizedPhotonBunchDecorator.

Constructor.

Parameters:

polarized_photons (list, optional) – List of PolarizedPhoton instances.

classmethod initializeFromArrays(energy=[], vx=[], vy=[], vz=[], s0=[], s1=[], s2=[], s3=[])[source]

Construct a polarized photon bunch from arrays with photon energies, directions and stokes components.

Parameters:
  • energies (list, numpy array) – the array with photon energy in eV.

  • vx (list, numpy array) – the array with X component of the direction vector.

  • vy (list, numpy array) – the array with Y component of the direction vector.

  • vz (list, numpy array) – the array with Z component of the direction vector.

  • s0 (list, numpy array) – the array with S0 stokes vector.

  • s1 (list, numpy array) – the array with S1 stokes vector.

  • s2 (list, numpy array) – the array with S2 stokes vector.

  • s3 (list, numpy array) – the array with S4 stokes vector.

Return type:

PolarizedPhotonBunch instance

classmethod initializeFromPolarizedPhoton(photon_stack)[source]

Construct a polarized photon bunch from a polarized photon stack.

Parameters:

photon_stack (instance of PolarizedPhoton) –

Return type:

PolarizedPhotonBunch instance

class crystalpy.util.PolarizedPhotonBunch.PolarizedPhotonBunchDecorator[source]

Bases: PhotonBunchDecorator

addPhoton(to_be_added)[source]

Adds a photon to the bunch.

Parameters:

to_be_added (Photon instance) –

getPhotonIndex(index)[source]

Returns the photon in the bunch with a given index.

Parameters:

index (int) – The photon index to be referenced.

Returns:

The photon (referenced, not copied).

Return type:

Photon instance

setPhotonIndex(index, polarized_photon)[source]

Sets the photon in the bunch with a given index.

Parameters:
  • index (int) – The photon index to be modified.

  • polarized_photon (Photon instance) – The photon to be stored.

toDictionary()[source]

Created a dictionary containing information about the bunch.

Returns:

Information in tags: “number of photons”, “energies”, “deviations”, “vx”, “vy”, “vz”, “s0”, “s1”, “s2”, “s3” and “polarization degree”.

Return type:

dict

class crystalpy.util.PolarizedPhotonBunch.PolarizedPhotonBunchOld(polarized_photons=None)[source]

Bases: PhotonBunch

The PolarizadPhotonBunch is is a collection of PolarizedPhoton objects, making up the polarized photon beam.

Constructor.

Parameters:

polarized_photons (list, optional) – List of PolarizedPhoton instances.

toDictionary()[source]

Created a dictionary containing information about the bunch.

Returns:

Information in tags: “number of photons”, “energies”, “deviations”, “vx”, “vy”, “vz”, “s0”, “s1”, “s2”, “s3” and “polarization degree”.

Return type:

dict

toString()[source]

Returns a string containing the parameters characterizing each polarized photon in the bunch.

crystalpy.util.StokesVector module

Represents a Stokes vector (four components s0, s1, s2, s3). It accepts a stack (s0, etc. are arrays).

class crystalpy.util.StokesVector.StokesVector(element_list=[0.0, 0.0, 0.0, 0.0])[source]

Bases: object

StokesVector Constructor.

Parameters:

element_list (list, optional) – the Stokes parameters [S0,S1,S2,S3]

append(vector)[source]

Appends a stoked-vector to the stack.

Parameters:

vector (instance of StokesVector) –

circularPolarizationDegree()[source]

Calculates the degree of circular polarization of the radiation described by the Stokes parameter.

Returns:

Degree of circular polarization S3/S0

Return type:

float

components()[source]

Generates a numpy 1x4 array from the Stokes vector components.

Returns:

The four stokes components.

Return type:

numpy array

concatenate(vector)[source]

Concatenates a vector to the stack.

Parameters:

vector (instance of StokesVector) –

Returns:

The resulting vector with the concatenation.

Return type:

instance of StokesVector

duplicate()[source]

Duplicates a StokesVector.

Returns:

New StokesVector instance with identical x,y,z components.

Return type:

StokesVector instance

getList()[source]

Generates a 1x4 list with the four Stokes components.

Returns:

list containing the Stokes parameters.

Return type:

list

getS0()[source]

Returns the S0 component.

Returns:

The S0 component.

Return type:

float

getS1()[source]

Returns the S1 component.

Returns:

The S1 component.

Return type:

float

getS2()[source]

Returns the S2 component.

Returns:

The S2 component.

Return type:

float

getS3()[source]

Returns the S3 component.

Returns:

The S3 component.

Return type:

float

property s0

Gets s0 (first stokes parameter).

Return type:

float or numpy array

property s1

Gets s1 (second stokes parameter).

Return type:

float or numpy array

property s2

Gets s2 (first stokes parameter).

Return type:

float or numpy array

property s3

Gets s3 (first stokes parameter).

Return type:

float or numpy array

setFromArray(array)[source]

Set stokes components from a given array

Parameters:

array (list or numpy array) –

setFromValues(s0, s1, s2, s3)[source]

Set stokes components from given values

Parameters:
  • s0 (float) –

  • s1 (float) –

  • s2 (float) –

  • s3 (float) –

toString()[source]

Returns a string with the four Stokes parameters (separated by a blank).

Returns:

the four Stokes parameters.

Return type:

str

crystalpy.util.Vector module

Represents a 3d vector. Accept arrays of vectors.

vector.components() gives a numpy array with shape (3) or (3, npoints)

class crystalpy.util.Vector.Vector(x, y, z)[source]

Bases: object

Vector Constructor.

Parameters:
  • x (float) – x component. It can be an array.

  • y (float) – y component. It can be an array of the same size of x.

  • z (float) – z component. It can be an array of the same size of x.

addVector(summand)[source]

Adds two vectors.

Parameters:

summand (Vector instance) – The vector to be added.

Returns:

The sum as a new vector.

Return type:

Vector instance

angle(factor)[source]

Return the angle between this vector and the given vector.

Parameters:

factor (Vector instance) – Vector to determine the angle with.

Returns:

Angle between this vector and the given vector.

Return type:

float or numpy array

append(vector)[source]

Appends a vector to the stack.

Parameters:

vector (instance of Vector) –

components()[source]

Returns the components of this vector a 1d three element array.

Returns:

The Vector components (referenced, not copied).

Return type:

numpy array

componentsStack()[source]

Returns the components stack of shape (3, npoints) of this vector.

Returns:

The Vector components (referenced, not copied).

Return type:

numpy array

concatenate(vector)[source]

Concatenates a vector to the stack.

Parameters:

vector (instance of Vector) –

Returns:

The resulting vector with the concatenation.

Return type:

instance of Vector

crossProduct(factor)[source]

Calculates the cross product of two vectors.

Parameters:

factor – The vector to form the cross product with.

Returns:

Cross product of the two vectors as a new vector.

Return type:

Vector instance

duplicate()[source]

Duplicates a vector.

Returns:

result – New Vector instance with identical x,y,z components.

Return type:

Vector instance

extractStackItem(i)[source]
Parameters:

i (int) – Index of vector to be extracted

Returns:

A new vector instance with components of the i-th element only.

Return type:

Vector instance

getNormalizedVector()[source]

Returns a normalized vector of this vector. :return: Normalized vector of this vector.

Returns:

The Normalized vector as a new vector.

Return type:

Vector instance

getOnePerpendicularVector()[source]

Returns one arbitrary vector perpendicular to this vector.

Returns:

One arbitrary vector perpendicular to this vector.

Return type:

Vector instance

getVectorH(surface_normal, d_spacingSI, asymmetry_angle=0.0, azimuthal_angle=0.0, vector_parallel_surface=None)[source]

Returns the vector H. It is obtained from * copy the surface_normal * set its module to 2 pi / d_spacingSI * calculate an axis perpendicular to vector_parallel_surface and surface_normal * rotate it an angle -asymmetry_angle around this axis * rotate it an angle azimuthal_angle around this the surface_normal

Parameters:
  • surface_normal (instance of Vector) – the (normalized) upwards normal to the surface.

  • d_spacingSI (float or numpy array) – the d-spacing in m.

  • asymmetry_angle (float or numpy array) – the asymmetry angle in rad (from the crystal surface to crystal planes, positive if clockwise)

  • azimuthal_angle (float or numpy array) – the azimuthal angle in rad. It is the angle between the YZ plane and the diffraction plane.

  • vector_parallel_surface (instance of Vector, optional) – the vector parallel to the surface. If None it uses Vector(0,1,0)

Return type:

instance of Vector

getVectorWithAngle(angle)[source]

Returns one arbitrary vector with the vector rotated with a given angle.

Parameters:

angle (float) – The requested angle in radiants.

Returns:

Vector with given angle to this vector.

Return type:

Vector instance

getX()[source]

Returns the x component.

Returns:

The x component(s) (referenced, not copied).

Return type:

float, numpy array

getY()[source]

Returns the y component (referenced, not copied).

Returns:

The y component(s).

Return type:

float, numpy array

getZ()[source]

Returns the z component (referenced, not copied).

Returns:

The z component(s).

Return type:

float, numpy array

static initializeFromComponents(components)[source]

Creates a vector from a list/array of at least three elements.

Parameters:

components (list, numpy array) – A list with the [x,y,z] components of the vector.

isArray()[source]

Inform if the Vector instance contains a stack of vectors.

Returns:

True if Vector contsins a stack of vector, False if there is a single vector.

Return type:

bool

nStack()[source]

Returns the number of stacked vectors

Returns:

Number of stacked vectors

Return type:

int

norm()[source]

Returns the standard norm of this norm. :return: Norm of this vector,

Returns:

The vector norm.

Return type:

float, numpy array

parallelTo(vector)[source]

Returns the (parallel) projection of this vector along the given vector.

Parameters:

vector (Vector instance) – Vector defining the projection direction. It does not need to be normalized.

Returns:

Parallel projection along the vector.

Return type:

Vector instance

perpendicularTo(vector)[source]

Returns the projection perpendicular to the given vector.

Parameters:

vector (Vector instance) – Vector that defines the direction. It does not need to be normalized.

Returns:

Projection perpendicular to the given vector.

Return type:

Vector instance

printComponents()[source]

Print vector components

rotateAroundAxis(rotation_axis, angle)[source]

Rotates the vector around an axis. It uses the Rodrigues formula [rf]

Parameters:
  • rotation_axis (Vector instance) – Vector specifying the rotation axis (not necessarily unit vector).

  • angle (float) – Rotation angle in radiants.

Returns:

Rotated vector as a new vector.

Return type:

Vector instance

References

scalarMultiplication(k)[source]

Scalar multiplication of a vectors.

Parameters:

k – The scalar to multiply with.

Returns:

The scalar multiplied vector as a new vector.

Return type:

Vector instance

scalarProduct(factor)[source]

Calculates the scalar product of this vector with the given vector.

Parameters:

factor – The vector to calculate the scalar product with.

Returns:

Scalar product of the two vectors as a new vector.

Return type:

Vector instance

scatteringOnSurface(NORMAL, H, use_sign_of=1)[source]
Returns K_OUT vector following the scattering equation at a surface:

K_OUT_parallel = K_IN_parallel + H_parallel |K_OUT| = |K_IN|

Parameters:
  • NORMAL (instance of Vector) – The vector normal to the surface.

  • H (instance of Vector) – The scattering vector.

  • use_sign_of (float or numpy array) – The value to defing the sign of the sqrt that appears when doing |K_OUT| = |K_IN|. The sign used is numpy.sign(use_sign_of).

Returns:

Vector with K_OUT.

Return type:

Vector instance

scatteringOnSurfaceG(NORMAL, H, use_sign_of=1)[source]
setComponents(x, y, z)[source]

Sets vector components.

Parameters:
  • x – x component.

  • y – y component.

  • z – z component.

subtractVector(tosubstract)[source]

Subtract a vector from this Vector instance.

Parameters:

tosubstract – Vector to subtract.

Returns:

The difference of the two vectors as a new vector.

Return type:

Vector instance

toString()[source]

Returns a string object containing the components of the vector.

Returns:

Components of this vector.

Return type:

str

crystalpy.util.bragg_preprocessor_file_io module

Utilities to read and write Bragg preprocessor files and dictionaries.

Copied from xoppylib (https://github.com/oasys-kit/xoppylib) so that crystalpy does not depend on xoppylib.

crystalpy.util.bragg_preprocessor_file_io.bragg_preprocessor_file_v1_read(filename)[source]

Reads data from Bragg-preprocessor file V1 to dictionary.

Parameters:

filename (str) – Filename with input.

Return type:

dict

crystalpy.util.bragg_preprocessor_file_io.bragg_preprocessor_file_v1_write(out_dict, fileout='')[source]

Writes data from dictionary to Bragg-preprocessor file V1.

Parameters:
  • out_dict (dict) – Input dictionary to write to file

  • fileout (str) – Filename for output.

crystalpy.util.bragg_preprocessor_file_io.bragg_preprocessor_file_v2_read(filename='')[source]

Reads data from Bragg-preprocessor file V2 to dictionary.

Parameters:

filename (str) – Filename with input.

Return type:

dict

crystalpy.util.bragg_preprocessor_file_io.bragg_preprocessor_file_v2_write(output_dictionary, fileout=None)[source]

Writes data from dictionary to Bragg-preprocessor file V2.

Parameters:
  • out_dict (dict) – Input dictionary to write to file

  • fileout (str) – Filename for output.

crystalpy.util.calc_xcrystal module

Utility functions for crystal diffraction calculations (xcrystal tools).

crystalpy.util.calc_xcrystal.apply_convolution_on_bunch_out_dict(bunch_out_dict, sigma=0.1)[source]
crystalpy.util.calc_xcrystal.apply_convolution_with_gaussian(x, y, sigma=7.0)[source]
crystalpy.util.calc_xcrystal.calc_xcrystal_alphazachariasen_scan(crystal_name='Si', miller_h=1, miller_k=1, miller_l=1, thickness=0.01, asymmetry_angle=0.0, geometry_type_index=0, material_constants_library_flag=0, energy=8000.0, angle_deviation_min=-2, angle_deviation_max=2, angle_deviation_points=200, calculation_method=0, is_thick=0, use_transfer_matrix=0, do_plot=0, calculation_strategy_flag=0, dabax=None)[source]
crystalpy.util.calc_xcrystal.calc_xcrystal_angular_scan(crystal_name='Si', miller_h=1, miller_k=1, miller_l=1, thickness=0.01, asymmetry_angle=0.0, geometry_type_index=0, material_constants_library_flag=0, energy=8000.0, angle_deviation_min=-0.0001, angle_deviation_max=0.0001, angle_deviation_points=200, angle_center_flag=2, flag_calculate_stokes=0, chi_deg=0.0, jones_in=[1, 1], calculation_method=0, is_thick=0, use_transfer_matrix=0, do_plot=0, calculation_strategy_flag=0, dabax=None)[source]
crystalpy.util.calc_xcrystal.calc_xcrystal_double_scan(material_constants_library_flag=0, crystal_name='Si', thickness=0.01, miller_h=1, miller_k=1, miller_l=1, asymmetry_angle=0.0, energy_min=7990, energy_max=8010, energy_points=200, angle_deviation_min=-0.0001, angle_deviation_max=0.0001, angle_deviation_points=200, angle_center_flag=2, calculation_method=0, is_thick=0, use_transfer_matrix=0, geometry_type_index=0, do_plot=0, calculation_strategy_flag=0, dabax=None)[source]
crystalpy.util.calc_xcrystal.calc_xcrystal_energy_scan(crystal_name='Si', miller_h=1, miller_k=1, miller_l=1, thickness=0.01, asymmetry_angle=0.0, geometry_type_index=0, material_constants_library_flag=0, theta=None, energy_min=7990, energy_max=8010, energy_points=200, calculation_method=0, is_thick=0, use_transfer_matrix=0, do_plot=0, calculation_strategy_flag=0, dabax=None)[source]
crystalpy.util.calc_xcrystal.get_diffraction_setup(material_constants_library_flag=0, crystal_name='Si', thickness=0.01, miller_h=1, miller_k=1, miller_l=1, geometry_type_index=0, asymmetry_angle=0.0, dabax=None)[source]

Module contents