def __init__(self, image_file, **kwargs):
        from dxtbx import IncorrectFormatError
        if not self.understand(image_file):
            raise IncorrectFormatError(self, image_file)
        FormatHDF5.__init__(self, image_file, **kwargs)

        self.DET64 = DetectorFactory.from_dict(multi_det_dict.D)
        self._h5_handle = h5py.File(self.get_image_file(), 'r')
        self._geometry_define()
Beispiel #2
0
def basic_detector(
):  # from development, not actually used here but useful for reference
    # make a detector panel
    # monolithic camera description
    print("Make a dxtbx detector")
    detdist = 141.7
    pixsize = 0.088  # Rayonix MX340-XFEL, 2x2 binning mode
    im_shape = 3840, 3840
    det_descr = {
        'panels': [{
            'fast_axis': (1.0, 0.0, 0.0),
            'slow_axis': (0.0, -1.0, 0.0),
            'gain':
            1.0,
            'identifier':
            '',
            'image_size':
            im_shape,
            'mask': [],
            'material':
            '',
            'mu':
            0.0,
            'name':
            'Panel',
            'origin': (-im_shape[0] * pixsize / 2., im_shape[1] * pixsize / 2.,
                       -detdist),
            'pedestal':
            0.0,
            'pixel_size': (pixsize, pixsize),
            'px_mm_strategy': {
                'type': 'SimplePxMmStrategy'
            },
            'raw_image_offset': (0, 0),
            'thickness':
            0.0,
            'trusted_range': (-1e7, 1e7),
            'type':
            ''
        }]
    }
    return DetectorFactory.from_dict(det_descr)
def basic_detector():
    # make a detector panel
    # monolithic camera description
    print("Make a dxtbx detector")
    detdist = 100.
    pixsize = 0.1
    im_shape = 1536, 1536
    det_descr = {
        'panels': [{
            'fast_axis': (1.0, 0.0, 0.0),
            'slow_axis': (0.0, -1.0, 0.0),
            'gain':
            1.0,
            'identifier':
            '',
            'image_size':
            im_shape,
            'mask': [],
            'material':
            '',
            'mu':
            0.0,
            'name':
            'Panel',
            'origin': (-im_shape[0] * pixsize / 2., im_shape[1] * pixsize / 2.,
                       -detdist),
            'pedestal':
            0.0,
            'pixel_size': (pixsize, pixsize),
            'px_mm_strategy': {
                'type': 'SimplePxMmStrategy'
            },
            'raw_image_offset': (0, 0),
            'thickness':
            0.0,
            'trusted_range': (-1e7, 1e7),
            'type':
            ''
        }]
    }
    return DetectorFactory.from_dict(det_descr)
Beispiel #4
0
        'material': '',
        'mu': 0.0,
        'name': 'Panel',
        'origin': (-99.165, 99.05499999999999, -125.0),
        'pedestal': 0.0,
        'pixel_size': (0.11, 0.11),
        'px_mm_strategy': {
            'type': 'SimplePxMmStrategy'
        },
        'raw_image_offset': (0, 0),
        'slow_axis': (0.0, -1.0, 0.0),
        'thickness': 0.0,
        'trusted_range': (-29.0, 65505.0),
        'type': 'SENSOR_CCD'
    }]
}

beamDict = {
    'direction': (0.0, 0.0, 1.0),
    'divergence': 0.0,
    'flux': 0.0,
    'polarization_fraction': 0.999,
    'polarization_normal': (0.0, 1.0, 0.0),
    'sigma_divergence': 0.0,
    'transmission': 1.0,
    'wavelength': 1.37095
}

