Skip to content

Commit

Permalink
Add eps plot option and format plots
Browse files Browse the repository at this point in the history
  • Loading branch information
Athanaseus committed Dec 5, 2023
1 parent adc335f commit fe9e46e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 28 deletions.
4 changes: 2 additions & 2 deletions rfinder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def setArgs(self,args):
self.cfg_par['rfi']['chunks']['spw_enable'] = True

if args.no_movies == True :
self.cfg_par['plots']['movies']['movies_in_report'] = False
self.cfg_par['plots']['plot_details']['movies']['movies_in_report'] = False

if args.no_cleanup==True:
self.cfg_par['general']['cleanup_enable'] = False
Expand Down Expand Up @@ -631,7 +631,7 @@ def main (self,argv):
self.parser.print_help()

print("""\nRun a command. This can be:\n \nrfinder \nrfinder -c path_to_config_file.yml
rfinder -i <ngc1399.ms> -fl <num> -tel <meerkat/apertif/wsrt>\n""")
rfinder -i <ngc1399.ms> -fl <num> -tel <meerkat/apertif/wsrt>\n""")

sys.exit(0)

Expand Down
3 changes: 2 additions & 1 deletion rfinder/rfinder_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ rfi:
rfi_enable: false #if True this module is enabled else only obs info will logged
polarization: 'q' #xx, yy, xy, yx, q (also in CAPS)
bad_antenna: '[]' #list of bad antennas: for no antennas try '[]'
RFInder_mode: 'use_flags' #uses RFI clip method or simply reads the FLAG column 'use_flags' / 'rms_clip'
RFInder_mode: 'rms_clip' #uses RFI clip method or simply reads the FLAG column 'use_flags' / 'rms_clip'
rms_clip: 5 #Threshold for RFI identification
noise_measure_edges: [1.400e9, 1.420e9] #min frequency and maximum frequency where to measure average std of visibilities
baseline_cut: 200 #Cutoff baseline lenght: < = Short, > = Long (615m midpoint of baselines of WSRT)
Expand All @@ -39,6 +39,7 @@ plots:
enable: false
plot_noise: 'rfi' #choose to plot % of RFI, 'rfi', or noise, 'noise', or factor of noise increase, 'noise_factor' in 1D plots
plot_long_short: true #plot all baselines, or only the short and the long
plot_eps: true #also generate eps plots. If false only pngs/movies
movies:
__helpstr: make movies of output plots
2d_gif: true
Expand Down
8 changes: 4 additions & 4 deletions rfinder/rfinder_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def write_html_fullreport(cfg_par):
if os.path.exists(video_name3):
video_encoded3 = base64.b64encode(open(video_name3, "rb").read())

if cfg_par['plots']['movies']['movies_in_report'] == True:
if cfg_par['plots']['plot_details']['movies']['movies_in_report'] == True:
template = env.get_template('full_template.html')
with open(cfg_par['general']['rfidir']+'full_report.html', "w") as f:
lenghts = np.array([cfg_par['rfi']['baseline_lenghts']])+0.
Expand Down Expand Up @@ -325,7 +325,7 @@ def write_html_fullreport(cfg_par):
video_tag3 = '<img class="f" src="data:image/gif;base64,{0}">'.format(video_encoded3.decode())
))

elif cfg_par['plots']['movies']['movies_in_report'] == False:
elif cfg_par['plots']['plot_details']['movies']['movies_in_report'] == False:
template = env.get_template('fullshort_template.html')
with open(cfg_par['general']['rfidir']+'full_report.html', "w") as f:
lenghts = np.array([cfg_par['rfi']['baseline_lenghts']])+0.
Expand Down Expand Up @@ -389,7 +389,7 @@ def write_html_timereport(cfg_par):
else:
video_encoded3 = None

if cfg_par['plots']['movies']['movies_in_report'] == True:
if cfg_par['plots']['plot_details']['movies']['movies_in_report'] == True:

with open(cfg_par['general']['rfidir']+'time_report.html', "w") as f:
lenghts = np.array([cfg_par['rfi']['baseline_lenghts']])+0.
Expand Down Expand Up @@ -417,7 +417,7 @@ def write_html_timereport(cfg_par):
#video_tag4 = '<img class="g" src="data:image/gif;base64,{0}">'.format(video_encoded3.decode())
))

elif cfg_par['plots']['movies']['movies_in_report'] == False:
elif cfg_par['plots']['plot_details']['movies']['movies_in_report'] == False:

logger.info('\t ERROR: movies in report must be set to TRUE\n')

Expand Down
55 changes: 34 additions & 21 deletions rfinder/rfinder_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ def plot_rfi_imshow(self,cfg_par,time_step=-1):
params = {'font.family' :' serif',
'font.style' : 'normal',
'font.weight' : 'book',
'font.size' : 18.0,
'font.size' : 24.0,
'axes.linewidth' : 1,
'lines.linewidth' : 1,
'xtick.labelsize' : 16,
'ytick.labelsize' : 16,
'xtick.labelsize' : 18,
'ytick.labelsize' : 18,
'xtick.direction' :'in',
'ytick.direction' :'in',
#'xtick.top' : True, # draw ticks on the top side
Expand All @@ -191,7 +191,7 @@ def plot_rfi_imshow(self,cfg_par,time_step=-1):
plt.rcParams.update(params)
# Format axes
nullfmt = NullFormatter()
left, width = 0.05, 0.9 #|These determine where the subplots go
left, width = 0.06, 0.89 #|These determine where the subplots go
bottom, height = 0.1, 0.85
#left_h = left+width+0.015
#bottom_h = left+height+0.015
Expand Down Expand Up @@ -221,7 +221,7 @@ def plot_rfi_imshow(self,cfg_par,time_step=-1):
ax.set_yticklabels(input_baselines)

ax.set_xlabel('Frequency [MHz]')
ax.set_ylabel('Baseline lenght [m]')
ax.set_ylabel('Baseline length [m]')

# colorbar

Expand Down Expand Up @@ -263,8 +263,10 @@ def plot_rfi_imshow(self,cfg_par,time_step=-1):
ax.set_title(title_plot)

plt.savefig(rfi_freq_base_plot,format='png')
if cfg_par['plots']['plot_details']['plot_eps']:
plt.savefig(rfi_freq_base_plot.replace('png', 'eps'), format='eps')
plt.close(fig)
self.logger.info("\t ... RFI per baseline lenght and frequency plotted ... \n\n")
self.logger.info("\t ... RFI per baseline length and frequency plotted ... \n\n")

def plot_noise_frequency(self,cfg_par,time_step=-1):
'''
Expand Down Expand Up @@ -313,7 +315,6 @@ def plot_noise_frequency(self,cfg_par,time_step=-1):

#open file
if os.path.exists(rfi_table) == False:
print(rfi_table)
self.logger.error('### Table of RFI results does not exist ###')
else:

Expand Down Expand Up @@ -355,11 +356,12 @@ def plot_noise_frequency(self,cfg_par,time_step=-1):
params = {'font.family' :' serif',
'font.style' : 'normal',
'font.weight' : 'book',
'font.size' : 18.0,
#'font.size' : 18.0,
'font.size' : 26.0,
'axes.linewidth' : 1,
'lines.linewidth' : 1,
'xtick.labelsize' : 16,
'ytick.labelsize' : 16,
'xtick.labelsize' : 18,
'ytick.labelsize' : 18,
'xtick.direction' :'in',
'ytick.direction' :'in',
#'xtick.top' : True, # draw ticks on the top side
Expand All @@ -382,7 +384,7 @@ def plot_noise_frequency(self,cfg_par,time_step=-1):

# Format axes
nullfmt = NullFormatter()
left, width = 0.05, 0.9 #|These determine where the subplots go
left, width = 0.06, 0.89 #|These determine where the subplots go
bottom, height = 0.1, 0.85
#left_h = left+width+0.015
#bottom_h = left+height+0.015
Expand All @@ -391,6 +393,7 @@ def plot_noise_frequency(self,cfg_par,time_step=-1):

# initialize figure
fig = plt.figure(1, figsize=(18,8))

plt.rc('xtick', labelsize=20)

# Initialize subplots
Expand Down Expand Up @@ -507,6 +510,8 @@ def plot_noise_frequency(self,cfg_par,time_step=-1):
rfi_freq_plot = out_plot+'_rfi.png'

plt.savefig(rfi_freq_plot,format='png')
if cfg_par['plots']['plot_details']['plot_eps']:
plt.savefig(rfi_freq_plot.replace('png', 'eps'), format='eps')
plt.close(fig)
self.logger.info("\t ... RFI in 1D plotted ...\n\n")

Expand All @@ -520,7 +525,6 @@ def plot_altaz(self,cfg_par,number_chunks):
self.logger.info("\t ... Plotting Alt/Az for binned dataset ... \n")

if os.path.exists(cfg_par['general']['timetabledir']) == False:
print(cfg_par['general']['timetabledir'])
self.logger.error("\t Folder with time subsets missing")

table_tmp = str.split(cfg_par['general']['msname'][0],'.MS')
Expand Down Expand Up @@ -565,7 +569,6 @@ def plot_altaz(self,cfg_par,number_chunks):

#open file
if os.path.exists(rfi_table) == False:
print(rfi_table)
self.logger.error('### Table of RFI results does not exist ###')
continue
else:
Expand Down Expand Up @@ -601,11 +604,11 @@ def plot_altaz(self,cfg_par,number_chunks):
params = {'font.family' :' serif',
'font.style' : 'normal',
'font.weight' : 'book',
'font.size' : 18.0,
'font.size' : 20.0,
'axes.linewidth' : 1,
'lines.linewidth' : 1,
'xtick.labelsize' : 16,
'ytick.labelsize' : 16,
'xtick.labelsize' : 17,
'ytick.labelsize' : 17,
'xtick.direction' :'in',
'ytick.direction' :'in',
#'xtick.top' : True, # draw ticks on the top side
Expand Down Expand Up @@ -804,8 +807,8 @@ def plot_altaz_short(self,cfg_par):
'font.size' : 18.0,
'axes.linewidth' : 1,
'lines.linewidth' : 1,
'xtick.labelsize' : 16,
'ytick.labelsize' : 16,
'xtick.labelsize' : 18,
'ytick.labelsize' : 18,
'xtick.direction' :'in',
'ytick.direction' :'in',
'xtick.major.size' : 4,
Expand Down Expand Up @@ -890,11 +893,12 @@ def plot_summary_stats(self, flag_stats, cfg_par, key='corr'):
params = {'font.family' :' serif',
'font.style' : 'normal',
'font.weight' : 'book',
'font.size' : 20.0,
#'font.size' : 20.0,
'font.size' : 26.0,
'axes.linewidth' : 1,
'lines.linewidth' : 1,
'xtick.labelsize' : 16,
'ytick.labelsize' : 16,
'xtick.labelsize' : 18,
'ytick.labelsize' : 18,
'xtick.direction' :'in',
'ytick.direction' :'in',
'xtick.major.size' : 4,
Expand All @@ -909,6 +913,7 @@ def plot_summary_stats(self, flag_stats, cfg_par, key='corr'):
}
plt.rcParams.update(params)
fig, ax = plt.subplots(figsize=(16,9))
fig.subplots_adjust(bottom=0.2)

plt.ylim(0, 100.0)
antenna_plot = ax.bar(flag_stats.keys(), flag_stats.values(), color="orange", ec="red", align='center')
Expand All @@ -920,17 +925,23 @@ def plot_summary_stats(self, flag_stats, cfg_par, key='corr'):
if len(flag_stats.keys()) > 30:
plt.xticks(rotation=90)
plt.savefig(summaryplot)
if cfg_par['plots']['plot_details']['plot_eps']:
plt.savefig(summaryplot.replace('png', 'eps'), format='eps')
elif key in ["scan"]:
plt.title("Scan flags")
plt.xlabel("Scan Number")
plt.ylabel("% flagged visibilities")
plt.savefig(summaryplot)
if cfg_par['plots']['plot_details']['plot_eps']:
plt.savefig(summaryplot.replace('png', 'eps'), format='eps')
elif key in ["correlation", "corr"]:
plt.title("Correlation flags")
plt.xlabel("Correlation")
plt.ylabel("Flagged percentage (%)")
plt.ylabel("% flagged visibilities")
plt.savefig(summaryplot)
if cfg_par['plots']['plot_details']['plot_eps']:
plt.savefig(summaryplot.replace('png', 'eps'), format='eps')
elif key in ["frequency", "freq"]:
plt.title("Frequency flags")
plt.xlabel("Frequency (Hz)")
Expand All @@ -939,6 +950,8 @@ def plot_summary_stats(self, flag_stats, cfg_par, key='corr'):
ax2.set_xlabel("Channel Bin")
ax2.bar(list(range(len(flag_stats.keys()))), flag_stats.values(), color="orange", ec="orange", align='center')
plt.savefig(summaryplot)
if cfg_par['plots']['plot_details']['plot_eps']:
plt.savefig(summaryplot.replace('png', 'eps'), format='eps')
self.logger.info(f" ------ Saving: {summaryplot} ------\n")
plt.close()

Expand Down

0 comments on commit fe9e46e

Please sign in to comment.