def from_phil(params, reference=None): ''' Convert the phil parameters into a beam model ''' # Check the input if reference is None: beam = Beam() else: beam = reference # Set the parameters if params.beam.wavelength is not None: beam.set_wavelength(params.beam.wavelength) elif reference is None: raise RuntimeError("No wavelength set") if params.beam.direction is not None: beam.set_direction(params.beam.direction) elif reference is None: raise RuntimeError("No beam direction set") if params.beam.polarization_normal is not None: beam.set_polarization_normal(params.beam.polarization_normal) if params.beam.polarization_fraction is not None: beam.set_polarization_fraction(params.beam.polarization_fraction) # Return the model return beam
def make_beam(sample_to_source=None, wavelength=None, s0=None, unit_s0=None, divergence=None, sigma_divergence=None): if divergence is None or sigma_divergence is None: divergence = 0.0 sigma_divergence = 0.0 if sample_to_source: assert(wavelength) return Beam( tuple(map(float, sample_to_source)), float(wavelength), float(divergence), float(sigma_divergence)) elif unit_s0: assert(wavelength) return Beam( tuple(map(lambda x: - x, map(float, unit_s0))), float(wavelength), float(divergence), float(sigma_divergence)) else: assert(s0) return Beam(tuple(map(float, s0)))
def make_beam( sample_to_source=None, wavelength=None, s0=None, unit_s0=None, divergence=None, sigma_divergence=None, ): if divergence is None or sigma_divergence is None: divergence = 0.0 sigma_divergence = 0.0 if sample_to_source: assert wavelength return Beam( tuple(map(float, sample_to_source)), float(wavelength), float(divergence), float(sigma_divergence), ) elif unit_s0: assert wavelength return Beam( tuple(-float(x) for x in unit_s0), float(wavelength), float(divergence), float(sigma_divergence), ) else: assert s0 return Beam(tuple(map(float, s0)))
def make_polarized_beam( sample_to_source=None, wavelength=None, s0=None, unit_s0=None, polarization=None, polarization_fraction=None, divergence=None, sigma_divergence=None, flux=None, transmission=None, ): assert polarization assert polarization_fraction >= 0.0 assert polarization_fraction <= 1.0 if divergence is None or sigma_divergence is None: divergence = 0.0 sigma_divergence = 0.0 if flux is None: flux = 0 if transmission is None: transmission = 1.0 if sample_to_source: assert wavelength return Beam( tuple(map(float, sample_to_source)), float(wavelength), float(divergence), float(sigma_divergence), tuple(map(float, polarization)), float(polarization_fraction), float(flux), float(transmission), ) elif unit_s0: assert wavelength return Beam( tuple(map(lambda x: -x, map(float, unit_s0))), float(wavelength), float(divergence), float(sigma_divergence), tuple(map(float, polarization)), float(polarization_fraction), float(flux), float(transmission), ) else: assert s0 return Beam( tuple(map(float, s0)), float(divergence), float(sigma_divergence), tuple(map(float, polarization)), float(polarization_fraction), float(flux), float(transmission), )
def make_polarized_beam(sample_to_source=None, wavelength=None, s0=None, unit_s0=None, polarization=None, polarization_fraction=None, divergence=None, sigma_divergence=None): assert(polarization) assert(polarization_fraction) if divergence == None or sigma_divergence == None: divergence = 0.0 sigma_divergence = 0.0 if sample_to_source: assert(wavelength) return Beam( tuple(map(float, sample_to_source)), float(wavelength), float(divergence), float(sigma_divergence), tuple(map(float, polarization)), float(polarization_fraction)) elif unit_s0: assert(wavelength) return Beam( tuple(map(lambda x: - x, map(float, unit_s0))), float(wavelength), float(divergence), float(sigma_divergence), tuple(map(float, polarization)), float(polarization_fraction)) else: assert(s0) return Beam( tuple(map(float, s0)), float(divergence), float(sigma_divergence), tuple(map(float, polarization)), float(polarization_fraction))
def from_dict(d, t=None): """Convert the dictionary to a beam model Params: d The dictionary of parameters t The template dictionary to use Returns: The beam model """ if d is None and t is None: return None joint = t.copy() if t else {} joint.update(d) # Create the model from the joint dictionary return Beam.from_dict(joint)
def from_dict(d, t=None): ''' Convert the dictionary to a beam model Params: d The dictionary of parameters t The template dictionary to use Returns: The beam model ''' from dxtbx.model import Beam # If None, return None if d == None: if t == None: return None else: return from_dict(t, None) elif t != None: d = dict(t.items() + d.items()) # Create the model from the dictionary return Beam.from_dict(d)