@@ -460,9 +460,9 @@ def _str_units_to_float(str_units: str) -> float:
460460 "m" : 1e6 ,
461461 }
462462 match = re .match (r"([\d\.]+)\s*([a-zA-Z]+)" , str_units )
463- numeric_value = float (match .group (1 ) if match else 1.55 )
464- unit = match .group (2 ) if match else "um"
465- return float (numeric_value * unit_conversions [unit ])
463+ numeric_value = float (match .group (1 )) if match else None
464+ unit = match .group (2 ) if match else None
465+ return float (numeric_value * unit_conversions [unit ]) if unit in unit_conversions and numeric_value is not None else None
466466
467467
468468def get_wavelengths_to_plot (statements : StatementDictionary , num_samples : int = 100 ) -> Tuple [List [float ], List [float ]]:
@@ -484,16 +484,16 @@ def update_wavelengths(mapping: Dict[str, Optional[Computation]], min_wl: float,
484484 vlines = vlines | {
485485 _str_units_to_float (wl )
486486 for wl in (comp .arguments ["wavelengths" ] if isinstance (comp .arguments ["wavelengths" ], list ) else [])
487- if isinstance (wl , str )
487+ if isinstance (wl , str ) and _str_units_to_float ( wl ) is not None
488488 }
489489 if "wavelength_range" in comp .arguments :
490490 if (
491491 isinstance (comp .arguments ["wavelength_range" ], list )
492492 and len (comp .arguments ["wavelength_range" ]) == 2
493493 and all (isinstance (wl , str ) for wl in comp .arguments ["wavelength_range" ])
494494 ):
495- min_wl = min (min_wl , _str_units_to_float (comp .arguments ["wavelength_range" ][0 ]))
496- max_wl = max (max_wl , _str_units_to_float (comp .arguments ["wavelength_range" ][1 ]))
495+ min_wl = min (min_wl , _str_units_to_float (comp .arguments ["wavelength_range" ][0 ])) if _str_units_to_float ( comp . arguments [ "wavelength_range" ][ 0 ]) is not None else min_wl
496+ max_wl = max (max_wl , _str_units_to_float (comp .arguments ["wavelength_range" ][1 ])) if _str_units_to_float ( comp . arguments [ "wavelength_range" ][ 1 ]) is not None else max_wl
497497 return min_wl , max_wl , vlines
498498
499499 for cost_stmt in statements .cost_functions or []:
@@ -508,8 +508,8 @@ def update_wavelengths(mapping: Dict[str, Optional[Computation]], min_wl: float,
508508 min_wl = min (min_wl , min (vlines ))
509509 max_wl = max (max_wl , max (vlines ))
510510 if min_wl >= max_wl :
511- avg_wl = sum (vlines ) / len (vlines ) if vlines else 1550
512- min_wl , max_wl = avg_wl - 10 , avg_wl + 10
511+ avg_wl = sum (vlines ) / len (vlines ) if vlines else 1.55
512+ min_wl , max_wl = avg_wl - 0.01 , avg_wl + 0.01
513513 else :
514514 range_size = max_wl - min_wl
515515 min_wl -= 0.2 * range_size
0 commit comments