Esempio n. 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
Esempio n. 2
0
def plot_rt_analysis(reslist,xwin=True):
    '''
    plot the results of the R-T analysis
    we need to run fit_timeline() for this!
    '''
    global FIGSIZE
    
    TES=reslist[0]['TES']
    detector_name=reslist[0]['DET_NAME']
    asic=reslist[0]['ASIC']

    PIX=tes2pix(TES,asic)

    Tbath=[]
    R=[]
    dates=[]
    for res in reslist:
        Tbath.append(1000*res['Tbath'])
        R.append(res['R amplitude'])
        dates.append(res['date'])
                     
    ntemps=len(Tbath)
    sorted_index=sorted(range(ntemps), key=lambda i: Tbath[i])

    Tsorted=np.array(Tbath)[sorted_index]
    Rsorted=np.array(R)[sorted_index]

    # show the dates of the measurements (just the day, not the time)
    date_txt='Measurements taken:'
    dates.sort()
    d_prev=''
    for d in dates:
        d_str=d.strftime('%Y-%m-%d')
        if d_str!=d_prev: date_txt+='\n   %s' % d_str
        d_prev=d_str
    
    ttl='Array %s: Critical Temperature for TES %i (PIX %i) on ASIC %i' % (detector_name,TES,PIX,asic)
    pngname='QUBIC_Array-%s_TES%03i_ASIC%i_Tcritical.png' % (detector_name,TES,asic)

    if xwin: plt.ion()
    else: plt.ioff()
    fig=plt.figure(figsize=FIGSIZE)
    fig.canvas.set_window_title('plt: '+ttl)
    ax=plt.gca()
    plt.title(ttl)
    ax.plot(Tsorted,1e6*Rsorted,marker='D',color='blue')
    ax.set_xlabel('T$_\mathrm{bath}$ / mK')
    ax.set_ylabel('R$_\mathrm{TES}$ / $\mu\Omega$')

    text_x=0.98
    text_y=0.02
    boxprops = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
    ax.text(text_x,text_y,date_txt,va='bottom',ha='right',fontsize=10,transform = ax.transAxes,bbox=boxprops)

    plt.savefig(pngname,format='png',dpi=100,bbox_inches='tight')
    if xwin:plt.show()
    else: plt.close('all')
    return
