1+
2+ import numpy as np
3+ import pandas as pd
4+ import pytest
5+
6+ from tests .test_lhc_and_general import INPUTS_DIR , compare_tbt
7+ from turn_by_turn .structures import TbtData , TransverseData
8+ from turn_by_turn .madng import read_tbt
9+ from pymadng import MAD
10+
11+
12+ def test_read_ng (_ng_file ):
13+ with MAD () as mad :
14+ file_as_string = mad .quote_strings (str (_ng_file ))
15+ df = mad .mtable .read (file_as_string ).eval ().to_df ()
16+ new = read_tbt (df )
17+ origin = _original_simulation_data ()
18+ compare_tbt (origin , new , True )
19+
20+ # ---- Helpers ---- #
21+ def _original_simulation_data () -> TbtData :
22+ # Create a TbTData object with the original data
23+ names = np .array (["BPM1" , "BPM2" , "BPM3" ])
24+ bpm1_p1_x = np .array ([ 1e-3 , 0.002414213831 ,- 0.0009999991309 ])
25+ bpm1_p1_y = np .array ([- 1e-3 , 0.0004142133507 , 0.001000000149 ])
26+ bpm1_p2_x = np .array ([- 1e-3 ,- 0.002414213831 , 0.0009999991309 ])
27+ bpm1_p2_y = np .array ([ 1e-3 ,- 0.0004142133507 ,- 0.001000000149 ])
28+
29+ bpm2_p1_x = np .array ([- 0.0009999999503 ,- 0.0004142138307 , 0.0009999998012 ])
30+ bpm2_p1_y = np .array ([ 0.00100000029 ,- 0.002414213351 ,- 0.001000001159 ])
31+ bpm2_p2_x = np .array ([ 0.0009999999503 , 0.0004142138307 ,- 0.0009999998012 ])
32+ bpm2_p2_y = np .array ([- 0.00100000029 , 0.002414213351 , 0.001000001159 ])
33+
34+ bpm3_p1_x = np .array ([ 0.002414213831 ,- 0.0009999991309 ,- 0.002414214191 ])
35+ bpm3_p1_y = np .array ([ 0.0004142133507 , 0.001000000149 ,- 0.0004142129907 ])
36+ bpm3_p2_x = np .array ([- 0.002414213831 , 0.0009999991309 , 0.002414214191 ])
37+ bpm3_p2_y = np .array ([- 0.0004142133507 ,- 0.001000000149 , 0.0004142129907 ])
38+
39+ print (pd .DataFrame (index = names , data = [bpm1_p1_x , bpm2_p1_x , bpm3_p1_x ]))
40+ matrix = [
41+ TransverseData ( # first particle
42+ X = pd .DataFrame (index = names , data = [bpm1_p1_x , bpm2_p1_x , bpm3_p1_x ]),
43+ Y = pd .DataFrame (index = names , data = [bpm1_p1_y , bpm2_p1_y , bpm3_p1_y ]),
44+ ),
45+ TransverseData ( # second particle
46+ X = pd .DataFrame (index = names , data = [bpm1_p2_x , bpm2_p2_x , bpm3_p2_x ]),
47+ Y = pd .DataFrame (index = names , data = [bpm1_p2_y , bpm2_p2_y , bpm3_p2_y ]),
48+ ),
49+ ]
50+ return TbtData (matrices = matrix , bunch_ids = [0 , 1 ], nturns = 3 )
51+
52+
53+ # ---- Fixtures ---- #
54+ @pytest .fixture
55+ def _ng_file (tmp_path ):
56+ return INPUTS_DIR / "madng" / "fodo_track.tfs"
0 commit comments