44from ..data_model .bpm_data_collection import BPMDataCollection , BPMDataCollectionStats
55
66import pydev
7- pydev_supports_sequence = True
8-
97import sys
8+
9+ pydev_supports_sequence = True
1010stream = sys .stdout
1111
1212
@@ -18,12 +18,14 @@ class ViewBPMMonitoring:
1818 def __init__ (self , prefix : str ):
1919 self .prefix = prefix
2020
21- def update (self , * ,
22- names : Sequence [str ],
23- active : Sequence [bool ],
24- synchronised : Sequence [bool ],
25- usable : Sequence [bool ],
26- ):
21+ def update (
22+ self ,
23+ * ,
24+ names : Sequence [str ],
25+ active : Sequence [bool ],
26+ synchronised : Sequence [bool ],
27+ usable : Sequence [bool ],
28+ ):
2729 # names = string_array_to_bytes(names)
2830 names = list (names )
2931 label = self .prefix + ":" + "names"
@@ -50,7 +52,6 @@ def update(self, *,
5052 pydev .iointr (label , usable .tolist ())
5153
5254
53-
5455class ViewBPMDataCollection :
5556 def __init__ (self , prefix : str ):
5657 self .prefix = prefix
@@ -134,53 +135,16 @@ class ViewBPMDataAsBData:
134135 def __init__ (self , prefix : str ):
135136 self .prefix = prefix
136137
137- def update (self , data : BPMDataCollectionStats , * , n_bpms , scale_x_axis ):
138- """prepare data as expected
139- """
140- logger .debug ("view bdata: publishing data %s" , data )
141- nm2mm = 1e-6
142- n_entries = len (data .x .values )
143- if n_entries > n_bpms :
144- raise ValueError ("number of bpms %s too many. max %s" , n_entries , n_bpms )
145-
146- bdata = np .empty ([8 , n_bpms ], dtype = float )
147- bdata .fill (0.0 )
148- # is this the correct way to convert the data ?
149- scale_bits = 2 ** 15 / 10
150-
151- # flipping coordinate system to get the dispersion on the correct side
152- # todo: check at which state this should be done
153- # fmt:off
154- def convert (data , scale_axis = 1.0 ):
155- return data * (nm2mm * scale_bits * scale_axis )
156- bdata [0 , :n_entries ] = - convert (data .x .values , scale_axis = scale_x_axis )
157- bdata [1 , :n_entries ] = convert (data .y .values )
158- # fmt:on
159- # intensity z 1.3
160- # bdata[2] = 3
161- # intensityz z 1.3
162- # bdata[3] = 3
163- # AGC status needs to be three for valid data
164- # todo: find out what to set if only one plane is valid?
165- bdata [4 ,:n_entries ] = np .where ((data .x .n_readings > 0 ) | (data .y .n_readings > 0 ), 3 , 0 )
166- bdata [4 , - 1 ] = 2
167- # scale rms so that the slow orbit feedback accepts the data
168- # factor 100 seems to be enough.
169- # I think I should add some check that the noise is large enough
170- scale_rms = 20
171- def convert_noise (data , scale_axis = 1 ):
172- noise = convert (data .std , scale_axis = scale_axis * scale_rms )
173- noise [data .n_readings > 0 ] = np .clip (noise , 1 , None )[data .n_readings > 0 ]
174- # so sofb Orbit will consider it as not existing
175- noise [data .n_readings <= 0 ] = 0
176- return noise
177- bdata [6 , :n_entries ] = convert_noise (data .x , scale_axis = scale_x_axis )
178- bdata [7 , :n_entries ] = convert_noise (data .y )
138+ def update (self , bdata : Sequence [int ]):
139+ """prepare data as expected"""
140+ logger .debug ("view bdata: publishing data %s" , bdata )
179141
180142 label = f"{ self .prefix } "
181- bdata = [float (v ) for v in bdata .ravel ().astype (np .int16 )]
143+ bdata = np .asarray (bdata ).astype (np .int16 )
144+ if not pydev_supports_sequence :
145+ bdata = [int (v ) for v in bdata ]
182146 pydev .iointr (label , bdata )
183- logger .debug ("view bdata: label %s, %d n_entries" , label , n_entries )
147+ logger .debug ("view bdata: label %s, %d n_entries" , label , len ( bdata ) )
184148
185149
186150class ViewStringBuffer :
@@ -209,8 +173,8 @@ def __init__(self, prefix: str):
209173 def update (self , median : int , offset_from_median : Sequence [np .int32 ]):
210174 # stream.write(f"updating {self.prefix} with median {median}\n")
211175 # stream.flush()
212- pydev .iointr (self .prefix + ' :median' , median )
213- pydev .iointr (self .prefix + ' :offset' , list (offset_from_median ))
176+ pydev .iointr (self .prefix + " :median" , median )
177+ pydev .iointr (self .prefix + " :offset" , list (offset_from_median ))
214178
215179
216180class ViewConfiguration :
@@ -220,7 +184,7 @@ def __init__(self, prefix: str):
220184 def update (self , median_computation : bool ):
221185 stream .write (f"updating { self .prefix } with median { median_computation } \n " )
222186 stream .flush ()
223- pydev .iointr (self .prefix + ' :comp:median' , bool (median_computation ))
187+ pydev .iointr (self .prefix + " :comp:median" , bool (median_computation ))
224188
225189
226190class Views :
0 commit comments