o = optparse.OptionParser() o.set_usage('combine_and_fit_uCal.py [.uCalResults.npz files] [options]') o.add_option('--nofit', action='store_true', help='For speed, does not try to fit the bandpass.') o.add_option('--combinedSuffix', type='string', default='combined', help='Saves the result as the first uCalResults.npz file, but with .npz replaced by .[suffix].npz. Default "combined"') opts,args = o.parse_args(sys.argv[1:]) if len(args) == 0: print "WARNING!!! No arguments provided. Using testing parameters." resultsFiles = ["./Data/" + file for file in os.listdir("./Data") if file.startswith('zen.2456679.3') and file.endswith('xx.uCalResults.npz')] else: resultsFiles = args #%% Combine per-integration results allSourceFiles, allBandpasses, meanBandpass, stdBandpass, unflaggedChans, channelRMSs, overallChannelRMS, bandpassFit = uc.from_npz(resultsFiles[0]) for file in resultsFiles[1:]: sourceFiles, allBP, _, _, unflagged, RMSs, _, _ = uc.from_npz(file) for source in sourceFiles: allSourceFiles = np.append(allSourceFiles,source) allBandpasses = np.concatenate((allBandpasses,allBP)) unflaggedChans = np.concatenate((unflaggedChans,unflagged)) channelRMSs = np.concatenate((channelRMSs,RMSs)) #%% Recompute Summary Results meanBandpass = np.mean(np.ma.masked_equal(allBandpasses,0),axis=0).data stdBandpass = np.std(np.abs(np.ma.masked_invalid(np.ma.masked_equal(allBandpasses,0))),axis=0).data overallChannelRMS = np.mean(np.ma.masked_invalid(np.ma.masked_equal(channelRMSs,0))**2,axis=0).data ** .5 #%% Perform Fit bandpassFit = None if not opts.nofit:
'Saves the result as the first uCalResults.npz file, but with .npz replaced by .[suffix].npz. Default "combined"' ) opts, args = o.parse_args(sys.argv[1:]) if len(args) == 0: print "WARNING!!! No arguments provided. Using testing parameters." resultsFiles = [ "./Data/" + file for file in os.listdir("./Data") if file.startswith('zen.2456679.3') and file.endswith('xx.uCalResults.npz') ] else: resultsFiles = args #%% Combine per-integration results allSourceFiles, allBandpasses, meanBandpass, stdBandpass, unflaggedChans, channelRMSs, overallChannelRMS, bandpassFit = uc.from_npz( resultsFiles[0]) for file in resultsFiles[1:]: sourceFiles, allBP, _, _, unflagged, RMSs, _, _ = uc.from_npz(file) for source in sourceFiles: allSourceFiles = np.append(allSourceFiles, source) allBandpasses = np.concatenate((allBandpasses, allBP)) unflaggedChans = np.concatenate((unflaggedChans, unflagged)) channelRMSs = np.concatenate((channelRMSs, RMSs)) #%% Recompute Summary Results meanBandpass = np.mean(np.ma.masked_equal(allBandpasses, 0), axis=0).data stdBandpass = np.std(np.abs( np.ma.masked_invalid(np.ma.masked_equal(allBandpasses, 0))), axis=0).data overallChannelRMS = np.mean(np.ma.masked_invalid( np.ma.masked_equal(channelRMSs, 0))**2,
#! /usr/bin/env python import numpy as np import matplotlib.pyplot as plt import optparse, sys, os import capo.uCal as uc o = optparse.OptionParser() o.set_usage('plot_uCal_result.py [.uCalResults.npz file]') opts,args = o.parse_args(sys.argv[1:]) if len(args) == 0: print "WARNING!!! No arguments provided. Using testing parameters." resultsFile = './Data/zen.2456679.49577.xx.uCalResults.npz' else: resultsFile = args[0] dataFiles, allBandpasses, meanBandpass, stdBandpass, unflaggedChans, channelRMSs, overallChannelRMS, bandpassFit = uc.from_npz(resultsFile) allUnflaggedChans = sorted(np.unique([item for sublist in unflaggedChans for item in sublist])) #%% Plot bandpass plt.figure(1); plt.clf() for chans, bandpass in zip(unflaggedChans, allBandpasses): plt.plot(chans, np.abs(bandpass)[chans],':') plt.errorbar(allUnflaggedChans,np.abs(meanBandpass)[allUnflaggedChans],yerr=np.abs(stdBandpass)[allUnflaggedChans], fmt='k') plt.xlabel('channel'); plt.ylabel('abs(Bandpass)') #%% Plot phase plt.figure(2); plt.clf() for chans, bandpass in zip(unflaggedChans, allBandpasses): plt.plot(chans, np.angle(bandpass)[chans],':') plt.plot(allUnflaggedChans, np.angle(meanBandpass)[allUnflaggedChans],'k')