コード例 #1
0
def make_id_focalplane():
    '''
    make the matrix which has all the translation info for pixel identities
    '''
    global FPidentity
    tes_grid = assign_tes_grid()

    # initialize the matrix
    names = 'index,row,col,quadrant,matrix,TES,PIX,ASIC'
    fmts = 'int,int,int,int,a4,int,int,int'
    FPidentity = np.recarray(names=names,formats=fmts,shape=(34*34))

    fp_idx = 0
    for j in range(34):
        row = 33 - j
        for i in range(34):
            col = i
            if row < 17:
                if col < 17:
                    quadrant = 3
                    matrix = 'P87'
                    tes_y = 16 - col
                    tes_x = row
                else:
                    quadrant = 4
                    matrix = 'PXX'
                    tes_y = col - 17
                    tes_x = row
            else:
                if col < 17:
                    quadrant = 2
                    matrix = 'PXX'
                    tes_x = col
                    tes_y = row - 17
                else:
                    quadrant = 1
                    matrix = 'PXX'
                    tes_x = 33 - col
                    tes_y = row - 17
                    
                
            asic_no = tes_grid[tes_x,tes_y].ASIC
            TES_no = tes_grid[tes_x,tes_y].TES
            PIX = tes2pix(TES_no,asic_no)
            rotated_asic = 2*(quadrant-3) + asic_no
            if rotated_asic < 1:
                rotated_asic += 8
            if asic_no==0: rotated_asic = 0

            FPidentity[fp_idx].index = fp_idx
            FPidentity[fp_idx].quadrant = quadrant
            FPidentity[fp_idx].matrix = matrix
            FPidentity[fp_idx].TES = TES_no
            FPidentity[fp_idx].PIX = PIX
            FPidentity[fp_idx].ASIC =  rotated_asic
            FPidentity[fp_idx].row = row
            FPidentity[fp_idx].col = col
            fp_idx += 1
            
    return FPidentity
