Skip to content

Commit

Permalink
Streamlit show results (#233)
Browse files Browse the repository at this point in the history
* Show .png in results

* Show CSV in results

* Show Dataframe in results

* Show logfile in results

* Show Markdown in results

* Show SU2 Case folder in results

* Button to see SU2 mesh folder in results

* Button to see SUMO mesh folder in results

* Add aircraft visualisation on main page

* Add function to create the sidebar

* Add sidebar and help on each page

* Reduce logo size

* Save Weight results as Markdown

* bump Streamlit to 1.13
  • Loading branch information
aidanjungo authored Sep 30, 2022
1 parent 3abf294 commit 4b9ee87
Show file tree
Hide file tree
Showing 21 changed files with 4,158 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ ToolOutput.xml

aircraft_loads.csv
*.out
*mtomPrediction.png
*MTOM_Prediction.png
*Payload_vs_Range.png
*_Cog.png
**/ToolOutput/*.svg
Expand Down
4 changes: 4 additions & 0 deletions ceasiompy/CLCalculator/__specs__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pathlib import Path
from ceasiompy.utils.moduleinterfaces import CPACSInOut
from ceasiompy.utils.commonxpath import (
REF_XPATH,
Expand All @@ -6,6 +7,9 @@
SU2_TARGET_CL_XPATH,
)

# ===== Results directory path =====

RESULTS_DIR = Path("Results", "CLCalculator")

# ===== CPACS inputs and outputs =====

Expand Down
2 changes: 1 addition & 1 deletion ceasiompy/ExportCSV/__specs__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# ===== Results directory path =====

RESULTS_DIR = Path("Results", "Aeromaps")
RESULTS_DIR = Path("Results", "AeroCoefficients")


# ===== CPACS inputs and outputs =====
Expand Down
6 changes: 4 additions & 2 deletions ceasiompy/ExportCSV/exportcsv.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ def export_aeromaps(cpacs_path, cpacs_out_path):

aeromap_to_export_xpath = CEASIOMPY_XPATH + "/export/aeroMapToExport"

aeromap_uid_list = []
aeromap_uid_list = get_string_vector(cpacs.tixi, aeromap_to_export_xpath)
try:
aeromap_uid_list = get_string_vector(cpacs.tixi, aeromap_to_export_xpath)
except ValueError:
aeromap_uid_list = cpacs.get_aeromap_uid_list()

results_dir = get_results_directory("ExportCSV")

Expand Down
3,901 changes: 3,901 additions & 0 deletions ceasiompy/SU2Run/files/default_paraview_state.pvsm

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions ceasiompy/SkinFriction/skinfriction.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ def add_skin_friction(cpacs_path, cpacs_out_path):
# Get aeroMapToCalculate
aeroMap_to_calculate_xpath = SF_XPATH + "/aeroMapToCalculate"
if cpacs.tixi.checkElement(aeroMap_to_calculate_xpath):
aeromap_uid_list = get_string_vector(cpacs.tixi, aeroMap_to_calculate_xpath)
try:
aeromap_uid_list = get_string_vector(cpacs.tixi, aeroMap_to_calculate_xpath)
except ValueError:
aeromap_uid_list = []
else:
aeromap_uid_list = []

Expand Down Expand Up @@ -223,7 +226,11 @@ def add_skin_friction(cpacs_path, cpacs_out_path):
aeromap_to_plot_xpath = plot_xpath + "/aeroMapToPlot"

if cpacs.tixi.checkElement(aeromap_to_plot_xpath):
aeromap_uid_list = get_string_vector(cpacs.tixi, aeromap_to_plot_xpath)
try:
aeromap_uid_list = get_string_vector(cpacs.tixi, aeromap_to_plot_xpath)
except ValueError:
aeromap_uid_list = []

new_aeromap_to_plot = aeromap_uid_list + new_aeromap_uid_list
new_aeromap_to_plot = list(set(new_aeromap_to_plot))
add_string_vector(cpacs.tixi, aeromap_to_plot_xpath, new_aeromap_to_plot)
Expand Down
44 changes: 22 additions & 22 deletions ceasiompy/WeightConventional/func/cabin.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,31 +163,31 @@ def write_seat_config(self, cabin_output_file):
"""Write the seat configuration in a file in the result directory."""

lines = open(cabin_output_file, "w")
lines.write("\n---------------------------------------")
lines.write("\n-------------- CABIN-------------------")
lines.write("\n---------------------------------------")
lines.write("\nCrew ----------------------------------")
lines.write(f"\nPilot nb: {self.pilot_nb}")
lines.write(f"\nCabin crew nb: {self.cabin_crew_nb}")
lines.write(f"\nCrew mass: {self.crew_mass} [kg]")
lines.write("\n---------------------------------------")
lines.write("\nPassengers -----------------------------")
lines.write(f"\nPassengers nb: {self.passenger_nb}")
lines.write(f"\nPassengers mass: {self.passenger_mass} [kg]")
lines.write("\n---------------------------------------")
lines.write("\nSeats----------------------------------")
lines.write(f"\nAbreast nb.: {self.abreast_nb}")
lines.write(f"\nRow nb.: {self.row_nb}")
lines.write(f"\nSeats_nb : {self.passenger_nb}")
lines.write(f"\nNumber of lavatory: {int(self.toilet_nb)}")
lines.write("\n---------------------------------------")
lines.write("\nPossible seat configuration------------")
lines.write("\nSeat = X and Aisle = || ")
lines.write("\n---------------------------------------\n")

lines.write("\n### CABIN")

lines.write("\n#### Crew")
lines.write(f"\n- Number of pilot: {self.pilot_nb}")
lines.write(f"\n- Number of cabin crew member: {self.cabin_crew_nb}")
lines.write(f"\n- Crew mass: {self.crew_mass} [kg]")
lines.write("\n")
lines.write("\n#### Passengers ")
lines.write(f"\n- Number of passengers: {self.passenger_nb}")
lines.write(f"\n- Passengers mass: {self.passenger_mass} [kg]")
lines.write("\n")
lines.write("\n#### Seats")
lines.write(f"\n- Number of abreast: {self.abreast_nb}")
lines.write(f"\n- Number of row: {self.row_nb}")
lines.write(f"\n- Number of seats : {self.passenger_nb}")
lines.write(f"\n- Number of lavatory: {int(self.toilet_nb)}")
lines.write("\n")
lines.write("\n#### Possible seat configuration")
lines.write("\nSeat = X and Aisle = || ")
lines.write("\n")
lines.write("\n```")
for _ in range(self.row_nb):
lines.write(stringed_seat_row(self.abreast_nb))

lines.write("\n```")
lines.close()


Expand Down
27 changes: 12 additions & 15 deletions ceasiompy/WeightConventional/func/masses.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,26 +152,23 @@ def write_masses_output(self, masses_output_file):
"""Write the seat configuration in a file in the result directory."""

lines = open(masses_output_file, "w")
lines.write("\n---------------------------------------------")
lines.write("\n---------------- MASSES ---------------------")
lines.write("\n---------------------------------------------")
lines.write("\nMasses estimation ---------------------------")
lines.write(f"\nMaximum take off mass : {int(self.mtom)} [kg]")
lines.write(f"\nOperating empty mass : {int(self.oem)} [kg]")
lines.write(f"\nZero fuel mass : {int(self.zfm)} [kg]")
lines.write("\n---------------------------------------------")
lines.write("\nPayload and Fuel ----------------------------")
lines.write(f"\nMaximum payload mass : {int(self.payload_mass)} [kg]")
lines.write(f"\nCargo mass : {int(self.cargo_mass)} [kg]")
lines.write("\n### MASSES")
lines.write("\n#### Masses estimation")
lines.write(f"\n- Maximum take off mass : {int(self.mtom)} [kg]")
lines.write(f"\n- Operating empty mass : {int(self.oem)} [kg]")
lines.write(f"\n- Zero fuel mass : {int(self.zfm)} [kg]")
lines.write("\n#### Payload and Fuel")
lines.write(f"\n- Maximum payload mass : {int(self.payload_mass)} [kg]")
lines.write(f"\n- Cargo mass : {int(self.cargo_mass)} [kg]")
lines.write(
f"\nMaximum fuel mass with max passengers : {int(self.mass_fuel_max_passenger)} [kg]"
f"\n- Maximum fuel mass with max passengers : {int(self.mass_fuel_max_passenger)} [kg]"
)
lines.write(f"\nMaximum fuel mass with no passengers : {int(self.mass_fuel_max)} [kg]")
lines.write(f"\n- Maximum fuel mass with no passengers : {int(self.mass_fuel_max)} [kg]")
lines.write(
"\nMaximum fuel volume with no passengers:"
"\n- Maximum fuel volume with no passengers:"
f"{int(self.mass_fuel_max / self.fuel_density *1000)} [l]"
)
lines.write(f"\nWing loading: {int(self.wing_loading)} [kg/m^2]")
lines.write(f"\n- Wing loading: {int(self.wing_loading)} [kg/m^2]")

lines.close()

Expand Down
14 changes: 7 additions & 7 deletions ceasiompy/WeightConventional/tests/test_cabin.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,18 @@ def test_write_seat_config(self):
shutil.rmtree(TEST_OUT_PATH)
TEST_OUT_PATH.mkdir()

seat_config_file = Path(TEST_OUT_PATH, "Seats_disposition.out")
cabin_config_file = Path(TEST_OUT_PATH, "Cabin.md")

self.cabins[0].write_seat_config(seat_config_file)
self.cabins[0].write_seat_config(cabin_config_file)

assert seat_config_file.exists()
assert cabin_config_file.exists()

with open(seat_config_file, "r") as f:
with open(cabin_config_file, "r") as f:
lines = f.readlines()

assert any("Abreast nb.: 6" in line for line in lines)
assert any("Row nb.: 25" in line for line in lines)
assert any("Seats_nb : 150" in line for line in lines)
assert any("- Number of abreast: 6" in line for line in lines)
assert any("- Number of row: 25" in line for line in lines)
assert any("- Number of seats : 150" in line for line in lines)
assert any("X X X || X X X " in line for line in lines)


Expand Down
4 changes: 2 additions & 2 deletions ceasiompy/WeightConventional/weightconventional.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ def get_weight_estimations(cpacs_path, cpacs_out_path):
cabin_width = ag.fuse_width / (1 + (inside_dim.fuse_thick / 100))
cabin = Cabin(cpacs, cabin_length_tot, cabin_width, ac_masses.max_payload_mass)
cabin.save_to_cpacs()
cabin.write_seat_config(Path(result_dir, "Cabin.out"))
cabin.write_seat_config(Path(result_dir, "Cabin.md"))

ac_masses.get_payload_mass(cabin.passenger_mass)
ac_masses.save_to_cpacs()
ac_masses.write_masses_output(Path(result_dir, "Masses.out"))
ac_masses.write_masses_output(Path(result_dir, "Masses.md"))

log.info("---- Geometry evaluation from CPACS file ----")
log.info(f"Fuselage length: {round(ag.fuse_length[0], 3)} [m]")
Expand Down
2 changes: 1 addition & 1 deletion ceasiompy/utils/commonnames.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
ACTUATOR_DISK_OUTLET_SUFFIX = "_AD_Outlet"

# WEIGHT & BALANCE
MTOM_FIGURE_NAME = "mtomPrediction.png"
MTOM_FIGURE_NAME = "MTOM_Prediction.png"
5 changes: 4 additions & 1 deletion ceasiompy/utils/commonpaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
MODULES_DIR_PATH = Path(ceasiompy.__init__.__file__).parent

# /CEASIOMpy/documents/logos/CEASIOMpy_main_logos.png
CEASIOMPY_LOGO_PATH = Path(CEASIOMPY_PATH, "documents", "logos", "CEASIOMpy_main_logos.png")
CEASIOMPY_LOGO_PATH = Path(CEASIOMPY_PATH, "documents", "logos", "CEASIOMpy_512px.png")

# /CEASIOMpy/ceasiompy.log
LOGFILE = Path(CEASIOMPY_PATH, "ceasiompy.log")
Expand All @@ -47,3 +47,6 @@

# /CEASIOMpy/ceasiompy/WKDIR/
WKDIR_PATH = Path(CEASIOMPY_PATH, "WKDIR")

# /CEASIOMpy/ceasiompy/SU2Run/files/default_paraview_state.pvsm
DEFAULT_PARAVIEW_STATE = Path(MODULES_DIR_PATH, "SU2Run", "files", "default_paraview_state.pvsm")
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_get_results_directory():
with change_working_dir(TMP_DIR):

results_dir = get_results_directory("ExportCSV")
assert results_dir == Path(Path.cwd(), "Results", "Aeromaps")
assert results_dir == Path(Path.cwd(), "Results", "AeroCoefficients")

results_dir = get_results_directory("CPACS2SUMO")
assert results_dir == Path(Path.cwd(), "Results", "SUMO")
Expand Down
Binary file added documents/logos/CEASIOMpy_512px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ dependencies:
- codecov=2.1.11
- coverage=6.2
- flake8=4.0.1
- ipython=8.4.0
- ipywidgets=7.7.1
- matplotlib=3.5.2
- numpy=1.23.3
- openmdao=3.18.0
Expand All @@ -29,6 +31,8 @@ dependencies:
- pip=21.3.1
- pytest-cov=3.0.0
- python-kaleido=0.2.1
- pythreejs=2.3.0
- pyvista=0.36.1
- xmltodict=0.12.0
- vtk=9.0.1

Expand All @@ -40,5 +44,5 @@ dependencies:
- gmsh==4.10.3
- pytest==7.1.2
- smt==1.2.0
- streamlit==1.12.0
- streamlit==1.13.0
- streamlit-autorefresh
60 changes: 46 additions & 14 deletions src/streamlit/CEASIOMpy.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import io
from pathlib import Path

from ceasiompy.utils.commonpaths import CEASIOMPY_LOGO_PATH
import pyvista as pv
from ceasiompy.utils.workflowclasses import Workflow
from cpacspy.cpacspy import CPACS
from PIL import Image
from createsidbar import create_sidebar

import streamlit as st
import streamlit.components.v1 as components
from directory_picker import st_directory_picker

im = Image.open(CEASIOMPY_LOGO_PATH)
st.set_page_config(page_title="CEASIOMpy", page_icon=im)
how_to_text = (
"### How to use CEASIOMpy?\n"
"1. Chose your *Working directory*\n"
"1. Chose a *CPACS file*\n"
"1. Go to the *Workflow* page (with the menu above)\n"
)

create_sidebar(how_to_text)


def section_select_working_dir():
Expand Down Expand Up @@ -47,22 +55,46 @@ def section_select_cpacs():
if "cpacs" not in st.session_state:
st.session_state.cpacs = CPACS(cpacs_new_path)

else:

def show_aircraft():
"""Show a 3D view of the aircraft by exporting a STL file. The viewer is based on:
https://github.com/edsaac/streamlit-PyVista-viewer
"""
st.markdown("## 3D view")

if "cpacs" not in st.session_state:
st.warning("No CPACS file has been selected!")
return

stl_file = Path(st.session_state.workflow.working_dir, "aircraft.stl")

st.title("CEASIOMpy")
st.session_state.cpacs.aircraft.tigl.exportMeshedGeometrySTL(str(stl_file), 0.01)

# Using pythreejs as pyvista backend
pv.set_jupyter_backend("pythreejs")

col1, col2 = st.columns([5, 3])
color_stl = "#ff7f2a"
color_bkg = "#e0e0d4"

with col1:
st.markdown("### How to use CEASIOMpy?")
st.markdown("- Select a Working directory")
st.markdown("- Select a CPACS file")
st.markdown("- Use the side bar to go to the Workflow page")
# Initialize pyvista reader and plotter
plotter = pv.Plotter(border=False, window_size=[572, 600])
plotter.background_color = color_bkg
reader = pv.STLReader(str(stl_file))

with col2:
st.image(str(CEASIOMPY_LOGO_PATH), width=220)
# Read data and send to plotter
mesh = reader.read()
plotter.add_mesh(mesh, color=color_stl)

# Export to a pythreejs HTML
model_html = io.StringIO()
plotter.export_html(model_html, backend="pythreejs")

# Show in webpage
components.html(model_html.getvalue(), height=600, width=572, scrolling=False)


st.title("CEASIOMpy")

section_select_working_dir()
section_select_cpacs()
show_aircraft()
13 changes: 13 additions & 0 deletions src/streamlit/createsidbar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from ceasiompy.utils.commonpaths import CEASIOMPY_LOGO_PATH
from PIL import Image

import streamlit as st

im = Image.open(CEASIOMPY_LOGO_PATH)


def create_sidebar(how_to_text):

st.set_page_config(page_title="CEASIOMpy", page_icon=im)
st.sidebar.image(im)
st.sidebar.markdown(how_to_text)
12 changes: 10 additions & 2 deletions src/streamlit/pages/01_ ➡_Workflow.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import streamlit as st
from ceasiompy.utils.moduleinterfaces import get_submodule_list
from createsidbar import create_sidebar

how_to_text = (
"### How to use Create a workflow?\n"
"You can either:\n"
"- Select a predefined workflow and modify it\n"
"- Build your own workflow by selecting among available modules\n"
"When it is done, go to the *Settings* page\n"
)

st.set_page_config(page_title="Workflow", page_icon="➡")

create_sidebar(how_to_text)

# Custom CSS
st.markdown(
Expand Down
Loading

0 comments on commit 4b9ee87

Please sign in to comment.