title: Assign WCS coordinates to a FITS image
body: <p>I've been searching the documentation like crazy and cannot find an answer for this one. </p>
  
  <p>I'm generating FITS images in python and need to assign WCS coordinates to the image.  I know there are lots of ways to do this by matching up point sources with a known catalog, but in this case I'm generating a dust map, so point source matching won't work (as far as I can tell).</p>
  
  <p>So the image is a 2D Numpy array of shape (240,240).  It's written like so (the x and y coordinate assignments are a little weird, it works somehow):</p>
  
  <pre><code>H, xedges, yedges = np.histogram2d(glat, glon, bins=[ybins, xbins], weights=Av)
  count, x, y = np.histogram2d(glat, glon, bins=[ybins, xbins])
  H/=count
  hdu = pyfits.PrimaryHDU(H)
  hdu.writeto(filename)
  
  &gt;&gt;&gt; print H.shape
  (240,240)
  </code></pre>
  
  <p>That all works fine on its own.  For assigning galactic coordinates seems like all you'd need to do is something like:</p>
  
  <pre><code>glon_coords = np.linspace(np.amin(glon), np.amax(glon), 240)
  glat_coords = np.linspace(np.amin(glat), np.amax(glat), 240)
  </code></pre>
  
  <p>But I don't understand how the FITS image stores these coordinates, so I don't know how to write them.  I've tried assigning them in SAO DS9, too, but no luck.  I just need a straightforward way of assigning these coordinates to the image.</p>
  
  <p>Thanks for any help you can provide.</p>