@@ -37,23 +37,66 @@ def from_workspace(cls, input_workspace: MantidWorkspace):
3737 sample_logs = SampleLogValues (input_workspace )
3838 value = cls .REFLECTED_BEAM
3939 try :
40+ coordinate_system = CoordinateSystem .from_workspace (input_workspace )
4041 # Determine whether this is a direct beam based on the geometry
41- if (("BL4B:CS:Mode:Coordinates" in sample_logs and sample_logs ["BL4B:CS:Mode:Coordinates" ] == 0 ) or # This is a new log for earth-centered
42- sample_logs ["BL4B:CS:ExpPl:OperatingMode" ] == "Free Liquid" ): # This is for backward compatibility from before the new log value
43- # Earth-centered coordinate system
42+ if coordinate_system == CoordinateSystem .EARTH_CENTERED :
4443 thi = sample_logs ["thi" ]
4544 tthd = sample_logs ["tthd" ]
4645 if np .isclose (thi , tthd , atol = 0.01 ):
4746 value = cls .DIRECT_BEAM
48- else :
47+ elif coordinate_system == CoordinateSystem . BEAM_CENTERED :
4948 # Beam-centered coordinate system
5049 ths = sample_logs ["ths" ]
5150 tthd = sample_logs ["tthd" ]
5251 if np .fabs (tthd ) < 0.001 and np .fabs (ths ) < 0.001 :
5352 value = cls .DIRECT_BEAM
54- except KeyError as e :
53+ else :
54+ logger .warning ("Unknown coordinate system; assuming reflected beam" )
55+ except RuntimeError as e :
5556 logger .warning (f"Missing sample log { e } , assuming reflected beam" )
5657 return value
5758
5859 def __str__ (self ):
5960 return self .name
61+
62+
63+ class CoordinateSystem (IntEnum ):
64+ """
65+ Enum to represent the coordinate system used in the experiment.
66+
67+ Attributes:
68+ UNKNOWN (int): Represents unknown coordinate system.
69+ EARTH_CENTERED (int): Represents the Earth-centered coordinate system.
70+ BEAM_CENTERED (int): Represents the Beam-centered coordinate system.
71+ """
72+
73+ UNKNOWN = - 1
74+ EARTH_CENTERED = 0
75+ BEAM_CENTERED = 1
76+
77+ @classmethod
78+ def from_workspace (cls , input_workspace : MantidWorkspace ):
79+ """
80+ Determine the coordinate system from the given workspace.
81+ """
82+ sample_logs = SampleLogValues (input_workspace )
83+ value = cls .UNKNOWN
84+ try :
85+ # This is the new log for coordinate system mode
86+ if "BL4B:CS:Mode:Coordinates" in sample_logs :
87+ if sample_logs ["BL4B:CS:Mode:Coordinates" ] == 0 :
88+ value = cls .EARTH_CENTERED
89+ else :
90+ value = cls .BEAM_CENTERED
91+ # Fallback to older method using operating mode
92+ elif "BL4B:CS:ExpPl:OperatingMode" in sample_logs :
93+ if sample_logs ["BL4B:CS:ExpPl:OperatingMode" ] == "Free Liquid" :
94+ value = cls .EARTH_CENTERED
95+ else :
96+ value = cls .BEAM_CENTERED
97+ except RuntimeError as e :
98+ logger .warning (f"Missing sample log { e } , unable to determine coordinate system" )
99+ return value
100+
101+ def __str__ (self ):
102+ return self .name
0 commit comments