-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfbio.py
More file actions
58 lines (53 loc) · 1.65 KB
/
fbio.py
File metadata and controls
58 lines (53 loc) · 1.65 KB
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
54
55
56
57
58
"""
Writes numpy files into filterbank, needs sigproc.py now sigproc3
"""
import matplotlib.pyplot as plt
import numpy as np
import os
import sys
import logging
# import bilby
# from astropy import units as u
import sigproc3 as sgp
__author__ = "Harry Qiu"
class makefilterbank:
def __init__(self,filename,header=None):
# if header== "Empty":
# print("using default header with fch1=1464, nchan=336, foff=-1")
if header==None:
self.header={'az_start': 0.0,
'barycentric': None,
'data_type': 1,
'fch1':1464.0,
'fchannel': None,
'foff': -1.0,
'machine_id': 0,
'nbits': 8,
'nchans': 336,
'nifs': 1,
'nsamples': None,
'period': None,
'pulsarcentric': None,
'rawdatafile': None,
'refdm': None,
'source_name': 'None',
#'src_dej': -32441.084833752,
#'src_raj': 215344.63079648,
'src_raj':174540.1662,
'src_dej':-290029.896,
'telescope_id': 7,
'tsamp': 0.00126646875,
'tstart': 57946.52703893818,
'za_start': 0.0}
else:
self.header=header
self.fbank=sgp.SigprocFile(filename,'wb',header)
self.fbank.seek_data()
def writeblock(self,input):
input.T.tofile(self.fbank.fin)
def writenoise(self,nsamp,std,base):
noise=(np.random.randn(self.header['nchans'], nsamp)*std + base).astype(np.uint8)
noise.T.tofile(self.fbank.fin)
def closefile(self):
self.fbank.fin.flush()
self.fbank.fin.close()