Exemplo n.º 1
0
    def __init__(self, image_file, **kwargs):
        """Initialise the image structure from the given file, including a
        proper model of the experiment."""

        FormatCBFMiniPilatus.__init__(self, image_file, **kwargs)
        FormatStill.__init__(self, image_file, **kwargs)

        return
Exemplo n.º 2
0
  def __init__(self, image_file, **kwargs):
    '''Initialise the image structure from the given file, including a
    proper model of the experiment.'''

    assert(self.understand(image_file))

    FormatCBFMiniPilatus.__init__(self, image_file, **kwargs)

    return
Exemplo n.º 3
0
    def __init__(self, image_file, **kwargs):
        """Initialise the image structure from the given file, including a
        proper model of the experiment."""

        from dxtbx import IncorrectFormatError

        if not self.understand(image_file):
            raise IncorrectFormatError(self, image_file)

        FormatCBFMiniPilatus.__init__(self, image_file, **kwargs)
    def __init__(self, image_file):
        """Initialise the image structure from the given file, including a
    proper model of the experiment."""

        assert self.understand(image_file)

        FormatCBFMiniPilatus.__init__(self, image_file)

        self._raw_data = None

        return
  def __init__(self, image_file, **kwargs):
    '''Initialise the image structure from the given file, including a
    proper model of the experiment.'''

    assert(self.understand(image_file))

    self._raw_data = None
    self._multi_panel = kwargs.get('multi_panel', False)
    FormatCBFMiniPilatus.__init__(self, image_file, **kwargs)

    return
    def __init__(self, image_file, **kwargs):
        '''Initialise the image structure from the given file, including a
    proper model of the experiment.'''

        from dxtbx import IncorrectFormatError
        if not self.understand(image_file):
            raise IncorrectFormatError(self, image_file)

        self._raw_data = None
        self._multi_panel = kwargs.get('multi_panel', False)
        FormatCBFMiniPilatus.__init__(self, image_file, **kwargs)

        return
    def __init__(self, image_file, **kwargs):
        '''Initialise the image structure from the given file, including a
    proper model of the experiment.'''

        assert (self.understand(image_file))

        self._dynamic_shadowing = kwargs.get('dynamic_shadowing', False)
        self._multi_panel = kwargs.get('multi_panel', False)
        FormatCBFMiniPilatus.__init__(self, image_file, **kwargs)

        self._raw_data = None

        return
Exemplo n.º 8
0
    def __init__(self, image_file, **kwargs):
        """Initialise the image structure from the given file, including a
        proper model of the experiment."""

        from dxtbx import IncorrectFormatError

        if not self.understand(image_file):
            raise IncorrectFormatError(self, image_file)

        self._dynamic_shadowing = self.has_dynamic_shadowing(**kwargs)
        self._multi_panel = kwargs.get("multi_panel", False)
        FormatCBFMiniPilatus.__init__(self, image_file, **kwargs)

        self._raw_data = None
  def understand(image_file):
    '''Check to see if this looks like an Pilatus mini CBF format image,
    i.e. we can make sense of it.'''

    header = FormatCBFMiniPilatus.get_cbf_header(image_file)

    year = 0

    for record in header.split('\n'):
      if '# 20' in record:
        year = int(record.replace('-', ' ').replace('/', ' ').split()[1])
        break

    if (year <= 0):
      return False

    for record in header.split('\n'):
      if '# Detector' in record and \
             'PILATUS' in record and 'S/N 60-0119' in header:
        if year >= 2015:
          return True
        else:
          return False

    return False
    def understand(image_file):
        """Check to see if this looks like an Pilatus mini CBF format image,
        i.e. we can make sense of it."""

        header = FormatCBFMiniPilatus.get_cbf_header(image_file)

        year = 0

        for record in header.split("\n"):
            if "# 20" in record:
                year = int(
                    record.replace("-", " ").replace("/", " ").split()[1])
                break

        if year <= 0:
            return False

        for record in header.split("\n"):
            if ("# Detector" in record and "PILATUS" in record
                    and "S/N 60-0114" in header):
                if year >= 2017:
                    return True
                else:
                    return False

        return False
