Seems to work

This commit is contained in:
Kumi 2023-05-01 13:49:53 +00:00
commit 98abae7376
Signed by: kumi
GPG key ID: ECBCC9082395383F
3 changed files with 42 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*-looped.txt

1
ecg-test.txt Normal file
View file

@ -0,0 +1 @@
(0 0 10m 0.00001023 20m 0.000019995 30m 0.00003627 40m 0.0000744 50m 0.000093 60m 0.0001116 70m 0.0001209 80m 0.0001023 90m 0.0000744 100m 0.0000372 110m 0 120m -0.0000186 130m -0.0000279 140m -0.0000279 150m -0.0000372 160m -0.0000465 170m -0.0000558 180m -0.0000651 190m -0.0000744 200m -0.0000837 210m -0.000093 220m -0.0001116 230m -0.0001302 240m -0.0001488 250m -0.0001767 260m -0.0002232 270m -0.0002604 280m -0.000279 290m -0.0002511 300m -0.000093 310m 0.000465 320m 0.00186 330m 0.002046 340m 0.0016275 350m 0 360m -0.000186 370m -0.000372 380m -0.0004185 390m -0.0003255 400m -0.000186 410m -0.0001395 420m -0.000093 430m -0.0000465 440m -0.0000186 450m -0.0000093 460m 0 470m 0 480m 0 490m 0 500m 0 510m 0 520m 0 530m 0 540m 0 550m 0 560m 0 570m 0 580m 0 590m 0 600m 0.000009207 610m 0.0000186 620m 0.0000372 630m 0.0000465 640m 0.0000651 650m 0.0000837 660m 0.0001023 670m 0.0001209 680m 0.0001488 690m 0.0001953 700m 0.0002325 710m 0.0002511 720m 0.0002604 730m 0.0002418 740m 0.000186 750m 0.0001395 760m 0.000093 770m 0.0000558 780m 0.0000279 790m 0.0000186 800m 0.0000093 810m 0.0000093 820m 0 830m 0 840m 0 850m 0 860m 0 870m 0 880m 0 890m 0 900m 0 910m 0 920m 0 930m 0 940m 0 950m 0 960m 0 970m 0 980m 0 990m 0 1000m 0 )

40
pwl-multiplier.py Executable file
View file

@ -0,0 +1,40 @@
#!/usr/bin/env python3
from pathlib import Path
from argparse import ArgumentParser
parser = ArgumentParser(description='Loop an LTspice PWL file a given number of times.')
parser.add_argument('pwl_file', type=Path, help='Path to PWL file')
parser.add_argument('num_loops', type=int, help='Number of times to loop the PWL file')
parser.add_argument('--output', "-o", type=Path, help='Path to output file', default=None)
args = parser.parse_args()
output_file = args.output if args.output else args.pwl_file.parent / (args.pwl_file.stem + '-looped' + args.pwl_file.suffix)
with open(args.pwl_file, 'r') as f:
input_data = f.readline().lstrip("(").rstrip(")").strip()
input_data = input_data.split()
time_value_pairs = []
for i in range(0, len(input_data), 2):
time = input_data[i]
if not time.endswith('m'):
if time.isnumeric():
time = f"{int(time) * 1000}m"
value = float(input_data[i+1])
time_value_pairs.append((time, value))
for i in range(args.num_loops - 1):
last_time = float(time_value_pairs[-1][0][:-1])
for time, value in time_value_pairs[:len(input_data) // 2]:
new_time = last_time + float(time[:-1])
time_value_pairs.append((f"{int(new_time) if new_time.is_integer() else new_time}m", value))
with open(output_file, 'w') as f:
content = " ".join([f"{time} {int(value) if value.is_integer() else format(value, '.15f').rstrip('0').rstrip('.')}" for time, value in time_value_pairs])
f.write(f"({content})")