def get_sum_spectrum(fid, plot_indv): print fid full_file_array = file_scraper.get_h5py_data(fid) indv_spectra_array = full_file_array[:, 0, :] if plot_indv == True: plt.plot(indv_spectra_array.T) num_of_spectra = indv_spectra_array.shape[0] num_of_bins = indv_spectra_array.shape[1] print 'Number of spectra', num_of_spectra print 'Number of bins ', num_of_bins spectrum_sum_scaled = (1.0 / num_of_spectra) * indv_spectra_array.sum(axis=0) #Slight fudge, scale needs better way of arriving at answer scale_vortex_nrg = 8041.0 / 801.0 print 'Scale of Vortex to Energy', scale_vortex_nrg terminal_energy = scale_vortex_nrg * (num_of_bins - 1) print 'Terminal energy', terminal_energy x_axis = scale_vortex_nrg * np.arange(0, num_of_bins, 1) one_ev_energy_axis = np.arange(0, np.floor(terminal_energy), 1) #one_ev_energy_axis = np.arange(0, math.floor(terminal_energy), 1) spectrum_sum_scal_mapped = interp1d(x_axis, spectrum_sum_scaled, 'linear')(one_ev_energy_axis) #shift vertically spectrum_sum_scal_mapped = spectrum_sum_scal_mapped - 8.0 return one_ev_energy_axis, spectrum_sum_scal_mapped
def mapme(fid, scale_dict, cutoff, include_list): elem_list = [] scale_list = [] print 'CUTOFF =', cutoff for line_name, scale in scale_dict.items(): if scale >= cutoff: elem_list.append(line_name) scale_list.append(scale) xbox, ybox = get_factor_list(len(elem_list))[-1] if len(elem_list) > 16: print 'Too Long' xbox, ybox = 5, 5 xdim, ydim, x_step_size, y_step_size, x_start, y_start = file_scraper.get_gridscan_data( fid) print '\tData from .gridscan file' print '\tGrid Dimensions', xdim, ydim print '\tStep Sizes', x_step_size, y_step_size print '\tStart Position', x_start, y_start spacex = np.linspace(x_start, x_start + (xdim * (x_step_size / 1000.))) spacey = np.linspace(y_start, y_start + (xdim * (x_step_size / 1000.))) aspect = float(y_step_size) / float(x_step_size) print 15 * aspect, 15 * (1. / aspect) per_tab_dict = file_scraper.get_per_tab_dict() array = file_scraper.get_h5py_data(fid) #shp_array = shape_array(array, [xdim,ydim]) shp_array = shape_array(array, [xdim, ydim]) # - 15.0 print 'shaped array', shp_array.shape result_array = shp_array # Try mean subtraction? #mean_sub_array = shp_array - shp_array.mean(axis=2, keepdims=True) #print 'mean_sub ', mean_sub_array.shape #result_array = mean_sub_array print 'result ', result_array.shape print 'slicing out channels' slc_array_list = [] print 'element_list =', elem_list print 'element_list =', elem_list, '+', include_list print include_list #elem_list = elem_list + include_list for elem in elem_list: emission_line = get_emissions(per_tab_dict, elem) llm, hlm = emission_line[1], emission_line[2] Z = elem.split('_')[0] print elem, '\t', emission_line slc_array = slice_and_sum_array(result_array, [llm, hlm]) slc_array_list.append(slc_array) fig, axs2 = plt.subplots(xbox, ybox, figsize=((15 / aspect), 15), facecolor='0.3', edgecolor='k') #fig, axs2 = plt.subplots(xbox, ybox, facecolor='0.3', edgecolor='k') #fig, axs2 = plt.subplots(xbox, ybox, facecolor='0.3', edgecolor='k') axs2 = axs2.ravel() print 'Plotting' for i, elem in enumerate(elem_list): Z = elem.split('_')[0] ray = slc_array_list[i] pymol_c = per_tab_dict[Z][3] w2k = [(0, 0, 0), pymol_c] ct = LinearSegmentedColormap.from_list('ctest', w2k, N=300) #axs2[i].imshow(ray, cmap=ct, interpolation='nearest') axs2[i].imshow(ray, aspect='equal', extent=extents(spacex) + extents(spacey), origin='upper', cmap=ct, interpolation='nearest', vmin=0) axs2[i].set_title(elem, y=0.9, color='0.8', loc='left') #axs2[i].set_xticks([]) #axs2[i].set_yticks([]) fig.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95, wspace=0.00, hspace=0.0) #xfid = fid.split('/')[-1] #'/dls/i24/data/2017/nr16818-47/processing/GoldDigger_170512' #output_fid = xfid[:-5] + '%s.png' %time.strftime("_%Y%m%d_%H%M%S") #print 'Saved in /Snapshots' #print output_fid #plt.savefig(output_fid, dpi=400, bbox_inches='tight', pad_inches=0) return fig