@@ -144,6 +144,14 @@ def _generate_parameter_table_rst(df) -> str:
144
144
return tabulate (df .values , df .columns , tablefmt = "rst" )
145
145
146
146
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
+
147
155
def bidirectional_coupler (
148
156
wl : Union [float , ArrayLike ] = 1.55 ,
149
157
thickness : float = 220 ,
@@ -223,15 +231,25 @@ def directional_coupler(
223
231
gap coupling_length
224
232
===== =================
225
233
200 0
234
+ 200 2.5
226
235
200 5
236
+ 200 7.5
227
237
200 10
238
+ 200 12.5
228
239
200 15
240
+ 200 17.5
229
241
200 20
242
+ 200 22.5
230
243
200 25
244
+ 200 27.5
231
245
200 30
246
+ 200 32.5
232
247
200 35
248
+ 200 37.5
233
249
200 40
250
+ 200 42.5
234
251
200 45
252
+ 200 47.5
235
253
===== =================
236
254
"""
237
255
# df = self._generate_parameter_sets()
@@ -240,7 +258,7 @@ def directional_coupler(
240
258
# "Invalid parameter set, see the documentation for valid parameter sets"
241
259
# )
242
260
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"
244
262
245
263
file = _resolve_source_filepath (_datafile )
246
264
header , data = load_sparams (file )
@@ -727,7 +745,7 @@ def grating_coupler(
727
745
pol = pol .upper ()
728
746
729
747
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 " )
731
749
thickness = str (int (thickness ))
732
750
733
751
if dwidth not in [- 20.0 , 0.0 , 20.0 ]:
0 commit comments