-
Notifications
You must be signed in to change notification settings - Fork 1
/
alex_radiometer_equation
executable file
·171 lines (130 loc) · 6.62 KB
/
alex_radiometer_equation
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env python3
#################### ALESSANDRO RIDOLFI ########################
# Rome, 2020 #
################################################################
import sys, os, os.path, glob, shutil
import numpy as np
np.set_printoptions(threshold=1.0e7)
try:
import psrchive
flag_has_psrchive_python_module = 1
except:
flag_has_psrchive_python_module = 0
string_version = "1.1 (26Jul2020)"
def flux_with_radiometer_equation( SNR, beta, Tsys, G, npol, t_obs, bw, W_frac, P, flag_verbose_mode=False, errors=(0,0,0) ):
"""
SNR: Signal-to-noise ratio
beta: Digitization error
t_obs: Integration time [s]
npol: # of polarizations
G: Gain [K/Jy]
bw: Bandwidth [MHz]
W_frac: Pulse duty cycle
P: Pulsar Period [s]
errors: Errors for variables (SNR, Tsys, G)
"""
S_mean_mJy = ( (SNR * beta * Tsys) / (G * np.sqrt(npol * t_obs * bw) ) ) * np.sqrt( W_frac*P / ( P - W_frac*P))
if flag_verbose_mode==True:
print("S_mean [mJy] = ( (%.2f * %.2f * %.2f K) / (%.1f K/Jy * sqrt( %d * %.1f s * %.2f MHz) ) ) * sqrt( %.2f * %.4f s / ( %.4f s - %.2f * %.4f s)) = %.4f mJy" % (SNR, beta, Tsys, G, npol, t_obs, bw, W_frac, P, P , W_frac, P, S_mean_mJy))
if errors != (0,0,0):
delta_SNR = errors[0]
delta_Tsys = errors[1]
delta_G = errors[2]
#"Here f is the function S_mean_mJy"
df_dSNR = ( ( beta * Tsys) / ( G * np.sqrt(npol * t_obs * bw) ) ) * np.sqrt( W_frac*P / ( P - W_frac*P))
df_dTsys = ( (SNR * beta ) / ( G * np.sqrt(npol * t_obs * bw) ) ) * np.sqrt( W_frac*P / ( P - W_frac*P))
df_dG = -( (SNR * beta * Tsys) / (np.power(G,2) * np.sqrt(npol * t_obs * bw) ) ) * np.sqrt( W_frac*P / ( P - W_frac*P))
S_mean_mJy_Err = np.sqrt( np.power(df_dSNR * delta_SNR, 2) + np.power(df_dTsys * delta_Tsys, 2) + np.power(df_dG * delta_G, 2) )
return S_mean_mJy, S_mean_mJy_Err
else:
return S_mean_mJy
#SHELL ARGUMENTS
archive_filename = ""
verbosity_level = 1
flag_quiet_mode = 0
if (len(sys.argv) == 1 or ("-h" in sys.argv) or ("-help" in sys.argv) or ("--help" in sys.argv)):
print("USAGE: %s -SNR [8.0] -beta [1.0] -Tsys [K] -G [K/Jy] -npol [2] -W_frac [0.05] {-ar <archive> | -Tobs [s] -bw [MHz] -P [s]} [-V]" % (os.path.basename(sys.argv[0])))
print()
exit()
elif (("-version" in sys.argv) or ("--version" in sys.argv)):
print("Version: %s" % (string_version))
exit()
else:
for n in range(1, len(sys.argv)-1):
if (sys.argv[n] == "-SNR"):
SNR = np.float64(sys.argv[n+1])
elif (sys.argv[n] == "-beta"):
beta = np.float64(sys.argv[n+1])
elif (sys.argv[n] == "-Tsys"):
Tsys = np.float64(sys.argv[n+1])
elif (sys.argv[n] == "-G"):
G = np.float64(sys.argv[n+1])
elif (sys.argv[n] == "-npol"):
npol = np.float64(sys.argv[n+1])
elif (sys.argv[n] == "-W_frac"):
W_frac = np.float64(sys.argv[n+1])
#====================================================
elif (sys.argv[n] == "-P"):
P = np.float64(sys.argv[n+1])
elif (sys.argv[n] == "-bw"):
bw = np.float64(sys.argv[n+1])
elif (sys.argv[n] == "-Tobs"):
t_obs = np.float64(sys.argv[n+1])
#====================================================
elif (sys.argv[n] == "-ar"):
archive_filename = sys.argv[n+1]
elif (sys.argv[n] == "-q"):
flag_quiet_mode = 1
elif (sys.argv[n] == "-V"):
verbosity_level = 2
if archive_filename != "" and flag_quiet_mode==0:
verbosity_level = 2
if archive_filename != "":
ar = psrchive.Archive_load( archive_filename )
nbin = ar.get_nbin()
nsub = ar.get_nsubint()
npol = ar.get_npol()
nchan = ar.get_nchan()
bw_MHz = ar.get_bandwidth()
bw_chan_MHz = bw_MHz/ nchan
inte = ar.get_Integration(int(nsub/2.))
subint_length_s = inte.get_duration()
P = inte.get_folding_period()
weights = ar.get_weights()
list_subint_to_zap = []
flag_found_nonempty_subint = 0
for i in range(0,nsub):
if np.count_nonzero(weights[i]) == 0: #if the values are all zero
list_subint_to_zap.append(i)
elif flag_found_nonempty_subint == 0:
index_nonempty_subint = i
flag_found_nonempty_subint == 1
array_weights = ar.get_weights()[index_nonempty_subint]
list_channels_to_zap = np.where( array_weights == 0)[0]
nchan_effective = nchan - len(list_channels_to_zap)
nsub_effective = nsub - len(list_subint_to_zap)
bw_effective_MHz = np.fabs(bw_chan_MHz * nchan_effective)
t_obs_effective_s = subint_length_s * nsub_effective
if verbosity_level >=2:
print()
print("--------------------------------------------------------------------")
print()
print("%40s: '%s'" % ("Archive", archive_filename))
print()
print("%40s: %s" % ("List zapped channel",list_channels_to_zap))
print("%40s: %s" % ("List zapped subint", list_subint_to_zap))
print()
print("%40s: %.6f" % ("Folding period (s)", P))
print("%40s: %.6f" % ("Subint length (s)", subint_length_s))
print("%40s: %d" % ("Nsub", nsub))
print("%40s: %d" % ("Nsub effective", nsub_effective))
print("%40s: %.3f" % ("Effective BW (MHz)", bw_effective_MHz))
print("%40s: %.3f" % ("Effective Tobs (s)", t_obs_effective_s))
print()
print()
print("--------------------------------------------------------------------")
print()
t_obs = t_obs_effective_s
bw = bw_effective_MHz
S_mean_mJy = flux_with_radiometer_equation( SNR, beta, Tsys, G, npol, t_obs, bw, W_frac, P)
print("%-70s S_mean = %.5f mJy" % (archive_filename, S_mean_mJy))