def plot_trace(): # Trace 3900 in pik1 looks pretty nice. trace_idx = 3900 num_in_samples = 3437 num_out_samples = 3200 raw_y = 2 #(where to plot the raw data ...) raw_filename = WAIS + '/orig/xlob/TOT/JKB2d/X16a/RADnh3/bxds' # For plotting, I tried raw dB of trace ... I don't like it as much # If I try it again, gotta be careful - abs(elem) can cause overflow errors if we don't cast to float first! sweep_gen = pik1_utils.load_raw_nh3_subset_gen(raw_filename, 2, [50 * trace_idx], num_in_samples, num_out_samples, 0) raw_trace = [elem for elem in sweep_gen][0] raw_min = np.min(raw_trace) raw_range = 1.0 * np.max(raw_trace) - np.min(raw_trace) norm_raw_trace_ch2 = [ raw_y + (1.0 * elem - raw_min) / raw_range for elem in raw_trace ] sweep_gen = pik1_utils.load_raw_nh3_subset_gen(raw_filename, 1, [50 * trace_idx], num_in_samples, num_out_samples, 0) raw_trace = [elem for elem in sweep_gen][0] raw_min = np.min(raw_trace) raw_range = 1.0 * np.max(raw_trace) - np.min(raw_trace) norm_raw_trace_ch1 = [ raw_y + 1 + (1.0 * elem - raw_min) / raw_range for elem in raw_trace ] pik1_filename = 'TOT_LO' num_traces = pik1_utils.get_num_traces(pik1_filename, num_in_samples) pik1_data = np.memmap(pik1_filename, '>i4', mode='r', shape=(num_traces, num_out_samples)) processed_trace = pik1_data[trace_idx, :] trace_min = np.min(processed_trace) trace_range = np.max(processed_trace) - np.min(processed_trace) norm_processed_trace = [ 1.0 * (elem - trace_min) / trace_range for elem in processed_trace ] fig = Figure((30, 15)) canvas = FigureCanvas(fig) ax = fig.add_axes([0, 0, 1, 1]) ax.minorticks_off() ax.tick_params(which='both', bottom=False, top=False, left=False, right=False, labelbottom=False, labeltop=False, labelleft=False, labelright=False) for side in ['bottom', 'top', 'left', 'right']: ax.spines[side].set_visible(False) ax.set_xlim([0, 3200]) ylim = [0, raw_y + 2] ax.set_ylim(ylim) bar_y1 = 1.15 bar_y2 = 1.25 bar_y3 = 1.35 text_y1 = 1.0 text_y2 = 1.3 text_y3 = 1.4 fontsize = 50 xshift = 66 # WTF. Why do I have to offset the raw pulse to make it line up with the dechirped? # reference chirp 50-100 ax.plot([50, 100], [1.65, 1.65], color='red', linewidth=15) ax.text(25, 1.7, 'chirp', fontsize=50, color='red', horizontalalignment='left', verticalalignment='bottom') # "main bang" ax.plot([100, 540], [1.35, 1.35], '--', color='red', linewidth=15) ax.plot([100, 400], [1.35, 1.35], color='red', linewidth=15) ax.text(250, 1.4, 'main bang', fontsize=50, color='red', horizontalalignment='center', verticalalignment='bottom') # hardware blanking from 1-134 (in theory ... I don't trust this from the resulting plots ax.plot([xshift + 0, xshift + 134], [1.15, 1.15], color='red', linewidth=15) ax.text(xshift, 0.9, 'HW blanking', fontsize=50, color='red', horizontalalignment='left', verticalalignment='bottom') # software blanking from 1-200 ax.plot([0, 200], [0.85, 0.85], color='red', linewidth=15) ax.text(25, 0.6, 'SW blanking', fontsize=50, color='red', horizontalalignment='left', verticalalignment='bottom') # Surface at 555 ax.plot([555, 555], ylim, color='lightgray', linewidth=15) ax.text(575, 1.3, 'ice surface', fontsize=50, color='black', horizontalalignment='left', verticalalignment='bottom') # surface multiple at 950 ax.plot([950, 950], ylim, color='lightgray', linewidth=15) ax.text(970, 0.9, 'surface \nmultiple', fontsize=50, color='black', horizontalalignment='left', verticalalignment='bottom') # Crevasses at 1262 ax.plot([1262, 1262], ylim, color='lightgray', linewidth=15) ax.text(1282, 1.7, 'crevasse', fontsize=50, color='black', horizontalalignment='left', verticalalignment='bottom') # water at 1378 ax.plot([1378, 1378], ylim, color='lightgray', linewidth=15) ax.text(1398, 0.85, 'water', fontsize=50, color='black', horizontalalignment='left', verticalalignment='bottom') # off-nadir energy at 1400 - 1850 ax.plot([1400, 2100], [bar_y2, bar_y2], '--', color='red', linewidth=15) ax.plot([1500, 1850], [bar_y2, bar_y2], color='red', linewidth=15) ax.text(1750, text_y2, 'off-nadir energy', fontsize=50, color='red', horizontalalignment='center', verticalalignment='bottom') # bed multiple at 2204 ax.plot([2204, 2204], ylim, color='lightgray', linewidth=15) ax.text(2224, 0.5, 'bed multiple', fontsize=50, color='black', horizontalalignment='left', verticalalignment='bottom') # noise at 2400 - 3200 (Can I call this receiver noise?) ax.plot([2250, 3200], [bar_y2, bar_y2], '--', color='red', linewidth=15) ax.plot([2400, 3200], [bar_y2, bar_y2], color='red', linewidth=15) ax.text(2725, text_y2, 'receiver noise', fontsize=50, color='red', horizontalalignment='center', verticalalignment='bottom') # Ideas: # * have 3 different y values, for things that apply to one, the other, or both? # * shade the background to make it clearer what's going on? # or at least draw light vertical grey bars for the point events? # * Be sure to show where this trace comes from on a transect ... # ax1 = fig.add_axes([0.0, 0.05, 0.5, 0.9]) # ax1.set_ylim([3200, 0]) # ax1.minorticks_off() # ax1.tick_params(which='both', # bottom=False, top=False, left=False, right=False, # labelbottom=False, labeltop=False, labelleft=False, labelright=False) # for side in ['bottom', 'top', 'left', 'right']: # ax1.spines[side].set_visible(False) # ax2 = fig.add_axes([0.5, 0.05, 0.5, 0.9]) # ax2.plot(processed_trace, range(len(processed_trace)), 'k', markersize=1) # ax2.set_ylim([3200, 0]) # ax2.minorticks_on() # ax2.tick_params(which='both', direction='inout', labelsize=18, # bottom=False, top=False, left=True, right=False, # labelbottom=False, labeltop=False, labelleft=True, labelright=False) # for side in ['bottom', 'top', 'right']: # ax2.spines[side].set_visible(False) ax.plot(range(len(norm_processed_trace)), norm_processed_trace, 'k.', markersize=6) #ax.plot(range(len(norm_processed_trace)), norm_processed_trace, color='lightgrey', linewidth=1) ax.plot(np.arange(xshift, xshift + len(norm_raw_trace_ch2)), norm_raw_trace_ch2, 'k.', markersize=6) ax.plot(np.arange(xshift, xshift + len(norm_raw_trace_ch1)), norm_raw_trace_ch1, 'k.', markersize=6) canvas.print_figure('../FinalReport/figures/trace.jpg')
def plot_trace(): # Trace 3900 in pik1 looks pretty nice. trace_idx = 3900 num_in_samples = 3437 num_out_samples = 3200 raw_y = 2 #(where to plot the raw data ...) raw_filename = WAIS + '/orig/xlob/TOT/JKB2d/X16a/RADnh3/bxds' # For plotting, I tried raw dB of trace ... I don't like it as much # If I try it again, gotta be careful - abs(elem) can cause overflow errors if we don't cast to float first! sweep_gen = pik1_utils.load_raw_nh3_subset_gen( raw_filename, 2, [50*trace_idx], num_in_samples, num_out_samples, 0) raw_trace = [elem for elem in sweep_gen][0] raw_min = np.min(raw_trace) raw_range = 1.0*np.max(raw_trace) - np.min(raw_trace) norm_raw_trace_ch2 = [raw_y + (1.0*elem - raw_min) / raw_range for elem in raw_trace] sweep_gen = pik1_utils.load_raw_nh3_subset_gen( raw_filename, 1, [50*trace_idx], num_in_samples, num_out_samples, 0) raw_trace = [elem for elem in sweep_gen][0] raw_min = np.min(raw_trace) raw_range = 1.0*np.max(raw_trace) - np.min(raw_trace) norm_raw_trace_ch1 = [raw_y + 1 + (1.0*elem - raw_min) / raw_range for elem in raw_trace] pik1_filename = 'TOT_LO' num_traces = pik1_utils.get_num_traces(pik1_filename, num_in_samples) pik1_data = np.memmap(pik1_filename, '>i4', mode='r', shape=(num_traces, num_out_samples)) processed_trace = pik1_data[trace_idx,:] trace_min = np.min(processed_trace) trace_range = np.max(processed_trace) - np.min(processed_trace) norm_processed_trace = [1.0*(elem - trace_min) / trace_range for elem in processed_trace] fig = Figure((30, 15)) canvas = FigureCanvas(fig) ax = fig.add_axes([0, 0, 1, 1]) ax.minorticks_off() ax.tick_params(which='both', bottom=False, top=False, left=False, right=False, labelbottom=False, labeltop=False, labelleft=False, labelright=False) for side in ['bottom', 'top', 'left', 'right']: ax.spines[side].set_visible(False) ax.set_xlim([0, 3200]) ylim = [0, raw_y + 2] ax.set_ylim(ylim) bar_y1 = 1.15 bar_y2 = 1.25 bar_y3 = 1.35 text_y1 = 1.0 text_y2 = 1.3 text_y3 = 1.4 fontsize=50 xshift = 66 # WTF. Why do I have to offset the raw pulse to make it line up with the dechirped? # reference chirp 50-100 ax.plot([50, 100], [1.65, 1.65], color='red', linewidth=15) ax.text(25, 1.7, 'chirp', fontsize=50, color='red', horizontalalignment='left', verticalalignment='bottom') # "main bang" ax.plot([100, 540], [1.35, 1.35], '--', color='red', linewidth=15) ax.plot([100, 400], [1.35, 1.35], color='red', linewidth=15) ax.text(250, 1.4, 'main bang', fontsize=50, color='red', horizontalalignment='center', verticalalignment='bottom') # hardware blanking from 1-134 (in theory ... I don't trust this from the resulting plots ax.plot([xshift+0, xshift+134], [1.15, 1.15], color='red', linewidth=15) ax.text(xshift, 0.9, 'HW blanking', fontsize=50, color='red', horizontalalignment='left', verticalalignment='bottom') # software blanking from 1-200 ax.plot([0, 200], [0.85, 0.85], color='red', linewidth=15) ax.text(25, 0.6, 'SW blanking', fontsize=50, color='red', horizontalalignment='left', verticalalignment='bottom') # Surface at 555 ax.plot([555, 555], ylim, color='lightgray', linewidth=15) ax.text(575, 1.3, 'ice surface', fontsize=50, color='black', horizontalalignment='left', verticalalignment='bottom') # surface multiple at 950 ax.plot([950, 950], ylim, color='lightgray', linewidth=15) ax.text(970, 0.9, 'surface \nmultiple', fontsize=50, color='black', horizontalalignment='left', verticalalignment='bottom') # Crevasses at 1262 ax.plot([1262, 1262], ylim, color='lightgray', linewidth=15) ax.text(1282, 1.7, 'crevasse', fontsize=50, color='black', horizontalalignment='left', verticalalignment='bottom') # water at 1378 ax.plot([1378, 1378], ylim, color='lightgray', linewidth=15) ax.text(1398, 0.85, 'water', fontsize=50, color='black', horizontalalignment='left', verticalalignment='bottom') # off-nadir energy at 1400 - 1850 ax.plot([1400, 2100], [bar_y2, bar_y2], '--', color='red', linewidth=15) ax.plot([1500, 1850], [bar_y2, bar_y2], color='red', linewidth=15) ax.text(1750, text_y2, 'off-nadir energy', fontsize=50, color='red', horizontalalignment='center', verticalalignment='bottom') # bed multiple at 2204 ax.plot([2204, 2204], ylim, color='lightgray', linewidth=15) ax.text(2224, 0.5, 'bed multiple', fontsize=50, color='black', horizontalalignment='left', verticalalignment='bottom') # noise at 2400 - 3200 (Can I call this receiver noise?) ax.plot([2250, 3200], [bar_y2, bar_y2], '--', color='red', linewidth=15) ax.plot([2400, 3200], [bar_y2, bar_y2], color='red', linewidth=15) ax.text(2725, text_y2, 'receiver noise', fontsize=50, color='red', horizontalalignment='center', verticalalignment='bottom') # Ideas: # * have 3 different y values, for things that apply to one, the other, or both? # * shade the background to make it clearer what's going on? # or at least draw light vertical grey bars for the point events? # * Be sure to show where this trace comes from on a transect ... # ax1 = fig.add_axes([0.0, 0.05, 0.5, 0.9]) # ax1.set_ylim([3200, 0]) # ax1.minorticks_off() # ax1.tick_params(which='both', # bottom=False, top=False, left=False, right=False, # labelbottom=False, labeltop=False, labelleft=False, labelright=False) # for side in ['bottom', 'top', 'left', 'right']: # ax1.spines[side].set_visible(False) # ax2 = fig.add_axes([0.5, 0.05, 0.5, 0.9]) # ax2.plot(processed_trace, range(len(processed_trace)), 'k', markersize=1) # ax2.set_ylim([3200, 0]) # ax2.minorticks_on() # ax2.tick_params(which='both', direction='inout', labelsize=18, # bottom=False, top=False, left=True, right=False, # labelbottom=False, labeltop=False, labelleft=True, labelright=False) # for side in ['bottom', 'top', 'right']: # ax2.spines[side].set_visible(False) ax.plot(range(len(norm_processed_trace)), norm_processed_trace, 'k.', markersize=6) #ax.plot(range(len(norm_processed_trace)), norm_processed_trace, color='lightgrey', linewidth=1) ax.plot(np.arange(xshift, xshift+len(norm_raw_trace_ch2)), norm_raw_trace_ch2, 'k.', markersize=6) ax.plot(np.arange(xshift, xshift+len(norm_raw_trace_ch1)), norm_raw_trace_ch1, 'k.', markersize=6) canvas.print_figure('../FinalReport/figures/trace.jpg')
def plot_LO_fft(): # pik1_utils does all of this ... filename = WAIS + '/orig/xlob/TOT/JKB2d/X16a/RADnh3/bxds' trace_start, trace_end = 405450, 415450 # This is 8109 - 8309 in pik1 traces correction = pik1_utils.find_LO_params(filename, 2, 3437, trace_start, trace_end) print "LO correction: ", correction print "mag = %r, phs = %r" % (np.abs(correction), np.angle(correction)) # Plot the fft of the full traces input_sweeps = pik1_utils.load_raw_nh3_subset_gen( filename, 2, np.arange(trace_start, trace_end), 3437, 3200, 200) input_stacked = pik1_utils.coherent_stack_gen(input_sweeps, 50) radar_data = np.array([trace for trace in input_stacked]) radar_fft = np.fft.fft(radar_data, n=3200) fftfreq3200 = np.fft.fftfreq(3200, 1 / 50.) fig2 = Figure((10, 8)) canvas2 = FigureCanvas(fig2) ax2 = fig2.add_axes([0, 0, 1, 1]) ax2.imshow(np.abs(radar_fft), cmap='gray', aspect='auto') canvas2.print_figure('../FinalReport/figures/data_fft.jpg') # Plot the fft of the bottom portion only input_sweeps = pik1_utils.load_raw_nh3_subset_gen( filename, 2, np.arange(trace_start, trace_end), 3437, 3437, 200) input_stacked = pik1_utils.coherent_stack_gen(input_sweeps, 50) noise_data = np.array([trace[-800:] for trace in input_stacked]) noise_fft = np.fft.fft(noise_data, n=800) fftfreq800 = np.fft.fftfreq(800, 1 / 50.) fig3 = Figure((10, 8)) canvas3 = FigureCanvas(fig3) ax3 = fig3.add_axes([0, 0, 1, 1]) ax3.imshow(np.abs(noise_fft), cmap='gray', aspect='auto') canvas3.print_figure('../FinalReport/figures/noise_fft.jpg') # TODO: Maybe just to nice clean line plots showing full transect and bottom? fig4 = Figure((15, 5)) canvas4 = FigureCanvas(fig4) ax4 = fig4.add_axes([0.01, 0.2, 0.98, 0.8]) abs_noise_fft = np.sum(np.abs(noise_fft), axis=0) # cancel out constant term. abs_noise_fft[0] = 0 plot_noise_fft = abs_noise_fft / np.max(abs_noise_fft) ax4.plot(fftfreq800[1:400], plot_noise_fft[1:400], color='black') ax4.plot(fftfreq800[401:800], plot_noise_fft[401:800], color='black') # Cancel out the two biggest peaks. abs_noise_fft[160] = 0 abs_noise_fft[640] = 0 plot_noise_fft2 = abs_noise_fft / np.max(abs_noise_fft) ax4.plot(fftfreq800[1:400], plot_noise_fft2[1:400], color='darkgrey') ax4.plot(fftfreq800[401:800], plot_noise_fft2[401:800], color='darkgrey') abs_radar_fft = np.sum(np.abs(radar_fft), axis=0) plot_radar_fft = abs_radar_fft / np.max(abs_radar_fft) # Plot in two chunks to avoid the awkward line across the figure. ax4.plot(fftfreq3200[1:1600], plot_radar_fft[1:1600], color='red') ax4.plot(fftfreq3200[1601:3200], plot_radar_fft[1601:3200], color='red') ax.set_ylim([0, 1.05]) ax4.set_xlim([-25, 25]) ax4.tick_params(which='both', bottom=True, top=False, left=False, right=False, labelbottom=True, labeltop=False, labelleft=False, labelright=False, labelsize=18) for side in ['top', 'left', 'right']: ax4.spines[side].set_visible(False) ax4.set_xlabel('Frequency (MHz)', fontsize=24) canvas4.print_figure('../FinalReport/figures/LO_fft.jpg')
def plot_LO_fft(): # pik1_utils does all of this ... filename = WAIS + '/orig/xlob/TOT/JKB2d/X16a/RADnh3/bxds' trace_start, trace_end = 405450, 415450 # This is 8109 - 8309 in pik1 traces correction = pik1_utils.find_LO_params(filename, 2, 3437, trace_start, trace_end) print "LO correction: ", correction print "mag = %r, phs = %r" % (np.abs(correction), np.angle(correction)) # Plot the fft of the full traces input_sweeps = pik1_utils.load_raw_nh3_subset_gen( filename, 2, np.arange(trace_start, trace_end), 3437, 3200, 200) input_stacked = pik1_utils.coherent_stack_gen(input_sweeps, 50) radar_data = np.array([trace for trace in input_stacked]) radar_fft = np.fft.fft(radar_data, n=3200) fftfreq3200 = np.fft.fftfreq(3200, 1/50.) fig2 = Figure((10, 8)) canvas2 = FigureCanvas(fig2) ax2 = fig2.add_axes([0, 0, 1, 1]) ax2.imshow(np.abs(radar_fft), cmap='gray', aspect='auto') canvas2.print_figure('../FinalReport/figures/data_fft.jpg') # Plot the fft of the bottom portion only input_sweeps = pik1_utils.load_raw_nh3_subset_gen( filename, 2, np.arange(trace_start, trace_end), 3437, 3437, 200) input_stacked = pik1_utils.coherent_stack_gen(input_sweeps, 50) noise_data = np.array([trace[-800:] for trace in input_stacked]) noise_fft = np.fft.fft(noise_data, n=800) fftfreq800 = np.fft.fftfreq(800, 1/50.) fig3 = Figure((10, 8)) canvas3 = FigureCanvas(fig3) ax3 = fig3.add_axes([0, 0, 1, 1]) ax3.imshow(np.abs(noise_fft), cmap='gray', aspect='auto') canvas3.print_figure('../FinalReport/figures/noise_fft.jpg') # TODO: Maybe just to nice clean line plots showing full transect and bottom? fig4 = Figure((15, 5)) canvas4 = FigureCanvas(fig4) ax4 = fig4.add_axes([0.01, 0.2, 0.98, 0.8]) abs_noise_fft = np.sum(np.abs(noise_fft), axis=0) # cancel out constant term. abs_noise_fft[0] = 0 plot_noise_fft = abs_noise_fft/np.max(abs_noise_fft) ax4.plot(fftfreq800[1:400], plot_noise_fft[1:400], color='black') ax4.plot(fftfreq800[401:800], plot_noise_fft[401:800], color='black') # Cancel out the two biggest peaks. abs_noise_fft[160] = 0 abs_noise_fft[640] = 0 plot_noise_fft2 = abs_noise_fft/np.max(abs_noise_fft) ax4.plot(fftfreq800[1:400], plot_noise_fft2[1:400], color='darkgrey') ax4.plot(fftfreq800[401:800], plot_noise_fft2[401:800], color='darkgrey') abs_radar_fft = np.sum(np.abs(radar_fft), axis=0) plot_radar_fft = abs_radar_fft/np.max(abs_radar_fft) # Plot in two chunks to avoid the awkward line across the figure. ax4.plot(fftfreq3200[1:1600], plot_radar_fft[1:1600], color='red') ax4.plot(fftfreq3200[1601:3200], plot_radar_fft[1601:3200], color='red') ax.set_ylim([0, 1.05]) ax4.set_xlim([-25, 25]) ax4.tick_params(which='both', bottom=True, top=False, left=False, right=False, labelbottom=True, labeltop=False, labelleft=False, labelright=False, labelsize=18) for side in ['top', 'left', 'right']: ax4.spines[side].set_visible(False) ax4.set_xlabel('Frequency (MHz)', fontsize=24) canvas4.print_figure('../FinalReport/figures/LO_fft.jpg')