-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsrstat.py
36 lines (29 loc) · 899 Bytes
/
psrstat.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
'''
Example:
psrstat -c nchan,nsubint filename
-> psrstat(filename,"nchan,nsubint")
-> psrstat(filename,["nchan","nsubint"])
-> psrstat(filename,np.ndarray(["nchan","nsubint"]))
Returns a list
'''
import subprocess
import numpy as np
import re
def psrstat(filename,parameters):
if not isinstance(parameters,(str,list,np.ndarray)):
raise ValueError("Bad parameter type")
if type(parameters) != type(""):
parameters = ",".join(parameters)
cmd = 'psrstat -Q -c %s %s' % (parameters,filename)
proc = subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True)
out, err = proc.communicate()
retval = out.split()[1:]
for i,item in enumerate(retval):
if item.isdigit():
retval[i] = int(item)
else:
try:
retval[i] = float(item)
except ValueError:
continue
return retval