oasys-elettra-kit / OASYS1-Wiser

The implementation of WISER into OASYS
MIT License
0 stars 1 forks source link

Slits GUI bug #19

Closed aljosahafner closed 4 years ago

aljosahafner commented 4 years ago

There is some bug with slits in the GUI...

image image

aljosahafner commented 4 years ago

This requires further attention!

the function for calculating do_wise_calculation(), located in orangecontrib/OasysWiser/widgets/gui/ow_optical_element.py, is not compliant with the slits (or better, slits aren't compatible with this function), because it contains all kind of properties (FigureError, etc.) that aren't present in class Slits(). class Slits() has OpticsNumerical as parent.

def do_wise_calculation(self):
        if self.input_data is None:
            raise Exception("No Input Data!")

        optical_element = self.get_optical_element(self.get_native_optical_element())

        native_optical_element = optical_element.native_optical_element

        if native_optical_element.Name == None:
            raise ValueError("No native_optical_element found")

        native_optical_element.CoreOptics.ComputationSettings.Ignore = (self.ignore == 1)
        native_optical_element.CoreOptics.Orientation = self.Orientation # Set orientation

        if self.use_small_displacements == 1:
            native_optical_element.CoreOptics.ComputationSettings.UseSmallDisplacements = True # serve per traslare/ruotare l'EO
            native_optical_element.CoreOptics.SmallDisplacements.Rotation = numpy.deg2rad(self.rotation)
            native_optical_element.CoreOptics.SmallDisplacements.Trans = self.transverse*self.workspace_units_to_m # Transverse displacement (rispetto al raggio uscente, magari faremo scegliere)
            native_optical_element.CoreOptics.SmallDisplacements.Long = self.longitudinal*self.workspace_units_to_m # Longitudinal displacement (idem)
        else:
            native_optical_element.CoreOptics.ComputationSettings.UseSmallDisplacements = False
            native_optical_element.CoreOptics.SmallDisplacements.Rotation = 0.0
            native_optical_element.CoreOptics.SmallDisplacements.Trans = 0.0
            native_optical_element.CoreOptics.SmallDisplacements.Long = 0.0

        if self.use_figure_error == 1:
            native_optical_element.CoreOptics.ComputationSettings.UseFigureError = True

            native_optical_element.CoreOptics.FigureErrorLoad(File = self.figure_error_file,
                                                              Step = self.figure_error_step * self.workspace_units_to_m, # passo del file
                                                              AmplitudeScaling = self.figure_error_amplitude_scaling * self.figure_error_um_conversion # fattore di scala
                                                              )
        else:
            native_optical_element.CoreOptics.ComputationSettings.UseFigureError = False

        if self.use_roughness == 1:
            self.use_roughness = 0
            self.set_UseRoughness()

            raise NotImplementedError("Roughness Not yet supported")
        else:
            native_optical_element.CoreOptics.ComputationSettings.UseRoughness = False

        if self.calculation_type == 0:
            native_optical_element.ComputationSettings.UseCustomSampling = False
        else:
            # l'utente decide di impostare a mano il campionamento
            native_optical_element.ComputationSettings.UseCustomSampling = True
            native_optical_element.ComputationSettings.NSamples = self.number_of_points

        output_data = self.input_data.duplicate()

        # if output_data != self.input_data:
        #     raise ValueError("duplicate() does not work")

        input_wavefront = output_data.wise_wavefront

        if output_data.wise_beamline is None: output_data.wise_beamline = WisePropagationElements()

        output_data.wise_beamline.add_beamline_element(WiserBeamlineElement(optical_element=optical_element))

        parameters = PropagationParameters(wavefront=input_wavefront if not input_wavefront is None else WiseWavefront(wise_computation_results=None),
                                           propagation_elements=output_data.wise_beamline)

        parameters.set_additional_parameters("single_propagation", True if PropagationManager.Instance().get_propagation_mode(WISE_APPLICATION) == PropagationMode.STEP_BY_STEP else (not self.is_full_propagator))
        parameters.set_additional_parameters("NPools", self.n_pools if self.use_multipool == 1 else 1)
        parameters.set_additional_parameters("is_full_propagator", self.is_full_propagator)

        # print("I came until here!")
        # print(output_data.wise_beamline.get_wise_propagation_elements())

        output_data.wise_wavefront = PropagationManager.Instance().do_propagation(propagation_parameters=parameters, handler_name=WisePropagator.HANDLER_NAME)

        return output_data
capitanevs commented 4 years ago

We have to discuss this on zoom.

I see that do_computations has a "manager structure", which means that he has a lot of "if" switching different cases. Normally do not like it (I prefer inheritance for instance), but it is a valid passepartout.

The "Slit" class should be compliant with such a structure, since slits inherits OpticsNumerical. So if UseFigureError==False, the code should work.

However do_wiser_computation is doing too many stuff here:

It a) gets info from GUI and puts to LibWiser (can this stuff be put closer to init?) b) handles Widget-Specific stuff (like figure error) c) truly perform computations.

I would try to put a) and b) in dedicated functions, which are separate from "propagation stuff". Where to put a) is linked to the question: where we init the LibWiser optical element.

For instance, what the user typically expect is to load the figure error then visualize it BEFORE doing the computation. We can not put this feature now, but it is just to say that it is better to handle the figure error separatedly.

Then b) is a complex self-standing operation and deserves its own function. LibWiser already has useful code

c) initializes and runs the computation.

capitanevs commented 4 years ago

The bug in red, is due to the fact that somewhere in the code SmallDisplacements =true/false. Perhaps was UseSmallDisplacements = true/false?

aljosahafner commented 4 years ago

Slits also has no FigureErrors property, maybe we can add it as FigureErrors = []? image

I solved the other one, SmallDisplacements wasn't specified in Slits before, now it's set to False.

aljosahafner commented 4 years ago

image

aljosahafner commented 4 years ago

Adding FigureErrors the code runs fine!