def write_component( component: Component, gdspath: Optional[PosixPath] = None, path_library: PosixPath = CONFIG["gds_directory"], precision: float = 1e-9, settings: None = None, with_settings_label: bool = conf.tech.with_settings_label, ) -> str: """write component GDS and metadata: - gds - ports - properties Args: component: gdspath: path_library precision: to save GDS points settings: dict of settings """ gdspath = gdspath or path_library / (component.name + ".gds") gdspath = pathlib.Path(gdspath) ports_path = gdspath.with_suffix(".ports") json_path = gdspath.with_suffix(".json") """ write GDS """ gdspath = write_gds( component=component, gdspath=str(gdspath), precision=precision, with_settings_label=with_settings_label, ) """ write .ports in CSV""" if len(component.ports) > 0: with open(ports_path, "w") as fw: for _, port in component.ports.items(): layer, texttype = pd._parse_layer(port.layer) fw.write("{}, {:.3f}, {:.3f}, {}, {:.3f}, {}, {}\n".format( port.name, port.x, port.y, int(port.orientation), port.width, layer, texttype, )) """ write JSON """ with open(json_path, "w+") as fw: fw.write(json.dumps(component.get_json(), indent=2)) return gdspath
def write_component( component: Component, gdspath: Optional[PosixPath] = None, gdsdir: PosixPath = tmp, precision: float = 1e-9, ) -> PosixPath: """write component GDS and metadata: - gds - ports - properties Args: component: gdspath: path_library precision: to save GDS points """ gdspath = gdspath or gdsdir / (component.name + ".gds") gdspath = pathlib.Path(gdspath) ports_path = gdspath.with_suffix(".ports") json_path = gdspath.with_suffix(".json") gdspath = write_gds( component=component, gdspath=str(gdspath), precision=precision, ) # component.ports CSV if len(component.ports) > 0: with open(ports_path, "w") as fw: for port in component.ports.values(): layer, purpose = pd._parse_layer(port.layer) fw.write( f"{port.name}, {port.x:.3f}, {port.y:.3f}, {int(port.orientation)}, {port.width:.3f}, {layer}, {purpose}\n" ) # component.json metadata dict with open(json_path, "w+") as fw: fw.write(json.dumps(component.get_json(), indent=2)) return gdspath
def write_component_report(component: Component, json_path=None) -> PosixPath: """write component GDS and metadata: Args: component: json_path """ json_path = json_path or CONFIG["gds_directory"] / f"{component.name}.json" ports_path = json_path.with_suffix(".ports") if len(component.ports) > 0: with open(ports_path, "w") as fw: for port in component.ports.values(): fw.write( f"{port.name}, {port.x:.3f}, {port.y:.3f}, {int(port.orientation)}, {port.width:.3f}, {port.layer}\n" ) with open(json_path, "w+") as fw: fw.write(json.dumps(component.get_json(), indent=2)) return json_path