Skip to content
Snippets Groups Projects
Commit 7d35b7cb authored by Vlad Kondratiev's avatar Vlad Kondratiev
Browse files

added scaling parameter to choose from dB and linear; few small label/axes...

added scaling parameter to choose from dB and linear; few small label/axes changes; also added the option --now to not open the GUI window, only saving to file
parent 0deb2ff6
Branches
No related tags found
No related merge requests found
...@@ -47,7 +47,13 @@ def read_hdf5_file(fname, tscrunch, fscrunch, memory_usage_limit): ...@@ -47,7 +47,13 @@ def read_hdf5_file(fname, tscrunch, fscrunch, memory_usage_limit):
freq = h5[group_name + "/COORDINATES/COORDINATE_1"].attrs["AXIS_VALUES_WORLD"] freq = h5[group_name + "/COORDINATES/COORDINATE_1"].attrs["AXIS_VALUES_WORLD"]
tsamp = h5[group_name + "/COORDINATES/COORDINATE_0"].attrs["INCREMENT"] tsamp = h5[group_name + "/COORDINATES/COORDINATE_0"].attrs["INCREMENT"]
station_list = h5[group_name].attrs["STATIONS_LIST"] station_list = h5[group_name].attrs["STATIONS_LIST"]
# coherent or incoherent addition of stations
signal_sum = h5[group_name].attrs["SIGNAL_SUM"]
if "IN" in signal_sum: signal_sum = "Incoh sum"
else: signal_sum = "Coh sum"
# number of Stokes components in the whole observation
obsnof = h5[group_name].attrs["OBSERVATION_NOF_STOKES"]
# number of Stokes components in the file # number of Stokes components in the file
nof = h5[group_name].attrs["NOF_STOKES"] nof = h5[group_name].attrs["NOF_STOKES"]
if nof>1: if nof>1:
...@@ -122,7 +128,7 @@ def read_hdf5_file(fname, tscrunch, fscrunch, memory_usage_limit): ...@@ -122,7 +128,7 @@ def read_hdf5_file(fname, tscrunch, fscrunch, memory_usage_limit):
# f-scrunching the freq values as well # f-scrunching the freq values as well
freq = np.mean(np.reshape(freq, (int(nchan/fscrunch), fscrunch)), axis=1) freq = np.mean(np.reshape(freq, (int(nchan/fscrunch), fscrunch)), axis=1)
return (tsamp, freq, chanbw, chanpersub, nsubs, data, stations, nstations, band, antenna_set, stokes_comp, obsid, targets) return (tsamp, freq, chanbw, chanpersub, nsubs, data, stations, signal_sum, nstations, band, antenna_set, stokes_comp, obsnof, obsid, targets)
### ###
###--- m a i n --- ###--- m a i n ---
...@@ -135,18 +141,22 @@ if __name__ == "__main__": ...@@ -135,18 +141,22 @@ if __name__ == "__main__":
default=1, type=int) default=1, type=int)
parser.add_argument("-f", "--fscrunch", help="scrunch factor in frequency (default: 1)", parser.add_argument("-f", "--fscrunch", help="scrunch factor in frequency (default: 1)",
default=1, type=int) default=1, type=int)
parser.add_argument("-s", "--scale", help="Scaling of the plot: 'linear' or 'dB' (default: dB)",
default="dB", type=str)
parser.add_argument("--flagger", help="Flagging routine/package/method to use (default: aoflagger)", parser.add_argument("--flagger", help="Flagging routine/package/method to use (default: aoflagger)",
default="aoflagger", type=str) default="aoflagger", type=str)
parser.add_argument("--noflag", help="Skip flagging of the data to calculate the RFI fraction", parser.add_argument("--noflag", help="Skip flagging of the data to calculate the RFI fraction",
action="store_true") action="store_true")
parser.add_argument("--memory_usage_limit", help="fraction of RAM aimed to be used (in percent, default: 5) [float]", parser.add_argument("--memory_usage_limit", help="fraction of RAM aimed to be used (in percent, default: 5) [float]",
default=5., type=float) default=5., type=float)
parser.add_argument("--noshow", help="Only save dynamic spectrum to file without opening GUI",
action="store_true")
parser.add_argument("-v", "--verbose", help="more verbose output", parser.add_argument("-v", "--verbose", help="more verbose output",
action="store_true") action="store_true")
args = parser.parse_args() args = parser.parse_args()
# Read data # Read data
(tsamp, freq, chanbw, chanpersub, nsubs, data, stations, nstations, band, antenna_set, stokes, obsid, targets) = \ (tsamp, freq, chanbw, chanpersub, nsubs, data, stations, signal_sum, nstations, band, antenna_set, stokes, obsnof, obsid, targets) = \
read_hdf5_file(args.h5file, args.tscrunch, args.fscrunch, args.memory_usage_limit) read_hdf5_file(args.h5file, args.tscrunch, args.fscrunch, args.memory_usage_limit)
nsamp, nchan = data.shape # here nsamp is already t-scrunched nsamp, nchan = data.shape # here nsamp is already t-scrunched
freq *= 1e-6 # in MHz freq *= 1e-6 # in MHz
...@@ -154,10 +164,14 @@ if __name__ == "__main__": ...@@ -154,10 +164,14 @@ if __name__ == "__main__":
# Extract data # Extract data
dB = lambda x: 10 * np.log10(x) dB = lambda x: 10 * np.log10(x)
v = dB(data)
zm = np.mean(data, axis=0) zm = np.mean(data, axis=0)
zs = np.std(data, axis=0) zs = np.std(data, axis=0)
if args.scale == "dB":
v = dB(data)
z = dB(zm) z = dB(zm)
else:
v = data
z = zm
if not args.noflag: if not args.noflag:
# Flag data # Flag data
...@@ -207,8 +221,11 @@ if __name__ == "__main__": ...@@ -207,8 +221,11 @@ if __name__ == "__main__":
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=(18, 8), sharex=True, gridspec_kw={"height_ratios": [0.1, 0.2, 0.7], "hspace": 0.02}) fig, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=(18, 8), sharex=True, gridspec_kw={"height_ratios": [0.1, 0.2, 0.7], "hspace": 0.02})
ylabel = "Power"
if args.scale == "dB": ylabel += " (dB)"
else: ylabel += " (arb. units)"
# Top RFI fraction subplot # Top RFI fraction subplot
ax1.set_title(f"L{obsid} | {antenna_set} | {band} | Nsub: {nsubs} | Nchan/sub = {chanpersub} | Nstations = {nstations} | {stations}", loc='left') ax1.set_title(f"L{obsid} | {antenna_set} | {band} | Nsub: {nsubs} | Nchan/sub = {chanpersub} | Nstations = {nstations} ({signal_sum}) | {stations}", loc='left')
ax1.set_title(f"{targets} | Stokes: {stokes}", loc='right') ax1.set_title(f"{targets} | Stokes: {stokes}", loc='right')
ax1.set_ylabel("RFI (%)") ax1.set_ylabel("RFI (%)")
ax1.set_ylim(-10, 110) ax1.set_ylim(-10, 110)
...@@ -218,7 +235,7 @@ if __name__ == "__main__": ...@@ -218,7 +235,7 @@ if __name__ == "__main__":
# Average spectrum # Average spectrum
ax2.plot(freq, z, color="k", linewidth=0.5) ax2.plot(freq, z, color="k", linewidth=0.5)
ax2.set_ylabel("Power (dB)") ax2.set_ylabel(ylabel)
ax2.set_ylim(vmin, vmax) ax2.set_ylim(vmin, vmax)
ax2.set_xlim(fmin, fmax) ax2.set_xlim(fmin, fmax)
...@@ -237,8 +254,9 @@ if __name__ == "__main__": ...@@ -237,8 +254,9 @@ if __name__ == "__main__":
ax3label=f"Tscrunch: {args.tscrunch} Fscrunch: {args.fscrunch}" ax3label=f"Tscrunch: {args.tscrunch} Fscrunch: {args.fscrunch}"
props = dict(boxstyle='round', facecolor='white', alpha=0.7) props = dict(boxstyle='round', facecolor='white', alpha=0.7)
ax3.text(0.01, 0.95, ax3label, transform=ax3.transAxes, fontsize=10, verticalalignment='center', bbox=props) ax3.text(0.01, 0.95, ax3label, transform=ax3.transAxes, fontsize=10, verticalalignment='center', bbox=props)
fig.colorbar(img, ax=ax3, location="bottom", orientation="horizontal", label="Power (dB)", shrink=1, pad=0.12, fraction=0.05) fig.colorbar(img, ax=ax3, location="bottom", orientation="horizontal", label=ylabel, shrink=1, pad=0.12, fraction=0.05)
plt.savefig(f"L{obsid}_bf_spectrum_stokes{stokes}_tscr{args.tscrunch}_fscr{args.fscrunch}.png", bbox_inches="tight") plt.savefig(f"L{obsid}_bf_spectrum_stokes{stokes}_tscr{args.tscrunch}_fscr{args.fscrunch}.png", bbox_inches="tight")
if not args.noshow:
plt.show() plt.show()
plt.close() plt.close()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment