Debian Codegraph @

pymeasure/instruments/agilent/agilentE4408B.py

raw
1 #
2 # This file is part of the PyMeasure package.
3 #
4 # Copyright (c) 2013-2024 PyMeasure Developers
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 # THE SOFTWARE.
23 #
24
25 from pymeasure.instruments import Instrument, SCPIUnknownMixin
26 from pymeasure.instruments.validators import truncated_range
27
28 from io import StringIO
29 import numpy as np
30 import pandas as pd
31
32
33 class AgilentE4408B(SCPIUnknownMixin, Instrument):
34 """ Represents the AgilentE4408B Spectrum Analyzer
35 and provides a high-level interface for taking scans of
36 high-frequency spectrums
37 """
38
39 def __init__(self, adapter, name="Agilent E4408B Spectrum Analyzer", **kwargs):
40 super().__init__(
41 adapter,
42 name,
43 **kwargs
44 )
45
46 start_frequency = Instrument.control(
47 ":SENS:FREQ:STAR?;", ":SENS:FREQ:STAR %e Hz;",
48 """ A floating point property that represents the start frequency
49 in Hz. This property can be set.
50 """
51 )
52 stop_frequency = Instrument.control(
53 ":SENS:FREQ:STOP?;", ":SENS:FREQ:STOP %e Hz;",
54 """ A floating point property that represents the stop frequency
55 in Hz. This property can be set.
56 """
57 )
58 frequency_points = Instrument.control(
59 ":SENSe:SWEEp:POINts?;", ":SENSe:SWEEp:POINts %d;",
60 """ An integer property that represents the number of frequency
61 points in the sweep. This property can take values from 101 to 8192.
62 """,
63 validator=truncated_range,
64 values=[101, 8192],
65 cast=int
66 )
67 frequency_step = Instrument.control(
68 ":SENS:FREQ:CENT:STEP:INCR?;", ":SENS:FREQ:CENT:STEP:INCR %g Hz;",
69 """ A floating point property that represents the frequency step
70 in Hz. This property can be set.
71 """
72 )
73 center_frequency = Instrument.control(
74 ":SENS:FREQ:CENT?;", ":SENS:FREQ:CENT %e Hz;",
75 """ A floating point property that represents the center frequency
76 in Hz. This property can be set.
77 """
78 )
79 sweep_time = Instrument.control(
80 ":SENS:SWE:TIME?;", ":SENS:SWE:TIME %.2e;",
81 """ A floating point property that represents the sweep time
82 in seconds. This property can be set.
83 """
84 )
85
86 @property
87 def frequencies(self):
88 """ Returns a numpy array of frequencies in Hz that
89 correspond to the current settings of the instrument.
90 """
91 return np.linspace(
92 self.start_frequency,
93 self.stop_frequency,
94 self.frequency_points,
95 dtype=np.float64
96 )
97
98 def trace(self, number=1):
99 """ Returns a numpy array of the data for a particular trace
100 based on the trace number (1, 2, or 3).
101 """
102 self.write(":FORMat:TRACe:DATA ASCII;")
103 data = np.loadtxt(
104 StringIO(self.ask(":TRACE:DATA? TRACE%d;" % number)),
105 delimiter=',',
106 dtype=np.float64
107 )
108 return data
109
110 def trace_df(self, number=1):
111 """ Returns a pandas DataFrame containing the frequency
112 and peak data for a particular trace, based on the
113 trace number (1, 2, or 3).
114 """
115 return pd.DataFrame({
116 'Frequency (GHz)': self.frequencies * 1e-9,
117 'Peak (dB)': self.trace(number)
118 })