<commit_before>#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# Agilent classes -- RF Sweeper, Vector Network Analyzer
#
# automate Python package
# Authors: <NAME>, <NAME>
# Copyright: 2014 Cornell University
#
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
from automate.instruments import Instrument, discreteTruncate, RangeException
import numpy as np
import time, struct, re
from StringIO import StringIO

class Agilent8257D(Instrument):
    def __init__(self, resourceName, delay=0.02, **kwargs):
        super(Agilent8257D, self).__init__(resourceName, 
            "Agilent 8257D RF Signal Generator",
            delay=delay, **kwargs
        )

        self.add_control("power",     ":pow?",  ":pow %g dbm;")
        self.add_control("frequency", ":freq?", ":freq %g Hz;")
        self.add_control("center_frequency", ":SOUR:FREQ:CENT?", ":SOUR:FREQ:CENT %e HZ")
        self.add_control("start_frequency", ":SOUR:FREQ:STAR?", ":SOUR:FREQ:STAR %e HZ")
        self.add_control("stop_frequency", ":SOUR:FREQ:STOP?", ":SOUR:FREQ:STOP %e HZ")
        self.add_control("start_power", ":SOUR:POW:STAR?", ":SOUR:POW:STAR %e DBM")
        self.add_control("stop_power", ":SOUR:POW:STOP?", ":SOUR:POW:STOP %e DBM")
        self.add_control("dwell_time", ":SOUR:SWE:DWEL1?", ":SOUR:SWE:DWEL1 %.3f")
        self.add_measurement("step_points", ":SOUR:SWE:POIN?")

    @property
    def output(self):
        return int(self.ask(":output?"))==1
    @output.setter
    def output(self, value):
        if value:
            self.write(":output on;")
        else:
            self.write(":output off;")
    
    @property
    def modulation(self):
        return True if int(self.ask(":output:mod?"))==1 else False 
    @modulation.setter
    def modulation(self, value):
        if value:
            self.write(":output:mod on;")
            self.write(":lfo:sour int; :lfo:ampl 2.0vp; :lfo:stat on;")
        else:
            self.write(":output:mod off;")
            self.write(":lfo:stat off;")

    def configure_modulation(self, freq=10.0e9, modType="amplitude", modDepth=100.0):
        if modType == "amplitude":
            #self.write(":AM1;")
            self.modulation = True
            self.write(":AM:SOUR INT; :AM:INT:FUNC:SHAP SINE; :AM:STAT ON;")
            self.write(":AM:INT:FREQ %g HZ; :AM %f" % (freq, modDepth))
        elif modType == "pulse":
            # Sets square pulse modulation at the desired freq
            self.modulation = True
            self.write(":PULM:SOUR:INT SQU; :PULM:SOUR INT; :PULM:STAT ON;")
            self.write(":PULM:INT:FREQ %g HZ;" % freq)
        else:
            print "This type of modulation does not exist."
        
    def setAmplitudeDepth(self, depth):
        """ Sets the depth of amplitude modulation which corresponds
        to the precentage of the signal modulated to
        """
        if depth > 0 and depth <= 100:
            self.write(":SOUR:AM %d" % depth)
        else:
            raise RangeException("Agilent E8257D amplitude modulation out of range")
            
    def setAmplitudeSource(self, source='INT'):
        """ Sets the source of the trigger for amplitude modulation """
        self.write(":SOUR:AM:SOUR %s" % source)
        
    def setAmplitudeModulation(self, enable=True):
        """ Enables (True) or disables (False) the amplitude modulation """
        self.write(":SOUR:AM:STAT %d" % enable)

    def setStepSweep(self):
        """ Sets up for a step sweep through frequency """
        self.write(":SOUR:FREQ:MODE SWE;:SOUR:SWE:GEN STEP;:SOUR:SWE:MODE AUTO;")
    
    def setRetrace(self, enable=True):
        self.write(":SOUR:LIST:RETR %d" % enable)
        
    def singleSweep(self):
        self.write(":SOUR:TSW")
        
    def startStepSweep(self):
        """ Initiates a step sweep """
        self.write(":SOUR:SWE:CONT:STAT ON")
        
    def stopStepSweep(self):
        """ Stops a step sweep """
        self.write(":SOUR:SWE:CONT:STAT OFF")

    def shutdown(self):
        self.modulation = False
        self.output = False


