示例#1
0
mesa_ids = sorted(dic_mesaid_xypr_default)
for mesa_id in mesa_ids:
    print('{} (mesa_id {})'.format(dic_mesaid_mesa[mesa_id], mesa_id))
    if mesa_id in [1, 2, 5, 6, 7, 8]:
        print('Skip mesa.')
        continue
    for (X, Y) in XYs:
        if first_measurement and sample == 'dummy_sample' and \
                not (mesa_id == 3 and (X, Y) == (3, 4)):
            print('({},{})'.format(X, Y), end=' ')
            continue
        if inst != 'suss_test':
            sql = ('SELECT suss_R2 FROM v04_device '
                   'WHERE sample=%s AND mesa_id=%s AND X=%s AND Y=%s')
            R2 = db_read.q_single_abs(sql, (sample, mesa_id, X, Y,))
            if al.num_9th(R2) < 1.5:
                print('NG({},{})'.format(X, Y), end=' ')
                continue
        print('X{}Y{}'.format(X, Y))
        if mesa_id in dic_mesaid_xypr_spec:
            xs = dic_mesaid_xypr_spec[mesa_id][0] + (X - X_min) * dX
            ys = dic_mesaid_xypr_spec[mesa_id][1] + (Y - Y_min) * dY
        else:
            xs = dic_mesaid_xypr_default[mesa_id][0] + (X - X_min) * dX
            ys = dic_mesaid_xypr_default[mesa_id][1] + (Y - Y_min) * dY
        suss.safe_move_contact('H', -xs, -ys)
        if first_measurement:
            input('Contact the prober.')
            first_measurement = False
        for V in agi_Vs:
            mesa = dic_mesaid_mesa[mesa_id]
