Skip to content

Commit

Permalink
Inner, outer class consistency (#321)
Browse files Browse the repository at this point in the history
* Move channel inside for SRS DG645

* Update docs for SRS

* Newport Agilis: Move Axis into class and fix docs

* Newport ESP301: Inner class consistencty and docs update
- Move Axis class into instrument
- Move HomeSearchMode, Units, MotorType enums into instrument

* Add test for Newport ESP301 - default search mode in axis method

* Tektronix DPO4104 move classes inside and update docs

* Abstract instrument Oscilloscope: Move classes inside and add to docs

* Tektronix TDS5xx: Move Channel, DataSource, Measurement inside class

* Tektronix TedTDS224: Move Channel, DataSource inside

* Cleanup and update docstrings of changed classes

* Abstract Instrument PowerSupply: Move Channel inside class, add to doc

* Abs Inst OpticalSpectrumAnalyzer: Move channel inside class, add to docs

* Add electrometer to docs and sort instruments alphabetically

* Fix copy/paste error in abstract instrument PowerSupply

* Fix commenting in Test for SRS DG645
  • Loading branch information
trappitsch authored Jan 26, 2022
1 parent 5cdba01 commit aa51148
Show file tree
Hide file tree
Showing 35 changed files with 2,263 additions and 2,279 deletions.
34 changes: 31 additions & 3 deletions doc/source/apiref/instrument.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Instrument Base Classes
:members:
:undoc-members:

:class:`Multimeter` - Abstract class for multimeter instruments
===============================================================
:class:`Electrometer` - Abstract class for electrometer instruments
===================================================================

.. autoclass:: instruments.abstract_instruments.Multimeter
.. autoclass:: instruments.abstract_instruments.Electrometer
:members:
:undoc-members:

Expand All @@ -28,6 +28,34 @@ Instrument Base Classes
:members:
:undoc-members:

:class:`Multimeter` - Abstract class for multimeter instruments
===============================================================

.. autoclass:: instruments.abstract_instruments.Multimeter
:members:
:undoc-members:

:class:`Oscilloscope` - Abstract class for oscilloscope instruments
===================================================================

.. autoclass:: instruments.abstract_instruments.Oscilloscope
:members:
:undoc-members:

:class:`OpticalSpectrumAnalyzer` - Abstract class for optical spectrum analyzer instruments
===========================================================================================

.. autoclass:: instruments.abstract_instruments.OpticalSpectrumAnalyzer
:members:
:undoc-members:

:class:`PowerSupply` - Abstract class for power supply instruments
==================================================================

.. autoclass:: instruments.abstract_instruments.PowerSupply
:members:
:undoc-members:

:class:`SignalGenerator` - Abstract class for Signal Generators
===============================================================

Expand Down
12 changes: 0 additions & 12 deletions doc/source/apiref/newport.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,13 @@ Newport
:members:
:undoc-members:

.. autoclass:: _Axis
:members:
:undoc-members:

:class:`NewportESP301` Motor Controller
=======================================

.. autoclass:: NewportESP301
:members:
:undoc-members:

.. autoclass:: NewportESP301Axis
:members:
:undoc-members:

.. autoclass:: NewportESP301HomeSearchMode
:members:
:undoc-members:

:class:`NewportError`
=====================

Expand Down
4 changes: 0 additions & 4 deletions doc/source/apiref/srs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,3 @@ Stanford Research Systems
.. autoclass:: SRSDG645
:members:
:undoc-members:

.. autoclass:: _SRSDG645Channel
:members:
:undoc-members:
8 changes: 0 additions & 8 deletions doc/source/apiref/tektronix.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ Tektronix
:members:
:undoc-members:

.. autoclass:: _TekDPO4104DataSource
:members:
:undoc-members:

.. autoclass:: _TekDPO4104Channel
:members:
:undoc-members:

:class:`TekDPO70000` Oscilloscope
=================================

Expand Down
19 changes: 4 additions & 15 deletions instruments/abstract_instruments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,9 @@


from .instrument import Instrument
from .multimeter import Multimeter
from .electrometer import Electrometer
from .function_generator import FunctionGenerator
from .oscilloscope import (
OscilloscopeChannel,
OscilloscopeDataSource,
Oscilloscope,
)
from .power_supply import (
PowerSupplyChannel,
PowerSupply,
)

from .optical_spectrum_analyzer import (
OSAChannel,
OpticalSpectrumAnalyzer,
)
from .multimeter import Multimeter
from .oscilloscope import Oscilloscope
from .optical_spectrum_analyzer import OpticalSpectrumAnalyzer
from .power_supply import PowerSupply
68 changes: 33 additions & 35 deletions instruments/abstract_instruments/optical_spectrum_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,50 @@
# CLASSES #####################################################################


class OSAChannel(metaclass=abc.ABCMeta):
class OpticalSpectrumAnalyzer(Instrument, metaclass=abc.ABCMeta):

"""
Abstract base class for physical channels on an optical spectrum analyzer.
Abstract base class for optical spectrum analyzer instruments.
All applicable concrete instruments should inherit from this ABC to
provide a consistent interface to the user.
"""

# METHODS #

@abc.abstractmethod
def wavelength(self, bin_format=True):
class Channel(metaclass=abc.ABCMeta):
"""
Gets the x-axis of the specified data source channel. This is an
abstract property.
Abstract base class for physical channels on an optical spectrum analyzer.
:param bool bin_format: If the waveform should be transfered in binary
(``True``) or ASCII (``False``) formats.
:return: The wavelength component of the waveform.
:rtype: `numpy.ndarray`
All applicable concrete instruments should inherit from this ABC to
provide a consistent interface to the user.
"""
raise NotImplementedError

@abc.abstractmethod
def data(self, bin_format=True):
"""
Gets the y-axis of the specified data source channel. This is an
abstract property.
:param bool bin_format: If the waveform should be transfered in binary
(``True``) or ASCII (``False``) formats.
:return: The y-component of the waveform.
:rtype: `numpy.ndarray`
"""
raise NotImplementedError


class OpticalSpectrumAnalyzer(Instrument, metaclass=abc.ABCMeta):

"""
Abstract base class for optical spectrum analyzer instruments.
All applicable concrete instruments should inherit from this ABC to
provide a consistent interface to the user.
"""
# METHODS #

@abc.abstractmethod
def wavelength(self, bin_format=True):
"""
Gets the x-axis of the specified data source channel. This is an
abstract property.
:param bool bin_format: If the waveform should be transfered in binary
(``True``) or ASCII (``False``) formats.
:return: The wavelength component of the waveform.
:rtype: `numpy.ndarray`
"""
raise NotImplementedError

@abc.abstractmethod
def data(self, bin_format=True):
"""
Gets the y-axis of the specified data source channel. This is an
abstract property.
:param bool bin_format: If the waveform should be transfered in binary
(``True``) or ASCII (``False``) formats.
:return: The y-component of the waveform.
:rtype: `numpy.ndarray`
"""
raise NotImplementedError

# PROPERTIES #

Expand Down
155 changes: 76 additions & 79 deletions instruments/abstract_instruments/oscilloscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,106 +13,103 @@
# CLASSES #####################################################################


class OscilloscopeDataSource(metaclass=abc.ABCMeta):
class Oscilloscope(Instrument, metaclass=abc.ABCMeta):

"""
Abstract base class for data sources (physical channels, math, ref) on
an oscilloscope.
Abstract base class for oscilloscope instruments.
All applicable concrete instruments should inherit from this ABC to
provide a consistent interface to the user.
"""

def __init__(self, parent, name):
self._parent = parent
self._name = name
self._old_dsrc = None

def __enter__(self):
self._old_dsrc = self._parent.data_source
if self._old_dsrc != self:
# Set the new data source, and let __exit__ cleanup.
self._parent.data_source = self
else:
# There's nothing to do or undo in this case.
self._old_dsrc = None

def __exit__(self, type, value, traceback):
if self._old_dsrc is not None:
self._parent.data_source = self._old_dsrc

def __eq__(self, other):
if not isinstance(other, type(self)):
return NotImplemented

return other.name == self.name

__hash__ = None

# PROPERTIES #

@property
@abc.abstractmethod
def name(self):
class Channel(metaclass=abc.ABCMeta):
"""
Gets the name of the channel. This is an abstract property.
Abstract base class for physical channels on an oscilloscope.
:type: `str`
All applicable concrete instruments should inherit from this ABC to
provide a consistent interface to the user.
"""
raise NotImplementedError

# METHODS #

@abc.abstractmethod
def read_waveform(self, bin_format=True):
"""
Gets the waveform of the specified data source channel. This is an
abstract property.
# PROPERTIES #

:param bool bin_format: If the waveform should be transfered in binary
(``True``) or ASCII (``False``) formats.
:return: The waveform with both x and y components.
:rtype: `numpy.ndarray`
"""
raise NotImplementedError
@property
@abc.abstractmethod
def coupling(self):
"""
Gets/sets the coupling setting for the oscilloscope. This is an
abstract method.
:type: `~enum.Enum`
"""
raise NotImplementedError

class OscilloscopeChannel(metaclass=abc.ABCMeta):
@coupling.setter
@abc.abstractmethod
def coupling(self, newval):
raise NotImplementedError

"""
Abstract base class for physical channels on an oscilloscope.
class DataSource(metaclass=abc.ABCMeta):

All applicable concrete instruments should inherit from this ABC to
provide a consistent interface to the user.
"""

# PROPERTIES #

@property
@abc.abstractmethod
def coupling(self):
"""
Gets/sets the coupling setting for the oscilloscope. This is an
abstract method.
Abstract base class for data sources (physical channels, math, ref) on
an oscilloscope.
:type: `~enum.Enum`
All applicable concrete instruments should inherit from this ABC to
provide a consistent interface to the user.
"""
raise NotImplementedError

@coupling.setter
@abc.abstractmethod
def coupling(self, newval):
raise NotImplementedError


class Oscilloscope(Instrument, metaclass=abc.ABCMeta):

"""
Abstract base class for oscilloscope instruments.
def __init__(self, parent, name):
self._parent = parent
self._name = name
self._old_dsrc = None

All applicable concrete instruments should inherit from this ABC to
provide a consistent interface to the user.
"""
def __enter__(self):
self._old_dsrc = self._parent.data_source
if self._old_dsrc != self:
# Set the new data source, and let __exit__ cleanup.
self._parent.data_source = self
else:
# There's nothing to do or undo in this case.
self._old_dsrc = None

def __exit__(self, type, value, traceback):
if self._old_dsrc is not None:
self._parent.data_source = self._old_dsrc

def __eq__(self, other):
if not isinstance(other, type(self)):
return NotImplemented

return other.name == self.name

__hash__ = None

# PROPERTIES #

@property
@abc.abstractmethod
def name(self):
"""
Gets the name of the channel. This is an abstract property.
:type: `str`
"""
raise NotImplementedError

# METHODS #

@abc.abstractmethod
def read_waveform(self, bin_format=True):
"""
Gets the waveform of the specified data source channel. This is an
abstract property.
:param bool bin_format: If the waveform should be transfered in binary
(``True``) or ASCII (``False``) formats.
:return: The waveform with both x and y components.
:rtype: `numpy.ndarray`
"""
raise NotImplementedError

# PROPERTIES #

Expand Down
Loading

0 comments on commit aa51148

Please sign in to comment.