示例#1
0
def get_scale_dict(poss_emis_dict, vortex_nrg_axis, sum_spec, spread, offset, cutoff, exclude_list, include_list):
    per_tab_dict = file_scraper.get_per_tab_dict()
    fig = plt.figure()
    ax = fig.add_subplot(1,1,1)
    fig.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95, wspace=0.0, hspace=0.0)
    ax.plot(vortex_nrg_axis, sum_spec, c='m', lw=1)
    scale_dict = {}
    params_dict = {}
    
    if 'all' in exclude_list:
        exclude_list = set.difference(set(per_tab_dict.keys()), set(include_list))
    
    print 'EXCLUDE LIST', exclude_list
    print '\nINCLUDE LIST', include_list
    for elem, emis_dict in poss_emis_dict.items():
        if elem in exclude_list:
            continue
        elem_color = per_tab_dict[elem][3]
	emis_line_list = []
        for line_type in poss_emis_dict[elem].keys():
            emis_line, rel_int = poss_emis_dict[elem][line_type]
            if emis_line == -1.0:
                #print ' %s %s has an emission peak of -1.0'%(elem, line_type)
		continue
            emis_line_list.append(emis_line)
        mini = int(min(emis_line_list) - 300)
        maxi = int(max(emis_line_list) + 300)
        emis_nrg_axis = np.arange(mini, maxi, 1)
        lo_index = np.where(vortex_nrg_axis==mini)[0][0]
        hi_index = np.where(vortex_nrg_axis==maxi)[0][0]
        sum_spec_cut = sum_spec[lo_index:hi_index]

        base = ft.base_spectra(emis_nrg_axis, poss_emis_dict[elem], spread, offset) 
        scale_result = ft.get_scale(base, sum_spec_cut)
    
	if scale_result < cutoff and elem not in include_list:
            continue
	else: 
            print elem, '\t', scale_result, '\t', poss_emis_dict[elem], 'cutoff', cutoff
	    scale_dict[elem] = scale_result
            #ax.plot(emis_nrg_axis, base, c=elem_color)
            ax.plot(emis_nrg_axis, scale_result*base, c=elem_color,lw=3, label=elem)
            ax.plot(emis_nrg_axis, sum_spec_cut, c='k')
            x = emis_nrg_axis[np.argmax(base)]
            y = max(scale_result*base)
            ax.annotate(elem, xy=(x,y), xycoords='data', xytext=(2,2), textcoords='offset points', color=elem_color, fontsize=15)
    return scale_dict, params_dict
示例#2
0
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