SachinSaud's picture
Upload folder using huggingface_hub
68da613 verified
from read_node import read_dat_file, read_result_file
import os
import numpy as np
import pyvista as pv
folder_path = r"D:\AnK\FatigueNet\Fatigue_Life\datasets\Raw data\shaft_high\life_D15_d5_r1"
folder_base_name = os.path.basename(folder_path).replace("_data", "")
dat_file_path = os.path.join(folder_path, f"{folder_base_name}.dat")
fatigue_life_path = os.path.join(folder_path, f"{folder_base_name}.txt")
#dat_file_path = "path/to/your/dat_file.dat"
#fatigue_life_path = "path/to/your/fatigue_life.txt"
positions,cells = read_dat_file(dat_file_path)
fatigue_life = read_result_file(fatigue_life_path)
#print(positions)
#print(fatigue_life)
# Step 3: Log scale for better contrast
log_fatigue_life = np.log10(fatigue_life)
# Step 4: Create point cloud
point_cloud = pv.PolyData(positions)
point_cloud["Fatigue Life (log10)"] = log_fatigue_life
# Step 5: Alternative approach - create glyphs from points
# This is often more reliable for point-based visualizations
sphere_source = pv.Sphere(radius=0.15)
glyphs = point_cloud.glyph(geom=sphere_source, scale=False)
# Step 6: Plotting
plotter = pv.Plotter()
# Add spheres with color mapping
plotter.add_mesh(
glyphs,
scalars="Fatigue Life (log10)",
cmap="viridis",
opacity=1.0,
show_edges=False
)
# Add scalar bar with better formatting
plotter.add_scalar_bar(
title="log₁₀(Fatigue Life)",
n_labels=6,
fmt="%.1f"
)
# Set background color for better contrast
plotter.set_background('white')
# Set camera position for better view
plotter.camera_position = 'iso'
# Add axes for reference
plotter.add_axes()
# Show the plot
plotter.show()
# Print some debug info
print(f"Created {len(positions)} spheres")
print(f"Fatigue life range: {fatigue_life.min():.0e} to {fatigue_life.max():.0e}")
print(f"Log fatigue life range: {log_fatigue_life.min():.2f} to {log_fatigue_life.max():.2f}")