-
Notifications
You must be signed in to change notification settings - Fork 0
/
bin_time.py
53 lines (43 loc) · 1.47 KB
/
bin_time.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import numpy as np
from astropy.time import Time
def get_tbinned(t, num):
start = Time(t[0], format='mjd').value
end = Time(t[-1], format='mjd').value
new_time = np.linspace(start, end, num)
return Time(new_time, format='mjd')
def read_and_bin_profile(I, t_init, t_new):
t_old = Time(t_init, format='mjd')
Ibinned = np.zeros((len(t_new),I.shape[1], I.shape[2]))
for i in range(I.shape[0]):
idx = np.searchsorted(t_new.mjd,t_old[i].mjd)
Ibinned[idx-1,:]+=I[i,:,:]
return Ibinned, t_new.value
def read_and_bin_file(fname,tbinned):
gpu = np.load(fname)
t = gpu['t']
I = gpu['I']
f = gpu['f']
if type(t) != np.ndarray:
for i in range (len(t)):
t[i] = np.float(t[i].value)
t = np.array(t, dtype=float)
t = Time(t,format='mjd')
Ibinned = np.zeros((len(tbinned),I.shape[1], I.shape[2]))
for i in range(I.shape[0]):
idx = np.searchsorted(tbinned.mjd,t[i].mjd)
Ibinned[idx-1,:]+=I[i,:,:]
#Ibinned = Ibinned/Ibinned.mean(axis=1,keepdims=True)
return Ibinned,f, tbinned
# OLD CODE
def read_and_bin(fname,tbinned):
gpu = np.load(fname)
t = gpu['time']
I = gpu['I']
f = gpu['freq']
t = Time(t,format='mjd')
Ibinned = np.zeros((len(tbinned),I.shape[1]))
for i in range(I.shape[0]):
idx = np.searchsorted(tbinned.mjd,t[i].mjd)
Ibinned[idx-1,:]+=I[i,:]
Ibinned = Ibinned/Ibinned.mean(axis=1,keepdims=True)
return Ibinned,f, tbinned