class Agilent8722ES(Instrument):
    """ Represents the Agilent8722ES Vector Network Analyzer
    and provides a high-level interface for taking scans of the
    scattering parameters.
    """

    SCAN_POINT_VALUES = [3, 11, 21, 26, 51, 101, 201, 401, 801, 1601]
    SCATTERING_PARAMETERS = ("S11", "S12", "S21", "S22")
    S11, S12, S21, S22 = SCATTERING_PARAMETERS

    def __init__(self, resourceName, **kwargs):
        super(Agilent8722ES, self).__init__(resourceName, "Agilent 8722ES Vector Network Analyzer", **kwargs)
        
        self.add_control("start_frequency", "STAR?", "STAR %.3e HZ")
        self.add_control("stop_frequency", "STOP?", "STOP %.3e HZ")
        self.add_control("sweep_time", "SWET?", "SWET%.2e")
    
    def setFixedFrequency(self, frequency):
        """ Sets the scan to be of only one frequency in Hz """
        self.setStartFrequency(frequency)
        self.setStopFrequency(frequency)
        self.setScanPoints(3)

    @property
    def parameter(self):
        for parameter in Agilent8722ES.SCATTERING_PARAMETERS:
            if int(self.values("%s?" % parameter))==1: return parameter
        return None
    @parameter.setter
    def parameter(self, value):
        if value in Agilent8722ES.SCATTERING_PARAMETERS:
            self.write("%s" % value)
        else:
            raise Exception("Invalid scattering parameter requested for Agilent 8722ES")
        
    def setScanPoints(self, points):
        """ Sets the number of scan points, truncating to an allowed
        value if not properly provided       
        """
        points = discreteTruncate(points, Agilent8722ES.SCAN_POINT_VALUES)
        if points:
            self.write("POIN%d" % points)
        else:
            raise RangeException("Maximum scan points (1601) for Agilent 8722ES"
                                 " exceeded")
                                 
    def getScanPoints(self):
        """ Gets the number of scan points
        """
        search = re.search(r"\d\.\d+E[+-]\d{2}$", self.ask("POIN?"), re.MULTILINE)
        if search:
           return int(float(search.group()))
        else:
            raise Exception("Improper message returned for the number of points")  
                                 
    def setIFBandwidth(self, bandwidth):
        """ Sets the resolution bandwidth (IF bandwidth) """
        allowedBandwidth = [10, 30, 100, 300, 1000, 3000, 3700, 6000]
        bandwidth = discreteTruncate(bandwidth, allowedBandwidth)
        if bandwidth:
            self.write("IFBW%d" % bandwidth)
        else:
            raise RangeException("Maximum IF bandwidth (6000) for Agilent "
                                 "8722ES exceeded")
    
    def setAveraging(self, averages):
        """ Turns on averaging of a specific number between 0 and 999        
        """
        if int(averages) > 999 or int(averages) < 0:
            raise RangeException("Averaging must be in the range 0 to 999")
        else:
            self.write("AVERO1")<commit_msg>Added scan points as property to Agilent8722ES<commit_after>#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# Agilent classes -- RF Sweeper, Vector Network Analyzer
#
# automate Python package
# Authors: <NAME>, <NAME>
# Copyright: 2014 Cornell University
#
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
from automate.instruments import Instrument, discreteTruncate, RangeException
import numpy as np
import time, struct, re
from StringIO import StringIO

class Agilent8257D(Instrument):
    def __init__(self, resourceName, delay=0.02, **kwargs):
        super(Agilent8257D, self).__init__(resourceName, 
            "Agilent 8257D RF Signal Generator",
            delay=delay, **kwargs
        )

        self.add_control("power",     ":pow?",  ":pow %g dbm;")
        self.add_control("frequency", ":freq?", ":freq %g Hz;")
        self.add_control("center_frequency", ":SOUR:FREQ:CENT?", ":SOUR:FREQ:CENT %e HZ")
        self.add_control("start_frequency", ":SOUR:FREQ:STAR?", ":SOUR:FREQ:STAR %e HZ")
        self.add_control("stop_frequency", ":SOUR:FREQ:STOP?", ":SOUR:FREQ:STOP %e HZ")
        self.add_control("start_power", ":SOUR:POW:STAR?", ":SOUR:POW:STAR %e DBM")
        self.add_control("stop_power", ":SOUR:POW:STOP?", ":SOUR:POW:STOP %e DBM")
        self.add_control("dwell_time", ":SOUR:SWE:DWEL1?", ":SOUR:SWE:DWEL1 %.3f")
        self.add_measurement("step_points", ":SOUR:SWE:POIN?")

    @property
    def output(self):
        return int(self.ask(":output?"))==1
    @output.setter
    def output(self, value):
        if value:
            self.write(":output on;")
        else:
            self.write(":output off;")
    
    @property
    def modulation(self):
        return True if int(self.ask(":output:mod?"))==1 else False 
    @modulation.setter
    def modulation(self, value):
        if value:
            self.write(":output:mod on;")
            self.write(":lfo:sour int; :lfo:ampl 2.0vp; :lfo:stat on;")
        else:
            self.write(":output:mod off;")
            self.write(":lfo:stat off;")

    def configure_modulation(self, freq=10.0e9, modType="amplitude", modDepth=100.0):
        if modType == "amplitude":
            #self.write(":AM1;")
            self.modulation = True
            self.write(":AM:SOUR INT; :AM:INT:FUNC:SHAP SINE; :AM:STAT ON;")
            self.write(":AM:INT:FREQ %g HZ; :AM %f" % (freq, modDepth))
        elif modType == "pulse":
            # Sets square pulse modulation at the desired freq
            self.modulation = True
            self.write(":PULM:SOUR:INT SQU; :PULM:SOUR INT; :PULM:STAT ON;")
            self.write(":PULM:INT:FREQ %g HZ;" % freq)
        else:
            print "This type of modulation does not exist."
        
    def setAmplitudeDepth(self, depth):
        """ Sets the depth of amplitude modulation which corresponds
        to the precentage of the signal modulated to
        """
        if depth > 0 and depth <= 100:
            self.write(":SOUR:AM %d" % depth)
        else:
            raise RangeException("Agilent E8257D amplitude modulation out of range")
            
    def setAmplitudeSource(self, source='INT'):
        """ Sets the source of the trigger for amplitude modulation """
        self.write(":SOUR:AM:SOUR %s" % source)
        
    def setAmplitudeModulation(self, enable=True):
        """ Enables (True) or disables (False) the amplitude modulation """
        self.write(":SOUR:AM:STAT %d" % enable)

    def setStepSweep(self):
        """ Sets up for a step sweep through frequency """
        self.write(":SOUR:FREQ:MODE SWE;:SOUR:SWE:GEN STEP;:SOUR:SWE:MODE AUTO;")
    
    def setRetrace(self, enable=True):
        self.write(":SOUR:LIST:RETR %d" % enable)
        
    def singleSweep(self):
        self.write(":SOUR:TSW")
        
    def startStepSweep(self):
        """ Initiates a step sweep """
        self.write(":SOUR:SWE:CONT:STAT ON")
        
    def stopStepSweep(self):
        """ Stops a step sweep """
        self.write(":SOUR:SWE:CONT:STAT OFF")

    def shutdown(self):
        self.modulation = False
        self.output = False


