# nmonte realisations for nd, spectra in enumerate(data.data): for nm in xrange(nmonte): buffer[nd][nm] = np.random.normal(spectra.flux, spectra.ferr) # allocate space for results as we need to complete all # computations before getting answers. chisq = np.empty((nfreq,nmonte,len(cond))) # outer loop over frequency so SVD need only to be done once per # frequency for nf, f in enumerate(fs): grid.period = 1/f # generate the matrix A = doppler.genmat(grid, data, ntdiv) # Carry out full SVD, returning smallest matrices possible u, s, v = np.linalg.svd(A,full_matrices=False) # replace u and v by their transposes v = np.transpose(v) u = np.transpose(u) smax = s[0] # Go through each value of the conditioning numbers to compute maximum # number of SVDs to use mok = 0 for nc, c in enumerate(cond): # select the highest singular values with a method
parser.add_argument('data', help='data file') parser.add_argument('svd', help='name of the SVD output file') # optional parser.add_argument('-n', dest='ntdiv', type=int, default=11, help='spectrum sub-division factor') # OK, done with arguments. args = parser.parse_args() # load grid and data grid = doppler.Grid.rfits(doppler.afits(args.grid)) data = doppler.Data.rfits(doppler.afits(args.data)) # generate the matrix A = doppler.genmat(grid, data, args.ntdiv) # Carry out full SVD, returning smallest matrices possible u, s, v = np.linalg.svd(A,full_matrices=False) ng = grid.data.shape[0] # Matrix v is the one we want. It should have dimensions (ng*ng) x (ng*ng) where # N is number along each side of the grids. Need to re-shape v = np.reshape(v, (ng*ng,ng,ng)) # now write to FITS head = fits.Header() head['SOURCE'] = 'svd.py' hdu = fits.PrimaryHDU(data=v, header=head) hdu.writeto(doppler.afits(args.svd))