Skip to content

Commit

Permalink
Clean up pix2world a little
Browse files Browse the repository at this point in the history
Get WCS as argument, no need to re-read fits header.
  • Loading branch information
Mikea1985 committed Aug 12, 2018
1 parent 1e84694 commit 1c3507f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
2 changes: 1 addition & 1 deletion maphot/maphot.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@
inputName, outfile=outfile, repfact=repfact, remove=remove)

#Run function to save photometry in MPC format
pix2world(inputFile, EXPTIME, MJD, finalTNOphotPS1[0], xUse, yUse, FILTER,
pix2world(WCS, EXPTIME, MJD, finalTNOphotPS1[0], xUse, yUse, FILTER,
extno)

print('Done with ' + inputFile + '!')
Expand Down
24 changes: 6 additions & 18 deletions maphot/pix2world.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
"""
This function reads in the wcs header of a file,
then converts an x-y pixel coordinate to a RA and Dec.
This function converts a bunch of inputs to a nicely formatted MPC line.
"""
from __future__ import print_function, division
import datetime
from astropy import units as u
from astropy.coordinates import Angle
from astropy.io import fits
#import astropy.io.fits as pyf
from astropy.time import Time
from astropy import wcs

def pix2world(fitsfile, expt, mjd, mg, xc, yc, fil, extn, observatory=568):
def pix2MPC(WCS, aEXPTIME, aMJD, mag, xcoo, ycoo, filtr, extn,
observatory=568):
"""
This function takes variables (given in maphot.py),
reads in the wcs header of a file,
then converts an x-y pixel coordinate to a RA and Dec.
Also converts the time of observation to an MPC friendly format.
Returns an MPC formatted line.
"""
aEXPTIME = expt #EXPTIME
aMJD = mjd #MJD
mag = mg #finalTNOphotPS1[0]
xcoo = xc #xUse
ycoo = yc #yUse
filter = fil #FILTER
name = 'extno{0:02.0f}'.format(extn)
#Get WCS and convert pixel coordinates to world coordinates
hdulist = fits.open(fitsfile)
#WCS = wcs.WCS(hdulist[0].header)
WCS = wcs.WCS(hdulist[extn].header)
#Convert pixel coordinates to world coordinates
ra, dec = WCS.all_pix2world(xcoo, ycoo, 1)
#Convert the ra/dec (which is in degrees) to sexagesimals
raString = Angle(str(ra) + 'degrees').to_string(unit=u.hour,
Expand All @@ -45,7 +33,7 @@ def pix2world(fitsfile, expt, mjd, mg, xc, yc, fil, extn, observatory=568):
#Put it all together in an MPC line
MPCString = (' ' + name + ' C' + midTimeString[:16] + ' ' +
raString[:12] + decString[:12] +
' {0:4.1f} '.format(mag) + filter[:1] +
' {0:4.1f} '.format(mag) + filtr[:1] +
' {0:3.0f}'.format(observatory))
wf = open("{}.mpc".format(name), "a+")
wf.write("{}\n".format(MPCString))
Expand Down

0 comments on commit 1c3507f

Please sign in to comment.