Skip to content

Commit

Permalink
Use only first and last chopper in non-Fermi chopper width
Browse files Browse the repository at this point in the history
  • Loading branch information
Rastislav Turanyi committed Nov 22, 2024
1 parent ea992c4 commit 8568814
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions src/resolution_functions/models/pychop.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ def get_long_frequency(frequency: list[int],
def _get_chop_times(cls,
model_data: PyChopModelDataNonFermi,
e_init: float,
chopper_frequency: list[int]) -> list[list[np.ndarray]]:
chopper_frequency: list[int]) -> list[list[Float[np.ndarray, 'times']]]:
frequencies = cls.get_long_frequency(chopper_frequency, model_data)
choppers = model_data.choppers

Expand All @@ -549,8 +549,8 @@ def _get_chop_times(cls,
# if there's only one disk we prepend a dummy disk with full opening at zero distance
# so that the distance calculations (which needs the difference between disk pos) works
if len(choppers) == 1:
choppers = {
'prepended': {
choppers = [
{
'distance': 0,
'nslot': 1,
'slot_ang_pos': None,
Expand All @@ -559,15 +559,17 @@ def _get_chop_times(cls,
'radius': 500,
'num_disk': 1
},
**choppers
}
*list(choppers.values())
]
frequencies = np.array([model_data.source_frequency, frequencies[0]])
else:
choppers = list(choppers.values())

chop_times = []

# first we optimise on the main Ei
# TODO: Calculate only the first and last choppers (only those used upstream)
for i, (frequency, chopper) in enumerate(zip(frequencies, choppers.values())):
for frequency, chopper in zip([frequencies[0], frequencies[-1]], [choppers[0], choppers[-1]]):
chopper: DiskChopper
this_phase, phase_independence = chopper['default_phase'], chopper['is_phase_independent']

Expand Down Expand Up @@ -605,7 +607,7 @@ def _get_chop_times(cls,
next_win_t = uSec / model_data.source_frequency + (uSec / frequency)

while realTimeOp[0] < next_win_t:
chop_times[i].append(deepcopy(realTimeOp))
chop_times[-1].append(deepcopy(realTimeOp))
slt0 = islt % slot
slt1 = (islt + 1) % slot
angdiff = angles[slt1] - angles[slt0]
Expand All @@ -619,7 +621,7 @@ def _get_chop_times(cls,
realTimeOp -= next_win_t * np.ceil(realTimeOp[0] / next_win_t)

while realTimeOp[0] < (uSec / p_frames + next_win_t):
chop_times[i].append(deepcopy(realTimeOp))
chop_times[-1].append(deepcopy(realTimeOp))
realTimeOp += next_win_t

return chop_times
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_pychop.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def test_chop_times(matrix, pychop_nonfermi_data):

actual = PyChopModelNonFermi._get_chop_times(data, e_init, chopper_frequencies)

for aa, ee in zip(actual, expected):
for aa, ee in zip(actual, [expected[0], expected[-1]]):
for a, e in zip(aa, ee):
try:
assert_allclose(a, e, rtol=0, atol=1e-8)
Expand Down

0 comments on commit 8568814

Please sign in to comment.