Skip to content

Commit cd20eac

Browse files
committed
added save to dropbox
1 parent 7ccc06e commit cd20eac

File tree

14 files changed

+162
-25
lines changed

14 files changed

+162
-25
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
proj/secrets.py
2+
13
.vscode/*
24
.vscode/
35
.vscode

proj/environment/manager.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
from fcutils.file_io.io import save_yaml
1010

1111

12-
from proj.utils import timestamp
12+
from proj.utils.misc import timestamp
1313
from proj import paths
1414
from proj.animation.animate import animate_from_images
1515
from proj.plotting.results import plot_results
16+
from proj.utils.dropbox import DropBoxUtils, upload_folder
1617

1718
FORMAT = "%(message)s"
1819
logging.basicConfig(
@@ -136,6 +137,13 @@ def _save_video(self):
136137
except (FileNotFoundError, PermissionError):
137138
print("could not remove frames folder")
138139

140+
def _upload_to_dropbox(self):
141+
dbx = DropBoxUtils()
142+
dpx_path = self.datafolder.name
143+
logging.info(f"Uploading data to dropbox at: {dpx_path}")
144+
145+
upload_folder(dbx, self.datafolder, dpx_path)
146+
139147
def conclude(self):
140148
self._save_results()
141149
self._save_video()
@@ -146,3 +154,7 @@ def conclude(self):
146154
plot_every=self.plot_every,
147155
save_path=self.datafolder / "outcome",
148156
)
157+
158+
# Upload results to dropbox
159+
if self.winstor:
160+
self._upload_to_dropbox()

proj/environment/plotter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from fcutils.plotting.colors import desaturate_color
77
from fcutils.plotting.plot_elements import plot_line_outlined
88

9-
from proj.utils import salmon
109
from proj.animation import variables_colors as colors
1110

1211

@@ -54,7 +53,7 @@ def _plot_xy(self, ax, curr_goals):
5453
curr_goals[:, 0],
5554
curr_goals[:, 1],
5655
lw=10,
57-
color=salmon,
56+
color="r",
5857
zorder=-1,
5958
solid_capstyle="round",
6059
)

proj/environment/trajectories.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
)
1515
from fcutils.maths.filtering import line_smoother
1616

17-
from proj.utils import interpolate_nans
17+
from proj.utils.misc import interpolate_nans
1818

1919

2020
def complete_given_xy(x, y, params, planning_params):
@@ -36,7 +36,9 @@ def complete_given_xy(x, y, params, planning_params):
3636
)
3737

3838

39-
def compute_trajectory_stats(trajectory, duration, planning_params):
39+
def compute_trajectory_stats(
40+
trajectory, duration, planning_params, min_dist_travelled=150
41+
):
4042
# Compute stats
4143
n_points = len(trajectory)
4244
distance_travelled = np.sum(
@@ -96,15 +98,21 @@ def compute_trajectory_stats(trajectory, duration, planning_params):
9698
print(table)
9799

98100
if waypoint_density < 2 or waypoint_density > 3:
99-
print(
100-
f"[bold red]Waypoint density of {round(waypoint_density, 3)} out of range, it should be 2 < wp < 3!"
101+
log.info(
102+
f"[bold red]Waypoint density of {round(waypoint_density, 3)} out of range, it should be 2 < wp < 3!",
103+
extra={"markdown": True},
101104
)
102105

103106
if perc_lookahead < 0.05:
104-
print(
105-
f"[bold red]Lookahead of {lookahead} is {perc_lookahead} of the # of waypoints, that might be too low. Values closer to 5% are advised."
107+
log.info(
108+
f"[bold red]Lookahead of {lookahead} is {perc_lookahead} of the # of waypoints, that might be too low. Values closer to 5% are advised.",
109+
extra={"markdown": True},
106110
)
107111

112+
if distance_travelled < min_dist_travelled:
113+
log.warning("Distance travelled below minimal requirement, erroring")
114+
raise ValueError("Distance travelled below minimal requirement")
115+
108116
return trajectory, duration
109117

110118

proj/environment/world.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from fcutils.maths.geometry import calc_distance_between_points_2d
55

66
from proj.environment.plotter import Plotter
7-
from proj.utils import polar_to_cartesian
7+
from proj.utils.misc import polar_to_cartesian
88

99
_xy = namedtuple("xy", "x, y")
1010
_xyt = namedtuple("xyt", "x, y, t")

proj/model/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from fcutils.maths.geometry import calc_distance_between_points_2d
1515

1616
from proj.model.config import Config
17-
from proj.utils import merge
17+
from proj.utils.misc import merge
1818
from proj.control.utils import fit_angle_in_range
1919
from proj.model.fast import (
2020
fast_dqdt,

proj/paths.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
frames_cache = Path(
1111
"/Users/federicoclaudi/Dropbox (UCL - SWC)/Rotation_vte/Locomotion/control/frames_cache"
1212
)
13+
14+
db_app = "/Users/federicoclaudi/Dropbox (UCL - SWC)/Apps/loco_upload"
1315
else:
1416
trials_cache = "D:\\Dropbox (UCL - SWC)\\Rotation_vte\\Locomotion\\control\\behav_data\\m46_cache.h5"
1517

@@ -20,9 +22,12 @@
2022
"D:\\Dropbox (UCL - SWC)\\Rotation_vte\\Locomotion\\control\\frames_cache"
2123
)
2224

25+
raise NotImplementedError("db app missing")
26+
2327

2428
# winstor paths
2529
winstor_main = Path("/nfs/winstor/branco/Federico/Locomotion/control")
2630
winstor_trial_cache = (
2731
"/nfs/winstor/branco/Federico/Locomotion/control/m46_cache.h5"
2832
)
33+
winstor_db_app = ""

proj/plotting/results.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from fcutils.plotting.plot_elements import plot_line_outlined
88
from fcutils.maths.utils import derivative
99

10-
from proj.utils import load_results_from_folder
10+
from proj.utils.misc import load_results_from_folder
1111
from proj.animation import variables_colors as colors
1212

1313

proj/plotting/trajectories.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import matplotlib.pyplot as plt
22
import numpy as np
33

4-
from proj.utils import polar_to_cartesian
4+
from proj.utils.misc import polar_to_cartesian
55

66

77
def plot_trajectory_polar(traj):

proj/utils/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)