Skip to content

Commit

Permalink
Merge pull request #924 from lnls-sirius/add-switching-freq-bpms
Browse files Browse the repository at this point in the history
Changes in BPM and FamBPMs classes
  • Loading branch information
murilobalves authored Mar 13, 2023
2 parents 4b1fc4d + 9da7941 commit de05d6b
Showing 1 changed file with 80 additions and 12 deletions.
92 changes: 80 additions & 12 deletions siriuspy/siriuspy/devices/bpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class BPM(_Device):
'ACQTriggerDataThres-SP', 'ACQTriggerDataThres-RB',
'ACQTriggerDataPol-Sel', 'ACQTriggerDataPol-Sts',
'ACQTriggerDataHyst-SP', 'ACQTriggerDataHyst-RB',
'SwTagEn-Sel', 'SwTagEn-Sts',
'SwTagEn-Sel', 'SwTagEn-Sts', 'SwDivClk-RB',
'TbTTagEn-Sel', 'TbTTagEn-Sts',
'FAcqTagEn-Sel', 'FAcqTagEn-Sts',
'MonitTagEn-Sel', 'MonitTagEn-Sts',
Expand Down Expand Up @@ -179,6 +179,22 @@ def switching_mode_str(self):
"""."""
return _csbpm.SwModes._fields[self.switching_mode]

@property
def switching_rate(self):
"""Switching rate manifested at BPM readings.
NOTE: Actually this property maps the rate of the effect of
switching on the orbit, which is twice the switching rate,
because the switching has two states.
"""
return self['SwDivClk-RB'] * 2

@property
def switching_period(self):
"""Switching period manifested at BPM readings."""
return self.switching_rate / self.adcfreq

@property
def harmonic_number(self):
"""."""
Expand Down Expand Up @@ -824,6 +840,42 @@ def cmd_sync_monit(self):
self.monit_sync_enbl = 0
return self._wait('FAcqTagEn-Sts', 0)

def get_sampling_frequency(
self, rf_freq: float, acq_rate='') -> float:
"""Return the sampling frequency of the acquisition.
Args:
rf_freq (float): RF frequency.
acq_rate (str, optional): acquisition rate. Defaults to ''.
If empty string, it gets the configured acq. rate on BPMs
Returns:
float: acquisition frequency.
"""
acq_rate = self.acq_channel_str if not acq_rate else acq_rate
fadc = rf_freq / self.harmonic_number * self.tbt_rate
if acq_rate.lower().startswith('tbt'):
return fadc / self.tbt_rate
elif acq_rate.lower().startswith('fofb'):
return fadc / self.fofb_rate
elif acq_rate.lower().startswith('facq'):
return fadc / self.facq_rate
return fadc / self.monit_rate

def get_switching_frequency(self, rf_freq: float) -> float:
"""Return the switching frequency.
Args:
rf_freq (float): RF frequency.
Returns:
float: switching frequency.
"""
fadc = rf_freq / self.harmonic_number * self.tbt_rate
return fadc / self.switching_rate

def _get_propname(self, prop):
if not self._ispost_mortem:
return prop
Expand Down Expand Up @@ -976,16 +1028,32 @@ def get_sampling_frequency(self, rf_freq: float, acq_rate='') -> float:
float: acquisition frequency.
"""
bpm = self._devices[0]
acq_rate = bpm.acq_channel_str if not acq_rate else acq_rate
fadc = rf_freq / bpm.harmonic_number * bpm.tbt_rate
if acq_rate.lower().startswith('tbt'):
return fadc / bpm.tbt_rate
elif acq_rate.lower().startswith('fofb'):
return fadc / bpm.fofb_rate
elif acq_rate.lower().startswith('monit'):
return fadc / bpm.monit_rate
return fadc / bpm.facq_rate
fs_bpms = {
dev.get_sampling_frequency(rf_freq, acq_rate)
for dev in self.devices}
if len(fs_bpms) == 1:
return fs_bpms.pop()
else:
print('BPMs are not configured with the same ACQChannel.')
return None

def get_switching_frequency(self, rf_freq: float) -> float:
"""Return the switching frequency.
Args:
rf_freq (float): RF frequency.
Returns:
float: switching frequency.
"""
fsw_bpms = {
dev.get_switching_frequency(rf_freq) for dev in self.devices}
if len(fsw_bpms) == 1:
return fsw_bpms.pop()
else:
print('BPMs are not configured with the same SwMode.')
return None

def mturn_config_acquisition(
self, nr_points_after: int, nr_points_before=0,
Expand Down Expand Up @@ -1227,7 +1295,7 @@ def mturn_wait_update_orbit(self, timeout=10, consider_sum=False) -> int:
return -4

def mturn_wait_update(self, timeout=10, consider_sum=False) -> int:
"""Combine wait_acquistion_finish and mturn_wait_update_orbit.
"""Combine mturn_wait_update_flags and mturn_wait_update_orbit.
Args:
timeout (int, optional): Waiting timeout. Defaults to 10.
Expand Down

0 comments on commit de05d6b

Please sign in to comment.