cleanup and restructure code for writing output files in tsmap()
cleanup and restructure code for writing output files in tsmap()

jefemagril/fermipy,jefemagril/fermipy,fermiPy/fermipy,jefemagril/fermipy