-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relative data file path printing #79
Changes from 4 commits
d590ed4
bfc7db9
362612b
106d2f7
ae816aa
524100f
fcb53fa
d820b43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,7 +158,7 @@ def test_write_detached_raw_as_nrrd(self): | |
output_filename = os.path.join(self.temp_write_dir, 'testfile_detached_raw.nhdr') | ||
output_data_filename = os.path.join(self.temp_write_dir, 'testfile_detached_raw.nrrd') | ||
|
||
nrrd.write(output_data_filename, self.data_input, {u'encoding': 'raw'}, detached_header=True) | ||
nrrd.write(output_data_filename, self.data_input, {u'encoding': 'raw'}, detached_header=True, relative_data_path= False) | ||
|
||
# Read back the same file | ||
data, header = nrrd.read(output_filename) | ||
|
@@ -198,7 +198,7 @@ def test_write_detached_gz(self): | |
output_filename = os.path.join(self.temp_write_dir, 'testfile_detached_raw.nhdr') | ||
output_data_filename = os.path.join(self.temp_write_dir, 'testfile_detached_raw.raw.gz') | ||
|
||
nrrd.write(output_filename, self.data_input, {u'encoding': 'gz'}, detached_header=False) | ||
nrrd.write(output_filename, self.data_input, {u'encoding': 'gz'}, detached_header=False, relative_data_path=False) | ||
|
||
# Read back the same file | ||
data, header = nrrd.read(output_filename) | ||
|
@@ -216,7 +216,7 @@ def test_write_detached_bz2(self): | |
data, header = nrrd.read(output_filename) | ||
self.assertEqual(self.expected_data, data.tostring(order='F')) | ||
self.assertEqual(header['encoding'], 'bz2') | ||
self.assertEqual(header['data file'], output_data_filename) | ||
self.assertEqual(header['data file'], os.path.basename(output_data_filename)) | ||
|
||
def test_write_detached_ascii(self): | ||
output_filename = os.path.join(self.temp_write_dir, 'testfile_detached_raw.nhdr') | ||
|
@@ -228,7 +228,7 @@ def test_write_detached_ascii(self): | |
data, header = nrrd.read(output_filename) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, one small thing. Since you directly placed the string to be asserted, the Same for above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will review your other PRs, but may take some time. |
||
self.assertEqual(self.expected_data, data.tostring(order='F')) | ||
self.assertEqual(header['encoding'], 'txt') | ||
self.assertEqual(header['data file'], output_data_filename) | ||
self.assertEqual(header['data file'], os.path.basename(output_data_filename)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Easier if we just replace Repeat for above case too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, didn't see the relative filename exists here. |
||
|
||
|
||
if __name__ == '__main__': | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,7 +93,7 @@ def _format_field_value(value, field_type): | |
raise NRRDError('Invalid field type given: %s' % field_type) | ||
|
||
|
||
def write(filename, data, header={}, detached_header=False, custom_field_map=None, | ||
def write(filename, data, header={}, detached_header=False, relative_data_path=True, custom_field_map=None, | ||
compression_level = 9): | ||
"""Write :class:`numpy.ndarray` to NRRD file | ||
|
||
|
@@ -121,6 +121,9 @@ def write(filename, data, header={}, detached_header=False, custom_field_map=Non | |
Data to save to the NRRD file | ||
detached_header : :obj:`bool`, optional | ||
Whether the header and data should be saved in separate files. Defaults to :obj:`False` | ||
relative_data_path : :class:`bool` | ||
whether the data file name in detached_header is saved with relative path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line wrapped at 82 characters, only wrap at 120 characters. Capitalize W in whether. detached_header should be detached header because you are not referencing the boolean variable but rather the actual detached header. I think we should include a note that this parameter is ignored if the data is attached just to be safe. And, you say that the "data file name is saved with a relative path", but that sounds odd. The data filename isn't what is saved as a relative path, it's the data file itself. Altogether, here's what I'm thinking. Comments welcome
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that is odd, rather the suggested one sounds like because data is not saved in the detached header. However, counter suggestion combining with yours:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PR is ready, let me know your final thoughts on this. |
||
or absolute path. Defaults to :obj:`True` | ||
custom_field_map : :class:`dict` (:class:`str`, :class:`str`), optional | ||
Dictionary used for parsing custom field types where the key is the custom field name and the value is a | ||
string identifying datatype for the custom field. | ||
|
@@ -183,12 +186,12 @@ def write(filename, data, header={}, detached_header=False, custom_field_map=Non | |
else: | ||
raise NRRDError('Invalid encoding specification while writing NRRD file: %s' % header['encoding']) | ||
|
||
header['data file'] = data_filename | ||
header['data file'] = os.path.basename(data_filename) if relative_data_path else os.path.abspath(data_filename) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap at 120 characters please, below line is fine at just under 120. |
||
else: | ||
data_filename = header['data file'] | ||
elif filename.endswith('.nrrd') and detached_header: | ||
data_filename = filename | ||
header['data file'] = data_filename | ||
header['data file'] = os.path.basename(data_filename) if relative_data_path else os.path.abspath(data_filename) | ||
filename = '%s.nhdr' % os.path.splitext(filename)[0] | ||
else: | ||
# Write header & data as one file | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is > 120 characters, can you break it at this argument. Repeat for the one other case. Remove the additional space like shown.
Sorry, never explicitly stated that the syntax is to keep lines less than 120 characters, but it's just the standard I use.