Restructured TS map computation

As close to final as it could get today.
This makes travis-ci fail:
https://travis-ci.org/gammapy/gammapy/jobs/42900392#L724

Put all imports at the top for test files.