コード例 #1
0
ファイル: main.go プロジェクト: npadmana/npgo
func splineCosmo(om, zmin, zmax float64) (*spline.Spline, error) {
	lcdm := cosmo.NewFlatLCDMSimple(om, 1)
	nz := 1000
	dz := (zmax - zmin) / float64(nz)
	avals := make([]float64, nz+1)
	zvals := make([]float64, nz+1)
	for i := 0; i <= nz; i++ {
		zvals[i] = zmin + float64(i)*dz
		avals[i] = cosmo.Z2A(zvals[i])
	}
	dist := cosmo.ComDis(lcdm, avals)

	sp, err := spline.New(spline.Cubic, zvals, dist)
	if err != nil {
		return nil, err
	}

	return sp, nil
}
コード例 #2
0
ファイル: main.go プロジェクト: npadmana/npgo
// The weight file is assumed to have a first header line, and then two columns
// with z and n(z)
func readWeight(wfn string, Pk float64) (*spline.Spline, error) {
	var err error

	fmt.Println("Reading in ", wfn)
	var wstr fkpstruct
	wstr.Pk = Pk
	if err := lineio.Read(wfn, &wstr); err != nil {
		return nil, err
	}

	sp, err := spline.New(spline.Cubic, wstr.zz, wstr.fkp)
	if err != nil {
		return nil, err
	}

	// Test the spline
	plot, err := gnuplot.New(false)
	defer close(plot)
	if err != nil {
		return nil, err
	}
	plot <- "set term pngcairo"
	plot <- "set output 'fkp_test.png'"
	plot <- "plot '-' w points ps 3, '-' w lines lw 2"
	for i := range wstr.zz {
		plot <- fmt.Sprintln(wstr.zz[i], wstr.fkp[i])
	}
	plot <- "e"
	var nz float64
	for z1 := wstr.zz[0]; z1 < wstr.zz[len(wstr.zz)-1]; z1 = z1 + 0.001 {
		if nz, err = sp.Eval(z1); err != nil {
			return nil, err
		}
		plot <- fmt.Sprint(z1, nz)
	}
	plot <- "e"
	plot <- "set output"

	// Return the spline
	return sp, nil

}