def computeEdgesCenter(edges): alpha = fileutil.DEGTORAD(edges[0]) dec = fileutil.DEGTORAD(edges[1]) xmean = np.mean(np.cos(dec)*np.cos(alpha)) ymean = np.mean(np.cos(dec)*np.sin(alpha)) zmean = np.mean(np.sin(dec)) crval1 = fileutil.RADTODEG(np.arctan2(ymean,xmean))%360.0 crval2 = fileutil.RADTODEG(np.arctan2(zmean,np.sqrt(xmean*xmean+ymean*ymean))) return crval1,crval2
def build_pixel_transform(chip,output_wcs): driz_pars = {} driz_pars['pxg'] = np.zeros([2,2],dtype=np.float32) driz_pars['pyg'] = np.zeros([2,2],dtype=np.float32) # Use default C mapping function _inwcs = np.zeros([8],dtype=np.float64) driz_pars['inwcs'] = convertWCS(output_wcs.wcs,_inwcs) indx = chip.outputNames['data'].find('.fits') driz_pars['coeffs_name'] = chip.outputNames['data'][:indx]+'_coeffs'+str(chip.detnum)+'.dat' # # Need to compute and write out coeffs files for each chip as well. # xcoeffs,ycoeffs = coeff_converter.sip2idc(chip.wcs) # account for the case where no IDCSCALE has been set, due to a # lack of IDCTAB or to 'coeffs=False'. idcscale = chip.wcs.idcscale if idcscale is None: idcscale = chip.wcs.pscale xcoeffs /= idcscale ycoeffs /= idcscale driz_pars['coeffs'] = [xcoeffs,ycoeffs] abxt,cdyt = wcsfit(chip.wcs,output_wcs) #abxt[2] -= xzero #cdyt[2] -= yzero driz_pars['abxt'] = abxt driz_pars['cdyt'] = cdyt driz_pars['delta_rot'] = fileutil.RADTODEG(np.arctan2(abxt[1],cdyt[0])) # Compute scale from fit to allow WFPC2 (and similar) data to be handled correctly driz_pars['scale'] = 1./np.sqrt(abxt[0]**2 + abxt[1]**2) driz_pars['tddalpha'] = chip.header['tddalpha'] driz_pars['tddbeta'] = chip.header['tddbeta'] return driz_pars
def fitlin_rscale(xy, uv, verbose=False): """ Performs a linear, orthogonal fit between matched lists of positions 'xy' (input) and 'uv' (output). Output: (same as for fit_arrays_general) """ mu = uv[:, 0].mean() mv = uv[:, 1].mean() mx = xy[:, 0].mean() my = xy[:, 1].mean() u = uv[:, 0] - mu v = uv[:, 1] - mv x = xy[:, 0] - mx y = xy[:, 1] - my Sxx = np.dot(x, x) Syy = np.dot(y, y) Sux = np.dot(u, x) Suy = np.dot(u, y) Svx = np.dot(v, x) Svy = np.dot(v, y) # implement parity check if (np.dot(Sux, Svy) > 0): p = 1 else: p = -1 XX = p * Sux + Svy YY = Suy - p * Svx # derive output values theta_deg = fileutil.RADTODEG(np.arctan2(YY, XX)) % 360.0 scale = np.sqrt(XX**2 + YY**2) / (Sxx + Syy) shift = (mu - mx, mv - my) if verbose: print('Linear RSCALE fit: rotation = ', theta_deg, ' scale = ', scale, ' offset = ', shift) coeffs = scale * fileutil.buildRotMatrix(-theta_deg) P = [coeffs[0, 0], coeffs[0, 1], shift[0]] Q = [coeffs[1, 1], coeffs[1, 0], shift[1]] return P, Q