Exemplo n.º 11
0
def test_multi_panel(dials_data, tmpdir):
    filename = dials_data("x4wide") / "X4_wide_M1S4_2_0001.cbf"

    assert FormatCBFMiniPilatus.understand(filename.strpath)
    expts = ExperimentListFactory.from_filenames(
        [filename.strpath], format_kwargs={"multi_panel": True})
    assert len(expts) == 1
    assert len(expts[0].detector) == 60
    assert len(expts[0].imageset.get_raw_data(0)) == 60
    expected_xoffset = [-212.47848, -127.51048, -42.54248, 42.42552, 127.39352]
    expected_yoffset = [
        220.00176,
        183.53776,
        147.07376,
        110.60976,
        74.14576,
        37.68176,
        1.21776,
        -35.24624,
        -71.71024,
        -108.17424,
        -144.63824,
        -181.10224,
    ]
    for i, p in enumerate(expts[0].detector):
        assert p.get_image_size() == (487, 195)
        origin = p.get_origin()
        assert origin[0] == pytest.approx(expected_xoffset[i % 5])
        assert origin[1] == pytest.approx(expected_yoffset[i // 5])
        assert origin[2] == pytest.approx(-190.18)
Exemplo n.º 12
0
    def understand(image_file):
        '''Check to see if this looks like an Pilatus mini CBF format image,
    i.e. we can make sense of it.'''

        header = FormatCBFMiniPilatus.get_cbf_header(image_file)

        year = 0

        for record in header.split('\n'):
            if '# 20' in record:
                year = int(
                    record.replace('-', ' ').replace('/', ' ').split()[1])
                break

        if (year <= 0):
            return False

        for record in header.split('\n'):
            if '# Detector' in record and \
                   'PILATUS' in record and 'S/N 60-0114' in header:
                if year >= 2017:
                    return True
                else:
                    return False

        return False
Exemplo n.º 13
0
def test_imagesetdata(centroid_files):
    ReaderClass = FormatClass.get_reader()

    reader = ReaderClass(centroid_files)
    masker = FormatClass(centroid_files[0]).get_masker()

    handle = ImageSetData(reader, masker)

    assert handle.get_data(0).as_int().tile(0).data()

    assert handle.has_single_file_reader() is False

    path = handle.get_path(0)
    assert path == centroid_files[0]

    master_path = handle.get_master_path()
    assert master_path == ""

    identifier = handle.get_image_identifier(0)
    assert identifier == centroid_files[0]

    beam = FormatClass(centroid_files[0]).get_beam()
    detector = FormatClass(centroid_files[0]).get_detector()
    goniometer = FormatClass(centroid_files[0]).get_goniometer()
    scan = FormatClass(centroid_files[0]).get_scan()

    handle.set_beam(beam, 0)
    handle.set_detector(detector, 0)
    handle.set_goniometer(goniometer, 0)
    handle.set_scan(scan, 0)

    beam2 = handle.get_beam(0)
    detector2 = handle.get_detector(0)
    goniometer2 = handle.get_goniometer(0)
    scan2 = handle.get_scan(0)

    assert beam2 == beam
    assert detector2 == detector
    assert goniometer2 == goniometer
    assert scan2 == scan

    mask = flex.bool(flex.grid(10, 10), True)
    gain = flex.double(flex.grid(10, 10), 1)
    pedestal = flex.double(flex.grid(10, 10), 2)

    handle.external_lookup.mask.data = dxtbx.format.image.ImageBool(
        dxtbx.format.image.ImageTileBool(mask))
    handle.external_lookup.gain.data = dxtbx.format.image.ImageDouble(
        dxtbx.format.image.ImageTileDouble(gain))
    handle.external_lookup.pedestal.data = dxtbx.format.image.ImageDouble(
        dxtbx.format.image.ImageTileDouble(pedestal))

    mask2 = handle.external_lookup.mask.data.tile(0).data()
    gain2 = handle.external_lookup.gain.data.tile(0).data()
    pedestal2 = handle.external_lookup.pedestal.data.tile(0).data()

    assert mask2.all_eq(mask)
    assert gain2.all_eq(gain)
    assert pedestal2.all_eq(pedestal)
Exemplo n.º 14
0
def test_single_panel(dials_data, tmpdir):
    filename = dials_data("x4wide") / "X4_wide_M1S4_2_0001.cbf"

    assert FormatCBFMiniPilatus.understand(filename.strpath)
    expts = ExperimentListFactory.from_filenames([filename.strpath])
    assert len(expts) == 1
    assert len(expts[0].detector) == 1
    assert len(expts[0].imageset.get_raw_data(0)) == 1
    def __init__(self, image_file, **kwargs):
        '''Initialise the image structure from the given file, including a
    proper model of the experiment.'''

        assert (self.understand(image_file))

        # if multi_panel == False, then interpret data as 24 panels, where each row
        # of 5 panels is grouped as one "panel"
        # elif multi_panel == True, then interpret data as 120 panels,
        # 24 rows * 5 columns
        self._dynamic_shadowing = kwargs.get('dynamic_shadowing', False)
        self._multi_panel = kwargs.get('multi_panel', False)
        FormatCBFMiniPilatus.__init__(self, image_file, **kwargs)

        self._raw_data = None

        return
def write_cbf(SIM, fileout="noiseimage_00001.cbf"):
    # first and foremost, convert the pixel data to integers
    dxData = SIM.raw_pixels.iround()
    # now get the image writing goodies
    import dxtbx
    from dxtbx.format.FormatCBFMiniPilatus import FormatCBFMiniPilatus
    # apparently, cant initialize a detector witout doing a panel first
    dxPanel = dxtbx.model.Panel()
    dxPanel.set_name('Panel')
    dxPanel.set_type('SENSOR_PAD')
    dxPanel.set_image_size(SIM.detpixels_fastslow)
    dxPanel.set_pixel_size((SIM.pixel_size_mm, SIM.pixel_size_mm))
    dxPanel.set_gain(SIM.quantum_gain)
    dxPanel.set_trusted_range((-1, 1.3e6))
    dxPanel.set_frame(SIM.fdet_vector, SIM.sdet_vector, SIM.dials_origin_mm)
    dxPanel.set_material('Si')
    dxPanel.set_thickness(SIM.detector_thick_mm)
    dxPanel.set_mu(SIM.detector_attenuation_length_mm * 10)
    # use this panel to create a detector
    dxDet = dxtbx.model.Detector(dxPanel)
    # now create a beam from nothing
    dxBeam = dxtbx.model.Beam()
    #dxBeam.set_direction(tuple(flex.double(SIM.beam_vector)*-1))
    dxBeam.set_s0(SIM.beam_vector)
    dxBeam.set_wavelength(SIM.wavelength_A)
    dxBeam.set_flux(SIM.flux)
    dxBeam.set_divergence(SIM.divergence_hv_mrad[0])
    dxBeam.set_polarization_normal(tuple(flex.double(SIM.polar_Bvector) * -1))
    dxBeam.set_polarization_fraction(SIM.polarization)
    # or cheat and choose first internal sub-beam
    #dxBeam = SIM.xray_beams[0]
    # create a goniomater from nothing
    dxGoni = dxtbx.model.Goniometer()
    dxGoni.set_rotation_axis(SIM.spindle_axis)
    # define the scan from nothing
    dxScan = dxtbx.model.Scan()
    dxScan.set_image_range((1, 1))
    dxScan.set_oscillation([SIM.phi_deg, SIM.osc_deg])
    dxScan.set_exposure_times([SIM.exposure_s])
    # now, finally, do the image write
    FormatCBFMiniPilatus.as_file(detector=dxDet,
                                 beam=dxBeam,
                                 gonio=dxGoni,
                                 scan=dxScan,
                                 data=dxData,
                                 path=fileout)
    def __init__(self, image_file, **kwargs):
        """Initialise the image structure from the given file, including a
        proper model of the experiment."""

        from dxtbx import IncorrectFormatError

        if not self.understand(image_file):
            raise IncorrectFormatError(self, image_file)

        # if multi_panel == False, then interpret data as 24 panels, where each
        # row of 5 panels is grouped as one "panel"
        # elif multi_panel == True, then interpret data as 120 panels,
        # 24 rows * 5 columns
        self._dynamic_shadowing = self.has_dynamic_shadowing(**kwargs)
        self._multi_panel = kwargs.get("multi_panel", False)
        FormatCBFMiniPilatus.__init__(self, image_file, **kwargs)

        self._raw_data = None
  def __init__(self, image_file, **kwargs):
    '''Initialise the image structure from the given file, including a
    proper model of the experiment.'''

    assert(self.understand(image_file))

    # if multi_panel == False, then interpret data as 24 panels, where each row
    # of 5 panels is grouped as one "panel"
    # elif multi_panel == True, then interpret data as 120 panels,
    # 24 rows * 5 columns
    self._dynamic_shadowing = kwargs.get('dynamic_shadowing', False)
    self._multi_panel = kwargs.get('multi_panel', False)
    FormatCBFMiniPilatus.__init__(self, image_file, **kwargs)

    self._raw_data = None


    return
  def understand(image_file):
    '''Check to see if this looks like an Pilatus mini CBF format image,
    i.e. we can make sense of it.'''

    header = FormatCBFMiniPilatus.get_cbf_header(image_file)

    for record in header.split('\n'):
      if 'Detector: PILATUS 6M-F, S/N 60-0115-F' in record:
        return True

    return False
Exemplo n.º 20
0
    def understand(image_file):
        """Check to see if this looks like an Pilatus mini CBF format image,
        i.e. we can make sense of it."""

        header = FormatCBFMiniPilatus.get_cbf_header(image_file)

        for record in header.split("\n"):
            if "Detector: PILATUS 6M-F, S/N 60-0115-F" in record:
                return True

        return False
    def understand(image_file):
        """Check to see if this looks like an Pilatus mini CBF format image,
    i.e. we can make sense of it."""

        header = FormatCBFMiniPilatus.get_cbf_header(image_file)

        for record in header.split("\n"):
            if "# Detector" in record and "PILATUS" in record and "S/N 60-0100 Diamond" in header:
                return True

        return False
Exemplo n.º 22
0
    def understand(image_file):
        '''Check to see if this looks like an Pilatus mini CBF format image,
    i.e. we can make sense of it.'''

        header = FormatCBFMiniPilatus.get_cbf_header(image_file)

        for record in header.split('\n'):
            if '# Detector' in record and \
                   'PILATUS' in record and 'S/N 60-0106, Soleil' in record:
                return True

        return False
    def understand(image_file):
        """Check to see if this looks like an Pilatus mini CBF format image,
        i.e. we can make sense of it."""

        header = FormatCBFMiniPilatus.get_cbf_header(image_file)

        for record in header.split("\n"):
            if ("# Detector" in record and "PILATUS" in record
                    and "S/N 60-0100 Diamond" in header):
                return True

        return False
  def understand(image_file):
    '''Check to see if this looks like an Pilatus mini CBF format image,
    i.e. we can make sense of it.'''

    header = FormatCBFMiniPilatus.get_cbf_header(image_file)

    for record in header.split('\n'):
      if '# Detector' in record and \
             'PILATUS' in record and 'S/N XX-XXX' in header:
        return True

    return False
Exemplo n.º 25
0
    def understand(image_file):
        """Check to see if this looks like an Pilatus mini CBF format image,
        i.e. we can make sense of it."""

        if os.environ.get("I02_DMM", "0") != "1":
            return False

        header = FormatCBFMiniPilatus.get_cbf_header(image_file)

        for record in header.split("\n"):
            if ("# Detector" in record and "PILATUS" in record
                    and "S/N 60-0114-F" in header):
                return True

        return False
  def understand(image_file):
    '''Check to see if this looks like an Pilatus mini CBF format image,
    i.e. we can make sense of it.'''

    import os
    if os.environ.get('I02_DMM', '0') != '1':
      return False

    header = FormatCBFMiniPilatus.get_cbf_header(image_file)

    for record in header.split('\n'):
      if '# Detector' in record and \
             'PILATUS' in record and 'S/N 60-0114-F' in header:
        return True

    return False
    def understand(image_file):
        '''Check to see if this looks like an Pilatus mini CBF format image,
    i.e. we can make sense of it.'''

        import os
        if os.environ.get('I02_DMM', '0') != '1':
            return False

        header = FormatCBFMiniPilatus.get_cbf_header(image_file)

        for record in header.split('\n'):
            if '# Detector' in record and \
                   'PILATUS' in record and 'S/N 60-0114-F' in header:
                return True

        return False
Exemplo n.º 28
0
def run_sim2smv(fileout):
    SIM = nanoBragg(detpixels_slowfast=(1000, 1000),
                    pixel_size_mm=0.1,
                    Ncells_abc=(5, 5, 5),
                    verbose=9)
    import sys
    if len(sys.argv) > 2:
        SIM.seed = int(sys.argv[2])
        print "GOTHERE seed=", SIM.seed
    if len(sys.argv) > 1:
        if sys.argv[1] == "random": SIM.randomize_orientation()
    SIM.distance_mm = 100
    #SIM = nanoBragg(detpixels_slowfast=(2527,2463),pixel_size_mm=0.172,Ncells_abc=(5,5,5),verbose=9)
    #SIM.distance_mm=200
    # get same noise each time this test is run
    SIM.seed = 1
    SIM.oversample = 1
    SIM.wavelength_A = 1
    SIM.polarization = 1
    #SIM.unit_cell_tuple=(50,50,50,90,90,90)
    print "unit_cell_Adeg=", SIM.unit_cell_Adeg
    print "unit_cell_tuple=", SIM.unit_cell_tuple
    # this will become F000, marking the beam center
    SIM.default_F = 100
    #SIM.missets_deg= (10,20,30)
    print "mosaic_seed=", SIM.mosaic_seed
    print "seed=", SIM.seed
    print "calib_seed=", SIM.calib_seed
    print "missets_deg =", SIM.missets_deg
    sfall = fcalc_from_pdb(resolution=1.6,
                           algorithm="direct",
                           wavelength=SIM.wavelength_A)
    # use crystal structure to initialize Fhkl array
    SIM.Fhkl = sfall
    # fastest option, least realistic
    SIM.xtal_shape = shapetype.Tophat
    # only really useful for long runs
    SIM.progress_meter = False
    # prints out value of one pixel only.  will not render full image!
    #SIM.printout_pixel_fastslow=(500,500)
    #SIM.printout=True
    SIM.show_params()
    # flux is always in photons/s
    SIM.flux = 1e12
    # assumes round beam
    SIM.beamsize_mm = 0.1
    SIM.exposure_s = 0.1
    temp = SIM.Ncells_abc
    print "Ncells_abc=", SIM.Ncells_abc
    SIM.Ncells_abc = temp
    print "Ncells_abc=", SIM.Ncells_abc
    print "xtalsize_mm=", SIM.xtalsize_mm
    print "unit_cell_Adeg=", SIM.unit_cell_Adeg
    print "unit_cell_tuple=", SIM.unit_cell_tuple
    print "missets_deg=", SIM.missets_deg
    print "Amatrix=", SIM.Amatrix
    print "beam_center_mm=", SIM.beam_center_mm
    print "XDS_ORGXY=", SIM.XDS_ORGXY
    print "detector_pivot=", SIM.detector_pivot
    print "xtal_shape=", SIM.xtal_shape
    print "beamcenter_convention=", SIM.beamcenter_convention
    print "fdet_vector=", SIM.fdet_vector
    print "sdet_vector=", SIM.sdet_vector
    print "odet_vector=", SIM.odet_vector
    print "beam_vector=", SIM.beam_vector
    print "polar_vector=", SIM.polar_vector
    print "spindle_axis=", SIM.spindle_axis
    print "twotheta_axis=", SIM.twotheta_axis
    print "distance_meters=", SIM.distance_meters
    print "distance_mm=", SIM.distance_mm
    print "close_distance_mm=", SIM.close_distance_mm
    print "detector_twotheta_deg=", SIM.detector_twotheta_deg
    print "detsize_fastslow_mm=", SIM.detsize_fastslow_mm
    print "detpixels_fastslow=", SIM.detpixels_fastslow
    print "detector_rot_deg=", SIM.detector_rot_deg
    print "curved_detector=", SIM.curved_detector
    print "pixel_size_mm=", SIM.pixel_size_mm
    print "point_pixel=", SIM.point_pixel
    print "polarization=", SIM.polarization
    print "nopolar=", SIM.nopolar
    print "oversample=", SIM.oversample
    print "region_of_interest=", SIM.region_of_interest
    print "wavelength_A=", SIM.wavelength_A
    print "energy_eV=", SIM.energy_eV
    print "fluence=", SIM.fluence
    print "flux=", SIM.flux
    print "exposure_s=", SIM.exposure_s
    print "beamsize_mm=", SIM.beamsize_mm
    print "dispersion_pct=", SIM.dispersion_pct
    print "dispsteps=", SIM.dispsteps
    print "divergence_hv_mrad=", SIM.divergence_hv_mrad
    print "divsteps_hv=", SIM.divsteps_hv
    print "divstep_hv_mrad=", SIM.divstep_hv_mrad
    print "round_div=", SIM.round_div
    print "phi_deg=", SIM.phi_deg
    print "osc_deg=", SIM.osc_deg
    print "phisteps=", SIM.phisteps
    print "phistep_deg=", SIM.phistep_deg
    print "detector_thick_mm=", SIM.detector_thick_mm
    print "detector_thicksteps=", SIM.detector_thicksteps
    print "detector_thickstep_mm=", SIM.detector_thickstep_mm
    print "mosaic_spread_deg=", SIM.mosaic_spread_deg
    print "mosaic_domains=", SIM.mosaic_domains
    print "indices=", SIM.indices
    print "amplitudes=", SIM.amplitudes
    print "Fhkl_tuple=", SIM.Fhkl_tuple
    print "default_F=", SIM.default_F
    print "interpolate=", SIM.interpolate
    print "integral_form=", SIM.integral_form
    # now actually burn up some CPU
    SIM.add_nanoBragg_spots()
    # simulated crystal is only 125 unit cells (25 nm wide)
    # amplify spot signal to simulate physical crystal of 4000x larger: 100 um (64e9 x the volume)
    SIM.raw *= 64e9
    SIM.to_smv_format(fileout="intimage_001.img")
    # rough approximation to water: interpolation points for sin(theta/lambda) vs structure factor
    bg = flex.vec2_double([(0, 2.57), (0.0365, 2.58), (0.07, 2.8), (0.12, 5),
                           (0.162, 8), (0.2, 6.75),
                           (0.18, 7.32), (0.216, 6.75), (0.236, 6.5),
                           (0.28, 4.5), (0.3, 4.3), (0.345, 4.36),
                           (0.436, 3.77), (0.5, 3.17)])
    SIM.Fbg_vs_stol = bg
    SIM.amorphous_sample_thick_mm = 0.1
    SIM.amorphous_density_gcm3 = 1
    SIM.amorphous_molecular_weight_Da = 18
    SIM.flux = 1e12
    SIM.beamsize_mm = 0.1
    SIM.exposure_s = 0.1
    SIM.add_background()
    SIM.to_smv_format(fileout="intimage_002.img")
    # rough approximation to air
    bg = flex.vec2_double([(0, 14.1), (0.045, 13.5), (0.174, 8.35),
                           (0.35, 4.78), (0.5, 4.22)])
    SIM.Fbg_vs_stol = bg
    SIM.amorphous_sample_thick_mm = 35  # between beamstop and collimator
    SIM.amorphous_density_gcm3 = 1.2e-3
    SIM.amorphous_sample_molecular_weight_Da = 28  # nitrogen = N2
    print "amorphous_sample_size_mm=", SIM.amorphous_sample_size_mm
    print "amorphous_sample_thick_mm=", SIM.amorphous_sample_thick_mm
    print "amorphous_density_gcm3=", SIM.amorphous_density_gcm3
    print "amorphous_molecular_weight_Da=", SIM.amorphous_molecular_weight_Da
    SIM.add_background()
    # set this to 0 or -1 to trigger automatic radius.  could be very slow with bright images
    SIM.detector_psf_kernel_radius_pixels = 5
    SIM.detector_psf_fwhm_mm = 0.08
    SIM.detector_psf_type = shapetype.Fiber
    #SIM.apply_psf()
    print SIM.raw[500000]
    SIM.to_smv_format(fileout="intimage_003.img")
    #SIM.detector_psf_fwhm_mm=0
    print "quantum_gain=", SIM.quantum_gain
    print "adc_offset_adu=", SIM.adc_offset_adu
    print "detector_calibration_noise_pct=", SIM.detector_calibration_noise_pct
    print "flicker_noise_pct=", SIM.flicker_noise_pct
    print "readout_noise_adu=", SIM.readout_noise_adu
    print "detector_psf_type=", SIM.detector_psf_type
    print "detector_psf_fwhm_mm=", SIM.detector_psf_fwhm_mm
    print "detector_psf_kernel_radius_pixels=", SIM.detector_psf_kernel_radius_pixels
    SIM.add_noise()

    #fileout = "intimage_001.img"
    print "raw=", SIM.raw
    SIM.to_smv_format(fileout="noiseimage_001.img", intfile_scale=1)

    # try to write as CBF
    import dxtbx
    from dxtbx.format.FormatCBFMiniPilatus import FormatCBFMiniPilatus
    img = dxtbx.load("noiseimage_001.img")
    print img
    FormatCBFMiniPilatus.as_file(detector=img.get_detector(),
                                 beam=img.get_beam(),
                                 gonio=img.get_goniometer(),
                                 scan=img.get_scan(),
                                 data=img.get_raw_data(),
                                 path=fileout)
Exemplo n.º 29
0
def run_sim2smv(prefix, crystal, spectra, rotation, rank, quick=False):
    local_data = data()
    smv_fileout = prefix + ".img"
    if quick is not True:
        if not write_safe(smv_fileout):
            print("File %s already exists, skipping in rank %d" %
                  (smv_fileout, rank))
            return

    direct_algo_res_limit = 1.7

    wavlen, flux, wavelength_A = next(
        spectra)  # list of lambdas, list of fluxes, average wavelength
    if quick:
        wavlen = flex.double([wavelength_A])
        flux = flex.double([flex.sum(flux)])
        print("Quick sim, lambda=%f, flux=%f" % (wavelength_A, flux[0]))

    GF = gen_fmodel(resolution=direct_algo_res_limit,
                    pdb_text=local_data.get("pdb_lines"),
                    algorithm="fft",
                    wavelength=wavelength_A)
    GF.set_k_sol(0.435)
    GF.make_P1_primitive()
    sfall_main = GF.get_amplitudes()

    # use crystal structure to initialize Fhkl array
    sfall_main.show_summary(prefix="Amplitudes used ")
    N = crystal.number_of_cells(sfall_main.unit_cell())

    #SIM = nanoBragg(detpixels_slowfast=(2000,2000),pixel_size_mm=0.11,Ncells_abc=(5,5,5),verbose=0)
    SIM = nanoBragg(
        detpixels_slowfast=(3000, 3000),
        pixel_size_mm=0.11,
        Ncells_abc=(N, N, N),
        # workaround for problem with wavelength array, specify it separately in constructor.
        wavelength_A=wavelength_A,
        verbose=0)
    SIM.adc_offset_adu = 0  # Do not offset by 40
    SIM.adc_offset_adu = 10  # Do not offset by 40
    import sys
    if len(sys.argv) > 2:
        SIM.seed = -int(sys.argv[2])
        print("GOTHERE seed=", SIM.seed)
    if len(sys.argv) > 1:
        if sys.argv[1] == "random": SIM.randomize_orientation()
    SIM.mosaic_spread_deg = 0.05  # interpreted by UMAT_nm as a half-width stddev
    SIM.mosaic_domains = n_mosaic_domains  # 77 seconds.  With 100 energy points, 7700 seconds (2 hours) per image
    # 3000000 images would be 100000 hours on a 60-core machine (dials), or 11.4 years
    # using 2 nodes, 5.7 years.  Do this at SLAC? NERSC? combination of all?
    # SLAC downtimes: Tues Dec 5 (24 hrs), Mon Dec 11 (72 hrs), Mon Dec 18 light use, 24 days
    # mosaic_domains setter must come after mosaic_spread_deg setter
    SIM.distance_mm = 141.7

    UMAT_nm = flex.mat3_double()
    mersenne_twister = flex.mersenne_twister(seed=0)
    scitbx.random.set_random_seed(1234)
    rand_norm = scitbx.random.normal_distribution(mean=0,
                                                  sigma=SIM.mosaic_spread_deg *
                                                  math.pi / 180.)
    g = scitbx.random.variate(rand_norm)
    mosaic_rotation = g(SIM.mosaic_domains)
    for m in mosaic_rotation:
        site = col(mersenne_twister.random_double_point_on_sphere())
        UMAT_nm.append(site.axis_and_angle_as_r3_rotation_matrix(m, deg=False))
    SIM.set_mosaic_blocks(UMAT_nm)

    #SIM.detector_thick_mm = 0.5 # = 0 for Rayonix
    #SIM.detector_thicksteps = 1 # should default to 1 for Rayonix, but set to 5 for CSPAD
    #SIM.detector_attenuation_length_mm = default is silicon

    # get same noise each time this test is run
    SIM.seed = 1
    SIM.oversample = 1
    SIM.wavelength_A = wavelength_A
    SIM.polarization = 1
    # this will become F000, marking the beam center
    SIM.default_F = 0
    #SIM.missets_deg= (10,20,30)
    print("mosaic_seed=", SIM.mosaic_seed)
    print("seed=", SIM.seed)
    print("calib_seed=", SIM.calib_seed)
    print("missets_deg =", SIM.missets_deg)
    SIM.Fhkl = sfall_main
    print("Determinant", rotation.determinant())
    Amatrix_rot = (
        rotation *
        sqr(sfall_main.unit_cell().orthogonalization_matrix())).transpose()
    print("RAND_ORI", prefix, end=' ')
    for i in Amatrix_rot:
        print(i, end=' ')
    print()

    SIM.Amatrix_RUB = Amatrix_rot
    #workaround for failing init_cell, use custom written Amatrix setter
    print("unit_cell_Adeg=", SIM.unit_cell_Adeg)
    print("unit_cell_tuple=", SIM.unit_cell_tuple)
    Amat = sqr(SIM.Amatrix).transpose()  # recovered Amatrix from SIM
    from cctbx import crystal_orientation
    Ori = crystal_orientation.crystal_orientation(
        Amat, crystal_orientation.basis_type.reciprocal)
    print("Python unit cell from SIM state", Ori.unit_cell())

    # fastest option, least realistic
    #SIM.xtal_shape=shapetype.Tophat # RLP = hard sphere
    #SIM.xtal_shape=shapetype.Square # gives fringes
    SIM.xtal_shape = shapetype.Gauss  # both crystal & RLP are Gaussian
    #SIM.xtal_shape=shapetype.Round # Crystal is a hard sphere
    # only really useful for long runs
    SIM.progress_meter = False
    # prints out value of one pixel only.  will not render full image!
    #SIM.printout_pixel_fastslow=(500,500)
    #SIM.printout=True
    SIM.show_params()
    # flux is always in photons/s
    SIM.flux = 1e12
    SIM.exposure_s = 1.0  # so total fluence is e12
    # assumes round beam
    SIM.beamsize_mm = 0.003  #cannot make this 3 microns; spots are too intense
    temp = SIM.Ncells_abc
    print("Ncells_abc=", SIM.Ncells_abc)
    SIM.Ncells_abc = temp
    print("Ncells_abc=", SIM.Ncells_abc)
    print("xtal_size_mm=", SIM.xtal_size_mm)
    print("unit_cell_Adeg=", SIM.unit_cell_Adeg)
    print("unit_cell_tuple=", SIM.unit_cell_tuple)
    print("missets_deg=", SIM.missets_deg)
    print("Amatrix=", SIM.Amatrix)
    print("beam_center_mm=", SIM.beam_center_mm)
    print("XDS_ORGXY=", SIM.XDS_ORGXY)
    print("detector_pivot=", SIM.detector_pivot)
    print("xtal_shape=", SIM.xtal_shape)
    print("beamcenter_convention=", SIM.beamcenter_convention)
    print("fdet_vector=", SIM.fdet_vector)
    print("sdet_vector=", SIM.sdet_vector)
    print("odet_vector=", SIM.odet_vector)
    print("beam_vector=", SIM.beam_vector)
    print("polar_vector=", SIM.polar_vector)
    print("spindle_axis=", SIM.spindle_axis)
    print("twotheta_axis=", SIM.twotheta_axis)
    print("distance_meters=", SIM.distance_meters)
    print("distance_mm=", SIM.distance_mm)
    print("close_distance_mm=", SIM.close_distance_mm)
    print("detector_twotheta_deg=", SIM.detector_twotheta_deg)
    print("detsize_fastslow_mm=", SIM.detsize_fastslow_mm)
    print("detpixels_fastslow=", SIM.detpixels_fastslow)
    print("detector_rot_deg=", SIM.detector_rot_deg)
    print("curved_detector=", SIM.curved_detector)
    print("pixel_size_mm=", SIM.pixel_size_mm)
    print("point_pixel=", SIM.point_pixel)
    print("polarization=", SIM.polarization)
    print("nopolar=", SIM.nopolar)
    print("oversample=", SIM.oversample)
    print("region_of_interest=", SIM.region_of_interest)
    print("wavelength_A=", SIM.wavelength_A)
    print("energy_eV=", SIM.energy_eV)
    print("fluence=", SIM.fluence)
    print("flux=", SIM.flux)
    print("exposure_s=", SIM.exposure_s)
    print("beamsize_mm=", SIM.beamsize_mm)
    print("dispersion_pct=", SIM.dispersion_pct)
    print("dispsteps=", SIM.dispsteps)
    print("divergence_hv_mrad=", SIM.divergence_hv_mrad)
    print("divsteps_hv=", SIM.divsteps_hv)
    print("divstep_hv_mrad=", SIM.divstep_hv_mrad)
    print("round_div=", SIM.round_div)
    print("phi_deg=", SIM.phi_deg)
    print("osc_deg=", SIM.osc_deg)
    print("phisteps=", SIM.phisteps)
    print("phistep_deg=", SIM.phistep_deg)
    print("detector_thick_mm=", SIM.detector_thick_mm)
    print("detector_thicksteps=", SIM.detector_thicksteps)
    print("detector_thickstep_mm=", SIM.detector_thickstep_mm)
    print("***mosaic_spread_deg=", SIM.mosaic_spread_deg)
    print("***mosaic_domains=", SIM.mosaic_domains)
    print("indices=", SIM.indices)
    print("amplitudes=", SIM.amplitudes)
    print("Fhkl_tuple=", SIM.Fhkl_tuple)
    print("default_F=", SIM.default_F)
    print("interpolate=", SIM.interpolate)
    print("integral_form=", SIM.integral_form)

    from libtbx.development.timers import Profiler
    P = Profiler("nanoBragg")
    # now actually burn up some CPU
    #SIM.add_nanoBragg_spots()
    del P

    # simulated crystal is only 125 unit cells (25 nm wide)
    # amplify spot signal to simulate physical crystal of 4000x larger: 100 um (64e9 x the volume)
    print(crystal.domains_per_crystal)
    SIM.raw_pixels *= crystal.domains_per_crystal
    # must calculate the correct scale!

    # Use single wavelength for all energy channels for the purpose of Fcalc
    wavelength_hi_remote = wavlen[-1]
    GF.reset_wavelength(wavelength_hi_remote)
    GF.reset_specific_at_wavelength(label_has="FE1",
                                    tables=local_data.get("Fe_oxidized_model"),
                                    newvalue=wavelength_hi_remote)
    GF.reset_specific_at_wavelength(label_has="FE2",
                                    tables=local_data.get("Fe_reduced_model"),
                                    newvalue=wavelength_hi_remote)
    sfall_channel = GF.get_amplitudes()

    # sources
    channel_source_XYZ = flex.vec3_double(len(flux), SIM.xray_source_XYZ[0])

    CP = channel_pixels(
        wavlen, flux,
        channel_source_XYZ)  # class interface for multi-wavelength
    print("+++++++++++++++++++++++++++++++++++++++ Multiwavelength call")
    CH = CP(N=N,
            UMAT_nm=UMAT_nm,
            Amatrix_rot=Amatrix_rot,
            sfall_channel=sfall_channel)
    SIM.raw_pixels += CH.raw_pixels * crystal.domains_per_crystal
    CH.free_all()
    if quick: SIM.to_smv_format(fileout=prefix + "_intimage_001.img")

    # rough approximation to water: interpolation points for sin(theta/lambda) vs structure factor
    bg = flex.vec2_double([(0, 2.57), (0.0365, 2.58), (0.07, 2.8), (0.12, 5),
                           (0.162, 8), (0.2, 6.75),
                           (0.18, 7.32), (0.216, 6.75), (0.236, 6.5),
                           (0.28, 4.5), (0.3, 4.3), (0.345, 4.36),
                           (0.436, 3.77), (0.5, 3.17)])
    SIM.Fbg_vs_stol = bg
    SIM.amorphous_sample_thick_mm = 0.1
    SIM.amorphous_density_gcm3 = 1
    SIM.amorphous_molecular_weight_Da = 18
    SIM.flux = 1e12
    SIM.beamsize_mm = 0.003  # square (not user specified)
    SIM.exposure_s = 1.0  # multiplies flux x exposure
    SIM.add_background()
    if quick: SIM.to_smv_format(fileout=prefix + "_intimage_002.img")

    # rough approximation to air
    bg = flex.vec2_double([(0, 14.1), (0.045, 13.5), (0.174, 8.35),
                           (0.35, 4.78), (0.5, 4.22)])
    SIM.Fbg_vs_stol = bg
    #SIM.amorphous_sample_thick_mm = 35 # between beamstop and collimator
    SIM.amorphous_sample_thick_mm = 10  # between beamstop and collimator
    SIM.amorphous_density_gcm3 = 1.2e-3
    SIM.amorphous_sample_molecular_weight_Da = 28  # nitrogen = N2
    print("amorphous_sample_size_mm=", SIM.amorphous_sample_size_mm)
    print("amorphous_sample_thick_mm=", SIM.amorphous_sample_thick_mm)
    print("amorphous_density_gcm3=", SIM.amorphous_density_gcm3)
    print("amorphous_molecular_weight_Da=", SIM.amorphous_molecular_weight_Da)
    SIM.add_background()

    #apply beamstop mask here

    # set this to 0 or -1 to trigger automatic radius.  could be very slow with bright images
    # settings for CCD
    SIM.detector_psf_kernel_radius_pixels = 5
    #SIM.detector_psf_fwhm_mm=0.08;
    #SIM.detector_psf_type=shapetype.Fiber # rayonix=Fiber, CSPAD=None (or small Gaussian)
    SIM.detector_psf_type = shapetype.Unknown  # for CSPAD
    SIM.detector_psf_fwhm_mm = 0
    #SIM.apply_psf()
    print("One pixel-->", SIM.raw_pixels[500000])

    # at this point we scale the raw pixels so that the output array is on an scale from 0 to 50000.
    # that is the default behavior (intfile_scale<=0), otherwise it applies intfile_scale as a multiplier on an abs scale.
    if quick: SIM.to_smv_format(fileout=prefix + "_intimage_003.img")

    print("quantum_gain=",
          SIM.quantum_gain)  #defaults to 1. converts photons to ADU
    print("adc_offset_adu=", SIM.adc_offset_adu)
    print("detector_calibration_noise_pct=",
          SIM.detector_calibration_noise_pct)
    print("flicker_noise_pct=", SIM.flicker_noise_pct)
    print("readout_noise_adu=", SIM.readout_noise_adu
          )  # gaussian random number to add to every pixel (0 for PAD)
    # apply Poissonion correction, then scale to ADU, then adc_offset.
    # should be 10 for most Rayonix, Pilatus should be 0, CSPAD should be 0.

    print("detector_psf_type=", SIM.detector_psf_type)
    print("detector_psf_fwhm_mm=", SIM.detector_psf_fwhm_mm)
    print("detector_psf_kernel_radius_pixels=",
          SIM.detector_psf_kernel_radius_pixels)
    SIM.add_noise()  #converts phtons to ADU.

    print("raw_pixels=", SIM.raw_pixels)
    extra = "PREFIX=%s;\nRANK=%d;\n" % (prefix, rank)
    SIM.to_smv_format_py(fileout=smv_fileout,
                         intfile_scale=1,
                         rotmat=True,
                         extra=extra,
                         gz=True)

    # try to write as CBF
    if False:
        import dxtbx
        from dxtbx.format.FormatCBFMiniPilatus import FormatCBFMiniPilatus
        img = dxtbx.load(prefix + ".img")
        print(img)
        FormatCBFMiniPilatus.as_file(detector=img.get_detector(),
                                     beam=img.get_beam(),
                                     gonio=img.get_goniometer(),
                                     scan=img.get_scan(),
                                     data=img.get_raw_data(),
                                     path=prefix + ".cbf")
    SIM.free_all()
Exemplo n.º 30
0
    def run(self):

        from dxtbx.imageset import ImageSetData
        from dxtbx.format.image import ImageTileBool
        from dxtbx.format.image import ImageTileDouble
        from dxtbx.format.image import ImageBool
        from dxtbx.format.image import ImageDouble
        from scitbx.array_family import flex
        import os.path
        from glob import glob
        from dxtbx.format.FormatCBFMiniPilatus import FormatCBFMiniPilatus as FormatClass
        from os.path import join

        dials_regression = libtbx.env.dist_path('dials_regression')
        filenames = sorted(
            glob(join(dials_regression, "centroid_test_data", "*.cbf")))

        ReaderClass = FormatClass.get_reader()
        MaskerClass = FormatClass.get_masker()

        reader = ReaderClass(filenames)
        masker = MaskerClass(filenames)

        handle = ImageSetData(reader, masker)

        data = handle.get_data(0).as_int().tile(0).data()
        mask = handle.get_mask(0).tile(0).data()

        assert handle.has_single_file_reader() == False

        path = handle.get_path(0)
        assert path == filenames[0]

        master_path = handle.get_master_path()
        assert master_path == ""

        identifier = handle.get_image_identifier(0)
        assert identifier == filenames[0]

        beam = FormatClass(filenames[0]).get_beam()
        detector = FormatClass(filenames[0]).get_detector()
        goniometer = FormatClass(filenames[0]).get_goniometer()
        scan = FormatClass(filenames[0]).get_scan()

        handle.set_beam(beam, 0)
        handle.set_detector(detector, 0)
        handle.set_goniometer(goniometer, 0)
        handle.set_scan(scan, 0)

        beam2 = handle.get_beam(0)
        detector2 = handle.get_detector(0)
        goniometer2 = handle.get_goniometer(0)
        scan2 = handle.get_scan(0)

        assert beam2 == beam
        assert detector2 == detector
        assert goniometer2 == goniometer
        assert scan2 == scan

        mask = flex.bool(flex.grid(10, 10), True)
        gain = flex.double(flex.grid(10, 10), 1)
        pedestal = flex.double(flex.grid(10, 10), 2)

        handle.external_lookup.mask.data = ImageBool(ImageTileBool(mask))
        handle.external_lookup.gain.data = ImageDouble(ImageTileDouble(gain))
        handle.external_lookup.pedestal.data = ImageDouble(
            ImageTileDouble(pedestal))

        mask2 = handle.external_lookup.mask.data.tile(0).data()
        gain2 = handle.external_lookup.gain.data.tile(0).data()
        pedestal2 = handle.external_lookup.pedestal.data.tile(0).data()

        assert mask2.all_eq(mask)
        assert gain2.all_eq(gain)
        assert pedestal2.all_eq(pedestal)

        print 'OK'