def traceOpticalElement(self):
        try:
            self.error(self.error_id)
            self.setStatusMessage("")
            self.progressBarInit()

            if ShadowCongruence.checkEmptyBeam(self.input_beam):
                if ShadowCongruence.checkGoodBeam(self.input_beam):
                    sys.stdout = EmittingStream(textWritten=self.writeStdOut)

                    self.checkFields()

                    shadow_oe = ShadowOpticalElement.create_screen_slit()

                    self.populateFields(shadow_oe)
                    self.doSpecificSetting(shadow_oe)

                    self.progressBarSet(10)

                    self.completeOperations(shadow_oe)
                else:
                    raise Exception("Input Beam with no good rays")
            else:
                raise Exception("Empty Input Beam")

        except Exception as exception:
            QtGui.QMessageBox.critical(self, "QMessageBox.critical()",
                                       str(exception),
                                       QtGui.QMessageBox.Ok)

            self.error_id = self.error_id + 1
            self.error(self.error_id, "Exception occurred: " + str(exception))

        self.progressBarFinished()
Beispiel #2
0
    def traceOpticalElement(self):
        try:
            self.error(self.error_id)
            self.setStatusMessage("")
            self.progressBarInit()

            if ShadowCongruence.checkEmptyBeam(self.input_beam):
                if ShadowCongruence.checkGoodBeam(self.input_beam):
                    sys.stdout = EmittingStream(textWritten=self.writeStdOut)

                    self.checkFields()

                    shadow_oe = ShadowOpticalElement.create_screen_slit()

                    self.populateFields(shadow_oe)
                    self.doSpecificSetting(shadow_oe)

                    self.progressBarSet(10)

                    self.completeOperations(shadow_oe)
                else:
                    raise Exception("Input Beam with no good rays")
            else:
                raise Exception("Empty Input Beam")

        except Exception as exception:
            QtGui.QMessageBox.critical(self, "QMessageBox.critical()",
                                       str(exception), QtGui.QMessageBox.Ok)

            self.error_id = self.error_id + 1
            self.error(self.error_id, "Exception occurred: " + str(exception))

        self.progressBarFinished()
Beispiel #3
0
    def retrace(self):
        try:
            if not self.input_beam is None:
                output_beam = self.input_beam.duplicate(history=True)

                empty_element = ShadowOpticalElement.create_empty_oe()

                empty_element._oe.DUMMY = 1.0 # self.workspace_units_to_cm

                empty_element._oe.T_SOURCE     = 0.0
                empty_element._oe.T_IMAGE      = self.retrace_distance
                empty_element._oe.T_INCIDENCE  = 0.0
                empty_element._oe.T_REFLECTION = 180.0
                empty_element._oe.ALPHA        = 0.0

                empty_element._oe.FWRITE = 3
                empty_element._oe.F_ANGLE = 0

                output_beam = ShadowBeam.traceFromOE(output_beam, empty_element, history=True)

                self.setStatusMessage("Plotting Results")

                self.plot_results(output_beam)

                self.setStatusMessage("")
                self.progressBarFinished()

                self.send("Beam", output_beam)
                self.send("Trigger", TriggerIn(new_object=True))
        except Exception as exception:
            QMessageBox.critical(self, "Error", str(exception), QMessageBox.Ok)

            if self.IS_DEVELOP: raise exception
Beispiel #4
0
    def get_zone_plate_beam(self):       # WS Units

        empty_element = ShadowOpticalElement.create_empty_oe()

        empty_element._oe.DUMMY        = self.workspace_units_to_cm
        empty_element._oe.T_SOURCE     = self.source_plane_distance
        empty_element._oe.T_IMAGE      = 0.0
        empty_element._oe.T_INCIDENCE  = 0.0
        empty_element._oe.T_REFLECTION = 180.0
        empty_element._oe.ALPHA        = 0.0

        empty_element._oe.FWRITE = 3
        empty_element._oe.F_ANGLE = 0

        n_screen = 1
        i_screen = numpy.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
        i_abs = numpy.zeros(10)
        i_slit = numpy.array([1, 0, 0, 0, 0, 0, 0, 0, 0, 0])
        i_stop = numpy.zeros(10)
        k_slit = numpy.array([1, 0, 0, 0, 0, 0, 0, 0, 0, 0])
        thick = numpy.zeros(10)
        file_abs = numpy.array(['', '', '', '', '', '', '', '', '', ''])
        rx_slit = numpy.zeros(10)
        rz_slit = numpy.zeros(10)
        sl_dis = numpy.zeros(10)
        file_scr_ext = numpy.array(['', '', '', '', '', '', '', '', '', ''])
        cx_slit = numpy.zeros(10)
        cz_slit = numpy.zeros(10)

        sl_dis[0] = 0.0
        rx_slit[0] = self.diameter*1e-6/self.workspace_units_to_m
        rz_slit[0] = self.diameter*1e-6/self.workspace_units_to_m
        cx_slit[0] = 0.0
        cz_slit[0] = 0.0

        empty_element._oe.set_screens(n_screen,
                                      i_screen,
                                      i_abs,
                                      sl_dis,
                                      i_slit,
                                      i_stop,
                                      k_slit,
                                      thick,
                                      file_abs,
                                      rx_slit,
                                      rz_slit,
                                      cx_slit,
                                      cz_slit,
                                      file_scr_ext)

        output_beam = ShadowBeam.traceFromOE(self.input_beam, empty_element, history=True)

        go = numpy.where(output_beam._beam.rays[:, 9] == GOOD)
        lo = numpy.where(output_beam._beam.rays[:, 9] != GOOD)

        print("Zone Plate Beam: ", "GO", len(go[0]), "LO", len(lo[0]))

        return output_beam
