"""
Some of the frames come with completely bogus WCS.  This script
attempts to fix it.
"""


from __future__ import with_statement

import csv
import math
import os
import re
import resource
import shutil
import sys

from gavo import api
from gavo import utils
from gavo.base import coords
from gavo.helpers import anet
from gavo.helpers import processing
from gavo.utils import fitstools
from gavo.utils import pyfits


class MindstepProcessor(AnetHeaderProcessor):
	"""A processor only touching files with bogus WCS.
	"""
	sp_indices = ["/data/gavo/inputs/maidanak/customindex/custom2.idx",
		"/data/gavo/inputs/maidanak/customindex/custom3.idx",
		"/data/gavo/inputs/maidanak/customindex/custom4.idx",]
	sp_endob = 100
	sexControl = ""
	sp_plots = False

	def classify(self, srcName):
		hdr = self.getPrimaryHeader(srcName)
		if hdr["CRVAL1"]!=1:
			return "fixed or ok"
		stem = os.path.splitext(os.path.basename(srcName))[0]
		if os.path.exists(self._makeCacheName(srcName)):
			return "unfixed, solved"
		return "Not solved"

	def _isProcessed(self, srcName):
		return self.classify(srcName)=="fixed or ok"

	def historyFilter(self, value):
		return not ("Created by" in value
			or "more details" in value
			or "Subversion" in value
			or "svn+ssh" in value
			or "2007)" in value)


if __name__=="__main__":
	processing.procmain(MindstepProcessor, "danish/red.rd", "import")
