oasys-elettra-kit / OASYS1-Wiser

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

GUI GetParent exception warning #10

Closed capitanevs closed 3 years ago

capitanevs commented 4 years ago

It happened to me to waste a lot of time in a script because I got this error (LibWiser) immagine

the reason was that I had a beamline with all HORIZONTAL optical elements, and I changed the orientation of the last two (focussing mirror and detector) but the source was not set to ISOTROPIC or ANY.

We could a) throw a proper warning in LibWiser ( Something like "No Optical Element with the same orientation found. Check Source orientation"). b) ensure that the source is alway isotropic/any in the GUI ?

capitanevs commented 4 years ago

The same error occurs when I use two detectors in tandem. This looks more like a 'bug'. The second one, can not automatically look for the "f2" of its mirror. I do not remember if it is a known issue or not.

Example (the relevant part is at the end)

# Source
s = OpticalElement(
            Name = 'FEL2',
            IsSource = True,
            CoreOpticsElement = Optics.SourceGaussian(
                    Lambda = Lambda,
                    Waist0 = Waist0,
                    Orientation = Optics.OPTICS_ORIENTATION.ISOTROPIC), # **kwargs
            PositioningDirectives = Foundation.PositioningDirectives(
                    ReferTo = 'absolute',
                    XYCentre = [0,0],
                    Angle = 0)
            )

#---kb_v
#------------------------------------------------------------
f11 = 87.9096
f21 = 1.8
kb_v = OpticalElement(
                Name = 'kb_v',
                CoreOpticsElement = Optics.MirrorElliptic(
                                                    L = 0.4,
                                                    f1 = f11,
                                                    f2 = f21,
                                                    Alpha = np.deg2rad(Angle_kb_deg),
                                                    Orientation = Optics.OPTICS_ORIENTATION.HORIZONTAL),
                PositioningDirectives = Foundation.PositioningDirectives(
                                                    PlaceWhat = 'upstream focus',
                                                    PlaceWhere = 'centre',
                                                    ReferTo = 'source'))

#---kb_h
#------------------------------------------------------------
kb_h = OpticalElement(
                Name = 'kb_h',
                CoreOpticsElement = Optics.MirrorElliptic(
                                                    L = 0.4,
                                                    f1 = 88.5096,
                                                    f2 = 1.25,
                                                    Alpha = np.deg2rad(Angle_kb_deg),
                                                    Orientation = Optics.OPTICS_ORIENTATION.HORIZONTAL),
                PositioningDirectives = Foundation.PositioningDirectives(
                                                    PlaceWhat = 'upstream focus',
                                                    PlaceWhere = 'centre',
                                                    ReferTo = 'source'))

#---Detector_h h
#------------------------------------------------------------
Detector_h = OpticalElement(
                Name = 'det_h',
                CoreOpticsElement = Optics.Detector(
                                                    L = DetectorSize,
                                                    AngleGrazing = np.deg2rad(90),
                                                    Orientation = Optics.OPTICS_ORIENTATION.HORIZONTAL),
                PositioningDirectives = Foundation.PositioningDirectives(
                                                    PlaceWhat = 'centre',
                                                    PlaceWhere = 'downstream focus',
                                                    ReferTo = 'upstream')
                            )
#---Detector
#------------------------------------------------------------
Detector_v = OpticalElement(
                Name = 'det_v',
                CoreOpticsElement = Optics.Detector(
                                                    L = DetectorSize,
                                                    AngleGrazing = np.deg2rad(90),
                                                    Orientation = Optics.OPTICS_ORIENTATION.VERTICAL),
                PositioningDirectives = Foundation.PositioningDirectives(
                                                    PlaceWhat = 'centre',
                                                    PlaceWhere = 'downstream focus',
                                                    ReferTo = 'upstream'))
# Create Beamlinee beamline starting from Beamlinee Beamline Elements Objects
#------------------------------------------------------------
Beamline = None
Beamline = Foundation.BeamlineElements()
Beamline.Append(s)
Beamline.Append(kb_v)
Beamline.Append(kb_h)
Beamline.Append(Detector_h)
Beamline.Append(Detector_v) # If I Comment this one, it works.
Beamline.RefreshPositions()
print(Beamline) #
aljosahafner commented 4 years ago

Yes, this is known behaviour and I agree that a proper warning or error has to be raised. Probably it's better if a warning is raised and the detector returns zeros or nans in such case.

aljosahafner commented 4 years ago

Please refer to issue number #15 , they are related. If we don't want to raise an error in the whole program, then we need to give NA/None or something into the box...

capitanevs commented 4 years ago

Action:

aljosahafner commented 4 years ago

I renamed the issue, as only the last point remains (GUI warning)

aljosahafner commented 4 years ago

Please provide a correct Oasys workspace for debugging this.