Exemplo n.º 1
0
func loadloop() {
	for _, fname := range flag.Args() {
		log.Println("loading", fname)
		cachedData, cachedMeta = oommf.MustReadFile(fname) // TODO: preprocess here
		inpipe <- inp{cachedData, cachedMeta}
	}
	close(inpipe)
}
Exemplo n.º 2
0
func mainSpatial() {

	// time points
	Nt := flag.NArg()
	if Nt < 2 {
		log.Fatal("need at least 2 inputs")
	}

	go loadloop()

	// select one component
	comp := 0 // todo

	// get size, time span from first and last file
	data1, meta1 := oommf.MustReadFile(flag.Args()[0])
	_, metaL := oommf.MustReadFile(flag.Args()[Nt-1])

	t0 := float32(meta1.Time)
	t1 := float32(metaL.Time)
	deltaT := t1 - t0
	deltaF := 1 / deltaT // frequency resolution

	size := data1.Size()
	Nx := size[0]
	Ny := size[1]
	Nz := size[2]

	// allocate buffer for everything
	dataList := make([]complex64, Nt*Nx*Ny*Nz)
	dataLists := matrix.ReshapeC2(dataList, [2]int{Nt, Nz * Ny * Nx})

	// interpolate non-equidistant time points
	// make complex in the meanwhile
	time0 := t0                  // start time, not neccesarily 0
	si := 0                      // source index
	for di := 0; di < Nt; di++ { // dst index
		want := time0 + float32(di)*deltaT/float32(Nt) // wanted time
		for si < Nt-1 && !(time(si) <= want && time(si+1) > want && time(si) != time(si+1)) {
			si++
		}

		x := (want - time(si)) / (time(si+1) - time(si))
		if x < 0 || x > 1 {
			panic(fmt.Sprint("x=", x))
		}
		interp3D(dataLists[di], 1-x, file(si).Host()[comp], x, file(si + 1).Host()[comp])
	}

	log.Println("FFT")
	fftMany(dataList, Nt, Nx*Ny*Nz)

	spectrum := magSpectrum(dataLists)
	freqs := make([]float32, len(spectrum))
	for i := range freqs {
		freqs[i] = float32(i) * deltaF
	}
	header := []string{"f (Hz)", "Mag ()"}
	f := httpfs.MustCreate("spectrum.txt")
	writeTable(f, header, [][]float32{freqs, spectrum})
	f.Close()

	log.Println("normalize")
	normalize(dataLists)

	log.Println("output")
	for _, o := range outputs {
		if *o.Enabled {
			output3D(dataLists, o.Filter, size, "fft_"+o.Name, deltaF)
		}
	}
}