Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions pySC/configuration/bpm_system_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging

from ..core.simulated_commissioning import SimulatedCommissioning
from ..core.bpm_system import BPM_FIELDS_TO_INITIALISE, BPM_FIELDS_TO_INITIALISE_ONES
from .general import get_error, get_indices_and_names
from .supports_conf import generate_element_misalignments

Expand Down Expand Up @@ -87,11 +86,7 @@ def configure_bpms(SC: SimulatedCommissioning) -> None:
SC.bpm_system.noise_tbt_x = np.array(bpms_tbt_noise)
SC.bpm_system.noise_tbt_y = np.array(bpms_tbt_noise)

nbpm = len(bpms_indices)
for field in BPM_FIELDS_TO_INITIALISE:
setattr(SC.bpm_system, field, np.zeros(nbpm, dtype=float))
for field in BPM_FIELDS_TO_INITIALISE_ONES:
setattr(SC.bpm_system, field, np.ones(nbpm, dtype=float))
SC.bpm_system.initialize_empty_arrays()

for index, bpm_category in zip(bpms_indices, bpms_categories):
generate_element_misalignments(SC, index, bpms_conf[bpm_category])
Expand Down
17 changes: 14 additions & 3 deletions pySC/core/bpm_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
def _rotation_matrix(a):
return np.array([[np.cos(a), -np.sin(a)], [np.sin(a), np.cos(a)]])

BPM_FIELDS_TO_INITIALISE = ['offsets_x', 'offsets_y', 'rolls',
'bba_offsets_x', 'bba_offsets_y',
'reference_x', 'reference_y']
BPM_FIELDS_TO_INITIALISE_ZEROS = ['offsets_x', 'offsets_y', 'rolls',
'bba_offsets_x', 'bba_offsets_y',
'reference_x', 'reference_y']

# These fields are initialized to ones (not zeros) — multiplicative corrections
BPM_FIELDS_TO_INITIALISE_ONES = ['gain_corrections_x', 'gain_corrections_y']
Expand Down Expand Up @@ -54,8 +54,19 @@ class BPMSystem(BaseModel, extra='forbid'):
def initialize(self):
if len(self.rolls) > 0:
self.update_rot_matrices()
if len(self.indices):
self.initialize_empty_arrays()
return self

def initialize_empty_arrays(self):
nbpm = len(self.indices)
for field in BPM_FIELDS_TO_INITIALISE_ZEROS:
if not len(getattr(self, field)): # array is empty
setattr(self, field, np.zeros(nbpm, dtype=float))
for field in BPM_FIELDS_TO_INITIALISE_ONES:
if not len(getattr(self, field)): # array is empty
setattr(self, field, np.ones(nbpm, dtype=float))

def update_rot_matrices(self):
self._rot_matrices = _rotation_matrix(self.rolls)

Expand Down
Loading