From 4a98183253e29a66be4def63a381e084b36a5c7e Mon Sep 17 00:00:00 2001 From: jaseg Date: Sat, 12 May 2018 12:43:39 +0200 Subject: Initial commit --- csv_to_svg_path.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 csv_to_svg_path.py (limited to 'csv_to_svg_path.py') diff --git a/csv_to_svg_path.py b/csv_to_svg_path.py new file mode 100755 index 0000000..5f638ed --- /dev/null +++ b/csv_to_svg_path.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +import textwrap + +def svg_path_from_points(points, r): + points_joined = ' '.join(f'{x:.6f} {y:.6f}' for x, y in points) + return textwrap.dedent(f''' + + + + + + + ''').strip() + +if __name__ == '__main__': + import argparse + parser = argparse.ArgumentParser() + parser.add_argument('locus_csv', help='CSV file containing locus coordinates. Format: lambda, x, y, z.') + parser.add_argument('-r', '--radius', type=float, default=100, help='Radius of plot area in mm') + args = parser.parse_args() + + import csv, ast + points = [] + with open(args.locus_csv, newline='') as f: + for row in csv.reader(f): + # use literal_eval to handle entries like "1.153E-5" + λ, x, y, z = (ast.literal_eval(e.strip()) for e in row) + points.append((x*args.radius*2, y*args.radius*2)) + + print(svg_path_from_points(points, args.radius)) -- cgit