antmicro / gerber2ems

Apache License 2.0
76 stars 9 forks source link

touchstone Export, feature request (code inside) #3

Open oe2lsp opened 9 months ago

oe2lsp commented 9 months ago

Hi, one last comment from my side, added touchstone export to postprocess.py/ function save_to_file so that postprocessing in other engineering programs is easier

        net = skrf.Network(frequency=self.frequencies, s=self.s_params.transpose(2, 0, 1))
        file_path = 'export.sXp'
        touchstone_path = os.path.join(RESULTS_DIR,file_path) 
        logger.debug("Saving touchstone file %s ", touchstone_path)
        net.write_touchstone(filename=touchstone_path, write_z0=False, skrf_comment=True)

        with open(touchstone_path, 'r') as touchstone_file:
            touchstone_data = touchstone_file.read()
        #replace as some touchstone readers are picky
        touchstone_data = touchstone_data.replace(' 0 ', ' 0.0 ')
        touchstone_data = touchstone_data.replace('nan', '0.0')
        with open(touchstone_path, 'w') as touchstone_file:
            touchstone_file.write(touchstone_data)

if required I could file a pull request

dan-gies commented 9 months ago

@oe2lsp if you wouldn't mind forking the repo and adding this code in, it would make it way easier for others (like me!) to pull it in to our own forks 😄