コード例 #1
0
ファイル: spec.py プロジェクト: jkyl/xhorn
 def clear_ogp(self):
     '''
     Clears the OGP registers on the ADC.
     '''
     for core in range(1, 5):
         adc.set_spi_gain(self._roach, 0, core, 0)
         adc.set_spi_offset(self._roach, 0, core, 0)
         adc.set_spi_phase(self._roach, 0, core, 0)
コード例 #2
0
ファイル: rww_tools.py プロジェクト: TCioms/adc_tests
def clear_ogp():
  """
  Clear all of the Offset, Gain and Phase corrections registers on the adc.
  """
  for core in range(1,5):
    adc5g.set_spi_gain(roach2,zdok, core, 0)
    adc5g.set_spi_offset(roach2,zdok, core, 0)
    adc5g.set_spi_phase(roach2,zdok, core, 0)
コード例 #3
0
ファイル: rww_tools.py プロジェクト: indrajitbarve/adc_tests
def clear_ogp():
    """
  Clear all of the Offset, Gain and Phase corrections registers on the adc.
  """
    for core in range(1, 5):
        adc5g.set_spi_gain(roach2, zdok, core, 0)
        adc5g.set_spi_offset(roach2, zdok, core, 0)
        adc5g.set_spi_phase(roach2, zdok, core, 0)
コード例 #4
0
ファイル: spec.py プロジェクト: jkyl/xhorn
 def set_ogp(self, ogp):
     '''
     Sets the OGP registers on the ADC. Input shape must be (4, 3). 
     '''
     offs = ogp[:, 0]
     gains = ogp[:, 1]
     phase = ogp[:, 2]
     for i in range(len(offs)):
          adc.set_spi_offset(self._roach, 0, i+1, offs[i])
          adc.set_spi_gain(self._roach, 0, i+1, gains[i])
          adc.set_spi_phase(self._roach, 0, i+1, phase[i])
コード例 #5
0
    def clear_ogp(self, chans=[0, 1, 2, 3]):
        """
	   Sets OGP to 0 for channels in 'chans'
        """

        for chan in chans:

            zdok, cores = self.get_channel_core_spi(chan)

            for core in cores:

                adc5g.set_spi_offset(self.roach, zdok, core, 0)

                adc5g.set_spi_gain(self.roach, zdok, core, 0)

                adc5g.set_spi_phase(self.roach, zdok, core, 0)
コード例 #6
0
ファイル: adc5g_cal.py プロジェクト: umass-wares/wares_spec
    def clear_ogp(self, chans = [0,1,2,3]):

        """
	   Sets OGP to 0 for channels in 'chans'
        """

	for chan in chans:

		zdok, cores = self.get_channel_core_spi(chan)

		for core in cores:

			adc5g.set_spi_offset(self.roach, zdok, core, 0)

			adc5g.set_spi_gain(self.roach, zdok, core, 0)

			adc5g.set_spi_phase(self.roach, zdok, core, 0)
コード例 #7
0
ファイル: rww_tools.py プロジェクト: TCioms/adc_tests
def set_gains(g1, g2, g3, g4):
  """
  Set the gains for each core in the order a, b, c, d.
  """
  t = float(g1)
  print math.floor(.5+t*255/36.)+0x80,
  adc5g.set_spi_gain(roach2,zdok, 1, t)
  t = float(g2)
  print math.floor(.5+t*255/36.)+0x80,
  adc5g.set_spi_gain(roach2,zdok, 2, t)
  t = float(g3)
  print math.floor(.5+t*255/36.)+0x80,
  adc5g.set_spi_gain(roach2,zdok, 3, t)
  t = float(g4)
  print math.floor(.5+t*255/36.)+0x80
  adc5g.set_spi_gain(roach2,zdok, 4, t)
