-
Notifications
You must be signed in to change notification settings - Fork 0
/
format_cpl_jlc.py
41 lines (31 loc) · 1.73 KB
/
format_cpl_jlc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import pandas as pd
import argparse
def transform_to_cpl_format(csv_filepath, output_filepath):
# Load data from the CSV file
csv_data = pd.read_csv(csv_filepath)
# Convert negative rotation angles to positive by taking modulo 360
csv_data['Rot'] = csv_data['Rot'].apply(lambda x: 360 + x if x < 0 else x)
# Convert PosX and PosY to strings with "mm" appended, matching the CPL format
# csv_data['Mid X'] = csv_data['PosX'].apply(lambda x: f"{x:.4f}mm")
# csv_data['Mid Y'] = csv_data['PosY'].apply(lambda x: f"{x:.4f}mm")
csv_data['Mid X'] = csv_data['PosX'].apply(lambda x: f"{x}")
csv_data['Mid Y'] = csv_data['PosY'].apply(lambda x: f"{x}")
# Map Side to Layer (assuming 'top' -> 'Top' and 'bottom' -> 'Bottom')
# csv_data['Layer'] = csv_data['Side'].map({'top': 'Top', 'bottom': 'Bottom'})
csv_data['Layer'] = csv_data['Side'] # may not require reconfiguration
# Rename columns to match CPL format
csv_data.rename(columns={
'Ref': 'Designator',
'Rot': 'Rotation'
}, inplace=True)
# Select and order columns to match the CPL format
transformed_data = csv_data[['Designator', 'Mid X', 'Mid Y', 'Layer', 'Rotation']]
# Save the transformed data to a new CSV file
transformed_data.to_csv(output_filepath, index=False)
print(f"Transformed CPL data saved to {output_filepath}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Transform CSV data to CPL format.")
parser.add_argument("input_file", help="Path to the input CSV file")
parser.add_argument("output_file", help="Path to the output CSV file")
args = parser.parse_args()
transform_to_cpl_format(args.input_file, args.output_file)