Exemplo n.º 1
0
    def initialize(self):
        # get settings
        self._start = Settings()['generator']['orbit']['start']
        self._stop = Settings()['generator']['orbit']['stop']
        self._show_progress = Settings()['application']['progress_bar']

        # load the lattice
        self._lattice.load([os.path.join(Settings()['application']['conf_path'],
                            fname) for fname in Settings()['machine']['lattice']])

        # initialise the sub-systems
        self._orbit.initialize(self._lattice)
        self._twiss.initialize(self._lattice)
        self._photons.initialize(self._lattice)
        
        # initialise step and beam
        self._step = self._orbit.create_step()
        self._beam = self._twiss.create_beam()

        # output
        self._output_lattice = Output('regions')
        self._output_orbit = Output('orbit_parameters')
        self._output_twiss = Output('twiss_parameters')
        self._output_num_photons = Output('radiated_number_photons')
        self._output_spectrum = Output('spectrum_lut')
        self._output_lattice.open()
        self._output_orbit.open()
        self._output_twiss.open()
        self._output_num_photons.open()
        self._output_spectrum.open()

        # hepevt output
        self._hepevt = Hepevt()
        self._hepevt.open()
Exemplo n.º 2
0
    def show_labels(dataset_item):
        """Puts the dataset image into the output dir with the labeled quad"""
        img = np.copy(dataset_item.img)

        # red receipt outline
        cv2.polylines(img, [dataset_item.quad.to_polyline()], True,
                      (0, 0, 255), 5)

        # purple region of interest
        cv2.polylines(img, [dataset_item.distribution_rect.to_polyline()],
                      True, (255, 0, 255), 3)

        # blue inner region of interest
        cv2.polylines(img, [dataset_item.small_roi_rect().to_polyline()], True,
                      (255, 0, 0), 2)

        Output.write_image(dataset_item.file + "_0_labeled.jpg", img)
Exemplo n.º 3
0
from app.dataset import Dataset
from app.output import Output
from app.segmenter import Segmenter
from app.utils import Utils
from app.debug import Debug
import numpy as np
import cv2

dataset = Dataset()
dataset.load()

segmenter = Segmenter()

Output.clear()
for item in dataset.items:
    print(item.file)

    #if item.file != "008.jpg":
    #    continue

    #
    # run the segmentation algorithm
    #

    quad = segmenter.segment(item.img, item.distribution_rect)

    #
    # draw the result
    #

    # reference image
Exemplo n.º 4
0
class Generator():
    """
    The main Synchrotron Radiation generator.
    """
    def __init__(self):
        self._lattice = Lattice()
        self._orbit = Orbit()
        self._twiss = Twiss()
        self._photons = Photons()


    def initialize(self):
        # get settings
        self._start = Settings()['generator']['orbit']['start']
        self._stop = Settings()['generator']['orbit']['stop']
        self._show_progress = Settings()['application']['progress_bar']

        # load the lattice
        self._lattice.load([os.path.join(Settings()['application']['conf_path'],
                            fname) for fname in Settings()['machine']['lattice']])

        # initialise the sub-systems
        self._orbit.initialize(self._lattice)
        self._twiss.initialize(self._lattice)
        self._photons.initialize(self._lattice)
        
        # initialise step and beam
        self._step = self._orbit.create_step()
        self._beam = self._twiss.create_beam()

        # output
        self._output_lattice = Output('regions')
        self._output_orbit = Output('orbit_parameters')
        self._output_twiss = Output('twiss_parameters')
        self._output_num_photons = Output('radiated_number_photons')
        self._output_spectrum = Output('spectrum_lut')
        self._output_lattice.open()
        self._output_orbit.open()
        self._output_twiss.open()
        self._output_num_photons.open()
        self._output_spectrum.open()

        # hepevt output
        self._hepevt = Hepevt()
        self._hepevt.open()



    def run(self):
        # write lattice and spectrum
        self._lattice.write(self._output_lattice)
        self._photons.write_spectrum(self._output_spectrum)

        # progress bar
        if self._show_progress:
            progress_ds = 0.0
            progress = ProgressBar(widgets=['Stepping: ', Percentage(),
                                            ' ', Bar(), ' ', ETA()],
                                   maxval=math.fabs(self._stop - self._start)).start()

        # first ideal orbit step
        self._orbit.step_ideal_orbit(self._step)

        # step through the lattice until the stop point is reached
        while self._orbit.valid(self._step):

            # step the actual orbit and evolve the twiss parameters
            self._orbit.step_actual_orbit(self._step)
            self._twiss.evolve(self._step, self._beam)

            # integrate over the beam profile and create the photons
            self._photons.create(self._step, self._beam,
                                 self._output_num_photons,
                                 self._hepevt)

            # write orbit and twiss parameters to file
            self._step.write(self._output_orbit)
            self._beam.write(self._step, self._output_twiss)

            # update progress bar
            if self._show_progress:
                progress_ds += math.fabs(self._step.ds)
                progress.update(progress_ds)

            # next ideal orbit step
            self._orbit.step_ideal_orbit(self._step)

        if self._show_progress:
            progress.finish()


    def terminate(self):
        self._output_lattice.close()
        self._output_orbit.close()
        self._output_twiss.close()
        self._output_num_photons.close()
        self._output_spectrum.close()
        self._hepevt.close()
Exemplo n.º 5
0
 def setUp(self):
     self.input = Input()
     self.output = Output()
     self.solver = Solver()
     self.testclass = Creator(self.input, self.output)