BEAM = BeamFactory.from_dict(beamDict)
DET = DetectorFactory.from_dict(detDict)
Beispiel #5
0
def main():
    from cxid9114.sim import sim_utils
    from dxtbx.model.crystal import CrystalFactory
    from dxtbx_model_ext import flex_Beam
    from dxtbx.model.detector import DetectorFactory
    from dxtbx.model.beam import BeamFactory
    from simtbx.nanoBragg.tst_nanoBragg_basic import fcalc_from_pdb

    import numpy as np
    from cxid9114.parameters import ENERGY_CONV

    energies = np.arange(8920, 8930)
    fluxes = np.ones(len(energies)) * 5e11

    patt_args = {"Ncells_abc": (20, 20, 20), "profile": "square", "verbose": 0}

    beam_descr = {
        'direction': (0.0, 0.0, 1.0),
        'divergence': 0.0,
        'flux': 5e11,
        'polarization_fraction': 1.,
        'polarization_normal': (0.0, 1.0, 0.0),
        'sigma_divergence': 0.0,
        'transmission': 1.0,
        'wavelength': ENERGY_CONV / energies[0]
    }

    cryst_descr = {
        '__id__': 'crystal',
        'real_space_a': (79, 0, 0),
        'real_space_b': (0, 79, 0),
        'real_space_c': (0, 0, 38),
        'space_group_hall_symbol': '-P 4 2'
    }

    det_descr = {
        'panels': [{
            'fast_axis': (-1.0, 0.0, 0.0),
            'gain': 1.0,
            'identifier': '',
            'image_size': (196, 196),
            'mask': [],
            'material': '',
            'mu': 0.0,
            'name': 'Panel',
            'origin': (19.6, -19.6, -550),
            'pedestal': 0.0,
            'pixel_size': (0.1, 0.1),
            'px_mm_strategy': {
                'type': 'SimplePxMmStrategy'
            },
            'raw_image_offset': (0, 0),
            'slow_axis': (0.0, 1.0, 0.0),
            'thickness': 0.0,
            'trusted_range': (0.0, 65536.0),
            'type': ''
        }]
    }

    DET = DetectorFactory.from_dict(det_descr)
    BEAM = BeamFactory.from_dict(beam_descr)

    crystal = CrystalFactory.from_dict(cryst_descr)
    Patt = sim_utils.PatternFactory(crystal=crystal,
                                    detector=DET,
                                    beam=BEAM,
                                    **patt_args)

    img = None
    Fens = []
    xrbeams = flex_Beam()
    for fl, en in zip(fluxes, energies):
        wave = ENERGY_CONV / en
        F = fcalc_from_pdb(resolution=4, algorithm="fft", wavelength=wave)
        Patt.primer(crystal, energy=en, flux=fl, F=F)
        if img is None:
            img = Patt.sim_rois(reset=True)  # defaults to full detector
        else:
            img += Patt.sim_rois(reset=True)

        Fens.append(F)

        xrb = BeamFactory.from_dict(beam_descr)
        xrb.set_wavelength(wave *
                           1e-10)  # need to fix the necessity to do this..
        xrb.set_flux(fl)
        xrb.set_direction(BEAM.get_direction())

        xrbeams.append(xrb)

    #import pylab as plt
    #def plot_img(ax,img):
    #    m = img[img >0].mean()
    #    s = img[img > 0].std()
    #    vmax = m+5*s
    #    vmin = 0
    #    ax.imshow(img, vmin=vmin, vmax=vmax, cmap='gnuplot')

    print("\n\n\n")
    print("<><><><><><><><><><>")
    print("NEXT TRIAL")
    print("<><><><><><><><><><>")
    #

    patt2 = sim_utils.PatternFactory(crystal=crystal,
                                     detector=DET,
                                     beam=xrbeams,
                                     **patt_args)

    patt2.prime_multi_Fhkl(multisource_Fhkl=Fens)
    img2 = patt2.sim_rois(reset=True)

    #plt.figure()
    #ax1 = plt.gca()
    #plt.figure()
    #ax2 = plt.gca()
    #plot_img(ax1, img)
    #plot_img(ax2, img2)
    #plt.show()

    assert (np.allclose(img, img2))
Beispiel #6
0
                 'mask': [],
                 'material': '',
                 'mu': 0.0,
                 'name': 'Panel',
                 'origin': (-im_shape[0]*pixsize/2., im_shape[1]*pixsize/2., -detdist),
                 'pedestal': 0.0,
                 'pixel_size': (pixsize, pixsize),
                 'px_mm_strategy': {'type': 'SimplePxMmStrategy'},
                 'raw_image_offset': (0, 0),
                 'thickness': 0.0,
                 'trusted_range': (-1e7, 1e7),
                 'type': ''}]}

# make the dxtbx objects
BEAM = BeamFactory.from_dict(beam_descr)
DETECTOR = DetectorFactory.from_dict(det_descr)
CRYSTAL = CrystalFactory.from_dict(cryst_descr)

# make a dummie HKL table with constant HKL intensity
# this is just to make spots
DEFAULT_F = 1e2
symbol = CRYSTAL.get_space_group().info().type().lookup_symbol()  # this is just P43212
sgi = sgtbx.space_group_info(symbol)
symm = symmetry(unit_cell=CRYSTAL.get_unit_cell(), space_group_info=sgi)
miller_set = symm.build_miller_set(anomalous_flag=True, d_min=1.6, d_max=999)
Famp = flex.double(np.ones(len(miller_set.indices())) * DEFAULT_F)
Famp = miller.array(miller_set=miller_set, data=Famp).set_observation_type_xray_amplitude()

