Skip to content

Instantly share code, notes, and snippets.

@Miladiouss
Last active October 29, 2019 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Miladiouss/a199176aafaab869b46df5ed4c790df8 to your computer and use it in GitHub Desktop.
Save Miladiouss/a199176aafaab869b46df5ed4c790df8 to your computer and use it in GitHub Desktop.
Demonstrates that evaluating wcs.pixel_to_world is efficient for large vectors but very inefficient for single calls.
from time import sleep, time
import numpy as np
from astropy import wcs
w = wcs.WCS(naxis=2)
w.wcs.ctype = ["RA---SIN","DEC--SIN"]
w.wcs.cdelt = (6.2/3600, 6.2/3600)
w.wcs.crval = (30, 60)
w.wcs.crota = (0, 15)
# ----------------------------------------
N = 100
xs=np.random.randint(0, 128, N)
ys=np.random.randint(0, 128, N)
t1 = time()
M = 100
for i in range(M):
coord = w.pixel_to_world(xs, ys)
t2 = time()
print('I. Process duration for array of size N = {}: {:.3f} ms per iteration'.format(N, (t2-t1)/M*1000))
# ----------------------------------------
N = 1000
xs=np.random.randint(0, 128, N)
ys=np.random.randint(0, 128, N)
t1 = time()
for i in range(M):
coord = w.pixel_to_world(xs, ys)
t2 = time()
print('II. Process duration for array of size N = {}: {:.3f} ms per iteration'.format(N, (t2-t1)/M*1000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment