-
-
Notifications
You must be signed in to change notification settings - Fork 208
Enh/motor thrustcurve api #870
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
base: develop
Are you sure you want to change the base?
Changes from all commits
05ab711
da39fcb
9fdc704
d123b47
d6c5dee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,11 +1,14 @@ | ||||||||||||
| import base64 | ||||||||||||
| import re | ||||||||||||
| import tempfile | ||||||||||||
| import warnings | ||||||||||||
| import xml.etree.ElementTree as ET | ||||||||||||
| from abc import ABC, abstractmethod | ||||||||||||
| from functools import cached_property | ||||||||||||
| from os import path | ||||||||||||
| from os import path, remove | ||||||||||||
|
|
||||||||||||
| import numpy as np | ||||||||||||
| import requests | ||||||||||||
|
|
||||||||||||
| from ..mathutils.function import Function, funcify_method | ||||||||||||
| from ..plots.motor_plots import _MotorPlots | ||||||||||||
|
|
@@ -1914,6 +1917,93 @@ def load_from_rse_file( | |||||||||||
| coordinate_system_orientation=coordinate_system_orientation, | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| @staticmethod | ||||||||||||
| def load_from_thrustcurve_api(name: str, **kwargs): | ||||||||||||
| """ | ||||||||||||
| Creates a Motor instance by downloading a .eng file from the ThrustCurve API | ||||||||||||
| based on the given motor name. | ||||||||||||
|
|
||||||||||||
| Parameters | ||||||||||||
| ---------- | ||||||||||||
| name : str | ||||||||||||
| The motor name according to the API (e.g., "Cesaroni_M1670" or "M1670"). | ||||||||||||
| Both manufacturer-prefixed and shorthand names are commonly used; if multiple | ||||||||||||
| motors match the search, the first result is used. | ||||||||||||
| **kwargs : | ||||||||||||
| Additional arguments passed to the Motor constructor or loader, such as | ||||||||||||
| dry_mass, nozzle_radius, etc. | ||||||||||||
|
|
||||||||||||
| Returns | ||||||||||||
| ------- | ||||||||||||
| instance : GenericMotor | ||||||||||||
| A new GenericMotor instance initialized using the downloaded .eng file. | ||||||||||||
|
|
||||||||||||
| Raises | ||||||||||||
| ------ | ||||||||||||
| ValueError | ||||||||||||
| If no motor is found or if the downloaded .eng data is missing. | ||||||||||||
| requests.exceptions.RequestException | ||||||||||||
| If a network or HTTP error occurs during the API call. | ||||||||||||
| """ | ||||||||||||
| base_url = "https://www.thrustcurve.org/api/v1" | ||||||||||||
|
|
||||||||||||
| # Step 1. Search motor | ||||||||||||
| response = requests.get(f"{base_url}/search.json", params={"commonName": name}) | ||||||||||||
| response.raise_for_status() | ||||||||||||
|
Comment on lines
+1951
to
+1952
|
||||||||||||
| data = response.json() | ||||||||||||
|
|
||||||||||||
| if not data.get("results"): | ||||||||||||
| raise ValueError( | ||||||||||||
| f"No motor found for name '{name}'. " | ||||||||||||
| "Please verify the motor name format (e.g., 'Cesaroni_M1670' or 'M1670') and try again." | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| motor_info = data["results"][0] | ||||||||||||
| motor_id = motor_info.get("motorId") | ||||||||||||
| designation = motor_info.get("designation", "").replace("/", "-") | ||||||||||||
| manufacturer = motor_info.get("manufacturer", "") | ||||||||||||
| warnings.warn(f"Motor found: {designation} ({manufacturer})", UserWarning) | ||||||||||||
|
|
||||||||||||
| # Step 2. Download the .eng file | ||||||||||||
| dl_response = requests.get( | ||||||||||||
| f"{base_url}/download.json", | ||||||||||||
| params={"motorIds": motor_id, "format": "RASP", "data": "file"}, | ||||||||||||
| ) | ||||||||||||
| dl_response.raise_for_status() | ||||||||||||
| dl_data = dl_response.json() | ||||||||||||
|
|
||||||||||||
|
||||||||||||
| if not data.get("results"): | |
| print("No .eng file found for this motor in the ThrustCurve API.") | |
| return None |
Gui-FernandesBR marked this conversation as resolved.
Show resolved
Hide resolved
Gui-FernandesBR marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Nov 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with the codebase comment style, use imperative mood: change 'Ensuring' to 'Ensure'.
| # Ensuring the temporary file is removed | |
| # Ensure the temporary file is removed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method signature includes
nameand**kwargsparameters, but the docstring example shows 'Cesaroni_M1670' format while the test uses 'M1670'. The documentation should clarify the expected input format and provide examples for both manufacturer-prefixed and non-prefixed motor names to avoid user confusion.