def callResetSettings(self):
     if ConfirmDialog.confirmed(parent=self, message="Confirm Reset of the accumulated beam"):
         self.current_number_of_rays = 0
         self.current_intensity = 0.0
         self.current_number_of_lost_rays = 0
         self.current_number_of_total_rays = 0
         self.input_beam = None
Пример #2
0
    def crl_insert_after(self):
        current_index = self.tab_crls.currentIndex()

        if ConfirmDialog.confirmed(
                parent=self,
                message="Confirm Insertion of a new element after " +
                self.tab_crls.tabText(current_index) + "?"):
            tab_crl = oasysgui.widgetBox(self.tab_crls,
                                         addToLayout=0,
                                         margin=4)
            crl_box = CRLBox(transfocator=self, parent=tab_crl)
            crl_box.after_change_workspace_units()

            if current_index == self.tab_crls.count() - 1:  # LAST
                self.tab_crls.addTab(tab_crl, "TEMP")
                self.crl_box_array.append(crl_box)
            else:
                self.tab_crls.insertTab(current_index + 1, tab_crl, "TEMP")
                self.crl_box_array.insert(current_index + 1, crl_box)

            self.dumpSettings()

            for index in range(current_index, self.tab_crls.count()):
                self.tab_crls.setTabText(index, "C.R.L " + str(index + 1))

            self.tab_crls.setCurrentIndex(current_index + 1)
Пример #3
0
 def clearResults(self):
     if ConfirmDialog.confirmed(parent=self):
         self.input_beam = ShadowBeam()
         self.plot_canvas.clear()
         return True
     else:
         return False
Пример #4
0
 def callResetSettings(self):
     if ConfirmDialog.confirmed(parent=self, message="Confirm Reset of the accumulated beam"):
         self.current_number_of_rays = 0
         self.current_intensity = 0.0
         self.current_number_of_lost_rays = 0
         self.current_number_of_total_rays = 0
         self.input_beam = None
Пример #5
0
    def callResetSettings(self):
        if ConfirmDialog.confirmed(parent=self,
                                   message="Confirm Reset of the Fields?"):
            self.resetSettings()

            while self.tab_crystals.count() > 0:
                self.tab_crystals.removeTab(0)

            tab_first_crystal = oasysgui.widgetBox(self.tab_crystals,
                                                   addToLayout=0,
                                                   margin=4)
            tab_second_crystal = oasysgui.widgetBox(self.tab_crystals,
                                                    addToLayout=0,
                                                    margin=4)

            self.crystal_1_box = CrystalBox(
                dcm=self,
                parent=tab_first_crystal,
                has_finite_dimensions=self.has_finite_dimensions[0],
                dimensions=self.dimensions[0])

            self.crystal_2_box = CrystalBox(
                dcm=self,
                parent=tab_second_crystal,
                has_finite_dimensions=self.has_finite_dimensions[1],
                dimensions=self.dimensions[1])

            self.tab_crystals.addTab(tab_first_crystal, "First Crystal")
            self.tab_crystals.addTab(tab_second_crystal, "Second Crystal")

            self.setupUI()
Пример #6
0
 def call_reset_settings(self):
     if ConfirmDialog.confirmed(parent=self, message="Confirm Reset of the Fields?"):
         try:
             self.resetSettings()
             self.reload_harmonics_table()
         except:
             pass
Пример #7
0
    def read_or_write_file(self):

        value = self.H5_FILE_DUMP

        if value == 0:
            return
        elif value == 1:  # write
            return
        elif value == 2:  # read

            self.H5_FILE_DUMP = 0

            tmp = ConfirmDialog.confirmed(
                self,
                message=
                "Please select in a hdf5 file a data block\n(such as XOPPY_RADIATION)\nthat contains a 'Radiation' entry",
                title="Confirm Action")
            if tmp == False: return

            dialog = DataFileDialog(self)
            dialog.setFilterMode(DataFileDialog.FilterMode.ExistingGroup)
            # dialog.setDirectory("")
            # Execute the dialog as modal
            result = dialog.exec_()

            if result:
                print("Selection:")
                print(dialog.selectedFile())
                print(dialog.selectedUrl())
                print(dialog.selectedDataUrl().data_path())

                calculation_output = self.extract_data_from_h5file(
                    dialog.selectedFile(),
                    dialog.selectedDataUrl().data_path())

                if calculation_output is None:
                    raise Exception("Bad data from file.")
                else:
                    self.calculated_data = self.extract_data_from_xoppy_output(
                        calculation_output)

                    try:
                        self.set_fields_from_h5file(
                            dialog.selectedFile(),
                            dialog.selectedDataUrl().data_path())
                    except:
                        pass

                    # self.add_specific_content_to_calculated_data(self.calculated_data)
                    #
                    self.setStatusMessage("Plotting Results")

                    self.plot_results(self.calculated_data,
                                      progressBarValue=60)

                    self.setStatusMessage("")

                    self.send("xoppy_data", self.calculated_data)

                self.set_enabled(True)
