def loadPolyfit(self, fitRoot, accel=0, arcsec=0, trimUnfound=True, silent=False): fitFile = fitRoot + '.linearFormal' t0File = fitRoot + '.lt0' if (accel == 1): fitFile = fitRoot + '.accelFormal' t0File = fitRoot + '.t0' f_fit = open(fitFile, 'r') f_t0 = open(t0File, 'r') # Get the align names array, since we will index out of it a lot. names = np.array([star.name for star in self.stars]) alignIdx = 0 trimIdx = [] for line in f_fit: _fit = line.split() _t0 = f_t0.readline().split() # First line should be a header line with "#" as the first letter if _fit[0].startswith("#"): # Determine the number of coefficients in this file. # Columns are 1 starname, 2*2 for chiSq and Q (x and y), # and 2*2*(N) for x and y coefficients and their # associated errors for each order of the polynomial # where N is the number of coefficients. numCols = len(_fit) numCoeffs = (numCols - 5) / 4 continue # Assume that the stars loaded from align are in the same # order as the polyfit output. if names[alignIdx] != _fit[0]: if silent == False: print '%-13s: Mis-match in align and polyfit...' % _fit[0] while names[alignIdx] != _fit[0]: if trimUnfound: msg = '\t trimming ' trimIdx.append(alignIdx) else: msg = '\t skipping ' if silent == False: print '%s %s' % (msg, names[alignIdx]) alignIdx += 1 star = self.stars[alignIdx] alignIdx += 1 t0x = float(_t0[1]) t0y = float(_t0[2]) if (numCoeffs >= 1): x0 = float(_fit[1]) x0err = float(_fit[ 1 + numCoeffs ]) y0 = float(_fit[ (2*numCoeffs) + 3 ]) y0err = float(_fit[ (3*numCoeffs) + 3 ]) if (numCoeffs >= 2): vx = float(_fit[2]) vxerr = float(_fit[ 2 + numCoeffs ]) vy = float(_fit[ (2*numCoeffs) + 4 ]) vyerr = float(_fit[ (3*numCoeffs) + 4 ]) if (numCoeffs >= 3): ax = float(_fit[ 3 ]) axerr = float(_fit[ 3 + numCoeffs ]) ay = float(_fit[ (2*numCoeffs) + 5 ]) ayerr = float(_fit[ (3*numCoeffs) + 5 ]) if (accel == 1): # Save the polyfit (in pixels) star.setFitpXa(t0x, x0, x0err, vx, vxerr, ax, axerr) star.setFitpYa(t0y, y0, y0err, vy, vyerr, ay, ayerr) fitpx = star.fitpXa fitpy = star.fitpYa # Save the polyfit (in arcsec) star.setFitXa(t0x, x0, x0err, vx, vxerr, ax, axerr) star.setFitYa(t0y, y0, y0err, vy, vyerr, ay, ayerr) fitx = star.fitXa fity = star.fitYa else: # Save the polyfit (in pixels) star.setFitpXv(t0x, x0, x0err, vx, vxerr) star.setFitpYv(t0y, y0, y0err, vy, vyerr) fitpx = star.fitpXv fitpy = star.fitpYv # Save the polyfit (in arcsec) star.setFitXv(t0x, x0, x0err, vx, vxerr) star.setFitYv(t0y, y0, y0err, vy, vyerr) fitx = star.fitXv fity = star.fitYv fitx.chi2 = float(_fit[(2*numCoeffs) + 1]) fitx.q = float(_fit[(2*numCoeffs) + 2]) fitx.dof = star.velCnt - numCoeffs fitx.chi2red = fitx.chi2 / fitx.dof fity.chi2 = float(_fit[(4*numCoeffs) + 3]) fity.q = float(_fit[(4*numCoeffs) + 4]) fity.dof = star.velCnt - numCoeffs fity.chi2red = fity.chi2 / fity.dof fitpx.chi2 = float(_fit[(2*numCoeffs) + 1]) fitpx.q = float(_fit[(2*numCoeffs) + 2]) fitpx.dof = star.velCnt - numCoeffs fitpx.chi2red = fitpx.chi2 / fitpx.dof fitpy.chi2 = float(_fit[(4*numCoeffs) + 3]) fitpy.q = float(_fit[(4*numCoeffs) + 4]) fitpy.dof = star.velCnt - numCoeffs fitpy.chi2red = fitpy.chi2 / fitpy.dof if (arcsec): (fitx.p, fity.p, fitx.perr, fity.perr) = \ util.rerrPix2Arc(fitx.p, fity.p, fitx.perr, fity.perr, self.t, relErr=self.relErr) (fitx.v, fity.v, fitx.verr, fity.verr) = \ util.verrPix2Arc(fitx.v, fity.v, fitx.verr, fity.verr, self.t, relErr=self.relErr) if (accel == 1): (fitx.a, fity.a, fitx.aerr, fity.aerr) = \ util.aerrPix2Arc(fitx.a, fity.a, fitx.aerr, fity.aerr, self.t, relErr = self.relErr) f_fit.close() f_t0.close() if trimUnfound and len(trimIdx) > 0: # Trim stars down to just those with polyfit information newStars = [] for ss in range(len(self.stars)): if not ss in trimIdx: newStars.append(self.stars[ss]) self.stars = newStars
def loadPolyfit(self, fitRoot, accel=0, arcsec=0, trimUnfound=True, silent=False): fitFile = fitRoot + '.linearFormal' t0File = fitRoot + '.lt0' if (accel == 1): fitFile = fitRoot + '.accelFormal' t0File = fitRoot + '.t0' f_fit = open(fitFile, 'r') f_t0 = open(t0File, 'r') # Get the align names array, since we will index out of it a lot. names = np.array([star.name for star in self.stars]) alignIdx = 0 trimIdx = [] for line in f_fit: _fit = line.split() _t0 = f_t0.readline().split() # First line should be a header line with "#" as the first letter if _fit[0].startswith("#"): # Determine the number of coefficients in this file. # Columns are 1 starname, 2*2 for chiSq and Q (x and y), # and 2*2*(N) for x and y coefficients and their # associated errors for each order of the polynomial # where N is the number of coefficients. numCols = len(_fit) numCoeffs = (numCols - 5) / 4 continue # Assume that the stars loaded from align are in the same # order as the polyfit output. if names[alignIdx] != _fit[0]: if silent == False: print '%-13s: Mis-match in align and polyfit...' % _fit[0] while names[alignIdx] != _fit[0]: if trimUnfound: msg = '\t trimming ' trimIdx.append(alignIdx) else: msg = '\t skipping ' if silent == False: print '%s %s' % (msg, names[alignIdx]) alignIdx += 1 star = self.stars[alignIdx] alignIdx += 1 t0x = float(_t0[1]) t0y = float(_t0[2]) if (numCoeffs >= 1): x0 = float(_fit[1]) x0err = float(_fit[1 + numCoeffs]) y0 = float(_fit[(2 * numCoeffs) + 3]) y0err = float(_fit[(3 * numCoeffs) + 3]) if (numCoeffs >= 2): vx = float(_fit[2]) vxerr = float(_fit[2 + numCoeffs]) vy = float(_fit[(2 * numCoeffs) + 4]) vyerr = float(_fit[(3 * numCoeffs) + 4]) if (numCoeffs >= 3): ax = float(_fit[3]) axerr = float(_fit[3 + numCoeffs]) ay = float(_fit[(2 * numCoeffs) + 5]) ayerr = float(_fit[(3 * numCoeffs) + 5]) if (accel == 1): # Save the polyfit (in pixels) star.setFitpXa(t0x, x0, x0err, vx, vxerr, ax, axerr) star.setFitpYa(t0y, y0, y0err, vy, vyerr, ay, ayerr) fitpx = star.fitpXa fitpy = star.fitpYa # Save the polyfit (in arcsec) star.setFitXa(t0x, x0, x0err, vx, vxerr, ax, axerr) star.setFitYa(t0y, y0, y0err, vy, vyerr, ay, ayerr) fitx = star.fitXa fity = star.fitYa else: # Save the polyfit (in pixels) star.setFitpXv(t0x, x0, x0err, vx, vxerr) star.setFitpYv(t0y, y0, y0err, vy, vyerr) fitpx = star.fitpXv fitpy = star.fitpYv # Save the polyfit (in arcsec) star.setFitXv(t0x, x0, x0err, vx, vxerr) star.setFitYv(t0y, y0, y0err, vy, vyerr) fitx = star.fitXv fity = star.fitYv fitx.chi2 = float(_fit[(2 * numCoeffs) + 1]) fitx.q = float(_fit[(2 * numCoeffs) + 2]) fitx.dof = star.velCnt - numCoeffs fitx.chi2red = fitx.chi2 / fitx.dof fity.chi2 = float(_fit[(4 * numCoeffs) + 3]) fity.q = float(_fit[(4 * numCoeffs) + 4]) fity.dof = star.velCnt - numCoeffs fity.chi2red = fity.chi2 / fity.dof fitpx.chi2 = float(_fit[(2 * numCoeffs) + 1]) fitpx.q = float(_fit[(2 * numCoeffs) + 2]) fitpx.dof = star.velCnt - numCoeffs fitpx.chi2red = fitpx.chi2 / fitpx.dof fitpy.chi2 = float(_fit[(4 * numCoeffs) + 3]) fitpy.q = float(_fit[(4 * numCoeffs) + 4]) fitpy.dof = star.velCnt - numCoeffs fitpy.chi2red = fitpy.chi2 / fitpy.dof if (arcsec): (fitx.p, fity.p, fitx.perr, fity.perr) = \ util.rerrPix2Arc(fitx.p, fity.p, fitx.perr, fity.perr, self.t, relErr=self.relErr) (fitx.v, fity.v, fitx.verr, fity.verr) = \ util.verrPix2Arc(fitx.v, fity.v, fitx.verr, fity.verr, self.t, relErr=self.relErr) if (accel == 1): (fitx.a, fity.a, fitx.aerr, fity.aerr) = \ util.aerrPix2Arc(fitx.a, fity.a, fitx.aerr, fity.aerr, self.t, relErr = self.relErr) f_fit.close() f_t0.close() if trimUnfound and len(trimIdx) > 0: # Trim stars down to just those with polyfit information newStars = [] for ss in range(len(self.stars)): if not ss in trimIdx: newStars.append(self.stars[ss]) self.stars = newStars
def __init__(self, root, verbose=0, relErr=0, trans=None): self.root = root self.verbose = verbose self.relErr = relErr # Set up the default position of Sgr A* from align output. # Uses the *.sgra and *.scale files. if (trans == None): self.t = objects.Transform() self.t.loadFromAlign(root) else: self.t = trans # Load up tables _date = asciidata.open(root + '.date') f_pos = open(root + '.pos', 'r') f_err = open(root + '.err', 'r') f_mag = open(root + '.mag', 'r') f_vel = open(root + '.vel', 'r') f_par = open(root + '.param', 'r') f_name = open(root + '.name', 'r') f_opos = open(root + '.origpos', 'r') f_b0 = open(root + '.b0', 'r') numEpochs = _date.ncols # Make an infinity float to compare against Inf = float('inf') # Read epochs years = [_date[i][0] for i in range(numEpochs)] dates = ['%4d' % math.floor(year) for year in years] objects.Star.years = years self.years = np.array(years) self.dates = np.array(dates) self.stars = [] for line in f_pos: _pos = line.split() _err = f_err.readline().split() _mag = f_mag.readline().split() _vel = f_vel.readline().split() _par = f_par.readline().split() _opos = f_opos.readline().split() _b0 = f_b0.readline().split() _name = f_name.readline().split() # Initialize a new star with the proper name. Append to the set. star = objects.Star(_vel[0]) self.stars.append(star) #if (len(self.stars) % 100) == 0: # print 'Processing star {0}: {1}'.format(len(self.stars), time.ctime()) # Parse velocity file star.velCnt = int(_vel[1]) star.mag = float(_mag[1]) star.magerr = float(_mag[2]) star.x = float(_vel[3]) star.y = float(_vel[4]) star.vx = float(_vel[5]) star.vxerr = float(_vel[6]) star.vy = float(_vel[7]) star.vyerr = float(_vel[8]) star.v2d = float(_vel[9]) star.v2derr = float(_vel[10]) # Do conversions for these values (star.x, star.y) = \ util.rPix2Arc(star.x, star.y, self.t, relErr=self.relErr) (star.vx, star.vy, star.vxerr, star.vyerr) = \ util.verrPix2Arc(star.vx, star.vy, star.vxerr, star.vyerr, self.t, relErr=self.relErr) (star.v2d, star.v2derr) = \ util.errPix2Arc(star.v2d, star.v2derr, self.t, relErr=self.relErr) # Parse b0 file t0 = float(_b0[1]) x0 = float(_b0[2]) x0err = float(_b0[3]) vx = float(_b0[4]) vxerr = float(_b0[5]) y0 = float(_b0[8]) y0err = float(_b0[9]) vy = float(_b0[10]) vyerr = float(_b0[11]) star.setFitpXalign(t0, x0, x0err, vx, vxerr) star.setFitpYalign(t0, y0, y0err, vy, vyerr) (x0, y0, x0err, y0err) = util.rerrPix2Arc(x0, y0, x0err, y0err, self.t, relErr=self.relErr) (vx, vy, vxerr, vyerr) = util.verrPix2Arc(vx, vy, vxerr, vyerr, self.t, relErr=self.relErr) star.setFitXalign(t0, x0, x0err, vx, vxerr) star.setFitYalign(t0, y0, y0err, vy, vyerr) # Parse err, mag, pos files for all epochs for ei in range(numEpochs): ep = star.e[ei] ep.name = _name[ei+1] ep.xpix = float(_pos[(ei*2)+1]) ep.ypix = float(_pos[(ei*2)+2]) ep.xorig = float(_opos[(ei*2)+1]) ep.yorig = float(_opos[(ei*2)+2]) if (len(_err) > (numEpochs*2 + 1)): ep.xpixerr_p = float(_err[(ei*4)+1]) ep.ypixerr_p = float(_err[(ei*4)+2]) ep.xpixerr_a = float(_err[(ei*4)+3]) ep.ypixerr_a = float(_err[(ei*4)+4]) if (ep.xpixerr_p < 0): ep.xpixerr_p = 0.0 if (ep.ypixerr_p < 0): ep.ypixerr_p = 0.0 else: ep.xpixerr_p = 0.0 ep.ypixerr_p = 0.0 ep.xpixerr_a = float(_err[(ei*2)+1]) ep.ypixerr_a = float(_err[(ei*2)+2]) # Check for the infinity case if (ep.xpixerr_a == Inf): ep.xpixerr_a = 0.0 ep.ypixerr_a = 0.0 ep.mag = float(_mag[ei+4]) ep.snr = float(_par[(ei*4)+1]) ep.corr = float(_par[(ei*4)+2]) ep.nframes = float(_par[(ei*4)+3]) ep.fwhm = float(_par[(ei*4)+4]) # Convert stuff into arcseconds (ep.x, ep.y, ep.xerr_p, ep.yerr_p) = \ util.rerrPix2Arc(ep.xpix, ep.ypix, ep.xpixerr_p, ep.ypixerr_p, self.t, relErr=self.relErr) (ep.x, ep.y, ep.xerr_a, ep.yerr_a) = \ util.rerrPix2Arc(ep.xpix, ep.ypix, ep.xpixerr_a, ep.ypixerr_a, self.t, relErr=self.relErr)
def __init__(self, root, verbose=0, relErr=0, trans=None): self.root = root self.verbose = verbose self.relErr = relErr # Set up the default position of Sgr A* from align output. # Uses the *.sgra and *.scale files. if (trans == None): self.t = objects.Transform() self.t.loadFromAlign(root) else: self.t = trans # Load up tables _date = Table.read(root + '.date') f_pos = open(root + '.pos', 'r') f_err = open(root + '.err', 'r') f_mag = open(root + '.mag', 'r') f_vel = open(root + '.vel', 'r') f_par = open(root + '.param', 'r') f_name = open(root + '.name', 'r') f_opos = open(root + '.origpos', 'r') f_b0 = open(root + '.b0', 'r') numEpochs = _date.ncols # Make an infinity float to compare against Inf = float('inf') # Read epochs years = [_date[i][0] for i in range(numEpochs)] dates = ['%4d' % math.floor(year) for year in years] objects.Star.years = years self.years = np.array(years) self.dates = np.array(dates) self.stars = [] for line in f_pos: _pos = line.split() _err = f_err.readline().split() _mag = f_mag.readline().split() _vel = f_vel.readline().split() _par = f_par.readline().split() _opos = f_opos.readline().split() _b0 = f_b0.readline().split() _name = f_name.readline().split() # Initialize a new star with the proper name. Append to the set. star = objects.Star(_vel[0]) self.stars.append(star) # Parse velocity file star.velCnt = int(_vel[1]) star.mag = float(_mag[1]) star.magerr = float(_mag[2]) star.x = float(_vel[3]) star.y = float(_vel[4]) star.vx = float(_vel[5]) star.vxerr = float(_vel[6]) star.vy = float(_vel[7]) star.vyerr = float(_vel[8]) star.v2d = float(_vel[9]) star.v2derr = float(_vel[10]) # Do conversions for these values (star.x, star.y) = \ util.rPix2Arc(star.x, star.y, self.t, relErr=self.relErr) (star.vx, star.vy, star.vxerr, star.vyerr) = \ util.verrPix2Arc(star.vx, star.vy, star.vxerr, star.vyerr, self.t, relErr=self.relErr) (star.v2d, star.v2derr) = \ util.errPix2Arc(star.v2d, star.v2derr, self.t, relErr=self.relErr) # Parse b0 file t0 = float(_b0[1]) x0 = float(_b0[2]) x0err = float(_b0[3]) vx = float(_b0[4]) vxerr = float(_b0[5]) y0 = float(_b0[8]) y0err = float(_b0[9]) vy = float(_b0[10]) vyerr = float(_b0[11]) star.setFitpXalign(t0, x0, x0err, vx, vxerr) star.setFitpYalign(t0, y0, y0err, vy, vyerr) (x0, y0, x0err, y0err) = util.rerrPix2Arc(x0, y0, x0err, y0err, self.t, relErr=self.relErr) (vx, vy, vxerr, vyerr) = util.verrPix2Arc(vx, vy, vxerr, vyerr, self.t, relErr=self.relErr) star.setFitXalign(t0, x0, x0err, vx, vxerr) star.setFitYalign(t0, y0, y0err, vy, vyerr) # Parse err, mag, pos files for all epochs for ei in range(numEpochs): ep = star.e[ei] ep.name = _name[ei + 1] ep.xpix = float(_pos[(ei * 2) + 1]) ep.ypix = float(_pos[(ei * 2) + 2]) ep.xorig = float(_opos[(ei * 2) + 1]) ep.yorig = float(_opos[(ei * 2) + 2]) if (len(_err) > (numEpochs * 2 + 1)): ep.xpixerr_p = float(_err[(ei * 4) + 1]) ep.ypixerr_p = float(_err[(ei * 4) + 2]) ep.xpixerr_a = float(_err[(ei * 4) + 3]) ep.ypixerr_a = float(_err[(ei * 4) + 4]) if (ep.xpixerr_p < 0): ep.xpixerr_p = 0.0 if (ep.ypixerr_p < 0): ep.ypixerr_p = 0.0 else: ep.xpixerr_p = 0.0 ep.ypixerr_p = 0.0 ep.xpixerr_a = float(_err[(ei * 2) + 1]) ep.ypixerr_a = float(_err[(ei * 2) + 2]) # Check for the infinity case if (ep.xpixerr_a == Inf): ep.xpixerr_a = 0.0 ep.ypixerr_a = 0.0 ep.mag = float(_mag[ei + 4]) ep.snr = float(_par[(ei * 4) + 1]) ep.corr = float(_par[(ei * 4) + 2]) ep.nframes = float(_par[(ei * 4) + 3]) ep.fwhm = float(_par[(ei * 4) + 4]) # Convert stuff into arcseconds (ep.x, ep.y, ep.xerr_p, ep.yerr_p) = \ util.rerrPix2Arc(ep.xpix, ep.ypix, ep.xpixerr_p, ep.ypixerr_p, self.t, relErr=self.relErr) (ep.x, ep.y, ep.xerr_a, ep.yerr_a) = \ util.rerrPix2Arc(ep.xpix, ep.ypix, ep.xpixerr_a, ep.ypixerr_a, self.t, relErr=self.relErr)