#!/usr/bin/env python
import numpy

from gavo import api
from gavo.utils import imgtools

class PreviewMaker(api.PreviewMaker):
	def getPreviewData(self, srcName):
		hdus = api.pyfits.open(srcName)
		spectVals = hdus[1].data
		# or should we mask those?
		spectVals[numpy.isnan(spectVals)] = 0
		# horizonally squeeze the spectra so we get credible sizes
		spectVals = numpy.transpose(numpy.array(
			[numpy.sum(spectVals[:, s:s+10], 1)
			for s in range(0, spectVals.shape[1], 10)]))
		return imgtools.jpegFromNumpyArray(spectVals, gamma=0.5)

if __name__=="__main__":
	api.procmain(PreviewMaker, "carmenes/q", "import")
