Skip to content

Commit

Permalink
[TASK] test stats with single vector
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreSchnizer committed Nov 5, 2024
1 parent f50b161 commit dfa06c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/bpm_data_combiner/app/bdata.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from typing import Sequence, Mapping

import numpy as np


from ..data_model.bpm_data_collection import BPMDataCollectionStats

# is this the correct way to convert the data ?
Expand All @@ -21,7 +19,7 @@ def convert(data: Sequence[float], scale_axis: float = 1.0):
Todo:
include conversion to np.int16 at this stage?
"""
return np.asarray(data) * (nm2mm * scale_bits * scale_axis)
return (np.asarray(data) * (nm2mm * scale_bits * scale_axis)).astype(np.int16)


def convert_noise(data, scale_axis: float = 1):
Expand Down Expand Up @@ -53,7 +51,7 @@ def stat_data_to_bdata(
if n_entries > n_bpms:
raise ValueError("number of bpms %s too many. max %s", n_entries, n_bpms)

bdata = np.empty([8, n_bpms], dtype=float)
bdata = np.empty([8, n_bpms], dtype=np.int16)
bdata.fill(0.0)

indices = [device_index[name] for name in data.names]
Expand Down
16 changes: 16 additions & 0 deletions src/tests/test_statistics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import numpy as np

from bpm_data_combiner.data_model.bpm_data_accumulation import BPMDataAccumulationForPlane
from bpm_data_combiner.post_processor.statistics import compute_mean_weight


def test_compute_mean_weight_single_data():
p = BPMDataAccumulationForPlane(
values=np.array([[1, 2, 3, 4]]),
valid=np.array([[True]*4])
)
print(p)
r = compute_mean_weight(p)
r.values == [1, 2, 3, 4]
assert (r.n_readings == 1).all()
assert (r.std == 0).all()

0 comments on commit dfa06c3

Please sign in to comment.