Skip to content

Commit 67109eb

Browse files
committed
Added sort_compass_files function
1 parent f2f9627 commit 67109eb

File tree

1 file changed

+31
-0
lines changed
  • libra_toolbox/neutron_detection/activation_foils

1 file changed

+31
-0
lines changed

libra_toolbox/neutron_detection/activation_foils/compass.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import numpy as np
2+
import os
13

24

35
def get_channel(filename):
@@ -23,4 +25,33 @@ def get_channel(filename):
2325
return int(filename.split('@')[0][7:])
2426

2527

28+
def sort_compass_files(directory):
29+
""" Gets Compass csv data filenames
30+
and sorts them according to channel and ending number.
31+
The filenames need to be sorted by ending number because only
32+
the first csv file for each channel contains a header.
33+
34+
Example of sorted filenames in directory:
35+
1st file: Data_CH4@...22.CSV
36+
2nd file: Data_CH4@...22_1.CSV
37+
3rd file: Data_CH4@...22_2.CSV """
38+
39+
filenames = os.listdir(directory)
40+
data_filenames = {}
41+
for filename in filenames:
42+
if filename.lower().endswith('.csv'):
43+
ch = get_channel(filename)
44+
# initialize filenames for each channel
45+
if ch not in data_filenames.keys():
46+
data_filenames[ch] = []
47+
48+
data_filenames[ch] = filename
49+
# Sort filenames by number at end
50+
for ch in data_filenames.keys():
51+
data_filenames[ch] = np.sort(data_filenames[ch])
52+
53+
return data_filenames
54+
55+
56+
2657

0 commit comments

Comments
 (0)