forked from UAVLab-SLU/DRV_public
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Issue165 #169
Open
Damerson1
wants to merge
2
commits into
main
Choose a base branch
from
Issue165
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Issue165 #169
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,22 +4,34 @@ | |
import plotly.express as px | ||
import os | ||
import threading | ||
from io import BytesIO | ||
from PythonClient.multirotor.airsim_application import AirSimApplication | ||
|
||
# create a lock object | ||
|
||
lock = threading.Lock() | ||
matplotlib.use('agg') | ||
|
||
class ThreeDimensionalGrapher(AirSimApplication): | ||
|
||
def setup_dir(dir): | ||
if not os.path.exists(dir): | ||
os.makedirs(dir) | ||
def __init__(self): | ||
super().__init__() | ||
|
||
#Function to upload html files to GCS. | ||
def _upload_html(self, fig, file_name): | ||
html_content = fig.to_html(full_html=True) | ||
self.save_report_to_storage(file_name, html_content, content_type="text/html") | ||
|
||
class ThreeDimensionalGrapher: | ||
#Function to upload png to GCS. | ||
def _upload_plot(self, fig, file_name): | ||
img_bytes = BytesIO() | ||
fig.savefig(img_bytes, format="png", dpi=200, bbox_inches='tight') | ||
img_bytes.seek(0) | ||
self.save_report_to_storage(file_name, img_bytes.getvalue(), content_type="image/png") | ||
plt.close(fig) | ||
|
||
@staticmethod | ||
def draw_trace(actual_position_list, full_target_directory, drone_name, title): | ||
|
||
def draw_trace(self, actual_position_list, full_target_directory, drone_name, title): | ||
with lock: | ||
fig = plt.figure() | ||
ax = fig.add_subplot(111, projection='3d') | ||
|
@@ -36,17 +48,13 @@ def draw_trace(actual_position_list, full_target_directory, drone_name, title): | |
ax.set_xlabel('North (+X) axis') | ||
ax.set_ylabel('East (+Y) axis') | ||
ax.set_zlabel('Height (+Z) axis') | ||
setup_dir(full_target_directory) | ||
file_name = os.path.join(full_target_directory, str(drone_name) + "_plot.png") | ||
# print(file_name) | ||
plt.title(title) | ||
plt.savefig(file_name, dpi=200, bbox_inches='tight') | ||
plt.close() | ||
fig.clf() | ||
|
||
@staticmethod | ||
def draw_trace_vs_planned(planed_position_list, actual_position_list, full_target_directory, drone_name, | ||
title): | ||
|
||
file_name = f"{drone_name}_plot.png" | ||
full_target_directory = os.path.join(self.log_subdir, self.__class__.__name__, file_name) | ||
self._upload_plot(full_target_directory ,fig) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are passing the arguments to |
||
|
||
def draw_trace_vs_planned(self, planed_position_list, full_target_directory, actual_position_list, drone_name, | ||
title): | ||
with lock: | ||
fig = plt.figure() | ||
ax = fig.add_subplot(111, projection='3d') | ||
|
@@ -70,16 +78,12 @@ def draw_trace_vs_planned(planed_position_list, actual_position_list, full_targe | |
ax.set_ylabel('East (+Y) axis') | ||
ax.set_zlabel('Height (+Z) axis') | ||
ax.legend() | ||
setup_dir(full_target_directory) | ||
file_name = os.path.join(full_target_directory, str(drone_name) + "_plot.png") | ||
# print(file_name) | ||
plt.title(title) | ||
plt.savefig(file_name, dpi=200, bbox_inches='tight') | ||
plt.close() | ||
fig.clf() | ||
|
||
@staticmethod | ||
def draw_trace_vs_point(destination_point, actual_position_list, full_target_directory, drone_name, | ||
|
||
file_name = f"{drone_name}_plot.png" | ||
full_target_directory = os.path.join(self.log_subdir, self.__class__.__name__, file_name) | ||
self._upload_plot(fig, file_name) | ||
|
||
def draw_trace_vs_point(self, destination_point, full_target_directory ,actual_position_list, drone_name, | ||
title): | ||
with lock: | ||
fig = plt.figure() | ||
|
@@ -108,15 +112,12 @@ def draw_trace_vs_point(destination_point, actual_position_list, full_target_dir | |
ax.set_zlabel('Height (+Z) axis') | ||
ax.set_box_aspect([1, 1, 1]) | ||
ax.legend() | ||
setup_dir(full_target_directory) | ||
file_name = os.path.join(full_target_directory, str(drone_name) + "_plot.png") | ||
plt.title(title) | ||
plt.savefig(file_name, dpi=200, bbox_inches='tight') | ||
plt.close() | ||
fig.clf() | ||
|
||
@staticmethod | ||
def draw_interactive_trace(actual_position, full_target_directory, drone_name, | ||
|
||
file_name = f"{drone_name}_plot.png" | ||
full_target_directory = os.path.join(self.log_subdir, self.__class__.__name__, file_name) | ||
self._upload_plot(fig, file_name) | ||
|
||
def draw_interactive_trace(self, actual_position, full_target_directory, drone_name, | ||
title): | ||
with lock: | ||
actual = actual_position | ||
|
@@ -132,17 +133,15 @@ def draw_interactive_trace(actual_position, full_target_directory, drone_name, | |
# scene=dict(xaxis_range=[-max_val, max_val], | ||
# yaxis_range=[-max_val, max_val], | ||
# zaxis_range=[-max_val, max_val])) | ||
setup_dir(full_target_directory) | ||
ax.set_xlabel('North (+X) axis') | ||
ax.set_ylabel('East (+Y) axis') | ||
ax.set_zlabel('Height (+Z) axis') | ||
file_name = os.path.join(full_target_directory, str(drone_name) + "_interactive.html") | ||
fig.write_html(file_name) | ||
plt.close() | ||
|
||
@staticmethod | ||
def draw_interactive_trace_vs_point(destination, actual_position, full_target_directory, drone_name, | ||
title): | ||
file_name = f"{drone_name}_interactive_trace.html" | ||
self._upload_html(fig, file_name) | ||
|
||
def draw_interactive_trace_vs_point(self, destination, actual_position, full_target_directory, drone_name | ||
,title): | ||
with lock: | ||
actual = actual_position | ||
fig = plt.figure() | ||
|
@@ -162,13 +161,13 @@ def draw_interactive_trace_vs_point(destination, actual_position, full_target_di | |
# fig.update_layout(scene=dict(xaxis_range=[-max_val, max_val], | ||
# yaxis_range=[-max_val, max_val], | ||
# zaxis_range=[-max_val, max_val])) | ||
setup_dir(full_target_directory) | ||
file_name = os.path.join(full_target_directory, str(drone_name) + "_interactive.html") | ||
fig.write_html(file_name) | ||
plt.close() | ||
|
||
@staticmethod | ||
def draw_interactive_trace_vs_planned(planed_position_list, actual_position_list, full_target_directory, | ||
|
||
|
||
file_name = f"{drone_name}_interactive_trace_vs_point.html" | ||
full_target_directory = os.path.join(self.log_subdir, self.__class__.__name__, file_name) | ||
self._upload_html(fig, file_name) | ||
def draw_interactive_trace_vs_planned(self, planed_position_list, actual_position_list, full_target_directory, | ||
drone_name, | ||
title): | ||
with lock: | ||
|
@@ -193,7 +192,7 @@ def draw_interactive_trace_vs_planned(planed_position_list, actual_position_list | |
# scene=dict(xaxis_range=[-max_val, max_val], | ||
# yaxis_range=[-max_val, max_val], | ||
# zaxis_range=[-max_val, max_val])) | ||
setup_dir(full_target_directory) | ||
file_name = os.path.join(full_target_directory, str(drone_name) + "_interactive.html") | ||
fig.write_html(file_name) | ||
plt.close() | ||
|
||
file_name = f"{drone_name}_interactive_trace_vs_planned.html" | ||
full_target_directory = os.path.join(self.log_subdir, self.__class__.__name__, file_name) | ||
self._upload_html(fig, file_name) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This conflicts with how
GCSStorageService
handles the upload path.