Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Improvement of stored results parameters #20

Merged
merged 8 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/test-pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: [3.8, 3.12]
python-version: [3.9, 3.12]
env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}
Expand Down
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
lint: isort black

isort:
isort .

black:
black .

pylint:
pylint rocketserializer/ --output="pylint_report.txt"

tests:
pytest

# tests-unit:

# tests-acceptance:

# tests-integration:

8 changes: 6 additions & 2 deletions examples/EPFL--BellaLui--2020/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"nozzle_radius": 0.02025,
"position": 2.3379117844381234,
"throat_radius": 0.0135,
"thrust_source": "examples/EPFL--BellaLui--2020/thrust_source.csv"
"thrust_source": "examples\\EPFL--BellaLui--2020\\thrust_source.csv"
},
"nosecones": {
"base_radius": 0.078,
Expand All @@ -56,7 +56,7 @@
"rocket": {
"center_of_mass_without_propellant": 1.559,
"coordinate_system_orientation": "nose_to_tail",
"drag_curve": "examples/EPFL--BellaLui--2020/drag_curve.csv",
"drag_curve": "examples\\EPFL--BellaLui--2020\\drag_curve.csv",
"inertia": [
0.096246,
0.096246,
Expand All @@ -66,13 +66,17 @@
"radius": 0.078
},
"stored_results": {
"burnout_stability_margin": 3.1703,
"flight_time": 92.782,
"ground_hit_velocity": 26.142,
"launch_rod_velocity": 14.728,
"max_acceleration": 122.07,
"max_altitude": 1190.0,
"max_mach": 0.5587,
"max_stability_margin": 4.8193,
"max_thrust": 1287.5,
"max_velocity": 189.56,
"min_stability_margin": 0.85185,
"time_to_apogee": 14.851
},
"tails": {
Expand Down
5 changes: 5 additions & 0 deletions examples/NDRT--Rocket--2020/parameters.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"elliptical_fins": {},
"environment": {
"base_pressure": null,
"base_temperature": null,
Expand Down Expand Up @@ -84,13 +85,17 @@
"radius": 0.1016
},
"stored_results": {
"burnout_stability_margin": 3.7288,
"flight_time": 86.725,
"ground_hit_velocity": 4.7426,
"launch_rod_velocity": 17.993,
"max_acceleration": 67.386,
"max_altitude": 1085.9,
"max_mach": 0.42789,
"max_stability_margin": 3.7685,
"max_thrust": 1785.0,
"max_velocity": 145.01,
"min_stability_margin": 1.2489,
"time_to_apogee": 15.761
},
"tails": {
Expand Down
5 changes: 5 additions & 0 deletions examples/ProjetoJupiter--Valetudo--2019/parameters.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"elliptical_fins": {},
"environment": {
"base_pressure": 94311.0,
"base_temperature": 300.76,
Expand Down Expand Up @@ -81,13 +82,17 @@
"radius": 0.04045000000000001
},
"stored_results": {
"burnout_stability_margin": 2.4363,
"flight_time": 64.161,
"ground_hit_velocity": 18.146,
"launch_rod_velocity": 26.397,
"max_acceleration": 108.52,
"max_altitude": 882.42,
"max_mach": 0.36177,
"max_stability_margin": 3.2714,
"max_thrust": 1067.7,
"max_velocity": 125.47,
"min_stability_margin": 0.0,
"time_to_apogee": 14.65
},
"tails": {},
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ disable = """
raise-missing-from,
fixme,
no-else-break,
no-else-return,
"""
82 changes: 79 additions & 3 deletions rocketserializer/components/stored_results.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import logging

import numpy as np

from .._helpers import _dict_to_string

logger = logging.getLogger(__name__)


def search_stored_results(bs):
def search_stored_results(bs, datapoints, data_labels, time_vector, burnout_position):
"""Search for the stored simulation results in the bs and return the
settings as a dict.

Expand All @@ -22,11 +24,9 @@ def search_stored_results(bs):
"flighttime", "groundhitvelocity" and "launchrodvelocity".
"""
settings = {}

sim = bs.find("simulation")
sim_data = sim.find("flightdata")
logger.info("Found the 'flightdata' tag in the 'simulation' tag.")

name_map = {
"max_altitude": "maxaltitude",
"max_velocity": "maxvelocity",
Expand All @@ -44,8 +44,84 @@ def search_stored_results(bs):
"Retrieved the '%s' value from the .ork file: %s", key, settings[key]
)

settings["max_stability_margin"] = __get_parameter(
datapoints,
data_labels,
time_vector,
"Stability margin calibers",
position="max",
)
settings["min_stability_margin"] = __get_parameter(
datapoints,
data_labels,
time_vector,
"Stability margin calibers",
position="min",
)
settings["burnout_stability_margin"] = __get_parameter(
datapoints,
data_labels,
time_vector,
"Stability margin calibers",
position=burnout_position,
)
settings["max_thrust"] = __get_parameter(
datapoints, data_labels, time_vector, "Thrust", position="max"
)

logger.info(
"The flight data was successfully retrieved:\n%s",
_dict_to_string(settings, indent=23),
)
return settings


def __get_parameter(datapoints, data_labels, time_vector, label, position):
"""Get the latitude and longitude from the .ork file.
Parameters
----------
label : str
Latitude or longitude.
datapoints : list
List of datapoints from the .ork file.
data_labels : list
List of labels for the datapoints.
time_vector : list
The time vector of the simulation.
position : str or int
The position to get the value from. Can be "last", "first", "max", "min"
or an integer.
"""

parameter = [
float(datapoint.text.split(",")[data_labels.index(label)])
for datapoint in datapoints
]
# convert to numpy array
parameter = np.array([time_vector, parameter]).T
# sort by time
parameter = parameter[parameter[:, 0].argsort()]
# clip the curve to remove negative values
parameter[parameter[:, 1] < 0, 1] = 0
# Assuming parameter is a NumPy array and 'NaN' values are represented as np.nan
# This will keep rows where the second column is not NaN
parameter = parameter[~np.isnan(parameter[:, 1])]

if isinstance(position, str):
if position == "last":
# return the end point (final time, final value)
return parameter[-1, 1]
elif position == "first":
# return the first point (initial time, initial value)
return parameter[0, 1]
elif position == "max":
return np.max(parameter[:, 1]) # return the maximum value
elif position == "min":
return np.min(parameter[:, 1]) # return the minimum value
else:
pass
if isinstance(position, np.int64):
return parameter[position, 1] # return the value at the specified position
else:
logger.error("Invalid position parameter")
raise ValueError("Error in position parameter")
4 changes: 3 additions & 1 deletion rocketserializer/ork_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ def ork_extractor(bs, filepath, output_folder, ork, eng):
transitions = search_transitions(bs, elements, ork)
rail_buttons = search_rail_buttons(bs, elements)
parachutes = search_parachutes(bs)
stored_results = search_stored_results(bs)
stored_results = search_stored_results(
bs, datapoints, data_labels, time_vector, burnout_position
)

# save everything to a dictionary
settings["id"] = id_info
Expand Down
6 changes: 6 additions & 0 deletions run-tests.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
ork2json --filepath="examples\EPFL--BellaLui--2020\rocket.ork"
ork2json --filepath="examples\NDRT--Rocket--2020\rocket.ork"
ork2json --filepath="examples\ProjetoJupiter--Valetudo--2019\rocket.ork"
ork2json --filepath="examples\WERT--Prometheus--2022\rocket.ork"

ork2ipynb --filepath="examples\EPFL--BellaLui--2020\rocket.ork"
ork2ipynb --filepath="examples\NDRT--Rocket--2020\rocket.ork"
ork2ipynb --filepath="examples\ProjetoJupiter--Valetudo--2019\rocket.ork"
ork2ipynb --filepath="examples\WERT--Prometheus--2022\rocket.ork"
6 changes: 5 additions & 1 deletion tests/acceptance/EPFL--BellaLui--2020/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@
"time_to_apogee": 14.851,
"flight_time": 92.782,
"ground_hit_velocity": 26.142,
"launch_rod_velocity": 14.728
"launch_rod_velocity": 14.728,
"max_stability_margin": 4.8193,
"min_stability_margin": 0.85185,
"burnout_stability_margin": 3.1703,
"max_thrust": 1287.5
}
}
6 changes: 5 additions & 1 deletion tests/acceptance/NDRT--Rocket--2020/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@
"time_to_apogee": 15.761,
"flight_time": 86.725,
"ground_hit_velocity": 4.7426,
"launch_rod_velocity": 17.993
"launch_rod_velocity": 17.993,
"max_stability_margin": 3.7685,
"min_stability_margin": 1.2489,
"burnout_stability_margin": 3.7288,
"max_thrust": 1785.0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@
"time_to_apogee": 14.65,
"flight_time": 64.161,
"ground_hit_velocity": 18.146,
"launch_rod_velocity": 26.397
"launch_rod_velocity": 26.397,
"max_stability_margin": 3.2714,
"min_stability_margin": 0.0,
"burnout_stability_margin": 2.4363,
"max_thrust": 1067.7
}
}
Loading