Пример #8
0
 def call_reset_settings(self):
     if ConfirmDialog.confirmed(parent=self,
                                message="Confirm Reset of the Fields?"):
         try:
             self.resetSettings()
         except:
             pass
    def setBeam(self, beam):
        if ShadowCongruence.checkEmptyBeam(beam):
            proceed = True

            if not ShadowCongruence.checkGoodBeam(beam):
                if not ConfirmDialog.confirmed(
                        parent=self,
                        message="Beam contains bad values, skip it?"):
                    proceed = False

            if proceed:
                scanned_variable_data = beam.scanned_variable_data

                go = numpy.where(beam._beam.rays[:, 9] == 1)

                nr_good = len(beam._beam.rays[go])
                nr_total = len(beam._beam.rays)
                nr_lost = nr_total - nr_good
                intensity = beam._beam.histo1(1, nolost=1, ref=23)['intensity']

                self.current_number_of_rays += nr_good
                self.current_intensity += intensity
                self.le_current_intensity.setText("{:10.3f}".format(
                    self.current_intensity))
                self.current_number_of_lost_rays += nr_lost
                self.current_number_of_total_rays += nr_total

                if (self.kind_of_accumulation == 0 and self.current_number_of_rays <= self.number_of_accumulated_rays) or \
                   (self.kind_of_accumulation == 1 and self.current_intensity <= self.number_of_accumulated_rays):
                    if self.keep_go_rays == 1:
                        beam._beam.rays = copy.deepcopy(beam._beam.rays[go])

                    if not self.input_beam is None:
                        self.input_beam = ShadowBeam.mergeBeams(
                            self.input_beam, beam)
                    else:
                        beam._beam.rays[:, 11] = numpy.arange(
                            1,
                            len(beam._beam.rays) + 1, 1)  # ray_index
                        self.input_beam = beam

                    self.input_beam.setScanningData(scanned_variable_data)

                    self.send("Trigger", TriggerIn(new_object=True))
                else:
                    if self.is_automatic_run:
                        self.sendSignal()

                        self.current_number_of_rays = 0
                        self.current_intensity = 0.0
                        self.current_number_of_lost_rays = 0
                        self.current_number_of_total_rays = 0
                        self.input_beam = None
                    else:
                        QtWidgets.QMessageBox.critical(
                            self, "Error",
                            "Number of Accumulated Rays reached, please push \'Send Signal\' button",
                            QtWidgets.QMessageBox.Ok)
Пример #10
0
    def clearResults(self):
        if ConfirmDialog.confirmed(parent=self):
            self.input_beam = None
            if not self.plot_canvas is None:
                self.plot_canvas.clear()

            return True
        else:
            return False
Пример #11
0
 def stopLoop(self):
     try:
         if ConfirmDialog.confirmed(
                 parent=self, message="Confirm Interruption of the Loop?"):
             self.run_loop = False
             self.reset_values()
             self.setStatusMessage("Interrupted by user")
     except Exception as e:
         if self.IS_DEVELOP: raise e
         else: pass
Пример #12
0
 def suspendLoop(self):
     try:
         if ConfirmDialog.confirmed(parent=self, message="Confirm Suspension of the Loop?"):
             self.run_loop = False
             self.suspend_loop = True
             self.stop_button.setEnabled(False)
             self.re_start_button.setEnabled(True)
             self.setStatusMessage("Suspended by user")
     except:
         pass