Beispiel #5
0
 def create_dummy_oe():
     empty_element = ShadowOpticalElement.create_empty_oe()
     empty_element._oe.DUMMY = 1.0  # self.workspace_units_to_cm
     empty_element._oe.T_SOURCE = 0.0
     empty_element._oe.T_IMAGE = 0.0
     empty_element._oe.T_INCIDENCE = 0.0
     empty_element._oe.T_REFLECTION = 180.0
     empty_element._oe.ALPHA = 0.0
     empty_element._oe.FWRITE = 3
     empty_element._oe.F_ANGLE = 0
     return empty_element
    def create_dummy_oe(self):
        empty_element = ShadowOpticalElement.create_empty_oe()

        empty_element._oe.DUMMY = self.workspace_units_to_cm

        empty_element._oe.T_SOURCE     = 0.0
        empty_element._oe.T_IMAGE = 0.0
        empty_element._oe.T_INCIDENCE  = 0.0
        empty_element._oe.T_REFLECTION = 180.0
        empty_element._oe.ALPHA        = 0.0

        empty_element._oe.FWRITE = 3
        empty_element._oe.F_ANGLE = 0

        return empty_element
Beispiel #7
0
    def get_output_beam(self, focused_beam):

        empty_element = ShadowOpticalElement.create_empty_oe()

        empty_element._oe.DUMMY = 1.0 # self.workspace_units_to_cm

        empty_element._oe.T_SOURCE     = 0.0
        empty_element._oe.T_IMAGE      = self.image_plane_distance
        empty_element._oe.T_INCIDENCE  = 0.0
        empty_element._oe.T_REFLECTION = 180.0
        empty_element._oe.ALPHA        = 0.0

        empty_element._oe.FWRITE = 3
        empty_element._oe.F_ANGLE = 0

        return ShadowBeam.traceFromOE(focused_beam, empty_element, history=True)
Beispiel #8
0
    def traceOpticalElement(self):
        try:
            self.error(self.error_id)
            self.setStatusMessage("")
            self.progressBarInit()

            if ShadowCongruence.checkEmptyBeam(self.input_beam):
                if ShadowCongruence.checkGoodBeam(self.input_beam):
                    sys.stdout = EmittingStream(textWritten=self.writeStdOut)

                    self.progressBarSet(10)

                    self.checkFields()

                    self.setStatusMessage("Running SHADOW")

                    if self.trace_shadow:
                        grabber = TTYGrabber()
                        grabber.start()

                    self.progressBarSet(50)

                    ###########################################
                    # TODO: TO BE ADDED JUST IN CASE OF BROKEN
                    #       ENVIRONMENT: MUST BE FOUND A PROPER WAY
                    #       TO TEST SHADOW
                    self.fixWeirdShadowBug()
                    ###########################################

                    shadow_oe_1 = ShadowOpticalElement.create_screen_slit()
                    self.populateFields_1(shadow_oe_1)

                    beam_out = ShadowBeam.traceFromOE(self.input_beam, shadow_oe_1)

                    self.adjust_first_divergence(beam_out)

                    self.progressBarSet(60)

                    shadow_oe_2 = ShadowOpticalElement.create_screen_slit()
                    self.populateFields_2(shadow_oe_2)

                    beam_out = ShadowBeam.traceFromOE(beam_out, shadow_oe_2)

                    self.adjust_second_divergence_and_intensity(beam_out)

                    self.progressBarSet(70)

                    shadow_oe_3 = ShadowOpticalElement.create_screen_slit()
                    self.populateFields_3(shadow_oe_3)

                    beam_out = ShadowBeam.traceFromOE(beam_out, shadow_oe_3)

                    if self.trace_shadow:
                        grabber.stop()

                        for row in grabber.ttyData:
                            self.writeStdOut(row)

                    self.setStatusMessage("Plotting Results")

                    self.plot_results(beam_out)

                    self.setStatusMessage("")

                    self.send("Beam", beam_out)
                    self.send("Trigger", TriggerIn(new_object=True))
                else:
                    raise Exception("Input Beam with no good rays")
            else:
                raise Exception("Empty Input Beam")

        except Exception as exception:
            QtWidgets.QMessageBox.critical(self, "QMessageBox.critical()",
                                       str(exception),
                                       QtWidgets.QMessageBox.Ok)

            self.error_id = self.error_id + 1
            self.error(self.error_id, "Exception occurred: " + str(exception))

        self.progressBarFinished()
