Skip to content

Commit 2195721

Browse files
committed
Fix some file name parameter formatting errors
1 parent b4cf901 commit 2195721

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

simphony/libraries/siepic/models.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ def _generate_parameter_table_rst(df) -> str:
144144
return tabulate(df.values, df.columns, tablefmt="rst")
145145

146146

147+
def _stringify_float(val: float, max_precision: int = 1) -> str:
148+
"""Convert a float to a string, with a maximum precision."""
149+
if val == int(val):
150+
return str(int(val))
151+
else:
152+
return f"{val:.{max_precision}f}"
153+
154+
147155
def bidirectional_coupler(
148156
wl: Union[float, ArrayLike] = 1.55,
149157
thickness: float = 220,
@@ -223,15 +231,25 @@ def directional_coupler(
223231
gap coupling_length
224232
===== =================
225233
200 0
234+
200 2.5
226235
200 5
236+
200 7.5
227237
200 10
238+
200 12.5
228239
200 15
240+
200 17.5
229241
200 20
242+
200 22.5
230243
200 25
244+
200 27.5
231245
200 30
246+
200 32.5
232247
200 35
248+
200 37.5
233249
200 40
250+
200 42.5
234251
200 45
252+
200 47.5
235253
===== =================
236254
"""
237255
# df = self._generate_parameter_sets()
@@ -240,7 +258,7 @@ def directional_coupler(
240258
# "Invalid parameter set, see the documentation for valid parameter sets"
241259
# )
242260

243-
_datafile = f"ebeam_dc_te1550/dc_gap={int(gap)}nm_Lc={coupling_length}um.sparam"
261+
_datafile = f"ebeam_dc_te1550/dc_gap={int(gap)}nm_Lc={_stringify_float(coupling_length)}um.sparam"
244262

245263
file = _resolve_source_filepath(_datafile)
246264
header, data = load_sparams(file)
@@ -727,7 +745,7 @@ def grating_coupler(
727745
pol = pol.upper()
728746

729747
if thickness not in [210.0, 220.0, 230.0]:
730-
raise ValueError("'thickness' must be one of 210.0, 220.0, or 230")
748+
raise ValueError("'thickness' must be one of 210.0, 220.0, or 230.0")
731749
thickness = str(int(thickness))
732750

733751
if dwidth not in [-20.0, 0.0, 20.0]:

0 commit comments

Comments
 (0)