Пример #13
0
    def read_or_write_file(self):

        value = self.H5_FILE_DUMP

        if value == 0:
            return
        elif value == 1: # write
            return
        elif value == 2: # read

            self.H5_FILE_DUMP = 0


            tmp = ConfirmDialog.confirmed(self,
                    message="Please select in a hdf5 file a data block\n(such as XOPPY_RADIATION)\nthat contains a 'Radiation' entry",
                    title="Confirm Action")
            if tmp == False: return

            dialog = DataFileDialog(self)
            dialog.setFilterMode(DataFileDialog.FilterMode.ExistingGroup)
            # dialog.setDirectory("")
            # Execute the dialog as modal
            result = dialog.exec_()

            if result:
                print("Selection:")
                print(dialog.selectedFile())
                print(dialog.selectedUrl())
                print(dialog.selectedDataUrl().data_path())

                calculation_output = self.extract_data_from_h5file(dialog.selectedFile(), dialog.selectedDataUrl().data_path() )


                if calculation_output is None:
                    raise Exception("Bad data from file.")
                else:
                    self.calculated_data = self.extract_data_from_xoppy_output(calculation_output)

                    try:
                        self.set_fields_from_h5file(dialog.selectedFile(), dialog.selectedDataUrl().data_path())
                    except:
                        pass

                    # self.add_specific_content_to_calculated_data(self.calculated_data)
                    #
                    self.setStatusMessage("Plotting Results")

                    self.plot_results(self.calculated_data, progressBarValue=60)

                    self.setStatusMessage("")

                    self.send("xoppy_data", self.calculated_data)


                self.set_enabled(True)
Пример #14
0
    def clearResults(self, interactive=True):
        if not interactive: proceed = True
        else: proceed = ConfirmDialog.confirmed(parent=self)

        if proceed:
            self.input_beam = ShadowBeam()
            self.cumulated_ticket = None
            self.plotted_ticket = None
            self.autosave_prog_id = 0
            if not self.autosave_file is None:
                self.autosave_file.close()
                self.autosave_file = None

            self.plot_canvas.clear()
    def setBeam(self, beam):
        if ShadowCongruence.checkEmptyBeam(beam):
            proceed = True

            if not ShadowCongruence.checkGoodBeam(beam):
                if not ConfirmDialog.confirmed(parent=self, message="Beam contains bad values, skip it?"):
                    proceed = False

            if proceed:
                go = numpy.where(beam._beam.rays[:, 9] == 1)

                nr_good = len(beam._beam.rays[go])
                nr_total = len(beam._beam.rays)
                nr_lost = nr_total - nr_good
                intensity = beam._beam.histo1(1, nolost=1, ref=23)['intensity']

                self.current_number_of_rays += nr_good
                self.current_intensity += intensity
                self.le_current_intensity.setText("{:10.3f}".format(self.current_intensity))
                self.current_number_of_lost_rays += nr_lost
                self.current_number_of_total_rays += nr_total



                if (self.kind_of_accumulation == 0 and self.current_number_of_rays <= self.number_of_accumulated_rays) or \
                   (self.kind_of_accumulation == 1 and self.current_intensity <= self.number_of_accumulated_rays):
                    if self.keep_go_rays == 1:
                        beam._beam.rays = copy.deepcopy(beam._beam.rays[go])

                    if not self.input_beam is None:
                        self.input_beam = ShadowBeam.mergeBeams(self.input_beam, beam)
                    else:
                        beam._beam.rays[:, 11] = numpy.arange(1, len(beam._beam.rays) + 1, 1) # ray_index
                        self.input_beam = beam

                    self.send("Trigger", ShadowTriggerIn(new_beam=True))
                else:
                    if self.is_automatic_run:
                        self.sendSignal()

                        self.current_number_of_rays = 0
                        self.current_intensity = 0.0
                        self.current_number_of_lost_rays = 0
                        self.current_number_of_total_rays = 0
                        self.input_beam = None
                    else:
                        QtGui.QMessageBox.critical(self, "Error",
                                                   "Number of Accumulated Rays reached, please push \'Send Signal\' button",
                                                   QtGui.QMessageBox.Ok)
