# Path: util.py
# def md5_storage_hash(s):
#   m = md5.new()
#   m.update(s)
#   return m.hexdigest()


import subprocess, datetime, os, time, signal
import tempfile
import time
import shutil
import sys, os
from StringIO import StringIO
from shove import Shove
from astLib import astWCS
from util import md5_storage_hash
  except:
    print "\033[91m No solution\033[0m"
    return None
  wcs_text = f_wcs.read()
  f_wcs.close()

  store[shovekey] = wcs_text

  # delete temp file
  f.close()
  # and the temp directory
  shutil.rmtree(output_dir)

  return wcs_text

def get_center_ra_dec(key):
  shovekey = 'neat_wcs_%s' % md5_storage_hash(key)
  if shovekey not in store:
    print "get_center_ra_dec: couldn't find matching key in store"
    return None
  wcs = astWCS.WCS(StringIO(store[shovekey]))
  return wcs.getCentreWCSCoords()


def get_pixel_offset(image_key1, image_key2, reference_ra, reference_dec):
  """
  Returns an (X, Y) tuple of pixel offsets to transform key1 to key2.
  reference_ra and reference_dec must appear in both images.
  """


# Path: util.py
# def md5_storage_hash(s):
#   m = md5.new()
#   m.update(s)
#   return m.hexdigest()


# Path: stackblink/astrometry.py
import subprocess, datetime, os, time, signal
import tempfile
import time
import shutil
import sys, os
from StringIO import StringIO
from shove import Shove
from astLib import astWCS
from util import md5_storage_hash

  except:
    print "\033[91m No solution\033[0m"
    return None
  wcs_text = f_wcs.read()
  f_wcs.close()

  store[shovekey] = wcs_text

  # delete temp file
  f.close()
  # and the temp directory
  shutil.rmtree(output_dir)

  return wcs_text

def get_center_ra_dec(key):
  shovekey = 'neat_wcs_%s' % md5_storage_hash(key)
  if shovekey not in store:
    print "get_center_ra_dec: couldn't find matching key in store"
    return None
  wcs = astWCS.WCS(StringIO(store[shovekey]))
  return wcs.getCentreWCSCoords()


def get_pixel_offset(image_key1, image_key2, reference_ra, reference_dec):
  """
  Returns an (X, Y) tuple of pixel offsets to transform key1 to key2.
  reference_ra and reference_dec must appear in both images.
  """


  shove_key1 = 'neat_wcs_%s' % md5_storage_hash(image_key1)