@@ -112,12 +112,17 @@ def plot_interactive_spectra(
112
112
A list of spectra, where each spectrum is a list of lists of float values, each
113
113
corresponding to the transmission of a single wavelength.
114
114
wavelengths : list of float
115
- A list of wavelength values corresponding to the x-axis of the plot, in nm .
115
+ A list of wavelength values corresponding to the x-axis of the plot, in um .
116
116
vlines : list of float, optional
117
- A list of x-values where vertical lines should be drawn, in nm . Defaults to an empty list.
117
+ A list of x-values where vertical lines should be drawn, in um . Defaults to an empty list.
118
118
hlines : list of float, optional
119
119
A list of y-values where horizontal lines should be drawn. Defaults to an empty list.
120
120
"""
121
+
122
+ # Convert wavelengths to nm
123
+ wavelengths = [wl * 1e3 for wl in wavelengths ]
124
+ vlines = [wl * 1e3 for wl in vlines ]
125
+
121
126
if isinstance (spectra , dict ):
122
127
port_keys = []
123
128
for key in spectra :
@@ -460,23 +465,25 @@ def print_statements(
460
465
461
466
462
467
def _str_units_to_float (str_units : str ) -> Optional [float ]:
468
+ """Returns the numeric value of a string with units in micrometers, e.g. '1550 nm' -> 1.55"""
469
+ """Return None if the string is not a valid unit."""
463
470
unit_conversions = {
464
- "nm" : 1 ,
465
- "um" : 1e3 ,
466
- "mm" : 1e6 ,
467
- "m" : 1e9 ,
471
+ "nm" : 1e-3 ,
472
+ "um" : 1 ,
473
+ "mm" : 1e3 ,
474
+ "m" : 1e6 ,
468
475
}
469
476
match = re .match (r"([\d\.]+)\s*([a-zA-Z]+)" , str_units )
470
477
numeric_value = float (match .group (1 )) if match else None
471
478
unit = match .group (2 ) if match else None
472
479
return float (numeric_value * unit_conversions [unit ]) if unit in unit_conversions and numeric_value is not None else None
473
480
474
481
475
- def get_wavelengths_to_plot (statements : StatementDictionary , num_samples : int = 100 ) -> Tuple [List [float ], List [float ]]:
482
+ def get_wavelengths_to_plot (statements : StatementDictionary , num_samples : int = 1000 ) -> Tuple [List [float ], List [float ]]:
476
483
"""
477
484
Get the wavelengths to plot based on the statements.
478
485
479
- Returns a list of wavelengths to plot the spectra and a list of vertical lines to plot on top the spectra, in nm .
486
+ Returns a list of wavelengths to plot the spectra and a list of vertical lines to plot on top the spectra, in um .
480
487
"""
481
488
482
489
min_wl = float ("inf" )
0 commit comments