class Agilent8722ES(Instrument):
    """ Represents the Agilent8722ES Vector Network Analyzer
    and provides a high-level interface for taking scans of the
    scattering parameters.
    """

    SCAN_POINT_VALUES = [3, 11, 21, 26, 51, 101, 201, 401, 801, 1601]
    SCATTERING_PARAMETERS = ("S11", "S12", "S21", "S22")
    S11, S12, S21, S22 = SCATTERING_PARAMETERS

    def __init__(self, resourceName, **kwargs):
        super(Agilent8722ES, self).__init__(resourceName, "Agilent 8722ES Vector Network Analyzer", **kwargs)
        
        self.add_control("start_frequency", "STAR?", "STAR %.3e HZ")
        self.add_control("stop_frequency", "STOP?", "STOP %.3e HZ")
        self.add_control("sweep_time", "SWET?", "SWET%.2e")
    
    def setFixedFrequency(self, frequency):
        """ Sets the scan to be of only one frequency in Hz """
        self.setStartFrequency(frequency)
        self.setStopFrequency(frequency)
        self.setScanPoints(3)

    @property
    def parameter(self):
        for parameter in Agilent8722ES.SCATTERING_PARAMETERS:
            if int(self.values("%s?" % parameter))==1: return parameter
        return None
    @parameter.setter
    def parameter(self, value):
        if value in Agilent8722ES.SCATTERING_PARAMETERS:
            self.write("%s" % value)
        else:
            raise Exception("Invalid scattering parameter requested for Agilent 8722ES")
        
    @property
    def scan_points(self):
        """ Gets the number of scan points
        """
        search = re.search(r"\d\.\d+E[+-]\d{2}$", self.ask("POIN?"), re.MULTILINE)
        if search:
           return int(float(search.group()))
        else:
            raise Exception("Improper message returned for the number of points")
    @scan_points.setter
    def scan_points(self, points):
        """ Sets the number of scan points, truncating to an allowed
        value if not properly provided       
        """
        points = discreteTruncate(points, Agilent8722ES.SCAN_POINT_VALUES)
        if points:
            self.write("POIN%d" % points)
        else:
            raise RangeException("Maximum scan points (1601) for Agilent 8722ES"
                                 " exceeded") 
                                 
    def setIFBandwidth(self, bandwidth):
        """ Sets the resolution bandwidth (IF bandwidth) """
        allowedBandwidth = [10, 30, 100, 300, 1000, 3000, 3700, 6000]
        bandwidth = discreteTruncate(bandwidth, allowedBandwidth)
        if bandwidth:
            self.write("IFBW%d" % bandwidth)
        else:
            raise RangeException("Maximum IF bandwidth (6000) for Agilent "
                                 "8722ES exceeded")
    
    def setAveraging(self, averages):
        """ Turns on averaging of a specific number between 0 and 999        
        """
        if int(averages) > 999 or int(averages) < 0:
            raise RangeException("Averaging must be in the range 0 to 999")
        else:
            self.write("AVERO1")
{'fraction_non_alphanumeric': 0.1467717194254637, 'fraction_numerical': 0.024961651094686933, 'mean_word_length': 2.55994043186895, 'pattern_counts': {'":': 80, '<': 11, '<?xml version=': 0, '>': 327, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3286471', 'n_tokens_mistral': 4853, 'n_tokens_neox': 4365, 'n_words': 1103}