Exemple #1
0
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()
Exemple #2
0
def get_fast_image(key):
    # This is not terribly fast, but if the archive's image is not fast,
    # this will load much much faster. If the image is cached, it will load
    # at about the same speed.
    # Pros: faster.
    # Cons: not "official" skymorph post-processing. The initial bytes are the same,
    # but the sharpness/contrast improvements are done by the API, not by NASA.
    storage_key = 'fast_%s' % (md5_storage_hash(key))
    store_mutex.acquire()
    if storage_key in store:
        store_mutex.release()
        return store[storage_key]
    store_mutex.release()
    data = [x for x in key.split('|') if x.strip() != '']
    id = data[0]
    x = float(data[12])
    y = float(data[13])
    width = height = IMAGE_SIZE
    x0 = max(0, x - IMAGE_SIZE / 2.)
    y0 = max(0, y - IMAGE_SIZE / 2.)
    ret = neat_binary.process_from_internet(id, x0, y0, width, height)
    store_mutex.acquire()
    store[storage_key] = ret
    store_mutex.release()
    return ret
Exemple #3
0
def get_fast_image(key):
  # This is not terribly fast, but if the archive's image is not fast,
  # this will load much much faster. If the image is cached, it will load
  # at about the same speed.
  # Pros: faster.
  # Cons: not "official" skymorph post-processing. The initial bytes are the same,
  # but the sharpness/contrast improvements are done by the API, not by NASA.
  storage_key = 'fast_%s' % (md5_storage_hash(key))
  store_mutex.acquire()
  if storage_key in store:
    store_mutex.release()
    return store[storage_key]
  store_mutex.release()
  data = [x for x in key.split('|') if x.strip() != '']
  id = data[0]
  x = float(data[12])
  y = float(data[13])
  width = height = IMAGE_SIZE
  x0 = max(0, x - IMAGE_SIZE/2.)
  y0 = max(0, y - IMAGE_SIZE/2.)
  ret = neat_binary.process_from_internet(id, x0, y0, width, height)
  store_mutex.acquire()
  store[storage_key] = ret
  store_mutex.release()
  return ret
Exemple #4
0
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()
Exemple #5
0
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)
  shove_key2 = 'neat_wcs_%s' % md5_storage_hash(image_key2)

  if shove_key1 not in store or shove_key2 not in store:
    print "get_pixel_offset: couldn't find matching keys in store - are you sure they've been processed?"
    return None

  wcs1 = astWCS.WCS(StringIO(store[shove_key1]))
  x1, y1 = wcs1.wcs2pix(reference_ra, reference_dec)
  wcs2 = astWCS.WCS(StringIO(store[shove_key2]))
  x2, y2 = wcs2.wcs2pix(reference_ra, reference_dec)

  return x2-x1, y2-y1
Exemple #6
0
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)
    shove_key2 = 'neat_wcs_%s' % md5_storage_hash(image_key2)

    if shove_key1 not in store or shove_key2 not in store:
        print "get_pixel_offset: couldn't find matching keys in store - are you sure they've been processed?"
        return None

    wcs1 = astWCS.WCS(StringIO(store[shove_key1]))
    x1, y1 = wcs1.wcs2pix(reference_ra, reference_dec)
    wcs2 = astWCS.WCS(StringIO(store[shove_key2]))
    x2, y2 = wcs2.wcs2pix(reference_ra, reference_dec)

    return x2 - x1, y2 - y1
Exemple #7
0
def get_image(key):
    storage_key = 'skymorph_%s' % (md5_storage_hash(key))
    store_mutex.acquire()
    if storage_key in store:
        store_mutex.release()
        return store[storage_key]
    store_mutex.release()
    info = get_image_info(key)
    if info and 'url' in info:
        r = requests.get(info['url'])
        ret = r.content
    else:
        ret = info
    store_mutex.acquire()
    store[storage_key] = ret
    store_mutex.release()
    return ret
Exemple #8
0
def get_image(key):
  storage_key = 'skymorph_%s' % (md5_storage_hash(key))
  store_mutex.acquire()
  if storage_key in store:
    store_mutex.release()
    return store[storage_key]
  store_mutex.release()
  info = get_image_info(key)
  if info and 'url' in info:
    r = requests.get(info['url'])
    ret = r.content
  else:
    ret = info
  store_mutex.acquire()
  store[storage_key] = ret
  store_mutex.release()
  return ret
Exemple #9
0
def process(png_data, estimated_ra, estimated_dec, key, key_prefix=''):
  """
  Returns astrometry data for a given sky image.
  """
  shovekey = 'neat_wcs_%s' % md5_storage_hash(key)
  if shovekey in store:
    return store[shovekey]

  # write png to temp file
  f = tempfile.NamedTemporaryFile(prefix='astrometry_')
  f.write(png_data)
  f.flush()

  output_dir = tempfile.mkdtemp(prefix='astrometry_results_')

  png_path = f.name

  print 'Solving field for', key, '...'
  result = _timeout_command('solve-field --no-plots --cpulimit 30 -o solution --scale-units degwidth --scale-low 0 --scale-high 2 %s --ra %f --dec %f --radius 1 -D %s' \
      % (png_path, estimated_ra, estimated_dec, output_dir), 60)

  if not result:
    print '\033[91m Could not solve field\033[0m'
    return None
  print 'Done solving field'

  wcs_path = output_dir + '/solution.new'
  try:
    f_wcs = open(wcs_path, 'r')
  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
Exemple #10
0
def process(png_data, estimated_ra, estimated_dec, key, key_prefix=''):
    """
  Returns astrometry data for a given sky image.
  """
    shovekey = 'neat_wcs_%s' % md5_storage_hash(key)
    if shovekey in store:
        return store[shovekey]

    # write png to temp file
    f = tempfile.NamedTemporaryFile(prefix='astrometry_')
    f.write(png_data)
    f.flush()

    output_dir = tempfile.mkdtemp(prefix='astrometry_results_')

    png_path = f.name

    print 'Solving field for', key, '...'
    result = _timeout_command('solve-field --no-plots --cpulimit 30 -o solution --scale-units degwidth --scale-low 0 --scale-high 2 %s --ra %f --dec %f --radius 1 -D %s' \
        % (png_path, estimated_ra, estimated_dec, output_dir), 60)

    if not result:
        print '\033[91m Could not solve field\033[0m'
        return None
    print 'Done solving field'

    wcs_path = output_dir + '/solution.new'
    try:
        f_wcs = open(wcs_path, 'r')
    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