Пример #16
0
    def crl_insert_before(self):
        current_index = self.tab_crls.currentIndex()

        if ConfirmDialog.confirmed(parent=self, message="Confirm Insertion of a new element before " + self.tab_crls.tabText(current_index) + "?"):
            tab_crl = oasysgui.widgetBox(self.tab_crls, addToLayout=0, margin=4)
            crl_box = CRLBox(transfocator=self, parent=tab_crl)
            crl_box.after_change_workspace_units()

            self.tab_crls.insertTab(current_index, tab_crl, "TEMP")
            self.crl_box_array.insert(current_index, crl_box)
            self.dumpSettings()

            for index in range(current_index, self.tab_crls.count()):
                self.tab_crls.setTabText(index, "C.R.L " + str(index + 1))

            self.tab_crls.setCurrentIndex(current_index)
Пример #17
0
    def clearResults(self, interactive=True):
        if not interactive: proceed = True
        else: proceed = ConfirmDialog.confirmed(parent=self)

        if proceed:
            self.input_beam = None
            self.cumulated_ticket = None
            self.plotted_ticket = None
            self.energy_min = None
            self.energy_max = None
            self.energy_step = None
            self.total_power = None
            self.cumulated_total_power = None

            if not self.plot_canvas is None:
                self.plot_canvas.clear()
Пример #18
0
    def crl_remove(self):
        if self.tab_crls.count() <= 1:
            QtGui.QMessageBox.critical(self, "Error",
                                       "Remove not possible, transfocator needs at least 1 element",
                                       QtGui.QMessageBox.Ok)
        else:
            current_index = self.tab_crls.currentIndex()

            if ConfirmDialog.confirmed(parent=self, message="Confirm Removal of " + self.tab_crls.tabText(current_index) + "?"):
                self.tab_crls.removeTab(current_index)
                self.crl_box_array.pop(current_index)
                self.dumpSettings()

                for index in range(current_index, self.tab_crls.count()):
                    self.tab_crls.setTabText(index, "C.R.L " + str(index + 1))

                self.tab_crls.setCurrentIndex(current_index)
Пример #19
0
    def callResetSettings(self):
        if ConfirmDialog.confirmed(parent=self,
                                   message="Confirm Reset of the Fields?"):
            self.resetSettings()

            while self.tab_mirrors.count() > 0:
                self.tab_mirrors.removeTab(0)

            tab_vertical = oasysgui.widgetBox(self.tab_mirrors,
                                              addToLayout=0,
                                              margin=4)
            tab_horizontal = oasysgui.widgetBox(self.tab_mirrors,
                                                addToLayout=0,
                                                margin=4)

            self.v_box = MirrorBox(
                kb=self,
                parent=tab_vertical,
                grazing_angles_mrad=self.grazing_angles_mrad[0],
                shape=self.shape[0],
                has_finite_dimensions=self.has_finite_dimensions[0],
                dimensions=self.dimensions[0],
                reflectivity_kind=self.reflectivity_kind[0],
                reflectivity_files=self.reflectivity_files[0],
                has_surface_error=self.has_surface_error[0],
                surface_error_files=self.surface_error_files[0])

            self.h_box = MirrorBox(
                kb=self,
                parent=tab_horizontal,
                grazing_angles_mrad=self.grazing_angles_mrad[1],
                shape=self.shape[1],
                has_finite_dimensions=self.has_finite_dimensions[1],
                dimensions=self.dimensions[1],
                reflectivity_kind=self.reflectivity_kind[1],
                reflectivity_files=self.reflectivity_files[1],
                has_surface_error=self.has_surface_error[1],
                surface_error_files=self.surface_error_files[1])

            self.tab_mirrors.addTab(tab_vertical, "Vertical Focusing Mirror")
            self.tab_mirrors.addTab(tab_horizontal,
                                    "Horizontal Focusing Mirror")

            self.setupUI()
