Exemplo n.º 1
0
        def local_process(beamLine, shineOnly1stSource=False):

            # This has to conserve the atomicity of the operation!
            local_it = self.beam_iterator.next()
            rnga = local_it * self.beam_chunk_size
            rngb = (local_it + 1) * self.beam_chunk_size

            print 'Taking beam from', rnga, 'to', rngb

            # This acts as xrt::shine()
            beam = ub.copy_by_index(self.source_beam, range(rnga, rngb))

            # Propagate photons through the capillary
            beamTotal, _ =\
            self.capillary.multiple_reflect(beam,\
                                            maxReflections=50)

            # Hold photons for export
            if self.beamTotal is None:
                self.beamTotal = beamTotal
            else:
                self.beamTotal.concatenate(beamTotal)

            # Use those screens for testing parameters
            exitScreen = beamLine.exitScreen.expose(beamTotal)
            farScreen = beamLine.farScreen.expose(beamTotal)

            # This screen is shown when creating new beam file
            totalScreen = beamLine.totalScreen.expose(beamTotal)

            # Show beamlines after exposition
            outDict = {'ExitScreen' : exitScreen}
            outDict['FarScreen'] = farScreen

            return outDict
def create_defects(beam, howmany):
    """ Try to simulate defect related imaging """
    # Container for single-defect ids
    dids = []

    # Define defect radius
    d_rad = 0.065

    for it in range(howmany):
	# Generate random positions from [-2 :: 2]
	rx = (-0.5 + np.random.random()) * 4.0
	ry = (-0.5 + np.random.random()) * 4.0
	pos = [rx, ry]

	print 'Creating defect at:', pos, 'With radius:', d_rad

	dids.append(outside_circle(beam, pos, d_rad))

    # Get final set of good rays
    fids = np.ones_like(dids[0])
    # Array of truth
    fids = fids < 2

    for ids in dids:
	fids &= ids

    ceam = ub.copy_by_index(beam, fids)

    return ceam
def cut_left_half(beam):
    """ why not """
    ids = beam.x <= 0

    ceam = ub.copy_by_index(beam, ids)

    return ceam
def make_wires(beam, shift = 0):
    """ Usage example """
    ids = cut_wires(beam, shift)

    ceam = ub.copy_by_index(beam, ids)

    return ceam
def cut_triangle(beam):
    """ Or any other irregular shape using matplotlib.path """
    triangle = mp.Path([(-0.04, -0.02), (0.08, 0.02), (-0.06, 0.02)])

    # Change 2 lists of coordinates into a list of paired coordinates
    points = zip(beam.x, beam.z)
    ids = triangle.contains_points(points)

    ceam = ub.copy_by_index(beam, ids)

    return ceam
def cut_circle(beam, position = [0, 0], radius = 0.01):
    """ Pinholes are circular! """
    N_ = 100
    s = [position[0] + radius * np.sin(2*np.pi*th/N_) for th in range(N_)]
    c = [position[1] + radius * np.cos(2*np.pi*th/N_) for th in range(N_)]

    circ = mp.Path(zip(s,c))

    ids = circ.contains_points(zip(beam.x, beam.z))

    ceam = ub.copy_by_index(beam, ids)

    return ceam