1
+ """
2
+ Optics
3
+ ------
4
+
5
+ Definitions for the optics measurements.
6
+ """
7
+ from __future__ import annotations
8
+
1
9
from dataclasses import dataclass , fields
2
10
3
11
import tfs
4
12
from omc3 .correction .constants import EXPECTED , DIFF
5
13
from omc3 .optics_measurements .constants import (
6
- BETA_NAME , AMP_BETA_NAME , ORBIT_NAME , DISPERSION_NAME , NORM_DISP_NAME ,
14
+ ALPHA , BETA_NAME , AMP_BETA_NAME , ORBIT_NAME , DISPERSION_NAME , NORM_DISP_NAME ,
7
15
PHASE_NAME , TOTAL_PHASE_NAME , AMPLITUDE , REAL , IMAG , DISPERSION , NORM_DISPERSION ,
8
- PHASE_ADV , MDL , S , KMOD_BETA_NAME ,
16
+ PHASE_ADV , MDL , S , S_MODEL , KMOD_BETA_NAME ,
9
17
EXT , NAME , DELTA , ERR , DRIVEN_TOTAL_PHASE_NAME , DRIVEN_PHASE_NAME , IP_NAME ,
10
18
KMOD_IP_NAME , KICK_NAME , BETA , PHASE , ORBIT , F1001_NAME , F1010_NAME , TUNE , RMS , MASKED )
11
19
from omc3 .plotting .utils .annotations import ylabels
@@ -37,8 +45,8 @@ class OpticsMeasurement(TfsCollection):
37
45
kick = Tfs (KICK_NAME )
38
46
ip = Tfs (IP_NAME )
39
47
ip_kmod = Tfs (KMOD_IP_NAME )
40
- f1001 = Tfs (F1001_NAME , two_planes = False )
41
- f1010 = Tfs (F1010_NAME , two_planes = False )
48
+ f1001 : TfsDataFrame = Tfs (F1001_NAME , two_planes = False )
49
+ f1010 : TfsDataFrame = Tfs (F1010_NAME , two_planes = False )
42
50
43
51
def _get_filename (self , name , plane = "" ) -> str :
44
52
""" Default way `optics_measurements` filenames are defined,
@@ -82,7 +90,7 @@ class ColumnsAndLabels:
82
90
# Other
83
91
needs_plane : bool = True
84
92
85
- def set_plane (self , plane : str ):
93
+ def set_plane (self , plane : str ) -> ColumnsAndLabels :
86
94
""" Fixes the plane in a new object. """
87
95
if not self .needs_plane :
88
96
raise AttributeError ("Cannot set the plane of a non-planed definition." )
@@ -91,6 +99,13 @@ def set_plane(self, plane: str):
91
99
needs_plane = False ,
92
100
** values_fixed_plane ,
93
101
)
102
+
103
+ def set_label_formatted (self , name : str ) -> ColumnsAndLabels :
104
+ """ Fixes the label in a new object (for RDTs). """
105
+ if self ._label is None :
106
+ raise AttributeError ("No label defined." )
107
+ new_label = self ._label .format (name )
108
+ return ColumnsAndLabels (** {f .name : getattr (self , f .name ) for f in fields (self ) if f .name != "_label" }, _label = new_label )
94
109
95
110
# Properties ----
96
111
@property
@@ -190,6 +205,7 @@ def delta_label(self):
190
205
# Defined Columns --------------------------------------------------------------
191
206
TUNE_COLUMN = ColumnsAndLabels (TUNE , _expected_column = f"{ EXPECTED } { TUNE } {{0}}" , _label = ylabels ['tune' ], _text_label = 'tune' )
192
207
BETA_COLUMN = ColumnsAndLabels (BETA , _label = ylabels ['beta' ], _text_label = 'beta' , _delta_label = ylabels ['betabeat' ])
208
+ ALPHA_COLUMN = ColumnsAndLabels (ALPHA , _label = ylabels ['alpha' ], _text_label = 'alpha' )
193
209
ORBIT_COLUMN = ColumnsAndLabels (ORBIT , _label = ylabels ['co' ], _text_label = 'orbit' )
194
210
DISPERSION_COLUMN = ColumnsAndLabels (DISPERSION , _label = ylabels ['dispersion' ], _text_label = 'dispersion' )
195
211
NORM_DISPERSION_COLUMN = ColumnsAndLabels (NORM_DISPERSION , _label = ylabels ['norm_dispersion' ], _text_label = 'normalized dispersion' )
@@ -198,6 +214,7 @@ def delta_label(self):
198
214
MU_COLUMN = ColumnsAndLabels (PHASE_ADV , _label = ylabels ['phasetot' ], _text_label = 'total phase' )
199
215
PHASE_ADVANCE_COLUMN = ColumnsAndLabels (f'{ PHASE_ADV } {{0}}{ MDL } ' , _label = r'Phase Advance [$2 \pi$]' , _text_label = 'phase advance' )
200
216
S_COLUMN = ColumnsAndLabels (S , _label = 'Location [m]' , _text_label = 'longitudinal location' , needs_plane = False )
217
+ S_MODEL_COLUMN = ColumnsAndLabels (S_MODEL , _label = 'Location [m]' , _text_label = 'longitudinal location' , needs_plane = False )
201
218
202
219
RDT_AMPLITUDE_COLUMN = ColumnsAndLabels (AMPLITUDE , _label = ylabels ['absolute' ], _text_label = 'amplitude' , needs_plane = False ) # label needs rdt
203
220
RDT_PHASE_COLUMN = ColumnsAndLabels (PHASE , _label = ylabels ['phase' ], _text_label = 'phase' , needs_plane = False ) # label needs rdt
@@ -227,4 +244,4 @@ def delta_label(self):
227
244
}
228
245
229
246
""" Find the Column Dataclass by column name for RDTs. """
230
- RDT_COLUMN_MAPPING = {c .column : c for c in [RDT_AMPLITUDE_COLUMN , RDT_PHASE_COLUMN , RDT_IMAG_COLUMN , RDT_REAL_COLUMN ]}
247
+ RDT_COLUMN_MAPPING = {c .column : c for c in [RDT_AMPLITUDE_COLUMN , RDT_PHASE_COLUMN , RDT_IMAG_COLUMN , RDT_REAL_COLUMN ]}
0 commit comments