Пример #20
0
    def callResetSettings(self):
        if ConfirmDialog.confirmed(
                parent=self,
                message=
                "Confirm Reset of the Fields?\n\nWarning: C.R.L. stack will be regenerated"
        ):
            self.resetSettings()

            while self.tab_crls.count() > 0:
                self.tab_crls.removeTab(0)

            self.crl_box_array = []

            for index in range(len(self.p)):
                tab_crl = oasysgui.widgetBox(self.tab_crls,
                                             addToLayout=0,
                                             margin=4)
                crl_box = CRLBox(
                    transfocator=self,
                    parent=tab_crl,
                    nlenses=self.nlenses[index],
                    slots_empty=self.slots_empty[index],
                    thickness=self.thickness[index],
                    p=self.p[index],
                    q=self.q[index],
                    surface_shape=self.surface_shape[index],
                    convex_to_the_beam=self.convex_to_the_beam[index],
                    has_finite_diameter=self.has_finite_diameter[index],
                    diameter=self.diameter[index],
                    is_cylinder=self.is_cylinder[index],
                    cylinder_angle=self.cylinder_angle[index],
                    ri_calculation_mode=self.ri_calculation_mode[index],
                    prerefl_file=self.prerefl_file[index],
                    refraction_index=self.refraction_index[index],
                    attenuation_coefficient=self.
                    attenuation_coefficient[index],
                    radius=self.radius[index],
                    interthickness=self.interthickness[index],
                    use_ccc=self.use_ccc[index])

                self.tab_crls.addTab(tab_crl, "C.R.L " + str(index + 1))
                self.crl_box_array.append(crl_box)

            self.setupUI()
Пример #21
0
    def crl_remove(self):
        if self.tab_crls.count() <= 1:
            QMessageBox.critical(
                self, "Error",
                "Remove not possible, transfocator needs at least 1 element",
                QMessageBox.Ok)
        else:
            current_index = self.tab_crls.currentIndex()

            if ConfirmDialog.confirmed(parent=self,
                                       message="Confirm Removal of " +
                                       self.tab_crls.tabText(current_index) +
                                       "?"):
                self.tab_crls.removeTab(current_index)
                self.crl_box_array.pop(current_index)
                self.dumpSettings()

                for index in range(current_index, self.tab_crls.count()):
                    self.tab_crls.setTabText(index, "C.R.L " + str(index + 1))

                self.tab_crls.setCurrentIndex(current_index)
Пример #22
0
    def xoppy_write_txt(self, calculated_data, method="3columns"):

        p0, e0, h0, v0 = self.input_beam.get_content("xoppy_data")
        p = p0.copy()
        p_spectral_power = p * codata.e * 1e3
        transmittance, absorbance, E, H, V = calculated_data

        if (os.path.splitext(self.FILE_NAME))[-1] not in [".txt",".dat",".TXT",".DAT"]:
            filename_alternative = (os.path.splitext(self.FILE_NAME))[0] + ".txt"
            tmp = ConfirmDialog.confirmed(self,
                                      message="Invalid file extension in output file: \n%s\nIt must be: .txt, .dat, .TXT, .DAT\nChange to: %s ?"%(self.FILE_NAME,filename_alternative),
                                      title="Invalid file extension")
            if tmp == False: return
            self.FILE_NAME = filename_alternative

        absorbed3d = p_spectral_power * absorbance / (H[0] / h0[0]) / (V[0] / v0[0])
        absorbed2d = numpy.trapz(absorbed3d, E, axis=0)

        f = open(self.FILE_NAME, 'w')
        if method == "3columns":
            for i in range(H.size):
                for j in range(V.size):
                    f.write("%g  %g  %g\n" % (H[i]*1e-3, V[i]*1e-3, absorbed2d[i,j]*1e6))
        elif method == "matrix":
            f.write("%10.5g" % 0)
            for i in range(H.size):
                f.write(", %10.5g" % (H[i] * 1e-3))
            f.write("\n")

            for j in range(V.size):
                    f.write("%10.5g" % (V[j] * 1e-3))
                    for i in range(H.size):
                        f.write(", %10.5g" % (absorbed2d[i,j] * 1e6))
                    f.write("\n")
        else:
            raise Exception("File type not understood.")
        f.close()

        print("File written to disk: %s" % self.FILE_NAME)
