ethz-asl / data-driven-dynamics

Data Driven Dynamics Modeling for Aerial Vehicles
Other
99 stars 14 forks source link

Log path uses absolute paths #41

Closed Jaeyoung-Lim closed 3 years ago

Jaeyoung-Lim commented 3 years ago

Problem Description When running trying to process a log, the log is passed as an absolute path, which just adds inconvenience of typing more of the path

$ python3 Tools/parametric_model/generate_parametric_model.py quad_plane_model logs/586524-01-/07_26_36.ulg 
Traceback (most recent call last):
  File "Tools/parametric_model/generate_parametric_model.py", line 38, in <module>
    start_model_estimation(arg_list)
  File "Tools/parametric_model/generate_parametric_model.py", line 21, in start_model_estimation
    quadPlaneModel = QuadPlaneModel(rel_ulog_path)
  File "/home/jaeyoung/dev/data-driven-dynamics/Tools/parametric_model/src/models/quad_plane_model.py", line 33, in __init__
    super(QuadPlaneModel, self).__init__(rel_ulog_path, req_topic_dict)
  File "/home/jaeyoung/dev/data-driven-dynamics/Tools/parametric_model/src/models/dynamics_model.py", line 19, in __init__
    self.ulog = load_ulog(rel_ulog_path)
  File "/home/jaeyoung/dev/data-driven-dynamics/Tools/parametric_model/src/tools/ulog_tools.py", line 15, in load_ulog
    ulog = core.ULog(log_file_path)
  File "/home/jaeyoung/.local/lib/python3.8/site-packages/pyulog/core.py", line 134, in __init__
    self._load_file(log_file, message_name_filter_list)
  File "/home/jaeyoung/.local/lib/python3.8/site-packages/pyulog/core.py", line 512, in _load_file
    self._file_handle = open(log_file, "rb")
FileNotFoundError: [Errno 2] No such file or directory: '/home/jaeyoung/logs/586524-01-/07_26_36.ulg'

Expected Behavior Be able to use relative paths since the logs directory is a symbolic link inside the repository

manumerous commented 3 years ago

As can be seen here we actually pass the log as a relative path and then in the function automatically uses the current working directory to generate the needed absolute path to interface with the pyulog library to load the ulog. Not sure if it is possible to pass a relative path to the library.

As far as I know the os.getcwd() function gets the current working directory from an environmental variable. Could it be that you somewhere change this variable in your process to /home/jaeyoung? As far as I know we should not expect a different behaviour of this method between ubuntu 20.04 and 18.04.

Furthermore I have tried to run the application without the virtual environment and it still works for me. So we can exclude that as a source of the error.

Jaeyoung-Lim commented 3 years ago

@manumerous I have always been running the script from the root of the repo (never cd-ing into the parametric_model directory).

Does it work for you this way? Can you also not reproduce it when using the docker environment?

manumerous commented 3 years ago

The problem is that currently the code takes the current working directory, goes back two directories and then searches the logs relative from there. As can be seen in code.

Therefore it fails when the python script is run using the Makefile, because the project directory will be the current working directory.

In contrast it works when directly calling the script using e.g. python3 generate_parametric_model.py simple_quadrotor_model logs/2021-04-12/14_28_28.ulg, because in that case the current working directory will always be the directory where generate_parametric_model.py is in regardless from where the script is called.

I guess we should either converge on one way of running the script or adapt load_ulog() to check for this. I think it would be good to do the latter anyways. But the former also makes sense.

Jaeyoung-Lim commented 3 years ago

@manumerous Okay now it makes more sense.

The script is assuming that the "current" directory is somewhere in the project. While it should always take the relative directory to where the user is running the directory (unless it is an absolute path).

Therefore, a more correct path is

python3 generate_parametric_model.py simple_quadrotor_model ../../logs/2021-04-12/14_28_28.ulg

Since the logs directory is not under the parametric_model directory