示例#2
0
def iv_matrix(db, sample, mesa, xlim=(-1.0, 1.0),
              XXYY=None, inst='%', save_path=None,
              R2_9th_lim=1.5, v_fit=(-0.1, 0.1),
              grayout_remarks={'i', 'lin', 'c', 'bd'},
              edit_remarks=False, db_rds=None, remarks_path=None, commit=False):
    """
    :param XXYY: (X_min, X_max, Y_min, Y_max). if is None -> all XYs
    """
    plt.close()
    sns.set_style("white")

    sql = ('SELECT device_id AS did, X, Y, area, suss_R0 AS R0, suss_RA0 AS RA0, '
           'VI_remarks as rem '
           'FROM v04_device WHERE sample=%s AND mesa=%s')
    df = db.pdq(sql, (sample, mesa,))

    if XXYY is None:
        X_min, X_max, Y_min, Y_max = \
            df.X.min(), df.X.max(), df.Y.min(), df.Y.max()
    else:
        X_min, X_max, Y_min, Y_max = XXYY

    # Number of columns and rows in matrix plot.
    numX = X_max - X_min + 1
    numY = Y_max - Y_min + 1
    if edit_remarks:
        devid_matrix = [[None for x in range(numX)] for y in range(numY)]
        remarks_matrix = [['NULL' for x in range(numX)] for y in range(numY)]

    # Takes long time.
    print('Making subplots frame...')
    #  http://matplotlib.org/api/pyplot_api.html
    subplot_kw = {'xlim': xlim, 'ylim': (-1, 1),
                  'xticks': [], 'yticks': [0]}
    f, axarr = plt.subplots(numY, numX, squeeze=False, subplot_kw=subplot_kw,
                            figsize=(numX, numY), facecolor='w')

    f.subplots_adjust(top=1, bottom=0, left=0, right=1, wspace=0, hspace=0)

    for i, d in df.iterrows():
        if not ((X_min <= d.X <= X_max) and (Y_min <= d.Y <= Y_max)):
            continue
        row = Y_max - d.Y
        col = -X_min + d.X
        ax = axarr[row, col]  # row, col
        ax.yaxis.set_major_formatter(plt.NullFormatter())  # Hide ticks labels

        if edit_remarks:
            devid_matrix[row][col] = d.did
            remarks_matrix[row][col] = d.rem

        tx_lb = d.rem.replace(' ', '\n')  # text left bottom
        ax.text(0.1, 0, tx_lb, ha='left', va='bottom',
                transform=ax.transAxes, size='x-small')

        print('Querying vis... (X{} Y{} {} device id: {})'.
              format(d.X, d.Y, mesa, d.did), end=' ', flush=True)
        sql = 'SELECT V, I FROM v_py_matrix ' \
              'WHERE device_id=%s AND inst LIKE %s'
        VI = db.pdq(sql, (d.did, inst,))
        print('Done.', end=' ', flush=True)
        if VI.empty:
            print()
            continue

        # fit
        VI_fit = VI[(v_fit[0] <= VI.V) & (VI.V <= v_fit[1])]
        c1, c2, c3, R2 = al.fit_R3(VI_fit)
        if not math.isclose(1/c1, d.R0, rel_tol=1e-2):  # tolerance: 2 digits
            print('R0 difference: db{} calc{}'.format(d.R0, 1/c1),
                  end=' ', flush=True)

        # Vs, Is, Rs
        VI['R'] = VI.V / VI.I
        VI['Ifit'] = c1 * VI.V + c2 * VI.V ** 2 + c3 * VI.V ** 3
        VI['Rfit'] = VI.V / VI.Ifit

        # Normalize to ylim(-1, 1)
        I_scale = VI.I.abs().max()
        VI['In'] = VI.I / I_scale  # [-1, 1]
        VI['Ifitn'] = VI.Ifit / I_scale  # [-1, 1]
        # Intervals: assuming R > 0
        R_scale = VI.R[(VI.R > 0) & (VI.R != np.inf)].max()
        R_scale = VI.Rfit.max()
        VI['Rn'] = (VI.R / R_scale) * 0.9  # (0, 0.9]
        VI['Rn'] = VI.Rn*2 - 1  # (-1, 0.9]
        VI['Rfitn'] = (VI.Rfit / R_scale)*0.9*2 - 1  # (-1, 0.9]

        R2_num_9th = al.num_9th(R2)
        if (R2_num_9th <= R2_9th_lim) or \
                (grayout_remarks & set(d.rem.split(' ')) != set()):
            blue, _, red = sns.color_palette('pastel')[:3]
        else:
            blue, _, red = sns.color_palette()[:3]
        ax.plot(VI.V, VI.Rn, c=red, lw=0.5)
        ax.plot(VI.V, VI.In, c=blue, lw=0.5)
        ax.plot(VI.V, VI.Rfitn, '--', c='gray', lw=0.5)
        ax.plot(VI.V, VI.Ifitn, '--', c='gray', lw=0.5)

        # X Y R2-#9th R0 RA0
        tx_lt = 'X{}Y{}\n{:d}'.format(d.X, d.Y, d.did)
        ax.text(0, 1, tx_lt, ha='left', va='top',
                transform=ax.transAxes, size='x-small')

        tx_rb = 'R2 {:.2f} {:.1f}\nR{:.1e}\nRA{:.1e}'. \
            format(R2, R2_num_9th, 1 / c1, d.area / c1)
        ax.text(1, 0, tx_rb, ha='right', va='bottom',
                transform=ax.transAxes, size='x-small')
        print('')  # newline

    if edit_remarks:
        with open(remarks_path, 'w') as f:
            f.write('\n'.join([','.join(row) for row in remarks_matrix]))

    if save_path is None:
        plt.show()
    else:
        plt.savefig(save_path)
    pass

    if edit_remarks:
        print('Edit', remarks_path, '.')
        input()
        with open(remarks_path, 'r') as f:
            remarks_matrix2 = f.readlines()
        remarks_matrix2 = [row.split(',') for row in remarks_matrix2]
        pairs_remarks_devid = []
        for row in range(numY):
            for col in range(numX):
                if devid_matrix[row][col] is None:
                    continue
                remarks = remarks_matrix2[row][col].strip()
                pairs_remarks_devid.append((remarks, devid_matrix[row][col]))
        oper = 'UPDATE device SET VI_remarks=%s WHERE device_id=%s'
        db_rds.exem(oper, pairs_remarks_devid)
        if commit:
            db_rds.cnx.commit()
            print('Edit comitted.')
示例#3
0
     continue
 for (X, Y) in XYs:
     if first_measurement and sample == 'dummy_sample' and \
             not (mesa_id == 3 and (X, Y) == (3, 4)):
         print('({},{})'.format(X, Y), end=' ')
         continue
     if inst != 'suss_test':
         sql = ('SELECT suss_R2 FROM v04_device '
                'WHERE sample=%s AND mesa_id=%s AND X=%s AND Y=%s')
         R2 = db_read.q_single_abs(sql, (
             sample,
             mesa_id,
             X,
             Y,
         ))
         if al.num_9th(R2) < 1.5:
             print('NG({},{})'.format(X, Y), end=' ')
             continue
     print('X{}Y{}'.format(X, Y))
     if mesa_id in dic_mesaid_xypr_spec:
         xs = dic_mesaid_xypr_spec[mesa_id][0] + (X - X_min) * dX
         ys = dic_mesaid_xypr_spec[mesa_id][1] + (Y - Y_min) * dY
     else:
         xs = dic_mesaid_xypr_default[mesa_id][0] + (X - X_min) * dX
         ys = dic_mesaid_xypr_default[mesa_id][1] + (Y - Y_min) * dY
     suss.safe_move_contact('H', -xs, -ys)
     if first_measurement:
         input('Contact the prober.')
         first_measurement = False
     for V in agi_Vs:
         mesa = dic_mesaid_mesa[mesa_id]