Beispiel #9
0
def sh_read_gfile(gfilename):
    return ShadowOpticalElement.create_oe_from_file(congruence.checkFile(gfilename))
Beispiel #10
0
        go, 7] = focused_beam._beam.rays[go, 7] * efficiency_weight_factor[:]
    focused_beam._beam.rays[
        go, 8] = focused_beam._beam.rays[go, 8] * efficiency_weight_factor[:]
    focused_beam._beam.rays[
        go, 15] = focused_beam._beam.rays[go, 15] * efficiency_weight_factor[:]
    focused_beam._beam.rays[
        go, 16] = focused_beam._beam.rays[go, 16] * efficiency_weight_factor[:]
    focused_beam._beam.rays[
        go, 17] = focused_beam._beam.rays[go, 17] * efficiency_weight_factor[:]

    return focused_beam


#################################

empty_element = ShadowOpticalElement.create_empty_oe()

empty_element._oe.DUMMY = 1.0  # self.workspace_units_to_cm

empty_element._oe.T_SOURCE = source_plane_distance
empty_element._oe.T_IMAGE = 0.0
empty_element._oe.T_INCIDENCE = 0.0
empty_element._oe.T_REFLECTION = 180.0
empty_element._oe.ALPHA = 0.0

empty_element._oe.FWRITE = 3
empty_element._oe.F_ANGLE = 0

n_screen = 1
i_screen = numpy.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
i_abs = numpy.zeros(10)
 def instantiateShadowOE(self):
     return ShadowOpticalElement.create_ellipsoid_mirror()
    def traceOpticalElement(self):
        try:
            self.error(self.error_id)
            self.setStatusMessage("")
            self.progressBarInit()

            if ShadowCongruence.checkEmptyBeam(self.input_beam):
                if ShadowCongruence.checkGoodBeam(self.input_beam):
                    sys.stdout = EmittingStream(textWritten=self.writeStdOut)

                    self.progressBarSet(10)

                    self.checkFields()

                    self.setStatusMessage("Running SHADOW")

                    if self.trace_shadow:
                        grabber = TTYGrabber()
                        grabber.start()

                    self.progressBarSet(50)

                    ###########################################
                    # TODO: TO BE ADDED JUST IN CASE OF BROKEN
                    #       ENVIRONMENT: MUST BE FOUND A PROPER WAY
                    #       TO TEST SHADOW
                    self.fixWeirdShadowBug()
                    ###########################################

                    shadow_oe_1 = ShadowOpticalElement.create_screen_slit()
                    self.populateFields_1(shadow_oe_1)

                    beam_out = ShadowBeam.traceFromOE(self.input_beam, shadow_oe_1)

                    self.adjust_first_divergence(beam_out)

                    self.progressBarSet(60)

                    shadow_oe_2 = ShadowOpticalElement.create_screen_slit()
                    self.populateFields_2(shadow_oe_2)

                    beam_out = ShadowBeam.traceFromOE(beam_out, shadow_oe_2)

                    self.adjust_second_divergence_and_intensity(beam_out)

                    self.progressBarSet(70)

                    shadow_oe_3 = ShadowOpticalElement.create_screen_slit()
                    self.populateFields_3(shadow_oe_3)

                    beam_out = ShadowBeam.traceFromOE(beam_out, shadow_oe_3)

                    if self.trace_shadow:
                        grabber.stop()

                        for row in grabber.ttyData:
                            self.writeStdOut(row)

                    self.setStatusMessage("Plotting Results")

                    self.plot_results(beam_out)

                    self.setStatusMessage("")

                    self.send("Beam", beam_out)
                    self.send("Trigger", ShadowTriggerIn(new_beam=True))
                else:
                    raise Exception("Input Beam with no good rays")
            else:
                raise Exception("Empty Input Beam")

        except Exception as exception:
            QtGui.QMessageBox.critical(self, "QMessageBox.critical()",
                                       str(exception),
                                       QtGui.QMessageBox.Ok)

            self.error_id = self.error_id + 1
            self.error(self.error_id, "Exception occurred: " + str(exception))

        self.progressBarFinished()