Пример #23
0
    def callResetSettings(self):
        if ConfirmDialog.confirmed(parent=self, message="Confirm Reset of the Fields?"):
            self.resetSettings()

            while self.tab_mirrors.count() > 0:
                self.tab_mirrors.removeTab(0)

            tab_vertical = oasysgui.widgetBox(self.tab_mirrors, addToLayout=0, margin=4)
            tab_horizontal = oasysgui.widgetBox(self.tab_mirrors, addToLayout=0, margin=4)

            self.v_box = MirrorBox(kb=self,
                                   parent=tab_vertical,
                                   grazing_angles_mrad=self.grazing_angles_mrad[0],
                                   shape=self.shape[0],
                                   has_finite_dimensions=self.has_finite_dimensions[0],
                                   dimensions=self.dimensions[0],
                                   reflectivity_kind=self.reflectivity_kind[0],
                                   reflectivity_files=self.reflectivity_files[0],
                                   has_surface_error=self.has_surface_error[0],
                                   surface_error_files=self.surface_error_files[0])

            self.h_box = MirrorBox(kb=self,
                                   parent=tab_horizontal,
                                   grazing_angles_mrad=self.grazing_angles_mrad[1],
                                   shape=self.shape[1],
                                   has_finite_dimensions=self.has_finite_dimensions[1],
                                   dimensions=self.dimensions[1],
                                   reflectivity_kind=self.reflectivity_kind[1],
                                   reflectivity_files=self.reflectivity_files[1],
                                   has_surface_error=self.has_surface_error[1],
                                   surface_error_files=self.surface_error_files[1])

            self.tab_mirrors.addTab(tab_vertical, "Vertical Focusing Mirror")
            self.tab_mirrors.addTab(tab_horizontal, "Horizontal Focusing Mirror")

            self.setupUI()
Пример #24
0
    def callResetSettings(self):
        if ConfirmDialog.confirmed(parent=self, message="Confirm Reset of the Fields?"):
            self.resetSettings()

            while self.tab_crystals.count() > 0:
                self.tab_crystals.removeTab(0)

            tab_first_crystal = oasysgui.widgetBox(self.tab_crystals, addToLayout=0, margin=4)
            tab_second_crystal = oasysgui.widgetBox(self.tab_crystals, addToLayout=0, margin=4)

            self.crystal_1_box = CrystalBox(dcm=self,
                                            parent=tab_first_crystal,
                                            has_finite_dimensions=self.has_finite_dimensions[0],
                                            dimensions=self.dimensions[0])

            self.crystal_2_box = CrystalBox(dcm=self,
                                            parent=tab_second_crystal,
                                            has_finite_dimensions=self.has_finite_dimensions[1],
                                            dimensions=self.dimensions[1])

            self.tab_crystals.addTab(tab_first_crystal, "First Crystal")
            self.tab_crystals.addTab(tab_second_crystal, "Second Crystal")

            self.setupUI()
Пример #25
0
    def callResetSettings(self):
        if ConfirmDialog.confirmed(parent=self, message="Confirm Reset of the Fields?\n\nWarning: C.R.L. stack will be regenerated"):
            self.resetSettings()

            while self.tab_crls.count() > 0:
                self.tab_crls.removeTab(0)

            self.crl_box_array = []

            for index in range(len(self.p)):
                tab_crl = oasysgui.widgetBox(self.tab_crls, addToLayout=0, margin=4)
                crl_box = CRLBox(transfocator=self,
                                 parent=tab_crl,
                                 nlenses=self.nlenses[index],
                                 slots_empty=self.slots_empty[index],
                                 thickness=self.thickness[index],
                                 p=self.p[index],
                                 q=self.q[index],
                                 surface_shape=self.surface_shape[index],
                                 convex_to_the_beam=self.convex_to_the_beam[index],
                                 has_finite_diameter=self.has_finite_diameter[index],
                                 diameter=self.diameter[index],
                                 is_cylinder=self.is_cylinder[index],
                                 cylinder_angle=self.cylinder_angle[index],
                                 ri_calculation_mode=self.ri_calculation_mode[index],
                                 prerefl_file=self.prerefl_file[index],
                                 refraction_index=self.refraction_index[index],
                                 attenuation_coefficient=self.attenuation_coefficient[index],
                                 radius=self.radius[index],
                                 interthickness=self.interthickness[index],
                                 use_ccc=self.use_ccc[index])

                self.tab_crls.addTab(tab_crl, "C.R.L " + str(index + 1))
                self.crl_box_array.append(crl_box)

            self.setupUI()
Пример #26
0
 def stopLoop(self):
     if ConfirmDialog.confirmed(parent=self, message="Confirm Interruption of the Loop?"):
         self.run_loop = False
         self.setStatusMessage("Interrupted by user")
 def clearResults(self):
     if ConfirmDialog.confirmed(parent=self):
         self.clear_data()