Esempio n. 3
0
def plot_timeline(self,
                  TES,
                  timeline_index=None,
                  fit=False,
                  ipeak0=None,
                  ipeak1=None,
                  plot_bias=True,
                  xwin=True,
                  timeaxis='pps',
                  ax=None,
                  fontsize=12):
    '''
    plot the timeline
    '''
    if not self.exist_timeline_data():
        self.printmsg('ERROR! No timeline data.')
        return None

    if timeline_index is None:
        # by default, plot the first one.  For QubicStudio files, there is only one timeline
        timeline_index = 0

    ntimelines = self.ntimelines()
    if timeline_index >= ntimelines:
        self.printmsg('Please enter a timeline between 0 and %i' %
                      (ntimelines - 1))
        return None

    tdata = self.tdata[timeline_index]
    keys = tdata.keys()

    warning_str = ''
    if 'WARNING' in keys and tdata['WARNING']:
        warning_str = '\n'.join(tdata['WARNING'])

    if 'R_FEEDBK' in keys:
        self.Rfeedback = tdata['R_FEEDBK']

    if 'NSAMPLES' in keys:
        self.nsamples = tdata['NSAMPLES']

    if 'DATE-OBS' in keys:
        timeline_date = tdata['DATE-OBS']
    else:
        timeline_date = self.obsdate

    if 'BEG-OBS' in keys:
        timeline_start = tdata['BEG-OBS']
    else:
        timeline_start = timeline_date

    if 'BIAS_MIN' in keys:
        self.min_bias = tdata['BIAS_MIN']
    if 'BIAS_MAX' in keys:
        self.max_bias = tdata['BIAS_MAX']

    biasphase = self.bias_phase()

    ttl = str('QUBIC Timeline curve for TES#%3i (%s)' %
              (TES, timeline_start.strftime('%Y-%b-%d %H:%M UTC')))

    if 'TES_TEMP' in keys:
        tempstr = '%.0f mK' % (1000 * tdata['TES_TEMP'])
    else:
        if self.temperature is None:
            tempstr = 'unknown'
        else:
            tempstr = str('%.0f mK' % (1000 * self.temperature))

    fbstr = ''
    if 'R_FEEDBK' in keys:
        if tdata['R_HEATER'] == 1:
            onoff = 'ON'
        else:
            onoff = 'OFF'
        fbstr = ', Feedback Relay: %.0fk$\Omega$, Heater %s' % (
            tdata['R_FEEDBK'] * 1e-3, onoff)

    subttl = str('Array %s, ASIC #%i, Pixel #%i, Temperature %s%s' %
                 (self.detector_name, self.asic, tes2pix(
                     TES, self.asic), tempstr, fbstr))

    if xwin: plt.ion()
    else: plt.ioff()

    if ax is None:
        newplot = True
        fig = plt.figure(figsize=self.figsize)
        figure_window_title(fig, ttl)
        ax = plt.gca()
    else:
        newplot = False

    ax.set_xlabel('time  /  seconds', fontsize=fontsize)
    ax.set_ylabel('Current  /  $\mu$A', fontsize=fontsize)
    ax.tick_params(axis='both', labelsize=fontsize)
    if warning_str:
        boxprops = {}
        boxprops['alpha'] = 0.4
        boxprops['color'] = 'red'
        boxprops['boxstyle'] = 'round'
        ax.text(0.5,
                0.5,
                warning_str,
                ha='center',
                va='center',
                fontsize=2 * fontsize,
                transform=ax.transAxes,
                bbox=boxprops)

    TES_idx = TES_index(TES)
    timeline = self.timeline(TES, timeline_index)
    current = self.ADU2I(timeline)  # uAmps
    timeline_npts = len(timeline)

    self.printmsg(
        'DEBUG: calling timeline_timeaxis from plot_timeline() with axistype=%s'
        % timeaxis,
        verbosity=4)
    time_axis = self.timeline_timeaxis(timeline_index, axistype=timeaxis)

    fitparms = None
    if fit:
        fitparms = self.fit_timeline(TES, timeline_index, ipeak0, ipeak1)

    ipeak0 = 0
    ipeak1 = timeline_npts - 1
    peak0 = time_axis[ipeak0]
    peak1 = time_axis[ipeak1]
    if plot_bias:
        if self.timeline_conversion is None:
            self.timeline2adu(TES=TES,
                              timeline_index=timeline_index,
                              timeaxis=timeaxis)

        if self.timeline_conversion is None or self.min_bias is None or self.max_bias is None:
            plot_bias = False
        else:
            ipeak0 = self.timeline_conversion['ipeak0']
            ipeak1 = self.timeline_conversion['ipeak1']
            peak0 = self.timeline_conversion['peak0']
            peak1 = self.timeline_conversion['peak1']
            shift = self.timeline_conversion['shift']

    if plot_bias:
        ysine = None
        if biasphase is not None:
            self.printmsg('DEBUG: taking ysine from QubicStudio FITS file',
                          verbosity=4)
            ysine = self.timeline_vbias
            sinelabel = 'V$_\mathrm{bias}$ from QubicStudio FITS file'
        elif fitparms is None:
            self.printmsg('DEBUG: taking ysine from peak to peak', verbosity=4)
            bias_period = peak1 - peak0
            amplitude = 0.5 * (self.max_bias - self.min_bias)
            offset = self.min_bias + amplitude
            sinelabel = 'sine curve period=%.2f seconds\npeaks determined from TES %i' % (
                bias_period, self.timeline_conversion['TES'])
            ysine = offset + amplitude * np.sin(
                (time_axis - peak0) * 2 * np.pi / bias_period + 0.5 * np.pi +
                shift * 2 * np.pi)
        else:
            self.printmsg(
                'DEBUG: taking ysine from timeline fit to sine curve',
                verbosity=4)
            bias_period = fitparms['period']
            amplitude = fitparms['amplitude']
            offset = fitparms['offset']
            shift = fitparms['phaseshift']
            if bias_period is not None and amplitude is not None:
                sinelabel = 'best fit sine curve: period=%.2f seconds, amplitude=%.2f $\mu$A' % (
                    bias_period, amplitude)
                ysine = self.model_timeline(time_axis, bias_period, shift,
                                            offset, amplitude)
    if ysine is None: plot_bias = False

    if newplot:
        fig.suptitle(ttl + '\n' + subttl, fontsize=fontsize)
    else:
        ax.text(0.5,
                1.0,
                ttl + '\n' + subttl,
                va='bottom',
                ha='center',
                fontsize=fontsize,
                transform=ax.transAxes)

    curve1 = ax.plot(time_axis, current, label='I-V timeline', color='blue')

    #ymax=max([current[ipeak0],current[ipeak1]])
    ymax = np.nanmax(current)
    if np.isnan(ymax):
        ymax = 1.0
    ymin = np.nanmin(current)
    if np.isnan(ymin):
        ymin = 1.0
    yrange = ymax - ymin
    if np.isnan(yrange) or yrange == 0:
        yrange = 0.1
    yminmax = (ymin - 0.02 * yrange, ymax + 0.02 * yrange)
    ax.plot([peak0, peak0], yminmax, color='red')
    ax.plot([peak1, peak1], yminmax, color='red')
    ax.set_ylim(yminmax)

    if plot_bias:
        if fitparms is None:
            ax_bias = ax.twinx()
            ax_bias.set_ylabel('Bias / V',
                               rotation=270,
                               va='bottom',
                               fontsize=fontsize)
            if self.min_bias == self.max_bias:
                ax_bias.set_ylim([self.min_bias - 1, self.max_bias + 1])
            else:
                ax_bias.set_ylim([self.min_bias, self.max_bias])
            ax_bias.tick_params(axis='both', labelsize=fontsize)
            curve2_ax = ax_bias
        else:
            curve2_ax = ax
        self.printmsg(
            'DEBUG: plotting sine curve for bias: len(time_axis)=%i, len(ysine)=%i'
            % (len(time_axis), len(ysine)),
            verbosity=4)
        curve2 = curve2_ax.plot(time_axis,
                                ysine,
                                label=sinelabel,
                                color='green')
        curves = curve1 + curve2
    else:
        curves = curve1

    labs = [l.get_label() for l in curves]
    ax.legend(curves, labs, loc=0, fontsize=fontsize)

    pngname = str('TES%03i_array-%s_ASIC%i_timeline_%s.png' %
                  (TES, self.detector_name, self.asic,
                   timeline_start.strftime('%Y%m%dT%H%M%SUTC')))
    pngname_fullpath = self.output_filename(pngname)
    if newplot and isinstance(pngname_fullpath, str):
        plt.savefig(pngname_fullpath,
                    format='png',
                    dpi=100,
                    bbox_inches='tight')
    if xwin: plt.show()
    else: plt.close('all')

    if fitparms: return fitparms
    return True