コード例 #2
0
ファイル: plot_fp.py プロジェクト: satorchi/qubicpack
def plot_fp(args):
    '''
    plot curves and background colour on the QUBIC focal plane
    
    the argument is a dictionary with the curves and options
    valid keywords (n is the ASIC number):
      'ASIC<n>' : the array of NPIXELS curves
      'ASIC<n> x-axis' : x-axis (use this to plot bias curves)
      'ASIC<n> bg' : the value to determine the background colour
      'ASIC<n> good' : an array of bool for each TES (good or not)
      'obsdate' : observation date (datetime object)
      'title' : plot title
      'subtitle' : plot subtitle
      'lutmin' : min value for colour look up table
      'lutmax' : max value for colour look up table
      'pngname' : name of file for saving the plot
      'nolabels' : if true, do not plot TES labels in each box
      'quadrant' : quadrant in which to plot the quarter focal plane (default=3)

    '''

    # initialize stuff
    pix_grid = assign_pix_grid()
    nrows = pix_grid.shape[0]
    ncols = pix_grid.shape[1]

    if 'figsize' in args.keys():
        figsize = args['figsize']
    else:
        figwidth = plt.rcParams['figure.figsize'][0]
        figsize = (figwidth, figwidth)
    fontsize = figsize[0]
    ttlfontsize = figsize[0] * 1.2

    quadrant = 3
    if 'quadrant' in args.keys():
        quadrant = args['quadrant']

    obsdate = None
    if 'obsdate' in args.keys():
        obsdate = args['obsdate']
    tes_grid = assign_tes_grid()

    if 'pngname' in args.keys():
        pngname = args['pngname']
    elif obsdate:
        pngname = 'QUBIC_focal_plane_%s.png' % obsdate.strftime(
            '%Y%m%dT%H%M%S')
    else:
        pngname = 'QUBIC_focal_plane.png'

    if 'title' in args.keys():
        ttl = args['title']
    else:
        ttl = 'QUBIC TES array'

    subttl = None
    if 'subtitle' in args.keys():
        subttl = args['subtitle']

    lutmin = 0.0
    if 'lutmin' in args.keys():
        lutmin = args['lutmin']
    lutmax = 10.0
    if 'lutmax' in args.keys():
        lutmax = args['lutmax']

    face_colours = {}
    face_colours['ASIC0'] = 'black'
    face_colours['ASIC1'] = 'white'
    face_colours['ASIC2'] = 'white'

    curve_colours = {}
    curve_colours['ASIC0'] = 'black'
    curve_colours['ASIC1'] = 'black'
    curve_colours['ASIC2'] = 'blue'

    label_boxprops = dict(boxstyle='round, pad=0.1',
                          facecolor='white',
                          alpha=1.0)
    label_colours = {}
    label_colours['ASIC0'] = 'black'
    label_colours['ASIC1'] = 'black'
    label_colours['ASIC2'] = 'blue'
    if 'nolabels' in args.keys() and args['nolabels']:
        print_labels = False
    else:
        print_labels = True

    plt.ion()
    fig, ax = plt.subplots(nrows, ncols, figsize=figsize)
    fig.text(0.5, 0.985, ttl, ha='center', fontsize=ttlfontsize)
    figure_window_title(fig, ttl)
    fig.suptitle(subttl, fontsize=ttlfontsize)

    for j in range(nrows):
        for i in range(ncols):

            if quadrant == 1:
                row = j
                col = i

            elif quadrant == 2:
                row = i
                col = j

            elif quadrant == 3:
                row = 16 - j
                col = 16 - i
            else:
                row = 16 - i
                col = 16 - j

            ax[row, col].get_xaxis().set_visible(False)
            ax[row, col].get_yaxis().set_visible(False)

            # the pixel identity associated with its physical location in the array
            TES = tes_grid[j, i].TES
            TES_str = '%03i' % TES
            asic = tes_grid[j, i].ASIC
            asic_str = '%i' % asic

            TES_idx = TES - 1
            pix_label = TES_str
            asic_key = 'ASIC%s' % asic_str
            asicbg_key = '%s bg' % asic_key
            asicgood_key = '%s good' % asic_key
            xaxis_key = '%s x-axis' % asic_key

            face_colour = face_colours[asic_key]
            label_colour = label_colours[asic_key]
            curve_colour = curve_colours[asic_key]

            text_x = 0.5
            text_y = 0.9
            labelfontsize = ttlfontsize

            if asic_key in args.keys() and args[asic_key] is not None:
                if xaxis_key in args.keys() and args[xaxis_key] is not None:
                    curve_x = args[xaxis_key][TES_idx]
                else:
                    curve_x = range(args[asic_key].shape[1])
                curve = args[asic_key][TES_idx]
                text_x = 0.5
                text_y = 0.9
                labelfontsize = 0.8 * fontsize
                if asicgood_key in args.keys(
                ) and not args[asicgood_key][TES_idx]:
                    face_colour = 'black'
                    label_colour = 'white'
                    curve_colour = 'white'
                elif asicbg_key in args.keys():
                    if args[asicbg_key][TES_idx] is None:
                        face_colour = 'white'
                    else:
                        face_colour = mylut(args[asicbg_key][TES_idx], lutmin,
                                            lutmax)

                ax[row, col].plot(curve_x, curve, color=curve_colour)

            #print('(%i,%i) : facecolour=%s, labelcolour=%s' % (row,col,face_colour,label_colour))
            ax[row, col].set_facecolor(face_colour)
            label_boxprops['facecolor'] = face_colour
            if print_labels:
                ax[row, col].text(text_x,
                                  text_y,
                                  pix_label,
                                  va='top',
                                  ha='center',
                                  color=label_colour,
                                  fontsize=labelfontsize,
                                  bbox=label_boxprops,
                                  transform=ax[row, col].transAxes)

    plt.savefig(pngname, format='png', dpi=100, bbox_inches='tight')
    plt.show()

    return