I've been struggling to get something to work for the following text file format. My overall goal is to extract the value for one of the variable names throughout the entire text file. For example, I want all the values for B rows and D rows. Then put them in a normal numpy array and run calculations.
Here is what the data file looks like:
[SECTION1a]
[a] 1424457484310
[b] 5313402937
[c] 873348378938
[d] 882992596992
[e] 14957596088
[SECTION1b]
243 62 184 145 250 180 106 208 248 87 186 137 127 204 18 142 37 67 36 72 48 204 255 30 243 78 44 121 112 139 76 71 131 50 118 10 42 8 67 4 98 110 37 5 208 104 56 55 225 56 0 102 0 21 0 156 0 174 255 171 0 42 0 233 0 50 0 254 0 245 255 110
[END SECTION1]
[SECTION2a]
[a] 1424457484310
[b] 5313402937
[c] 873348378938
[d] 882992596992
[e] 14957596088
[SECTION2b]
243 62 184 145 250 180 106 208 248 87 186 137 127 204 18 142 37 67 36 72 48 204 255 30 243 78 44 121 112 139 76 71 131 50 118 10 42 8 67 4 98 110 37 5 208 104 56 55 225 56 0 102 0 21 0 156 0 174 255 171 0 42 0 233 0 50 0 254 0 245 255 110
[END SECTION2]
That pattern continues for N sections.
Currently I read the file and put it into two columns:
filename_load = fileopenbox(msg=None, title='Load Data File',
default="Z:\*",
filetypes=None)
col1_data = np.genfromtxt(filename_load, skip_header=1, dtype=None,
usecols=(0,), usemask=True, invalid_raise=False)
col2_data = np.genfromtxt(filename_load, skip_header=1, dtype=None,
usecols=(1,), usemask=True, invalid_raise=False)
I was going to then use where, to find the index of the value I wanted, then make a new array of those values:
arr_index = np.where(col1_data == '[b]')
new_array = col2_data[arr_index]
Problem with that is, I end up with arrays of two different sizes because of the weird file format so obviously the data in the array won't match up properly to the right variable name.
I have tried a few other alternatives and get stuck due to the weird text file format and how to read it into python.
Not sure if I should stay on this track an if so how to address the problem, or, try a totally different approach.
Thanks in advance!