relativus commited on
Commit
b419552
·
verified ·
1 Parent(s): b4bf831

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +10 -12
src/streamlit_app.py CHANGED
@@ -4,23 +4,21 @@ import pandas as pd
4
  import numpy as np
5
  from scipy.spatial import Delaunay
6
  import pyvista as pv
7
- from pyvista.utilities import transformations
8
 
9
  # Настройка страницы
10
- st.set_page_config(page_title="Изотемпературные поверхности в тетраэдре", layout="wide")
11
  st.title("Визуализация изоповерхностей температуры в тетраэдре")
12
 
13
  # Загрузка файла
14
- uploaded_file = st.file_uploader("Загрузите файл Excel (.xlsx)", type=["xlsx"])
15
 
16
  if uploaded_file is not None:
17
  try:
18
  df = pd.read_excel(uploaded_file)
19
  except Exception as e:
20
- st.error(f"Ошибка при загрузке файла: {e}")
21
  st.stop()
22
 
23
- # Проверяем наличие необходимных колонок
24
  required_cols = ['x1', 'x2', 'x3', 'x4', 'T, C']
25
  if not all(col in df.columns for col in required_cols):
26
  st.error(f"Файл должен содержать колонки: {', '.join(required_cols)}")
@@ -29,12 +27,12 @@ if uploaded_file is not None:
29
  points = df[['x1', 'x2', 'x3', 'x4']].values
30
  temps = df['T, C'].values
31
 
32
- # Функция перевода барицентрических координат в 3D
33
  def barycentric_to_cartesian(bary_coords):
34
- A = np.array([0.0, 0.0, 0.0]) # x1
35
- B = np.array([1.0, 0.0, 0.0]) # x2
36
  C = np.array([0.5, np.sqrt(3)/2, 0.0]) # x3
37
- D = np.array([0.5, np.sqrt(3)/6, np.sqrt(6)/3]) # x4 (вершина сверху)
38
 
39
  cart_points = []
40
  for coords in bary_coords:
@@ -46,7 +44,7 @@ if uploaded_file is not None:
46
 
47
  cartesian_points = barycentric_to_cartesian(points)
48
 
49
- # Построение тетраэдрической сетки
50
  tri = Delaunay(cartesian_points)
51
 
52
  # Создаем PyVista сетку
@@ -73,11 +71,11 @@ if uploaded_file is not None:
73
  plotter.view_isometric()
74
  plotter.background_color = 'white'
75
 
76
- # Отображение в Streamlit
77
  st.subheader("Изоповерхность температуры")
78
  components.html(plotter.ren_win_to_js(), height=800, width=1000)
79
  except Exception as e:
80
  st.error(f"Ошибка при построении изоповерхности: {e}")
81
 
82
  else:
83
- st.info("Пожалуйста, загрузите файл Excel.")
 
4
  import numpy as np
5
  from scipy.spatial import Delaunay
6
  import pyvista as pv
 
7
 
8
  # Настройка страницы
9
+ st.set_page_config(page_title="Изоповерхности в тетраэдре", layout="wide")
10
  st.title("Визуализация изоповерхностей температуры в тетраэдре")
11
 
12
  # Загрузка файла
13
+ uploaded_file = st.file_uploader("Загрузите Excel файл (.xlsx)", type=["xlsx"])
14
 
15
  if uploaded_file is not None:
16
  try:
17
  df = pd.read_excel(uploaded_file)
18
  except Exception as e:
19
+ st.error(f"Ошибка при чтении файла: {e}")
20
  st.stop()
21
 
 
22
  required_cols = ['x1', 'x2', 'x3', 'x4', 'T, C']
23
  if not all(col in df.columns for col in required_cols):
24
  st.error(f"Файл должен содержать колонки: {', '.join(required_cols)}")
 
27
  points = df[['x1', 'x2', 'x3', 'x4']].values
28
  temps = df['T, C'].values
29
 
30
+ # Перевод барицентрических координат в 3D
31
  def barycentric_to_cartesian(bary_coords):
32
+ A = np.array([0.0, 0.0, 0.0]) # x1
33
+ B = np.array([1.0, 0.0, 0.0]) # x2
34
  C = np.array([0.5, np.sqrt(3)/2, 0.0]) # x3
35
+ D = np.array([0.5, np.sqrt(3)/6, np.sqrt(6)/3]) # x4 (верх)
36
 
37
  cart_points = []
38
  for coords in bary_coords:
 
44
 
45
  cartesian_points = barycentric_to_cartesian(points)
46
 
47
+ # Построение тетраэдров
48
  tri = Delaunay(cartesian_points)
49
 
50
  # Создаем PyVista сетку
 
71
  plotter.view_isometric()
72
  plotter.background_color = 'white'
73
 
74
+ # Встраиваем визуализацию в Streamlit
75
  st.subheader("Изоповерхность температуры")
76
  components.html(plotter.ren_win_to_js(), height=800, width=1000)
77
  except Exception as e:
78
  st.error(f"Ошибка при построении изоповерхности: {e}")
79
 
80
  else:
81
+ st.info("Пожалуйста, загрузите файл Excel.")