コード例 #8
0
ファイル: rww_tools.py プロジェクト: indrajitbarve/adc_tests
def set_gains(g1, g2, g3, g4):
    """
  Set the gains for each core in the order a, b, c, d.
  """
    t = float(g1)
    print math.floor(.5 + t * 255 / 36.) + 0x80,
    adc5g.set_spi_gain(roach2, zdok, 1, t)
    t = float(g2)
    print math.floor(.5 + t * 255 / 36.) + 0x80,
    adc5g.set_spi_gain(roach2, zdok, 2, t)
    t = float(g3)
    print math.floor(.5 + t * 255 / 36.) + 0x80,
    adc5g.set_spi_gain(roach2, zdok, 3, t)
    t = float(g4)
    print math.floor(.5 + t * 255 / 36.) + 0x80
    adc5g.set_spi_gain(roach2, zdok, 4, t)
コード例 #9
0
    def set_ogp(self, ogp_chan, chan):
        """
	   Sets ogp for two cores of channel 'chan'
	   multi_ogp is format (ogp1, ogp2)
        """

        zdok, cores = self.get_channel_core_spi(chan)

        i = 0
        for core in cores:

            off, gain, phase = ogp_chan[i]

            off_spi = math.floor(.5 + off * 255 / 100.) + 0x80
            adc5g.set_spi_offset(self.roach, zdok, core, float(off))

            gain_spi = math.floor(.5 + gain * 255 / 36.) + 0x80
            adc5g.set_spi_gain(self.roach, zdok, core, float(gain))

            phase_spi = math.floor(.5 + phase * 255 / 28.) + 0x80
            adc5g.set_spi_phase(self.roach, zdok, core, float(phase) * 0.65)

            i += 1
コード例 #10
0
ファイル: adc5g_cal.py プロジェクト: umass-wares/wares_spec
    def set_ogp(self, ogp_chan, chan):

        """
	   Sets ogp for two cores of channel 'chan'
	   multi_ogp is format (ogp1, ogp2)
        """

        zdok, cores = self.get_channel_core_spi(chan)

	i = 0
        for core in cores:
            
            off, gain, phase = ogp_chan[i]

            off_spi = math.floor(.5 + off*255/100.) + 0x80
            adc5g.set_spi_offset(self.roach, zdok, core, float(off))

            gain_spi = math.floor(.5 + gain*255/36.) + 0x80
            adc5g.set_spi_gain(self.roach, zdok, core, float(gain))

            phase_spi = math.floor(.5 + phase*255/28.) + 0x80
            adc5g.set_spi_phase(self.roach, zdok, core, float(phase)*0.65)

	    i += 1
