Skip to content
Snippets Groups Projects
Commit 684d60bd authored by Philipp Niedermayer's avatar Philipp Niedermayer
Browse files

Standarized dataclass for topos data

parent 7d3c0365
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,7 @@ from .common import *
from .ipm import IPMData
from .lassie import LassieSpillData
from .libera import LiberaData, LiberaBBBData, LiberaTBTData
from .topos import ToposData, ToposBBBData, ToposTBTData
from .nwa import NWAData, NWADataAverage
from .tdc import TDCSpill, TDCData
from .hitspill import HITSpill, HITSpillData
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Dataclasses for Libera BPM data
Classes to work with data from libera hadron beam position monitor system
"""
__author__ = "Philipp Niedermayer"
__contact__ = "p.niedermayer@gsi.de"
__date__ = "2022-08-29"
import numpy as np
from dataclasses import dataclass
from .common import Trace
@dataclass
class ToposData(Trace):
"""Container for data from topos
t - time array in seconds
"""
t: np.ndarray
x: np.ndarray
y: np.ndarray
x_unit: str = 'mm'
y_unit: str = 'mm'
@dataclass
class ToposBBBData(ToposData):
"""Container for bunch-by-bunch data from topos
"""
@classmethod
def from_file(cls, fname, time_offset=0, verbose=0):
"""Read in bunch-by-bunch data from a *.bin file saved with topos
:param fname: path to filename
:param time_offset: adds a given time offset (in s) to the timestamps
"""
reader = BpmBinaryExportReader()
t, x, y = reader.read(fname)
return ToposBBBData(t/1e3 + time_offset, x, y)
def to_tbt_data(self, h, b=None):
"""Returns the turn-by-turn data
:param h: the harmonic number of the RF system (number of bunches per turn)
:param b: the bunch index or None for an average
"""
wrap = lambda a: a[:(len(a)//h)*h].reshape(-1, h).mean(axis=1) if b is None else a[b::h]
return ToposTBTData(t=wrap(self.t), x=wrap(self.x), y=wrap(self.y),
x_unit=self.x_unit, y_unit=self.y_unit)
def __repr__(self):
return f'ToposBBBData(n_bunch={len(self.t)}, t={self.t[0]:.3f}..{self.t[-1]:.3f} s)'
@dataclass
class ToposTBTData(ToposData):
"""Container for turn-by-turn data from topos
"""
def __repr__(self):
return f'ToposBBBData(n_turn={len(self.t)}, t={self.t[0]:.3f}..{self.t[-1]:.3f} s)'
#######################################################
#
# Code below thankfully provided by d.vilsmeier@gsi.de
#
import numpy as np
from io import BufferedReader
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment