def plot_radar(ax, filename, num_samples, bounds=None, clim=None): ''' ax: axis to plot to filename: radargram to be plotted (in same file format as pik1) bounds: [min_trace, max_trace, min_sample, max_sample] of region to plot. If None, plot whole transect. clim: [min_counts, max_counts] for the data. If None, use automatically-generated bounds. ''' num_traces = pik1_utils.get_num_traces(filename, num_samples) radar_data = np.memmap(filename, '>i4', mode='r', shape=(num_traces, num_samples)) # TODO: How important is the radar skip for generating images? if bounds is None: plot_data = radar_data else: min_trace, max_trace, min_sample, max_sample = bounds plot_data = radar_data[min_trace:max_trace, min_sample:max_sample] radar_plot = ax.imshow(plot_data.T, aspect='auto', interpolation='nearest') if bounds is not None: min_trace, max_trace, min_sample, max_sample = bounds radar_plot.set_extent([min_trace, max_trace, max_sample, min_sample]) radar_plot.set_cmap('gray') if clim is not None: radar_plot.set_clim(clim)
def plot_radar(ax, filename, num_samples, bounds=None, clim=None): ''' ax: axis to plot to filename: radargram to be plotted (in same file format as pik1) bounds: [min_trace, max_trace, min_sample, max_sample] of region to plot. If None, plot whole transect. clim: [min_counts, max_counts] for the data. If None, use automatically-generated bounds. ''' num_traces = pik1_utils.get_num_traces(filename, num_samples) radar_data = np.memmap(filename, '>i4', mode='r', shape=(num_traces, num_samples)) # TODO: How important is the radar skip for generating images? if bounds is None: plot_data = radar_data else: min_trace, max_trace, min_sample, max_sample = bounds plot_data = radar_data[min_trace:max_trace, min_sample:max_sample] radar_plot = ax.imshow(plot_data.T, aspect='auto', interpolation='nearest') if bounds is not None: min_trace, max_trace, min_sample, max_sample = bounds radar_plot.set_extent([min_trace, max_trace, max_sample, min_sample]) radar_plot.set_cmap('gray') if clim is not None: radar_plot.set_clim(clim)
def generate_data_products(): ''' I need a variety of intermediate data products in order to create the figures. ''' TOT_bounds, VCD_bounds, THW_bounds = find_quiet_regions() VCD_rawfile = WAIS + '/orig/xlob/VCD/JKB2g/DVD01a/RADnh3/bxds' TOT_rawfile = WAIS + '/orig/xlob/TOT/JKB2d/X16a/RADnh3/bxds' THW_rawfile = WAIS + '/orig/xlob/THW/SJB2/DRP02a/RADjh1/bxds1' insamples = 3437 outsamples = 3200 channel = 2 blanking = 200 scale = 1000 num_sweeps = pik1_utils.get_num_traces(TOT_rawfile, insamples) reference_chirp = pik1_utils.generate_reference_chirp()
def generate_data_products(): ''' I need a variety of intermediate data products in order to create the figures. ''' TOT_bounds, VCD_bounds, THW_bounds = find_quiet_regions() VCD_rawfile = WAIS + '/orig/xlob/VCD/JKB2g/DVD01a/RADnh3/bxds' TOT_rawfile = WAIS + '/orig/xlob/TOT/JKB2d/X16a/RADnh3/bxds' THW_rawfile = WAIS + '/orig/xlob/THW/SJB2/DRP02a/RADjh1/bxds1' insamples = 3437 outsamples = 3200 channel = 2 blanking = 200 scale = 1000 num_sweeps = pik1_utils.get_num_traces(TOT_rawfile, insamples) reference_chirp = pik1_utils.generate_reference_chirp()
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')