forked from zhuww/ubc_AI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataprep.py
executable file
·39 lines (32 loc) · 978 Bytes
/
dataprep.py
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
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
from prepfold import pfd
import numpy as np
from pylab import *
import matplotlib.pyplot as plt
from scipy.interpolate import RectBivariateSpline as interp
from scipy import ndimage, array, ogrid, mgrid
import sys,os
if __name__ == '__main__':
f1 = sys.argv[1]
f2 = sys.argv[2]
if not (f1.endswith('pfd')):
print 'file name %s not end with pfd ' % (f1)
sys.exit(1)
pfdfile = pfd(f1)
pfdfile.dedisperse()
profs = pfdfile.profs
pshape = profs.shape
x, y, z = profs.shape
data = profs.reshape((-1,1))
del pfdfile
mean = np.mean(data)
var = np.std(data)
data = (data-mean)/var
profs = data.reshape(pshape)
X, Y, Z = ogrid[0:1:x,0:1:y,0:1:z]
coords = array([X, Y, Z])
coeffs = ndimage.spline_filter(profs )
X, Y, Z = mgrid[0:1:8j,0:1:8j,0:1:8j]
coords = array([X, Y, Z])
newf = ndimage.map_coordinates(coeffs, coords, prefilter=False)
np.save(f2, newf)