Skip to content

Commit

Permalink
Fix key-value writing: no space after ':=' identifier (#69)
Browse files Browse the repository at this point in the history
per the NRRD documentation: http://teem.sourceforge.net/nrrd/format.html#general.2

"""
Each of the "<key>:=<value>" lines specifies a key/value pair in the nrrd. These can appear in NRRD0002 (and higher version) files, but not NRRD0001 files. The key and value strings are delimited by the first ":=" to appear on the line: any spaces before or after ":=" are assumed part of the key or value, respectively.
"""
  • Loading branch information
ihnorton authored and addisonElliott committed Sep 24, 2018
1 parent 21366d2 commit eeb4df8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
40 changes: 20 additions & 20 deletions nrrd/tests/test_writing.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ def test_write_custom_fields_without_custom_field_map(self):
self.assertEqual(lines[8], 'kinds: domain')
self.assertEqual(lines[9], 'encoding: ASCII')
self.assertEqual(lines[10], 'spacings: 1.0458000000000001')
self.assertEqual(lines[11], 'int:= 24')
self.assertEqual(lines[12], 'double:= 25.5566')
self.assertEqual(lines[13], 'string:= This is a long string of information that is important.')
self.assertEqual(lines[14], 'int list:= 1 2 3 4 5 100')
self.assertEqual(lines[15], 'double list:= 0.2 0.502 0.8')
self.assertEqual(lines[16], 'string list:= words are split by space in list')
self.assertEqual(lines[17], 'int vector:= (100, 200, -300)')
self.assertEqual(lines[18], 'double vector:= (100.5,200.3,-300.99)')
self.assertEqual(lines[19], 'int matrix:= (1,0,0) (0,1,0) (0,0,1)')
self.assertEqual(lines[20], 'double matrix:= (1.2,0.3,0) (0,1.5,0) (0,-0.55,1.6)')
self.assertEqual(lines[11], 'int:=24')
self.assertEqual(lines[12], 'double:=25.5566')
self.assertEqual(lines[13], 'string:=This is a long string of information that is important.')
self.assertEqual(lines[14], 'int list:=1 2 3 4 5 100')
self.assertEqual(lines[15], 'double list:=0.2 0.502 0.8')
self.assertEqual(lines[16], 'string list:=words are split by space in list')
self.assertEqual(lines[17], 'int vector:=(100, 200, -300)')
self.assertEqual(lines[18], 'double vector:=(100.5,200.3,-300.99)')
self.assertEqual(lines[19], 'int matrix:=(1,0,0) (0,1,0) (0,0,1)')
self.assertEqual(lines[20], 'double matrix:=(1.2,0.3,0) (0,1.5,0) (0,-0.55,1.6)')

def test_write_custom_fields_with_custom_field_map(self):
output_filename = os.path.join(self.temp_write_dir, 'testfile_custom_fields.nrrd')
Expand Down Expand Up @@ -142,16 +142,16 @@ def test_write_custom_fields_with_custom_field_map(self):
self.assertEqual(lines[8], 'kinds: domain')
self.assertEqual(lines[9], 'encoding: ASCII')
self.assertEqual(lines[10], 'spacings: 1.0458000000000001')
self.assertEqual(lines[11], 'int:= 24')
self.assertEqual(lines[12], 'double:= 25.5566')
self.assertEqual(lines[13], 'string:= This is a long string of information that is important.')
self.assertEqual(lines[14], 'int list:= 1 2 3 4 5 100')
self.assertEqual(lines[15], 'double list:= 0.20000000000000001 0.502 0.80000000000000004')
self.assertEqual(lines[16], 'string list:= words are split by space in list')
self.assertEqual(lines[17], 'int vector:= (100,200,-300)')
self.assertEqual(lines[18], 'double vector:= (100.5,200.30000000000001,-300.99000000000001)')
self.assertEqual(lines[19], 'int matrix:= (1,0,0) (0,1,0) (0,0,1)')
self.assertEqual(lines[20], 'double matrix:= (1.2,0.29999999999999999,0) (0,1.5,0) (0,-0.55000000000000004,'
self.assertEqual(lines[11], 'int:=24')
self.assertEqual(lines[12], 'double:=25.5566')
self.assertEqual(lines[13], 'string:=This is a long string of information that is important.')
self.assertEqual(lines[14], 'int list:=1 2 3 4 5 100')
self.assertEqual(lines[15], 'double list:=0.20000000000000001 0.502 0.80000000000000004')
self.assertEqual(lines[16], 'string list:=words are split by space in list')
self.assertEqual(lines[17], 'int vector:=(100,200,-300)')
self.assertEqual(lines[18], 'double vector:=(100.5,200.30000000000001,-300.99000000000001)')
self.assertEqual(lines[19], 'int matrix:=(1,0,0) (0,1,0) (0,0,1)')
self.assertEqual(lines[20], 'double matrix:=(1.2,0.29999999999999999,0) (0,1.5,0) (0,-0.55000000000000004,'
'1.6000000000000001)')

def test_write_detached_raw_as_nrrd(self):
Expand Down
2 changes: 1 addition & 1 deletion nrrd/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def write(filename, data, header={}, detached_header=False, custom_field_map=Non

# Custom fields are written as key/value pairs with a := instead of : delimeter
if x >= custom_field_start_index:
fh.write(('%s:= %s\n' % (field, value_str)).encode('ascii'))
fh.write(('%s:=%s\n' % (field, value_str)).encode('ascii'))
else:
fh.write(('%s: %s\n' % (field, value_str)).encode('ascii'))

Expand Down

0 comments on commit eeb4df8

Please sign in to comment.