Skip to content

Commit 6740dac

Browse files
authored
Merge pull request #30 from Axiomatic-AI/hotfix-admit-comma-separated-keys
Hotfix admit comma separated keys
2 parents d2ca775 + bb08618 commit 6740dac

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/axiomatic/pic_helpers.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def plot_single_spectrum(
9898

9999

100100
def plot_interactive_spectra(
101-
spectra: Union[List[List[List[float]]], Dict[Tuple[str, str], List[List[float]]]],
101+
spectra: Union[List[List[List[float]]], Dict[Union[Tuple[str, str], str], List[List[float]]]],
102102
wavelengths: List[float],
103103
spectrum_labels: Optional[List[str]] = None,
104104
vlines: Optional[List[float]] = None,
@@ -108,7 +108,7 @@ def plot_interactive_spectra(
108108
Creates an interactive plot of spectra with a slider to select different indices.
109109
Parameters:
110110
-----------
111-
spectra : list of list of float
111+
spectra : list of list of float or a dictionary with tuple or string keys
112112
A list of spectra, where each spectrum is a list of lists of float values, each
113113
corresponding to the transmission of a single wavelength.
114114
wavelengths : list of float
@@ -118,10 +118,23 @@ def plot_interactive_spectra(
118118
hlines : list of float, optional
119119
A list of y-values where horizontal lines should be drawn. Defaults to an empty list.
120120
"""
121+
if isinstance(spectra, dict):
122+
port_keys = []
123+
for key in spectra:
124+
if isinstance(key, str):
125+
ports = key.split(",")
126+
if len(ports) != 2:
127+
raise ValueError("Port keys must be in the format 'port_in,port_out' with exactly one comma.")
128+
port_keys.append((key.split(",")[0], key.split(",")[1]))
129+
elif isinstance(key, tuple):
130+
port_keys.append(key)
131+
else:
132+
raise ValueError("Port keys must be either a string or a tuple.")
121133

122134
# Defaults
123135
if spectrum_labels is None and isinstance(spectra, dict):
124-
spectrum_labels = [f"T {port_in} -> {port_out}" for port_in, port_out in spectra.keys()]
136+
spectrum_labels = [f"T {port_in} -> {port_out}" for port_in, port_out in port_keys]
137+
125138
elif spectrum_labels is None:
126139
spectrum_labels = [f"Spectrum {i}" for i in range(len(spectra))]
127140
if vlines is None:

0 commit comments

Comments
 (0)