コード例 #11
0
ファイル: r2daq.py プロジェクト: project8/phasmid
    def calibrate_adc_gain(self, zdok=0, giter=10, gtol=0.005, verbose=10):
        """
		Attempt to match the core gains within the ADC.

		See ArtooDaq.calibrate_adc_ogp for more details.
		"""
        # gain controlled by float varying over [-18%,18%] with 0.14% resolution
        res_gain = 0.14
        lim_gain = [-18.0, 18.0]
        groups = 8
        test_step = 10 * res_gain
        if verbose > 3:
            print "  Gain calibration ZDOK{0}:".format(zdok)
        for ic in xrange(1, 5):
            adc5g.set_spi_gain(self.roach2, zdok, ic, 0)
        x1 = self._snap_per_core(zdok=zdok, groups=groups)
        sx1 = x1.std(axis=0)
        s0 = sx1[0]
        sx1 = sx1 / s0
        if verbose > 5:
            print "    ...gain: with zero-offsets, stds are                                    [{0}]".format(
                ", ".join(["{0:+7.4f}".format(isx) for isx in sx1]))
        # only adjust gains for last three cores, core1 is the reference
        for ic in xrange(2, 5):
            adc5g.set_spi_gain(self.roach2, zdok, ic, test_step)
        x2 = self._snap_per_core(zdok=zdok, groups=groups)
        sx2 = x2.std(axis=0)
        s0 = sx2[0]
        sx2 = sx2 / s0
        if verbose > 5:
            print "    ...gain: with {0:+6.2f}% gain, stds are                                    [{1}]".format(
                test_step, ", ".join(["{0:+7.4f}".format(isx) for isx in sx2]))
        d_sx = 100 * (sx2 - sx1) / test_step
        # give differential for core1 a non-zero value, it won't be used anyway
        d_sx[0] = 1.0
        # gains are in units percentage
        core_gains = 100 * (1.0 - sx1) / d_sx
        # set core1 gain to zero
        core_gains[0] = 0
        for ic in xrange(2, 5):
            adc5g.set_spi_gain(self.roach2, zdok, ic, core_gains[ic - 1])
            core_gains[ic - 1] = adc5g.get_spi_gain(self.roach2, zdok, ic)
        x = self._snap_per_core(zdok=zdok, groups=groups)
        sx = x.std(axis=0)
        s0 = sx[0]
        sx = sx / s0
        if verbose > 5:
            print "    ...gain: solution gains are [{0}]%, stds are [{1}]".format(
                ", ".join(["{0:+6.2f}".format(ico) for ico in core_gains]),
                ", ".join(["{0:+7.4f}".format(isx) for isx in sx]))
        if any(abs(1.0 - sx) >= gtol):
            if verbose > 5:
                print "    ...gain: solution not good enough, iterating (tol={0:4.4f},iter={1:d})".format(
                    gtol, giter)
            for ii in xrange(0, giter):
                for ic in xrange(2, 5):
                    if (1.0 - sx[ic - 1]) > gtol:
                        adc5g.set_spi_gain(self.roach2, zdok, ic,
                                           core_gains[ic - 1] + res_gain)
                    elif (1.0 - sx[ic - 1]) < -gtol:
                        adc5g.set_spi_gain(self.roach2, zdok, ic,
                                           core_gains[ic - 1] - res_gain)
                    core_gains[ic - 1] = adc5g.get_spi_gain(
                        self.roach2, zdok, ic)
                x = self._snap_per_core(zdok=zdok, groups=groups)
                sx = x.std(axis=0)
                s0 = sx[0]
                sx = sx / s0
                if verbose > 7:
                    print "    ...gain: solution gains are [{0}]%, stds are [{1}]".format(
                        ", ".join(
                            ["{0:+6.2f}".format(ico) for ico in core_gains]),
                        ", ".join(["{0:+7.4f}".format(isx) for isx in sx]))
                if all(abs(1.0 - sx) < gtol):
                    if verbose > 5:
                        print "    ...gain: solution good enough"
                    break
                if ii == giter - 1:
                    if verbose > 5:
                        print "    ...gain: maximum number of iterations reached, aborting"
        else:
            if verbose > 5:
                print "    ...gain: solution good enough"
        return core_gains
