<commit_before>#
# This file is part of the PyMeasure package.
#
# Copyright (c) 2013-2016 PyMeasure Developers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

from pymeasure.instruments import Instrument, RangeException


class Agilent8257D(Instrument):
    """Interface for the Agilent 8257D signal generator
    """

    def __init__(self, resourceName, delay=0.02, **kwargs):
        super(Agilent8257D, self).__init__(
            resourceName,
            "Agilent 8257D RF Signal Generator",
            **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;")

    def enable(self):
        self.output = True

    def disable(self):
        self.output = False

    @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:
            raise Exception("This type of modulation does not exist.")

    def set_amplitude_depth(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 set_amplitude_source(self, source='INT'):
        """ Sets the source of the trigger for amplitude modulation """
        self.write(":SOUR:AM:SOUR %s" % source)

    def set_amplitude_modulation(self, enable=True):
        """ Enables (True) or disables (False) the amplitude modulation """<commit_msg>Polish codes for Agilent RF generator<commit_after>#
# This file is part of the PyMeasure package.
#
# Copyright (c) 2013-2016 PyMeasure Developers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

from pymeasure.instruments import Instrument, RangeException


class Agilent8257D(Instrument):
    """Interface for the Agilent 8257D signal generator
    """

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

        self.add_control("power",     ":pow?",  ":pow %g dbm;",
                         docs = "RF power in dBm")
        self.add_control("frequency", ":freq?", ":freq %g Hz;",
                         docs = "RF frequency in 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",
                         docs = "Settling time in seconds at the current freq/power setting")
        self.add_measurement("step_points", ":SOUR:SWE:POIN?")

    def get_output(self):
        """ Return if the output is ON"""
        return int(self.ask(":output?")) == 1

    def set_output(self, value):
        """ Set output ON/OFF"""
        if value:
            self.write(":output on;")
        else:
            self.write(":output off;")
            
    output = property(get_output, set_output)
    
    def enable(self):
        """ Set output = ON"""
        self.output = True

    def disable(self):
        """ Set output = OFF"""
        self.output = False

    def get_modulation(self):
        """ Return if modulation is ON"""
        return True if int(self.ask(":output:mod?")) == 1 else False

    def set_modulation(self, value):
        """ Set modulation ON/OFF"""
        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;")

    modulation = property(get_modulation, set_modulation)
    
    def configure_modulation(self, freq=10.0e9, modType="amplitude",
                             modDepth=100.0):
        """ Configure modulation and turn modulation ON
        
        :param freq: Modulation frequency, Hz
        :param modType: 'amplitude' or 'pulse'
        :param modDepth: AM modulation magnitude in percentage
        """
        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:
            raise Exception("This type of modulation does not exist.")

    def set_amplitude_depth(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 set_amplitude_source(self, source='INT'):
        """ Sets the source of the trigger for amplitude modulation """
        self.write(":SOUR:AM:SOUR %s" % source)

    def set_amplitude_modulation(self, enable=True):
        """ Enables (True) or disables (False) the amplitude modulation """
{'fraction_non_alphanumeric': 0.11880154504645579, 'fraction_numerical': 0.010648293141246476, 'mean_word_length': 2.7539184952978055, 'pattern_counts': {'":': 68, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5207940', 'n_tokens_mistral': 2982, 'n_tokens_neox': 2771, 'n_words': 909}