Ncells_abc = 20, 20, 20
oversmaple = 2
        "", fast, slow, orig,
        (pixsize, pixsize), (s*1536,s*1536)) #, trusted_range=(0, 10000000))
    beam_descr = {
        'direction': (7.010833160725592e-06, -3.710515413340211e-06, 0.9999999999685403),
        'divergence': 0.0,
        'flux': 0.0,
        'polarization_fraction': 0.999,
        'polarization_normal': (0.0, 1.0, 0.0),
        'sigma_divergence': 0.0,
        'transmission': 1.0,
        'wavelength': 1.385}
    #beam = BeamFactory.simple(wavelen)
    beam = BeamFactory.from_dict(beam_descr)

elif lab_geom == "cspad":
    det = DetectorFactory.from_dict(dxtbx_cspad.cspad)

    # beam pointing off z-axis
    beam_descr = {
        'direction': (7.010833160725592e-06, -3.710515413340211e-06, 0.9999999999685403),
        'divergence': 0.0,
        'flux': 0.0,
        'polarization_fraction': 0.999,
        'polarization_normal': (0.0, 1.0, 0.0),
        'sigma_divergence': 0.0,
        'transmission': 1.0,
        'wavelength': 1.385}
    beam = BeamFactory.from_dict(beam_descr)


pix = sim_cryst_on_det(cryst, det, beam)
        'origin': (25.6, -12.8, -100),
        'pedestal': 0.0,
        'pixel_size': (0.1, 0.1),
        'px_mm_strategy': {
            'type': 'SimplePxMmStrategy'
        },
        'raw_image_offset': (0, 0),
        'slow_axis': (0.0, 1.0, 0.0),
        'thickness': 0.0,
        'trusted_range': (0.0, 65536.0),
        'type': ''
    }]
}

beam = BeamFactory.from_dict(beam_descr)
whole_det = DetectorFactory.from_dict(det_descr)
cryst = CrystalFactory.from_dict(cryst_descr)

# ---------

SIM = simtbx.nanoBragg.nanoBragg(whole_det, beam)
SIM.Amatrix = sqr(cryst.get_A()).transpose().elems
SIM.default_F = 1
SIM.F000 = 10
SIM.oversample = 2
SIM.Ncells_abc = (5, 5, 5)
SIM.show_params()
SIM.add_nanoBragg_spots()
SIM.raw_pixels *= 2000
wholepix = SIM.raw_pixels.as_numpy_array()
from __future__ import division
import numpy as np

import simtbx.nanoBragg
from dxtbx.model.beam import BeamFactory
from dxtbx.model.detector import DetectorFactory

import dxtbx_cspad

# flat CSPAD
cspad = DetectorFactory.from_dict(
    dxtbx_cspad.cspad)  # loads a 64 panel dxtbx cspad
# beam along Z
beam = BeamFactory.simple(1.3)  #  make a simple beam along z

print "# --- beam centers comparison for canonical setup -- #"
net_error_flat = 0
for pid in range(64):
    print "canonical: ", pid
    SIM = simtbx.nanoBragg.nanoBragg(detector=cspad,
                                     beam=beam,
                                     verbose=0,
                                     panel_id=pid)
    b1 = SIM.beam_center_mm
    b2 = cspad[pid].get_beam_centre(beam.get_s0())
    print "beam_XY simtbx:  %f, %f" % b1
    print "beam_XY python:  %f, %f" % b2
    print

    net_error_flat += np.sum(np.subtract(b1, b2)**2)
Beispiel #10
0
    'direction': (0.0, 0.0, 1.0),
    'divergence': 0.0,
    'flux': 1e12,
    'polarization_fraction': 1.,
    'polarization_normal': (0.0, 1.0, 0.0),
    'sigma_divergence': 0.0,
    'transmission': 1.0,
    'wavelength': 1.4
}

# dxtbx crystal description
hall_sym = sgtbx.space_group_info(
    number=19).type().hall_symbol()  # ' P 2ac 2ab'

cryst_descr = {
    '__id__': 'crystal',
    'real_space_a': (127.7, 0, 0),
    'real_space_b': (0, 225.4, 0),
    'real_space_c': (0, 0, 306.1),
    'space_group_hall_symbol': hall_sym
}

beam = BeamFactory.from_dict(beam_descr)
whole_det = DetectorFactory.from_dict(cspad)
cryst = CrystalFactory.from_dict(cryst_descr)

from cxid9114 import utils
utils.save_flex(whole_det, "ps2.det.pkl")
utils.save_flex(cryst, "ps2.cryst.pkl")
utils.save_flex(beam, "ps2.beam.pkl")