I would like to have my data in a format so that I can create a
contour plot.
My data is in a file with a format, where there may be multiple fields
field = 1
1a 0
2a 0
3a 5
4a 5
5a 5
6a 5
7a 5
8a 5
9a 0
10a 0
1b 0
2b 0
3b 5
4b 5
5b 5
6b 5
7b 5
8b 5
9b 0
10b 0
field = 2
1a 0
2a 0
3a 0
4a 4
5a 4
6a 4
7a 4
8a 0
9a 0
10a 0
1b 0
2b 0
3b 0
4b 4
5b 4
6b 4
7b 4
8b 0
9b 0
10b 0
field = 3
1a 0
2a 0
3a 0
4a 0
5a 3
6a 3
7a 0
8a 0
9a 0
10a 0
1b 0
2b 0
3b 0
4b 0
5b 3
6b 3
7b 0
8b 0
9b 0
10b 0
where the value is how far from the center it will be displaced,
a b a
b a b
10 0000000000|0000 000000 0000000000|0000 000000 0000000000|
0000000000
9 0000000000|0000 000000 0000000000|0000 000000 0000000000|
0000000000
8 0000011111|1111 100000 0000000000|0000 000000 0000000000|
0000000000
7 0000011111|1111 100000 0000001111|1111 000000 0000000000|
0000000000
6 0000011111|1111 100000 0000001111|1111 000000 0000000111|
1110000000
5 0000011111|1111 100000 0000001111|1111 000000 0000000111|
1110000000
4 0000011111|1111 100000 0000001111|1111 000000 0000000000|
0000000000
3 0000011111|1111 100000 0000000000|0000 000000 0000000000|
0000000000
2 0000000000|0000 000000 0000000000|0000 000000 0000000000|
0000000000
1 0000000000|0000 000000 0000000000|0000 000000 0000000000|
0000000000
I could possibly have many of these that I will add together and
normalize to one.
Also, there are 60 a and b blocks, the middle 40 are 0.5 times the
width of the outer 20.
I thought about filling an array, but there is not a one to one
symmetry.
I cannot seem to get my head around this. Can anybody help me get
started?
I have tried to use a dictionary, but cannot seem to get it to work
the way I want.
I try this,
---------------------------------------------------------------------------------
f = open('TEST1.MLC ')
fields = {}
for line in f:
if line.split()[0] == 'Field':
field = int(line.split( )[-1])
elif line.split()[0] == 'Leaf':
fields[field] = line.split()[-1]
else:
line = f.next()
---------------------------------------------------------------------------------
and get,
---------------------------------------------------------------------------------
Traceback (most recent call last):
File "<pyshell#1 >", line 1, in <module>
line.split()[0]
IndexError: list index out of range
---------------------------------------------------------------------------------
Here is my data file,
---------------------------------------------------------------------------------
File Rev = G
Treatment = Dynamic Dose
Last Name = Fodness
First Name = Bryan
Patient ID = 0001
Number of Fields = 4
Number of Leaves = 120
Tolerance = 0.50
Field = 10
Index = 0.0000
Carriage Group = 1
Operator =
Collimator = 0.0
Leaf 1A = 0.00
Leaf 2A = 0.00
Leaf 3A = 0.00
Leaf 4A = 0.00
Leaf 5A = 0.00
Leaf 6A = 0.00
Leaf 7A = 0.00
Leaf 8A = 0.00
Leaf 9A = 0.00
Leaf 10A = 0.00
Leaf 11A = 0.00
Leaf 12A = 0.00
Leaf 13A = 0.00
Leaf 14A = 0.00
Leaf 15A = 0.00
Leaf 16A = 0.00
Leaf 17A = 0.00
Leaf 18A = 0.00
Leaf 19A = 0.00
Leaf 20A = 0.00
Leaf 21A = 5.00
Leaf 22A = 5.00
Leaf 23A = 5.00
Leaf 24A = 5.00
Leaf 25A = 5.00
Leaf 26A = 5.00
Leaf 27A = 5.00
Leaf 28A = 5.00
Leaf 29A = 5.00
Leaf 30A = 5.00
Leaf 31A = 5.00
Leaf 32A = 5.00
Leaf 33A = 5.00
Leaf 34A = 5.00
Leaf 35A = 5.00
Leaf 36A = 5.00
Leaf 37A = 5.00
Leaf 38A = 5.00
Leaf 39A = 5.00
Leaf 40A = 5.00
Leaf 41A = 0.00
Leaf 42A = 0.00
Leaf 43A = 0.00
Leaf 44A = 0.00
Leaf 45A = 0.00
Leaf 46A = 0.00
Leaf 47A = 0.00
Leaf 48A = 0.00
Leaf 49A = 0.00
Leaf 50A = 0.00
Leaf 51A = 0.00
Leaf 52A = 0.00
Leaf 53A = 0.00
Leaf 54A = 0.00
Leaf 55A = 0.00
Leaf 56A = 0.00
Leaf 57A = 0.00
Leaf 58A = 0.00
Leaf 59A = 0.00
Leaf 60A = 0.00
Leaf 1B = 0.00
Leaf 2B = 0.00
Leaf 3B = 0.00
Leaf 4B = 0.00
Leaf 5B = 0.00
Leaf 6B = 0.00
Leaf 7B = 0.00
Leaf 8B = 0.00
Leaf 9B = 0.00
Leaf 10B = 0.00
Leaf 11B = 0.00
Leaf 12B = 0.00
Leaf 13B = 0.00
Leaf 14B = 0.00
Leaf 15B = 0.00
Leaf 16B = 0.00
Leaf 17B = 0.00
Leaf 18B = 0.00
Leaf 19B = 0.00
Leaf 20B = 0.00
Leaf 21B = 5.00
Leaf 22B = 5.00
Leaf 23B = 5.00
Leaf 24B = 5.00
Leaf 25B = 5.00
Leaf 26B = 5.00
Leaf 27B = 5.00
Leaf 28B = 5.00
Leaf 29B = 5.00
Leaf 30B = 5.00
Leaf 31B = 5.00
Leaf 32B = 5.00
Leaf 33B = 5.00
Leaf 34B = 5.00
Leaf 35B = 5.00
Leaf 36B = 5.00
Leaf 37B = 5.00
Leaf 38B = 5.00
Leaf 39B = 5.00
Leaf 40B = 5.00
Leaf 41B = 0.00
Leaf 42B = 0.00
Leaf 43B = 0.00
Leaf 44B = 0.00
Leaf 45B = 0.00
Leaf 46B = 0.00
Leaf 47B = 0.00
Leaf 48B = 0.00
Leaf 49B = 0.00
Leaf 50B = 0.00
Leaf 51B = 0.00
Leaf 52B = 0.00
Leaf 53B = 0.00
Leaf 54B = 0.00
Leaf 55B = 0.00
Leaf 56B = 0.00
Leaf 57B = 0.00
Leaf 58B = 0.00
Leaf 59B = 0.00
Leaf 60B = 0.00
Note = 0
Shape = 4
500 500
500 -500
-500 -500
-500 500
Magnification = 1.00
Field = 8
Index = 0.4000
Carriage Group = 1
Operator =
Collimator = 0.0
Leaf 1A = 0.00
Leaf 2A = 0.00
Leaf 3A = 0.00
Leaf 4A = 0.00
Leaf 5A = 0.00
Leaf 6A = 0.00
Leaf 7A = 0.00
Leaf 8A = 0.00
Leaf 9A = 0.00
Leaf 10A = 0.00
Leaf 11A = 0.00
Leaf 12A = 0.00
Leaf 13A = 0.00
Leaf 14A = 0.00
Leaf 15A = 0.00
Leaf 16A = 0.00
Leaf 17A = 0.00
Leaf 18A = 0.00
Leaf 19A = 0.00
Leaf 20A = 0.00
Leaf 21A = 0.00
Leaf 22A = 0.00
Leaf 23A = 4.00
Leaf 24A = 4.00
Leaf 25A = 4.00
Leaf 26A = 4.00
Leaf 27A = 4.00
Leaf 28A = 4.00
Leaf 29A = 4.00
Leaf 30A = 4.00
Leaf 31A = 4.00
Leaf 32A = 4.00
Leaf 33A = 4.00
Leaf 34A = 4.00
Leaf 35A = 4.00
Leaf 36A = 4.00
Leaf 37A = 4.00
Leaf 38A = 4.00
Leaf 39A = 0.00
Leaf 40A = 0.00
Leaf 41A = 0.00
Leaf 42A = 0.00
Leaf 43A = 0.00
Leaf 44A = 0.00
Leaf 45A = 0.00
Leaf 46A = 0.00
Leaf 47A = 0.00
Leaf 48A = 0.00
Leaf 49A = 0.00
Leaf 50A = 0.00
Leaf 51A = 0.00
Leaf 52A = 0.00
Leaf 53A = 0.00
Leaf 54A = 0.00
Leaf 55A = 0.00
Leaf 56A = 0.00
Leaf 57A = 0.00
Leaf 58A = 0.00
Leaf 59A = 0.00
Leaf 60A = 0.00
Leaf 1B = 0.00
Leaf 2B = 0.00
Leaf 3B = 0.00
Leaf 4B = 0.00
Leaf 5B = 0.00
Leaf 6B = 0.00
Leaf 7B = 0.00
Leaf 8B = 0.00
Leaf 9B = 0.00
Leaf 10B = 0.00
Leaf 11B = 0.00
Leaf 12B = 0.00
Leaf 13B = 0.00
Leaf 14B = 0.00
Leaf 15B = 0.00
Leaf 16B = 0.00
Leaf 17B = 0.00
Leaf 18B = 0.00
Leaf 19B = 0.00
Leaf 20B = 0.00
Leaf 21B = 0.00
Leaf 22B = 0.00
Leaf 23B = 4.00
Leaf 24B = 4.00
Leaf 25B = 4.00
Leaf 26B = 4.00
Leaf 27B = 4.00
Leaf 28B = 4.00
Leaf 29B = 4.00
Leaf 30B = 4.00
Leaf 31B = 4.00
Leaf 32B = 4.00
Leaf 33B = 4.00
Leaf 34B = 4.00
Leaf 35B = 4.00
Leaf 36B = 4.00
Leaf 37B = 4.00
Leaf 38B = 4.00
Leaf 39B = 0.00
Leaf 40B = 0.00
Leaf 41B = 0.00
Leaf 42B = 0.00
Leaf 43B = 0.00
Leaf 44B = 0.00
Leaf 45B = 0.00
Leaf 46B = 0.00
Leaf 47B = 0.00
Leaf 48B = 0.00
Leaf 49B = 0.00
Leaf 50B = 0.00
Leaf 51B = 0.00
Leaf 52B = 0.00
Leaf 53B = 0.00
Leaf 54B = 0.00
Leaf 55B = 0.00
Leaf 56B = 0.00
Leaf 57B = 0.00
Leaf 58B = 0.00
Leaf 59B = 0.00
Leaf 60B = 0.00
Note = 0
Shape = 4
400 400
400 -400
-400 -400
-400 400
Magnification = 1.00
Field = 4
Index = 0.8000
Carriage Group = 1
Operator =
Collimator = 0.0
Leaf 1A = 0.00
Leaf 2A = 0.00
Leaf 3A = 0.00
Leaf 4A = 0.00
Leaf 5A = 0.00
Leaf 6A = 0.00
Leaf 7A = 0.00
Leaf 8A = 0.00
Leaf 9A = 0.00
Leaf 10A = 0.00
Leaf 11A = 0.00
Leaf 12A = 0.00
Leaf 13A = 0.00
Leaf 14A = 0.00
Leaf 15A = 0.00
Leaf 16A = 0.00
Leaf 17A = 0.00
Leaf 18A = 0.00
Leaf 19A = 0.00
Leaf 20A = 0.00
Leaf 21A = 0.00
Leaf 22A = 0.00
Leaf 23A = 0.00
Leaf 24A = 0.00
Leaf 25A = 0.00
Leaf 26A = 0.00
Leaf 27A = 2.00
Leaf 28A = 2.00
Leaf 29A = 2.00
Leaf 30A = 2.00
Leaf 31A = 2.00
Leaf 32A = 2.00
Leaf 33A = 2.00
Leaf 34A = 2.00
Leaf 35A = 0.00
Leaf 36A = 0.00
Leaf 37A = 0.00
Leaf 38A = 0.00
Leaf 39A = 0.00
Leaf 40A = 0.00
Leaf 41A = 0.00
Leaf 42A = 0.00
Leaf 43A = 0.00
Leaf 44A = 0.00
Leaf 45A = 0.00
Leaf 46A = 0.00
Leaf 47A = 0.00
Leaf 48A = 0.00
Leaf 49A = 0.00
Leaf 50A = 0.00
Leaf 51A = 0.00
Leaf 52A = 0.00
Leaf 53A = 0.00
Leaf 54A = 0.00
Leaf 55A = 0.00
Leaf 56A = 0.00
Leaf 57A = 0.00
Leaf 58A = 0.00
Leaf 59A = 0.00
Leaf 60A = 0.00
Leaf 1B = 0.00
Leaf 2B = 0.00
Leaf 3B = 0.00
Leaf 4B = 0.00
Leaf 5B = 0.00
Leaf 6B = 0.00
Leaf 7B = 0.00
Leaf 8B = 0.00
Leaf 9B = 0.00
Leaf 10B = 0.00
Leaf 11B = 0.00
Leaf 12B = 0.00
Leaf 13B = 0.00
Leaf 14B = 0.00
Leaf 15B = 0.00
Leaf 16B = 0.00
Leaf 17B = 0.00
Leaf 18B = 0.00
Leaf 19B = 0.00
Leaf 20B = 0.00
Leaf 21B = 0.00
Leaf 22B = 0.00
Leaf 23B = 0.00
Leaf 24B = 0.00
Leaf 25B = 0.00
Leaf 26B = 0.00
Leaf 27B = 2.00
Leaf 28B = 2.00
Leaf 29B = 2.00
Leaf 30B = 2.00
Leaf 31B = 2.00
Leaf 32B = 2.00
Leaf 33B = 2.00
Leaf 34B = 2.00
Leaf 35B = 0.00
Leaf 36B = 0.00
Leaf 37B = 0.00
Leaf 38B = 0.00
Leaf 39B = 0.00
Leaf 40B = 0.00
Leaf 41B = 0.00
Leaf 42B = 0.00
Leaf 43B = 0.00
Leaf 44B = 0.00
Leaf 45B = 0.00
Leaf 46B = 0.00
Leaf 47B = 0.00
Leaf 48B = 0.00
Leaf 49B = 0.00
Leaf 50B = 0.00
Leaf 51B = 0.00
Leaf 52B = 0.00
Leaf 53B = 0.00
Leaf 54B = 0.00
Leaf 55B = 0.00
Leaf 56B = 0.00
Leaf 57B = 0.00
Leaf 58B = 0.00
Leaf 59B = 0.00
Leaf 60B = 0.00
Note = 0
Shape = 4
200 200
200 -200
-200 -200
-200 200
Magnification = 1.00
Field = 1
Index = 1.0000
Carriage Group = 1
Operator =
Collimator = 0.0
Leaf 1A = 0.00
Leaf 2A = 0.00
Leaf 3A = 0.00
Leaf 4A = 0.00
Leaf 5A = 0.00
Leaf 6A = 0.00
Leaf 7A = 0.00
Leaf 8A = 0.00
Leaf 9A = 0.00
Leaf 10A = 0.00
Leaf 11A = 0.00
Leaf 12A = 0.00
Leaf 13A = 0.00
Leaf 14A = 0.00
Leaf 15A = 0.00
Leaf 16A = 0.00
Leaf 17A = 0.00
Leaf 18A = 0.00
Leaf 19A = 0.00
Leaf 20A = 0.00
Leaf 21A = 0.00
Leaf 22A = 0.00
Leaf 23A = 0.00
Leaf 24A = 0.00
Leaf 25A = 0.00
Leaf 26A = 0.00
Leaf 27A = 0.00
Leaf 28A = 0.00
Leaf 29A = 0.00
Leaf 30A = 0.50
Leaf 31A = 0.50
Leaf 32A = 0.00
Leaf 33A = 0.00
Leaf 34A = 0.00
Leaf 35A = 0.00
Leaf 36A = 0.00
Leaf 37A = 0.00
Leaf 38A = 0.00
Leaf 39A = 0.00
Leaf 40A = 0.00
Leaf 41A = 0.00
Leaf 42A = 0.00
Leaf 43A = 0.00
Leaf 44A = 0.00
Leaf 45A = 0.00
Leaf 46A = 0.00
Leaf 47A = 0.00
Leaf 48A = 0.00
Leaf 49A = 0.00
Leaf 50A = 0.00
Leaf 51A = 0.00
Leaf 52A = 0.00
Leaf 53A = 0.00
Leaf 54A = 0.00
Leaf 55A = 0.00
Leaf 56A = 0.00
Leaf 57A = 0.00
Leaf 58A = 0.00
Leaf 59A = 0.00
Leaf 60A = 0.00
Leaf 1B = 0.00
Leaf 2B = 0.00
Leaf 3B = 0.00
Leaf 4B = 0.00
Leaf 5B = 0.00
Leaf 6B = 0.00
Leaf 7B = 0.00
Leaf 8B = 0.00
Leaf 9B = 0.00
Leaf 10B = 0.00
Leaf 11B = 0.00
Leaf 12B = 0.00
Leaf 13B = 0.00
Leaf 14B = 0.00
Leaf 15B = 0.00
Leaf 16B = 0.00
Leaf 17B = 0.00
Leaf 18B = 0.00
Leaf 19B = 0.00
Leaf 20B = 0.00
Leaf 21B = 0.00
Leaf 22B = 0.00
Leaf 23B = 0.00
Leaf 24B = 0.00
Leaf 25B = 0.00
Leaf 26B = 0.00
Leaf 27B = 0.00
Leaf 28B = 0.00
Leaf 29B = 0.00
Leaf 30B = 0.50
Leaf 31B = 0.50
Leaf 32B = 0.00
Leaf 33B = 0.00
Leaf 34B = 0.00
Leaf 35B = 0.00
Leaf 36B = 0.00
Leaf 37B = 0.00
Leaf 38B = 0.00
Leaf 39B = 0.00
Leaf 40B = 0.00
Leaf 41B = 0.00
Leaf 42B = 0.00
Leaf 43B = 0.00
Leaf 44B = 0.00
Leaf 45B = 0.00
Leaf 46B = 0.00
Leaf 47B = 0.00
Leaf 48B = 0.00
Leaf 49B = 0.00
Leaf 50B = 0.00
Leaf 51B = 0.00
Leaf 52B = 0.00
Leaf 53B = 0.00
Leaf 54B = 0.00
Leaf 55B = 0.00
Leaf 56B = 0.00
Leaf 57B = 0.00
Leaf 58B = 0.00
Leaf 59B = 0.00
Leaf 60B = 0.00
Note = 0
Shape = 4
50 50
50 -50
-50 -50
-50 50
Magnification = 1.00
CRC = B4DC
--------------------------------------------------------------------------------- 2 2025
Bryan.Fodn...@g mail.com wrote:
I would like to have my data in a format so that I can create a
contour plot.
My data is in a file with a format, where there may be multiple fields
field = 1
1a 0
2a 0
The above is NOT consistent with the later listing of your data file.
[big snip
10b 0
where the value is how far from the center it will be displaced,
a b a
b a b
10 0000000000|0000 000000 0000000000|0000 000000 0000000000|
[big snip of seemingly irrelevant stuff]
1 0000000000|0000 000000 0000000000|0000 000000 0000000000|
0000000000
I could possibly have many of these that I will add together and
normalize to one.
Also, there are 60 a and b blocks, the middle 40 are 0.5 times the
width of the outer 20.
I thought about filling an array, but there is not a one to one
symmetry.
I cannot seem to get my head around this. Can anybody help me get
started?
I have tried to use a dictionary, but cannot seem to get it to work
the way I want.
I try this,
---------------------------------------------------------------------------------
f = open('TEST1.MLC ')
fields = {}
for line in f:
if line.split()[0] == 'Field':
field = int(line.split( )[-1])
Do line.split() ONCE per line.
>
elif line.split()[0] == 'Leaf':
fields[field] = line.split()[-1]
else:
line = f.next()
Don't mix
for line in f
and
line = f.next()
otherwise you will you will skip lines that you don't want to skip and/
or become confused.
>
---------------------------------------------------------------------------------
and get,
---------------------------------------------------------------------------------
Traceback (most recent call last):
File "<pyshell#1 >", line 1, in <module>
line.split()[0]
IndexError: list index out of range
This indicates that you have a list for which 0 is not a valid index.
If it had 1 or more elements, then 0 would be a valid index. I
conclude that the list is empty. This would happen if line contained
no characters other than whitespace.
Here is my data file,
---------------------------------------------------------------------------------
File Rev = G
Treatment = Dynamic Dose
Last Name = Fodness
First Name = Bryan
Patient ID = 0001
Number of Fields = 4
Number of Leaves = 120
Tolerance = 0.50
Field = 10
Index = 0.0000
Carriage Group = 1
Operator =
Collimator = 0.0
Leaf 1A = 0.00
Leaf 2A = 0.00
[snip]
Leaf 20A = 0.00
Leaf 21A = 5.00
Leaf 22A = 5.00
[snip]
Leaf 40A = 5.00
[big snip -- your code failed no later than the 10th line in the data
file]
To find out what is going on, print out some variables:
8<--- fodness.py ----
f = open('fodness.d at')
fields = {}
for lino, line in enumerate(f):
tokens = line.split()
print "Line %d: tokens = %r" % (lino, tokens)
if not tokens:
continue # blank/empty line
tok0 = tokens[0]
if tok0 == 'Field':
field = int(tokens[-1])
elif tok0 == 'Leaf':
fields[field] = tokens[-1]
else:
continue
print " Fields:", fields
8<---
Results [truncated]:
C:\junk>fodness .py | more
Line 0: tokens = []
Line 1: tokens = ['File', 'Rev', '=', 'G']
[snip]
Line 8: tokens = ['Tolerance', '=', '0.50']
Line 9: tokens = []
Line 10: tokens = ['Field', '=', '10']
Fields: {}
Line 11: tokens = ['Index', '=', '0.0000']
Line 12: tokens = ['Carriage', 'Group', '=', '1']
Line 13: tokens = ['Operator', '=']
Line 14: tokens = ['Collimator', '=', '0.0']
Line 15: tokens = ['Leaf', '1A', '=', '0.00']
Fields: {10: '0.00'} <<<<<<<<<<===== = Don't you need a float
instead of a string??
Line 16: tokens = ['Leaf', '2A', '=', '0.00']
Fields: {10: '0.00'}
Line 17: tokens = ['Leaf', '3A', '=', '0.00']
Fields: {10: '0.00'}
Line 18: tokens = ['Leaf', '4A', '=', '0.00']
Fields: {10: '0.00'}
Don't you want/need to use the leaf IDs (1A, 2A, etc)?? I guess that
you want to end up with NESTED dictonaries, like this:
fields = {
10: {
'1A': 0.0,
'2A': 0.0,
etc,
},
8: {
etc,
},
etc,
}
HTH,
John
On Nov 12, 5:12 pm, John Machin <sjmac...@lexic on.netwrote:
Bryan.Fodn...@g mail.com wrote:
I would like to have my data in a format so that I can create a
contour plot.
My data is in a file with a format, where there may be multiple fields
field = 1
1a 0
2a 0
The above is NOT consistent with the later listing of your data file.
[big snip
10b 0
where the value is how far from the center it will be displaced,
a b a
b a b
10 0000000000|0000 000000 0000000000|0000 000000 0000000000|
[big snip of seemingly irrelevant stuff]
1 0000000000|0000 000000 0000000000|0000 000000 0000000000|
0000000000
I could possibly have many of these that I will add together and
normalize to one.
Also, there are 60 a and b blocks, the middle 40 are 0.5 times the
width of the outer 20.
I thought about filling an array, but there is not a one to one
symmetry.
I cannot seem to get my head around this. Can anybody help me get
started?
I have tried to use a dictionary, but cannot seem to get it to work
the way I want.
I try this,
---------------------------------------------------------------------------*------
f = open('TEST1.MLC ')
fields = {}
for line in f:
if line.split()[0] == 'Field':
field = int(line.split( )[-1])
Do line.split() ONCE per line.
elif line.split()[0] == 'Leaf':
fields[field] = line.split()[-1]
else:
line = f.next()
Don't mix
for line in f
and
line = f.next()
otherwise you will you will skip lines that you don't want to skip and/
or become confused.
---------------------------------------------------------------------------*------
and get,
---------------------------------------------------------------------------*------
Traceback (most recent call last):
File "<pyshell#1 >", line 1, in <module>
line.split()[0]
IndexError: list index out of range
This indicates that you have a list for which 0 is not a valid index.
If it had 1 or more elements, then 0 would be a valid index. I
conclude that the list is empty. This would happen if line contained
no characters other than whitespace.
In other words, the blank lines between the blocks of data.
>
Here is my data file,
---------------------------------------------------------------------------*------
File Rev = G
Treatment = Dynamic Dose
Last Name = Fodness
First Name = Bryan
Patient ID = 0001
Number of Fields = 4
Number of Leaves = 120
Tolerance = 0.50
Field = 10
Index = 0.0000
Carriage Group = 1
Operator =
Collimator = 0.0
Leaf 1A = 0.00
Leaf 2A = 0.00
[snip]
Leaf 20A = 0.00
Leaf 21A = 5.00
Leaf 22A = 5.00
[snip]
Leaf 40A = 5.00
[big snip -- your code failed no later than the 10th line in the data
file]
To find out what is going on, print out some variables:
8<--- fodness.py ----
f = open('fodness.d at')
fields = {}
for lino, line in enumerate(f):
tokens = line.split()
print "Line %d: tokens = %r" % (lino, tokens)
if not tokens:
continue # blank/empty line
tok0 = tokens[0]
if tok0 == 'Field':
field = int(tokens[-1])
elif tok0 == 'Leaf':
fields[field] = tokens[-1]
else:
continue
print " Fields:", fields
8<---
Results [truncated]:
C:\junk>fodness .py | more
Line 0: tokens = []
Line 1: tokens = ['File', 'Rev', '=', 'G']
[snip]
Line 8: tokens = ['Tolerance', '=', '0.50']
Line 9: tokens = []
Line 10: tokens = ['Field', '=', '10']
Fields: {}
Line 11: tokens = ['Index', '=', '0.0000']
Line 12: tokens = ['Carriage', 'Group', '=', '1']
Line 13: tokens = ['Operator', '=']
Line 14: tokens = ['Collimator', '=', '0.0']
Line 15: tokens = ['Leaf', '1A', '=', '0.00']
Fields: {10: '0.00'} <<<<<<<<<<===== = Don't you need a float
instead of a string??
Line 16: tokens = ['Leaf', '2A', '=', '0.00']
Fields: {10: '0.00'}
Line 17: tokens = ['Leaf', '3A', '=', '0.00']
Fields: {10: '0.00'}
Line 18: tokens = ['Leaf', '4A', '=', '0.00']
Fields: {10: '0.00'}
Yep, crahing on blank lines.
f = open(r'C:\pytho n25\user\MLC\TE ST1.MLC')
fields = {}
for line in f:
the_line = line.split() # split only once
if the_line: # test if the_line empty
if the_line[0] == 'Field': # if not, start checking
field = int(the_line[-1])
elif the_line[0] == 'Leaf':
fields[field] = the_line[-1]
## f.next() removed
Don't you want/need to use the leaf IDs (1A, 2A, etc)?? I guess that
you want to end up with NESTED dictonaries, like this:
fields = {
10: {
'1A': 0.0,
'2A': 0.0,
etc,
},
8: {
etc,
},
etc,
}
The fixed code returns only one leaf, since you are
continuously overwriting it.
>>fields
{8: '0.00', 1: '0.00', 10: '0.00', 4: '0.00'}
Note also that the values are still strings, you probably
have to fix that.
>
HTH,
John- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics | |
by: sdhyok |
last post by:
Hi, I am trying to build up a system handling time series data a lot.
Do you know any well-designed python class specially for time series data?
Thanks in advance.
Shin, Daehyok
|
by: Albert Tu |
last post by:
Dear there,
We have an x-ray CT system. The acquisition computer acquires x-ray
projections and outputs multiple data files in binary format (2-byte
unsigned integer) such as projection0.raw, projection1.raw,
projection2.raw ... up to projection500.raw. Each file is
2*1024*768-byte big.
I would like to read those files and convert to ascii files in %5.0f/n
format as projection0.data ... projection500.data so that our
|
by: Noname |
last post by:
Hi All
I am working for a EE Department. We are in the process of
developing some application that requires 3D visualization
and other display routines. Can anyone clarify that if
thats possible.
Thanks
Regards
|
by: Andrea M. Segovia |
last post by:
Hello,
I am a newbie to Oracle databases....
We have a visualization front-end tool connected to an Oracle back-end
database on a Tru64 UNIX server. We also have clients with MS access
databases who would like to share their data using this visualization
tool but do not want to import their data into the Oracle server
back-end.
|
by: Fie Pye |
last post by:
Hallo
I would like to have a high class open source tools for scientific computing and powerful 2D and 3D data visualisation. Therefore I chosepython, numpy and scipy as a base. Now I am in search for a visualisation tool. I tried matplotlib and py_opendx with OpenDx. OpenDx seems to me very good but the project py_opendx looks like closed. After py_opendx instalation and subsequent testing I got an error that needs discussion with author...
| | |
by: Xah Lee |
last post by:
REQUIREMENTS FOR A VISUALIZATION SOFTWARE SYSTEM FOR 2010
Xah Lee, 2007-03-16
In this essay, i give a list of requirements that i think is necessary
for a software system for creating scientific visualization for the
next decade (2007-2017).
(for a HTML version with images, please see
http://xahlee.org/3d/viz.html )
|
by: Boris Ozegovic |
last post by:
Hi
I don't know if someone is familiar with Java JUNG, framework for data
visualization (http://jung.sourceforge.net/), I am interested is there
anything lik JUNG for Python?
--
Greatest shits:
http://www.net.hr/vijesti/page/2007/03/30/0030006.html
|
by: tavares |
last post by:
(Our apologies for cross-posting.
We appreciate if you kindly distribute this information by your co-
workers and colleagues.)
***************************************************************************
Symposium “Image Processing and Data Visualization”
2nd South-East European Conference on Computational Mechanics (SEECCM
2009)
Island of Rhodes, Greece, 22-24 June 2009
|
by: JDeats |
last post by:
Looking to build an desktop application for a client using WPF/
Silverlight 2.0 or Adobe Flex 2.0 and because of my ability to use C#
and the integration requirements, the WPF solution would be the most
cost effective solution, except for the lack of visualization
controls.
I realize Infragistics and other vendors have products out there that
provide for this, but none that I've found are as cost effective as
the rich visualization...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| | |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| | |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |