Skip to content

Commit e1c4337

Browse files
committed
6 fatto
1 parent fb48034 commit e1c4337

File tree

2 files changed

+80
-105
lines changed

2 files changed

+80
-105
lines changed

.ipynb_checkpoints/06ex_Pandas-checkpoint.ipynb

Lines changed: 37 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 1,
5+
"execution_count": 2,
66
"metadata": {},
77
"outputs": [],
88
"source": [
@@ -57,10 +57,8 @@
5757
}
5858
],
5959
"source": [
60-
"N = 10000\n",
61-
"df = pd.read_csv('data_000637.txt', nrows = N)\n",
62-
"print(df.head())\n",
63-
"#df.describe() mi da anche info tipo media, st dev etc"
60+
"df = pd.read_csv('data_000637.txt')\n",
61+
"print(df.head())"
6462
]
6563
},
6664
{
@@ -84,9 +82,8 @@
8482
}
8583
],
8684
"source": [
87-
"max_bx_counter = df['BX_COUNTER'].max() #prendo df e cerco il max nella colonna \"BX_COUNTER\".\n",
88-
"num_bx_in_orbit = max_bx_counter + 1 #il max sarà max + 1\n",
89-
"print(f'The number of BX in an ORBIT is: {num_bx_in_orbit}') #l'f all'inizio mi fa stampare una stringa"
85+
"num_bx_in_orbit = df['BX_COUNTER'].max() + 1 \n",
86+
"print(f'The number of BX in an ORBIT is: {num_bx_in_orbit}') "
9087
]
9188
},
9289
{
@@ -110,12 +107,11 @@
110107
}
111108
],
112109
"source": [
113-
"df_full = pd.read_csv('data_000637.txt')\n",
114-
"max_orbit = df_full['ORBIT_CNT'].max() #valore max dell'orbit_cnt\n",
115-
"min_orbit = df_full['ORBIT_CNT'].min() #valore min\n",
116-
"duration_orbits = max_orbit - min_orbit + 1 #durata in orbits\n",
117-
"duration_bx = duration_orbits * num_bx_in_orbit #calcolo la durata in bx\n",
118-
"duration_ns = duration_bx * 25 #converto in ns dato che un bx sono 25 nanosecondi\n",
110+
"max_orbit = df['ORBIT_CNT'].max() \n",
111+
"min_orbit = df['ORBIT_CNT'].min() \n",
112+
"duration_orbits = max_orbit - min_orbit + 1 \n",
113+
"duration_bx = duration_orbits * num_bx_in_orbit \n",
114+
"duration_ns = duration_bx * 25 \n",
119115
"duration_seconds = duration_ns / 1e9\n",
120116
"print(f'Data taking lasted: {duration_seconds} seconds')"
121117
]
@@ -146,9 +142,7 @@
146142
}
147143
],
148144
"source": [
149-
"df['ABS_T'] = (df['TDC_MEAS']*25/30)+(df['BX_COUNTER']*25)+(df['ORBIT_CNT']*num_bx_in_orbit*25) \n",
150-
"#per aggiungere una colonna alla fine creo con df[]. poi in questo caso faccio la somma delle 3\n",
151-
"#colonne ricordando di convertire in nanosecondi\n",
145+
"df['ABS_T'] = (df['TDC_MEAS']*25/30) + (df['BX_COUNTER']*25) + (df['ORBIT_CNT']*num_bx_in_orbit*25) \n",
152146
"#df = df.drop(columns=['absolute_time_ns']) in caso volessi cancellare una colonna\n",
153147
"print(df.head())"
154148
]
@@ -171,16 +165,15 @@
171165
"text": [
172166
" HEAD FPGA TDC_CHANNEL ORBIT_CNT BX_COUNTER TDC_MEAS ABS_T\n",
173167
"0 0 0 123 3869200167 2374 26 3.447457e+14\n",
174-
"1 0 0 124 3869200167 2374 27 3.447457e+14\n",
168+
"1 1 0 124 3869200167 2374 27 3.447457e+14\n",
175169
"2 0 0 63 3869200167 2553 28 3.447457e+14\n",
176-
"3 1 0 64 3869200167 2558 19 3.447457e+14\n",
170+
"3 0 0 64 3869200167 2558 19 3.447457e+14\n",
177171
"4 1 0 64 3869200167 2760 25 3.447457e+14\n"
178172
]
179173
}
180174
],
181175
"source": [
182-
"df['HEAD'] = np.random.choice([0,1], size = len(df)) #np.random.choice([valori ammessi], numero di\n",
183-
"#righe da modificare)\n",
176+
"df['HEAD'] = np.random.choice([0,1], size = len(df))\n",
184177
"print(df.head())"
185178
]
186179
},
@@ -200,18 +193,17 @@
200193
"name": "stdout",
201194
"output_type": "stream",
202195
"text": [
203-
" HEAD FPGA TDC_CHANNEL ORBIT_CNT BX_COUNTER TDC_MEAS ABS_T\n",
204-
"3 1 0 64 3869200167 2558 19 3.447457e+14\n",
205-
"4 1 0 64 3869200167 2760 25 3.447457e+14\n",
206-
"7 1 0 139 3869200167 2776 0 3.447457e+14\n",
207-
"9 1 0 60 3869200167 2788 7 3.447457e+14\n",
208-
"11 1 0 64 3869200167 2786 19 3.447457e+14\n"
196+
" HEAD FPGA TDC_CHANNEL ORBIT_CNT BX_COUNTER TDC_MEAS ABS_T\n",
197+
"1 1 0 124 3869200167 2374 27 3.447457e+14\n",
198+
"4 1 0 64 3869200167 2760 25 3.447457e+14\n",
199+
"5 1 0 63 3869200167 2762 4 3.447457e+14\n",
200+
"7 1 0 139 3869200167 2776 0 3.447457e+14\n",
201+
"8 1 0 62 3869200167 2774 21 3.447457e+14\n"
209202
]
210203
}
211204
],
212205
"source": [
213-
"df_head_1 = df[df['HEAD'] == 1] #creo un df nuovo che copia il df precedente prendendo però solo\n",
214-
"#le righe dove df['HEAD'] == 1\n",
206+
"df_head_1 = df[df['HEAD'] == 1]\n",
215207
"print(df_head_1.head())"
216208
]
217209
},
@@ -224,7 +216,7 @@
224216
},
225217
{
226218
"cell_type": "code",
227-
"execution_count": 21,
219+
"execution_count": 9,
228220
"metadata": {},
229221
"outputs": [
230222
{
@@ -239,30 +231,27 @@
239231
}
240232
],
241233
"source": [
242-
"# ho due valori di FPGA (0 e 1)\n",
243-
"df_fpga0 = df[df['FPGA']==0] #creo un df con FPGA == 0\n",
244-
"df_fpga1 = df[df['FPGA']==1] #creo un df con FPGA == 1\n",
245-
"grouped_0 = df_fpga0.groupby('TDC_CHANNEL', dropna=False) #raggruppo con TDC_CHANNEL \n",
246-
"grouped_1 = df_fpga1.groupby('TDC_CHANNEL', dropna=False) #e non escludo i valori NaN\n",
247-
"counts_0 = grouped_0.count() #conta quanti valori ci sono\n",
248-
"#print(counts_0)\n",
234+
"df_fpga0 = df[df['FPGA']==0] \n",
235+
"df_fpga1 = df[df['FPGA']==1]\n",
236+
"grouped_0 = df_fpga0.groupby('TDC_CHANNEL', dropna=False)\n",
237+
"grouped_1 = df_fpga1.groupby('TDC_CHANNEL', dropna=False) \n",
238+
"counts_0 = grouped_0.count()\n",
249239
"counts_1 = grouped_1.count()\n",
250-
"#print(counts_1)\n",
251240
"\n",
252-
"figure, axis = plt.subplots(1, 2) #una figura con 2 \"axis\", ovvero due figure in una\n",
253-
"figure.set_figwidth(12) #larghezza \n",
254-
"figure.set_figheight(6) #altezza \n",
255-
"#setto la prima delle due figure\n",
241+
"figure, axis = plt.subplots(1, 2)\n",
242+
"figure.set_figwidth(12)\n",
243+
"figure.set_figheight(6)\n",
244+
"\n",
256245
"axis[0].plot(counts_0.axes[0], counts_0['FPGA']) \n",
257246
"axis[0].set_title(\"FPGA 0\") \n",
258247
"axis[0].set_xlabel(\"TDC Channel\")\n",
259248
"axis[0].set_ylabel(\"Counts\")\n",
260-
"#ora la seconda figura\n",
249+
"\n",
261250
"axis[1].plot(counts_1.axes[0], counts_1['FPGA'])\n",
262251
"axis[1].set_title(\"FPGA 1\") \n",
263252
"axis[1].set_xlabel(\"TDC Channel\")\n",
264253
"axis[1].set_ylabel(\"Counts\")\n",
265-
"figure.tight_layout(pad=5.0) #le metto attaccate"
254+
"figure.tight_layout(pad=5.0)"
266255
]
267256
},
268257
{
@@ -274,7 +263,7 @@
274263
},
275264
{
276265
"cell_type": "code",
277-
"execution_count": 25,
266+
"execution_count": 10,
278267
"metadata": {},
279268
"outputs": [
280269
{
@@ -316,7 +305,7 @@
316305
},
317306
{
318307
"cell_type": "code",
319-
"execution_count": 29,
308+
"execution_count": 11,
320309
"metadata": {},
321310
"outputs": [
322311
{
@@ -329,10 +318,10 @@
329318
}
330319
],
331320
"source": [
332-
"n_of_unique_orbits = df_full['ORBIT_CNT'].nunique() #unici in tutto il dataset\n",
321+
"n_of_unique_orbits = df['ORBIT_CNT'].nunique() #unici in tutto il dataset\n",
333322
"print(f\"Number of unique orbits: {n_of_unique_orbits}\")\n",
334323
"\n",
335-
"n_uniq_139 = df_full[df_full['TDC_CHANNEL'] == 139]['ORBIT_CNT'].nunique()\n",
324+
"n_uniq_139 = df[df['TDC_CHANNEL'] == 139]['ORBIT_CNT'].nunique()\n",
336325
"print(f\"Number of unique orbits with at least one meas from TDC_CHANNEL=139: {n_uniq_139}\")"
337326
]
338327
}

0 commit comments

Comments
 (0)