RF: use decodebytes() instead of deprecated decodestring()
RF: use "with" statement when opening file
RF: use "with" statement when opening file
ENH: use {en,de}codebytes or {en,de}codestring depending on Python version
Merge pull request #217 from nno/_tent/gifti_deprecation

RF: use decodebytes() instead of deprecated decodestring()

With python 2 / 3 compatibility
Merge pull request #213 from matthew-brett/zero-offset-on-load

MRG: reset file offset to zero creating image

This is a minor API break.

Before this PR, you would read an image, and the header would contain the data
offset value. For single file images, the data offset would typically point to
the end of the header, but it's also possible to have data at the beginning of
a file that is not part of the image. So the 'offset' field would be non-zero -
say 400.

When using this header to write out an image, or initialize a new image, the
offset field gets maintained - so the newly written image, and any image based
on the same header, also have an offset of e.g. 400.

This doesn't make much sense usually - because - if we save images to
filenames, we open 'wb' and write the whole file, so even if an existing output
image file had something interesting from 0-400, it would get overwritten with
zeros in the default write process.

The only time this doesn't happen is if you open the file object in append mode
and pass that into the image creation - but this is obviously rather rare.

This PR sets the offset to 0 in the header each time we create a new image or
load an image. The 0 signifies 'modify at will' to the code. The writing code
then sets the offset to whatever value is necessary.

If you really want to set the offset to a specific value, you can do that by
hand with:

img.header.set_data_offset(400)

in which case the writing code uses that offset, or raises an error if the
offset is too low.

This PR addresses : #105
ENH: through use of "with" statement, closing file manually is no longer necessary
Merge pull request #218 from nno/_tent/gifti_with

use "with" statement when opening GIFTI file
RF: add write0 to seek_tell function and test

Add flag to allow seek_tell to write zeros to reach a given file offset,
if it can't get there with a seek.
BF: test and fix writing of bz2 files with offsets

Writing a bz2 file that wasn't already at the data offset position
caused IOError because of failed write seek on bz2 files.

Use extended seek_tell function to write zeros to reach offset, when
seek fails.
RF: remove redundant _write_header method

We only used image _write_header method for seeking to the data position
in a nifti single image.  Now I've moved that logic to seek_tell, and
therefore 'Analyze.to_file_map', we don't need _write_header.  Remove.
There aren't any good tests for parrec2nii - so I have to hope changes
worked right.
NF: context manager for imageglobals error level

Context manager to set and unset imageglobals module constant
TST: add test for outputs from header scaling

I'm about to refactor the header scaling dramatically, but I don't want
to change the default output from given input header scalings.  Check
the output from some odd header scalings before the refactor.
RF: move slope inter and scaling tests to classes

Slightly expand test coverage by moving checks of slope and inter, and
of scaling, from functions to methods of the header test classes.
RF: break up nifti tests to ease refactoring

Break up nifti tests into separate methods for easier refactoring.

Add helper test function for checking no log errors
RF: expand scaling checks in get_slope_inter

Make header `get_slope_inter()` do checks for non-finite etc scaling for
all Analyze types.

Raise error in `get_slope_inter` if there is a valid slope but invalid
intercept.  This is the default when reading a header from disc from the
log checks, but I'm going to remove the log checks soon, and I want to
preserve the logic set in `TestAnalyzeImage.test_header_scaling()`
RF: remove all log checks and fixes for scaling

We're going to allow NaN as a valid slope and / or intercept. Up until
now we've ignored slope and intercept values in writing the image.

For simplicity, remove all header log checks and fixes for scaling.

Do all necessary reinterpretation of scale factors in `get_slope_inter`
RF: allow None as input to apply_read_scaling

Else where we've used None as shorthand for no scaling, so allow None
for slope and intercept in apply_read_scaling function.
RF: allow NaN in header.set_slope_inter()

NaN will the be signal to allow the image to do scaling on write, so
allow NaN as an input value to `set_slope_inter`
RF+API: NaN slope/inter default in set_slope_inter

Make NaN the default for slope and intercept when passing Nones to
`header.set_slope_inter()`