File: fits_fftdemo.rb

package info (click to toggle)
libnarray-ruby 0.5.9-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 564 kB
  • ctags: 564
  • sloc: ansic: 4,620; ruby: 1,513; python: 70; makefile: 5
file content (27 lines) | stat: -rw-r--r-- 602 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# FITS-FFT demo 
require 'fits'
require 'nimage'

f = Fits.new
f.read( $*.shift || 'dss_m51.fits' )
nx,ny = f.data.shape

NImage.show f.data #, 'M51'

# FFT low-pass filtering
x = NArray.float(nx).indgen! / (nx*0.1)
y = NArray.float(ny).indgen! / (nx*0.1)
x[-nx/2] = x[nx/2-1..0]
y[-ny/2] = y[ny/2-1..0]
y.reshape!(1,ny)
# Operation between [nx,1] and [1,ny] arrays makes [nx,ny].
filt = 1 / (x**2 + y**2 + 1)

print "Now executing FFT...\n"
spec = FFTW.fftw(f.data,-1)
lowpass = FFTW.fftw(spec*filt,1).real / (nx*ny)

NImage.show  lowpass #, 'M51 (FFT low-pass)'

print "Hit return key..."
STDIN.getc