Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 42 additions & 22 deletions Utilities/Python/scripts/prof3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
Use option --save_animation to save the animation (no slider) to a movie file

Example:
$ python prof3d.py --with-slider
$ python prof3d.py --with_slider
"""

import sys
import csv
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -24,8 +25,8 @@
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('--with-slider', action='store_true', help='Control animation with a time slider')
parser.add_argument('--save-animation', action='store_true', help='Save animation')
parser.add_argument('--with_slider', action='store_true', help='Control animation with a time slider')
parser.add_argument('--save_animation', action='store_true', help='Save animation')

args = parser.parse_args()

Expand All @@ -39,41 +40,60 @@
# Close all previously opened figures
plt.close('all')

tmpa = 20.
scalar_min = 20.
scalar_max = 360.
scalar_min = 0.
scalar_max = 120.

filenames = ['./my_prof_1.csv',
'./my_prof_2.csv',
'./my_prof_3.csv]
filenames = ['../Current_Results/pine_21O2_40_1C_cat_prof_4.csv']

# create lists to store information about each profile
IOR = []
X = []
Y = []
Z = []
df = []
df = {}

for i in range(len(filenames)):
for i, filename in enumerate(filenames):

data = []
max_cols = 0

# read header information

with open(filenames[i]) as f:
with open(filename,'r') as f:
# Skip the first 1 lines
for j in range(1):
next(f)
first_line = f.readline().strip('\n')

header=first_line.split(",")[1:5]
IOR.append(int(header[0])) #; print(IOR)
X.append(float(header[1])) #; print(X)
Y.append(float(header[2])) #; print(Y)
Z.append(float(header[3])) #; print(Z)

# sys.exit()

df.append(pd.read_csv(filenames[i],skiprows=3,header=None))
df[i].fillna(tmpa, inplace=True)
header=first_line.split(",")[1:5]
IOR.append(int(header[0])) ; print(IOR)
X.append(float(header[1])) ; print(X)
Y.append(float(header[2])) ; print(Y)
Z.append(float(header[3])) ; print(Z)
next(f)

# Read lines one at a time
while True:
line = f.readline()
if not line: # End of file
break
row = line.strip().split(',') # Adjust delimiter if needed

# Convert each element to float, handling errors gracefully
try:
row = [float(value) if value else None for value in row]
except ValueError:
# If a value cannot be converted, keep it as None
row = [float(value) if value.replace('.', '', 1).isdigit() else None for value in row]

data.append(row)
max_cols = max(max_cols, len(row)) # Track the maximum number of columns

# Normalize rows to have the same number of columns
data = [row + [None] * (max_cols - len(row)) for row in data]

# Convert to a Pandas DataFrame
df[i] = pd.DataFrame(data)

# sys.exit()

Expand Down
Loading