コード例 #12
0
ファイル: r2daq.py プロジェクト: project8/phasmid
	def calibrate_adc_gain(self,zdok=0,giter=10,gtol=0.005,verbose=10):
		"""
		Attempt to match the core gains within the ADC.

		See ArtooDaq.calibrate_adc_ogp for more details.
		"""
		# gain controlled by float varying over [-18%,18%] with 0.14% resolution
		res_gain = 0.14
		lim_gain = [-18.0,18.0]
		groups = 8
		test_step = 10*res_gain
		if verbose > 3:
			print "  Gain calibration ZDOK{0}:".format(zdok)
		for ic in xrange(1,5):
			adc5g.set_spi_gain(self.roach2,zdok,ic,0)
		x1 = self._snap_per_core(zdok=zdok,groups=groups)
		sx1 = x1.std(axis=0)
		s0 = sx1[0]
		sx1 = sx1/s0
		if verbose > 5:
			print "    ...gain: with zero-offsets, stds are                                    [{0}]".format(
				", ".join(["{0:+7.4f}".format(isx) for isx in sx1])
			)
		# only adjust gains for last three cores, core1 is the reference
		for ic in xrange(2,5):
			adc5g.set_spi_gain(self.roach2,zdok,ic,test_step)
		x2 = self._snap_per_core(zdok=zdok,groups=groups)
		sx2 = x2.std(axis=0)
		s0 = sx2[0]
		sx2 = sx2/s0
		if verbose > 5:
			print "    ...gain: with {0:+6.2f}% gain, stds are                                    [{1}]".format(
				test_step,
				", ".join(["{0:+7.4f}".format(isx) for isx in sx2])
			)
		d_sx = 100*(sx2 - sx1)/test_step
		# give differential for core1 a non-zero value, it won't be used anyway
		d_sx[0] = 1.0
		# gains are in units percentage
		core_gains = 100*(1.0-sx1)/d_sx
		# set core1 gain to zero
		core_gains[0] = 0
		for ic in xrange(2,5):
			adc5g.set_spi_gain(self.roach2,zdok,ic,core_gains[ic-1])
			core_gains[ic-1] = adc5g.get_spi_gain(self.roach2,zdok,ic)
		x = self._snap_per_core(zdok=zdok,groups=groups)
		sx = x.std(axis=0)
		s0 = sx[0]
		sx = sx/s0
		if verbose > 5:
			print "    ...gain: solution gains are [{0}]%, stds are [{1}]".format(
				", ".join(["{0:+6.2f}".format(ico) for ico in core_gains]),
				", ".join(["{0:+7.4f}".format(isx) for isx in sx])
			)
		if any(abs(1.0-sx) >= gtol):
			if verbose > 5:
				print "    ...gain: solution not good enough, iterating (tol={0:4.4f},iter={1:d})".format(gtol,giter)
			for ii in xrange(0,giter):
				for ic in xrange(2,5):
					if (1.0-sx[ic-1]) > gtol:
						adc5g.set_spi_gain(self.roach2,zdok,ic,core_gains[ic-1]+res_gain)
					elif (1.0-sx[ic-1]) < -gtol:
						adc5g.set_spi_gain(self.roach2,zdok,ic,core_gains[ic-1]-res_gain)
					core_gains[ic-1] = adc5g.get_spi_gain(self.roach2,zdok,ic)
				x = self._snap_per_core(zdok=zdok,groups=groups)
				sx = x.std(axis=0)
				s0 = sx[0]
				sx = sx/s0
				if verbose > 7:
					print "    ...gain: solution gains are [{0}]%, stds are [{1}]".format(
							", ".join(["{0:+6.2f}".format(ico) for ico in core_gains]),
        	                ", ".join(["{0:+7.4f}".format(isx) for isx in sx])
					)
				if all(abs(1.0-sx) < gtol):
					if verbose > 5:
						print "    ...gain: solution good enough"
					break
				if ii==giter-1:
					if verbose > 5:
						print "    ...gain: maximum number of iterations reached, aborting"
		else:
			if verbose > 5:
				print "    ...gain: solution good enough"
		return core_gains
コード例 #13
0
ファイル: og.py プロジェクト: sao-eht/lmtscripts
def ogapply(sol):
    for i in [0, 1]:
        for j in [0, 1, 2, 3]:
            adc5g.set_spi_offset(r2, i, corder[j], sol[i,j,0])
            adc5g.set_spi_gain(r2, i, corder[j], sol[i,j,1])
コード例 #14
0
ファイル: og.py プロジェクト: sao-eht/lmtscripts
            plt.xlim(-128, 128)
            plt.ylim(0, 1.05 * np.max(counts))
            plt.yticks([])
            plt.xticks([])
        means[j] = ret[1]
        stds[j] = ret[2]
        print "IF%d Core %d: mean %5.2f std %5.2f" % (i, j, ret[1], ret[2])
    avg_std = np.mean(stds) # target std
    for j in [0,1,2,3]:
        orig_off = adc5g.get_spi_offset(r2, i, corder[j])
        orig_gain = adc5g.get_spi_gain(r2, i, corder[j])
        new_off = orig_off - means[j] * 500./256.
        new_gain = (100. + orig_gain) * (avg_std / stds[j]) - 100.
        if setog:
            adc5g.set_spi_offset(r2, i, corder[j], new_off)
            adc5g.set_spi_gain(r2, i, corder[j], new_gain)
        sol[i,j,0] = new_off
        sol[i,j,1] = new_gain

if doplot:
    plt.suptitle('%s ADC 8bit population\n%s' % (open('/etc/hostname').read().strip(), tag))
    plt.subplots_adjust(hspace=0, wspace=0)
    plt.setp(plt.gcf(), figwidth=8, figheight=12)
    figfile = 'ogplot-%s.png' % tag
    print "saving figure to: %s" % figfile
    plt.savefig(figfile)

solfile = 'ogsol-%s.npy' % tag
print "saving solution to: %s" % solfile
np.save(solfile, sol)