Пример #28
0
    def xoppy_write_h5file(self,calculated_data):

        p0, e0, h0, v0 = self.input_beam.get_content("xoppy_data")
        p = p0.copy()
        e = e0.copy()
        h = h0.copy()
        v = v0.copy()
        code = self.input_beam.get_content("xoppy_code")
        p_spectral_power = p * codata.e * 1e3
        transmittance, absorbance, E, H, V = calculated_data

        if (os.path.splitext(self.FILE_NAME))[-1] not in [".h5",".H5",".hdf5",".HDF5"]:
            filename_alternative = (os.path.splitext(self.FILE_NAME))[0] + ".h5"
            tmp = ConfirmDialog.confirmed(self,
                                      message="Invalid file extension in output file: \n%s\nIt must be: .h5, .H5, .hdf5, .HDF5\nChange to: %s ?"%(self.FILE_NAME,filename_alternative),
                                      title="Invalid file extension")
            if tmp == False: return
            self.FILE_NAME = filename_alternative

        try:
            h5w = H5SimpleWriter.initialize_file(self.FILE_NAME, creator="power3Dcomponent.py")
            txt = "\n\n\n"
            txt += self.info_total_power(p, e, v, h, transmittance, absorbance)
            h5w.add_key("info", txt, entry_name=None)
        except:
            print("ERROR writing h5 file (info)")


        try:
            #
            # source
            #
            entry_name = "source"

            h5w.create_entry(entry_name, nx_default=None)

            h5w.add_stack(e, h, v, p, stack_name="Radiation stack", entry_name=entry_name,
                          title_0="Photon energy [eV]",
                          title_1="X [mm] (normal to beam)",
                          title_2="Y [mm] (normal to beam)")

            h5w.add_image(numpy.trapz(p_spectral_power, E, axis=0) , H, V,
                          image_name="Power Density", entry_name=entry_name,
                          title_x="X [mm] (normal to beam)",
                          title_y="Y [mm] (normal to beam)")

            h5w.add_dataset(E, numpy.trapz(numpy.trapz(p_spectral_power, v, axis=2), h, axis=1),
                            entry_name=entry_name, dataset_name="Spectral power",
                            title_x="Photon Energy [eV]",
                            title_y="Spectral density [W/eV]")

        except:
            print("ERROR writing h5 file (source)")

        try:
            #
            # optical element
            #
            entry_name = "optical_element"

            h5w.create_entry(entry_name, nx_default=None)

            h5w.add_stack(E, H, V, transmittance, stack_name="Transmittance stack", entry_name=entry_name,
                          title_0="Photon energy [eV]",
                          title_1="X [mm] (o.e. coordinates)",
                          title_2="Y [mm] (o.e. coordinates)")

            absorbed = p_spectral_power * absorbance / (H[0] / h0[0]) / (V[0] / v0[0])
            h5w.add_image(numpy.trapz(absorbed, E, axis=0), H, V,
                          image_name="Absorbed Power Density on Element", entry_name=entry_name,
                          title_x="X [mm] (o.e. coordinates)",
                          title_y="Y [mm] (o.e. coordinates)")

            h5w.add_dataset(E, numpy.trapz(numpy.trapz(absorbed, v, axis=2), h, axis=1),
                            entry_name=entry_name, dataset_name="Absorbed Spectral Power",
                            title_x="Photon Energy [eV]",
                            title_y="Spectral density [W/eV]")

            #
            # transmitted
            #

            # coordinates to send: the same as incident beam (perpendicular to the optical axis)
            # except for the magnifier
            if self.EL1_FLAG == 3:  # magnifier <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                h *= self.EL1_HMAG
                v *= self.EL1_VMAG

            transmitted = p_spectral_power * transmittance / (h[0] / h0[0]) / (v[0] / v0[0])
            h5w.add_image(numpy.trapz(transmitted, E, axis=0), h, v,
                          image_name="Transmitted Power Density on Element", entry_name=entry_name,
                          title_x="X [mm] (normal to beam)",
                          title_y="Y [mm] (normal to beam)")

            h5w.add_dataset(E, numpy.trapz(numpy.trapz(transmitted, v, axis=2), h, axis=1),
                            entry_name=entry_name, dataset_name="Transmitted Spectral Power",
                            title_x="Photon Energy [eV]",
                            title_y="Spectral density [W/eV]")
        except:
            print("ERROR writing h5 file (optical element)")

        try:
            h5_entry_name = "XOPPY_RADIATION"

            h5w.create_entry(h5_entry_name,nx_default=None)
            h5w.add_stack(e, h, v, transmitted,stack_name="Radiation",entry_name=h5_entry_name,
                title_0="Photon energy [eV]",
                title_1="X gap [mm]",
                title_2="Y gap [mm]")
        except:
            print("ERROR writing h5 file (adding XOPPY_RADIATION)")



        print("File written to disk: %s" % self.FILE_NAME)
