ChannelMap#
- class ChannelMap(
- channels: dict[str,
- str | None]=<factory>,
- include_unmapped: bool = False,
- instrument: str | None = None,
Bases:
objectWhich pymeasure properties publish, and under which channel names.
Generate one from an instrument, save it, edit the
channelof each entry (or set it tonullto stop publishing that property), and pass the file or object toPymeasureInstrumentorattach.A command channel is the mapped name plus
.cmd; a measurement channel is the mapped name. Both sit under the instrument name:<instrument name>.<mapped name>[.cmd].- Variables:
channels (dict[str, str | None]) – Attribute path (
"ch_1.voltage_setpoint") to channel name ("ch1.vset"), orNoneto leave that property unpublished.include_unmapped (bool) – Publish properties missing from
channelsunder their default names.instrument (str | None) –
module.Classof the instrument the map was generated from; informational.
- classmethod defaults() ChannelMap[source]#
Return the map used when none is given: every property under its default name.
- classmethod generate(
- target: CommonBase | type[CommonBase],
Build a map listing every publishable property of
targetunder its default name.- Parameters:
target
A pymeasure instrument instance (preferred: it sees channels added in
__init__) or class.- Returns:
A
ChannelMapwith one entry per property andinclude_unmapped=False.
- classmethod from_dict( ) ChannelMap[source]#
Parse the JSON-compatible form written by
to_dict.Each
channelsvalue may be a channel-name string,null, or an object whosechannelkey holds either; itskind/get/set/dockeys are informational.- Raises:
ValueError – The format tag is unknown or an entry is malformed.
- classmethod load( ) ChannelMap[source]#
Read a map from a JSON file written by
save(or theinstro pymeasure mapcommand).
- to_dict(
- specs: list[ChannelSpec] | None = None,
Return the JSON-compatible form.
- Parameters:
specs
Inspection results for the instrument. When given, each entry also records the property’s kind, SCPI commands, and docstring to make the file easier to edit.
- save( ) None[source]#
Write the map as JSON.
- Parameters:
path
Destination file.
target
Instrument the map belongs to; when given, entries carry each property’s kind, SCPI commands, and docstring.
- rename( ) ChannelMap[source]#
Set the channel name of each attribute path in
names(Nonestops publishing it).Example:
channel_map.rename({"ch_1.voltage_setpoint": "out1.v_set", "ch_1.current": "out1.i"})- Returns:
This map, so calls can be chained.
- Raises:
KeyError – A path is not in the map.
- exclude(
- *patterns: str,
Stop publishing every attribute path that matches one of the glob
patterns.Example:
channel_map.exclude("ch_2.*", "ch_3.*")- Returns:
This map, so calls can be chained.
- Raises:
KeyError – A pattern matches no path, which is usually a typo.
- select(
- *patterns: str,
Stop publishing every attribute path that matches none of the glob
patterns.Example:
channel_map.select("ch_1.*") # publish output 1 only- Returns:
This map, so calls can be chained.
- Raises:
KeyError – A pattern matches no path, which is usually a typo.
- preview( ) list[dict[str, str | None]][source]#
Show exactly which channels each property publishes, separately for commands and measurements.
Writing a property publishes a
Commandon thecommandchannel; reading it publishes aMeasurementon themeasurementchannel. A control has both, a measurement only the second, a setting only the first.Example:
import pandas as pd pd.DataFrame(channel_map.preview(supply, "psu"))
- Parameters:
target
The instrument (instance or class) the map is for.
name
Instrument name to prefix, as passed to
attachorPymeasureInstrument.
- Returns:
One row per property with keys
property,kind,command, andmeasurement; a channel isNonewhen the property doesn’t publish in that direction.- Raises:
ValueError – The map does not fit
target(seeresolve).
- resolve(
- specs: list[ChannelSpec],
Return attribute path to channel name for every property that publishes.
- Parameters:
specs
Inspection results for the instrument the map is applied to.
- Raises:
ValueError – The map names a path the instrument does not have (a typo, or a pymeasure upgrade renamed it), a channel name is invalid or ends in
.cmd, or two properties map to the same channel name.