|
11 | 11 | Use option --save_animation to save the animation (no slider) to a movie file |
12 | 12 |
|
13 | 13 | Example: |
14 | | -$ python prof3d.py --with-slider |
| 14 | +$ python prof3d.py --with_slider |
15 | 15 | """ |
16 | 16 |
|
17 | 17 | import sys |
| 18 | +import csv |
18 | 19 | import pandas as pd |
19 | 20 | import matplotlib.pyplot as plt |
20 | 21 | import numpy as np |
|
24 | 25 | import argparse |
25 | 26 |
|
26 | 27 | parser = argparse.ArgumentParser() |
27 | | -parser.add_argument('--with-slider', action='store_true', help='Control animation with a time slider') |
28 | | -parser.add_argument('--save-animation', action='store_true', help='Save animation') |
| 28 | +parser.add_argument('--with_slider', action='store_true', help='Control animation with a time slider') |
| 29 | +parser.add_argument('--save_animation', action='store_true', help='Save animation') |
29 | 30 |
|
30 | 31 | args = parser.parse_args() |
31 | 32 |
|
|
39 | 40 | # Close all previously opened figures |
40 | 41 | plt.close('all') |
41 | 42 |
|
42 | | -tmpa = 20. |
43 | | -scalar_min = 20. |
44 | | -scalar_max = 360. |
| 43 | +scalar_min = 0. |
| 44 | +scalar_max = 120. |
45 | 45 |
|
46 | | -filenames = ['./my_prof_1.csv', |
47 | | - './my_prof_2.csv', |
48 | | - './my_prof_3.csv] |
| 46 | +filenames = ['../Current_Results/pine_21O2_40_1C_cat_prof_4.csv'] |
49 | 47 |
|
50 | 48 | # create lists to store information about each profile |
51 | 49 | IOR = [] |
52 | 50 | X = [] |
53 | 51 | Y = [] |
54 | 52 | Z = [] |
55 | | -df = [] |
| 53 | +df = {} |
56 | 54 |
|
57 | | -for i in range(len(filenames)): |
| 55 | +for i, filename in enumerate(filenames): |
| 56 | + |
| 57 | + data = [] |
| 58 | + max_cols = 0 |
58 | 59 |
|
59 | 60 | # read header information |
60 | 61 |
|
61 | | - with open(filenames[i]) as f: |
| 62 | + with open(filename,'r') as f: |
62 | 63 | # Skip the first 1 lines |
63 | 64 | for j in range(1): |
64 | 65 | next(f) |
65 | 66 | first_line = f.readline().strip('\n') |
66 | 67 |
|
67 | | - header=first_line.split(",")[1:5] |
68 | | - IOR.append(int(header[0])) #; print(IOR) |
69 | | - X.append(float(header[1])) #; print(X) |
70 | | - Y.append(float(header[2])) #; print(Y) |
71 | | - Z.append(float(header[3])) #; print(Z) |
72 | | - |
73 | | - # sys.exit() |
74 | | - |
75 | | - df.append(pd.read_csv(filenames[i],skiprows=3,header=None)) |
76 | | - df[i].fillna(tmpa, inplace=True) |
| 68 | + header=first_line.split(",")[1:5] |
| 69 | + IOR.append(int(header[0])) ; print(IOR) |
| 70 | + X.append(float(header[1])) ; print(X) |
| 71 | + Y.append(float(header[2])) ; print(Y) |
| 72 | + Z.append(float(header[3])) ; print(Z) |
| 73 | + next(f) |
| 74 | + |
| 75 | + # Read lines one at a time |
| 76 | + while True: |
| 77 | + line = f.readline() |
| 78 | + if not line: # End of file |
| 79 | + break |
| 80 | + row = line.strip().split(',') # Adjust delimiter if needed |
| 81 | + |
| 82 | + # Convert each element to float, handling errors gracefully |
| 83 | + try: |
| 84 | + row = [float(value) if value else None for value in row] |
| 85 | + except ValueError: |
| 86 | + # If a value cannot be converted, keep it as None |
| 87 | + row = [float(value) if value.replace('.', '', 1).isdigit() else None for value in row] |
| 88 | + |
| 89 | + data.append(row) |
| 90 | + max_cols = max(max_cols, len(row)) # Track the maximum number of columns |
| 91 | + |
| 92 | + # Normalize rows to have the same number of columns |
| 93 | + data = [row + [None] * (max_cols - len(row)) for row in data] |
| 94 | + |
| 95 | + # Convert to a Pandas DataFrame |
| 96 | + df[i] = pd.DataFrame(data) |
77 | 97 |
|
78 | 98 | # sys.exit() |
79 | 99 |
|
|
0 commit comments