Пример #29
0
    def clearResults(self, interactive=True):
        if not interactive: proceed = True
        else: proceed = ConfirmDialog.confirmed(parent=self)

        if proceed:
            self.clear_data()
Пример #30
0
    def read_or_write_file(self):

        value = self.H5_FILE_DUMP

        if value == 0:
            return
        elif value == 1:  # write
            return
        elif value == 2:  # read

            self.H5_FILE_DUMP = 0

            use_silx_file_dialog = False  # silx dialog is freezing the linux system, change to traditional

            if use_silx_file_dialog:
                tmp = ConfirmDialog.confirmed(
                    self,
                    message=
                    "Please select in a hdf5 file a data block\n(such as XOPPY_RADIATION)\nthat contains a 'Radiation' entry",
                    title="Confirm Action")
                if tmp == False: return
                dialog = DataFileDialog(self)
                dialog.setFilterMode(DataFileDialog.FilterMode.ExistingGroup)
                result = dialog.exec_()
                if not result:
                    return
                print(dialog.selectedFile())
                print(dialog.selectedUrl())
                print(dialog.selectedDataUrl().data_path())
                calculation_output = self.extract_data_from_h5file(
                    dialog.selectedFile(),
                    dialog.selectedDataUrl().data_path())
                self.filename = dialog.selectedFile()
            else:
                tmp = ConfirmDialog.confirmed(
                    self,
                    message=
                    "Please select a hdf5 file containing a data block\n named XOPPY_RADIATION which includes 'Radiation' entry",
                    title="Confirm Action")
                if tmp == False: return

                self.filename = oasysgui.selectFileFromDialog(
                    self,
                    previous_file_path=self.filename,
                    message="Open hdf5 File",
                    start_directory="",
                    file_extension_filter="*.*5")
                if self.filename == "":
                    return

                try:
                    calculation_output = self.extract_data_from_h5file(
                        self.filename, "/XOPPY_RADIATION")
                except:
                    QMessageBox.critical(
                        self, "Error",
                        str("Failed to load hdf5 /XOPPY_RADIATION"),
                        QMessageBox.Ok)
                    calculation_output = None

            if calculation_output is None:
                QMessageBox.critical(self, "Error", str("Bad data from file."),
                                     QMessageBox.Ok)
            else:
                self.calculated_data = self.extract_data_from_xoppy_output(
                    calculation_output)
                try:
                    self.set_fields_from_h5file(self.filename,
                                                "/XOPPY_RADIATION")
                except:
                    QMessageBox.critical(
                        self, "Error",
                        "Failed to set fields hdf5 /XOPPY_RADIATION/parameters \n",
                        QMessageBox.Ok)

                # self.add_specific_content_to_calculated_data(self.calculated_data)
                #
                self.setStatusMessage("Plotting Results")

                self.plot_results(self.calculated_data, progressBarValue=60)

                self.setStatusMessage("")

                # p, e, h, v = self.calculated_data.get_content("xoppy_data")
                # traj = self.calculated_data.get_content("xoppy_data")
                # data_to_send = DataExchangeObject("XOPPY", self.get_data_exchange_widget_name())
                # data_to_send.add_content("xoppy_data", [p, e, h, v, traj])
                self.send("xoppy_data", self.calculated_data)

            self.set_enabled(True)
Пример #31
0
 def run_action(self):
     if ConfirmDialog.confirmed(self):
         self.send("my_output_data", "HI! I am a newborn widget!")
Пример #32
0
 def callResetSettings(self):
     if ConfirmDialog.confirmed(parent=self, message="Confirm Reset of the Fields?"):
         try:
             self.resetSettings()
         except:
             pass
 def stopLoop(self):
     if ConfirmDialog.confirmed(
             parent=self, message="Confirm Interruption of the Loop?"):
         self.run_loop = False
         self.current_value = None
         self.setStatusMessage("Interrupted by user")