diff --git a/rocketpy/simulation/flight_data_importer.py b/rocketpy/simulation/flight_data_importer.py index 58b03f52f..543d28866 100644 --- a/rocketpy/simulation/flight_data_importer.py +++ b/rocketpy/simulation/flight_data_importer.py @@ -30,7 +30,6 @@ "latitude": "Latitude (deg)", "longitude": "Longitude (deg)", "mach_number": "Mach number", - "name": "Time (s)", "speed": "Speed (m/s)", "stability_margin": "Stability margin", "static_margin": "Static margin", @@ -47,15 +46,8 @@ class FlightDataImporter: - """A class to create a rocketpy.Flight object from a .csv file. The data - frame must contain a time column in seconds. - - There are different ways of calculating a property from the data frame. - 1. The property is already in data frame and you want to use it as is - 2. The property is not in the data frame but you can calculate it from - other properties in the data frame. - - Initially, this class is designed to work with the option '1.' + """A class used to import flight data from a .csv or .txt file and build an + equivalent Flight object. """ def __init__( @@ -66,7 +58,7 @@ def __init__( units=None, interpolation="linear", extrapolation="zero", - separator=",", + delimiter=",", encoding="utf-8", ): """Initializes the FlightDataImporter class. @@ -75,15 +67,21 @@ def __init__( ---------- name : str The name of the FlightDataImporter object. - paths : list - A list of paths or strings representing the file paths or directories - containing the flight data files. Only .csv and .txt files are supported. + paths : str, list + A string with a path to a folder or file, or a list of strings + representing the file paths or directories containing the flight + data files. Only .csv and .txt files are supported. columns_map : dict, optional A dictionary mapping column names to desired column names. - Defaults to None, which will keep the original column names. + Defaults to None, which will keep the original column names. The + dictionary keys must be the original column names and the values + must be the desired column names. units : dict, optional A dictionary mapping column names to desired units. Defaults to None, which will consider that all the data is in SI. + The dictionary keys must be the original column names and the + values must be the units of the data in the column. There is no need + to specify the units for a column that is already in SI. interpolation : str, optional The interpolation method to use for missing data. Defaults to "linear", see rocketpy.mathutils.Function for more @@ -92,8 +90,8 @@ def __init__( The extrapolation method to use for data outside the range. Defaults to "zero", see rocketpy.mathutils.Function for more information. - separator : str, optional - The separator used in the data file. Defaults to ",". + delimiter : str, optional + The delimiter used in the data file. Defaults to ",". encoding : str, optional The encoding of the data file. Defaults to "utf-8". @@ -113,7 +111,7 @@ def __init__( self._time_cols = {} self._original_columns = {} self._data = {} - self._separators = {} + self._delimiters = {} self._encodings = {} self._files = None @@ -124,7 +122,7 @@ def __init__( units, interpolation, extrapolation, - separator, + delimiter, encoding, ) @@ -157,7 +155,7 @@ def __reveal_files(self, path): return [join(path, f) for f in listdir(path) if isfile(join(path, f))] - def __handle_dataset(self, filepath, separator, encoding): + def __handle_dataset(self, filepath, delimiter, encoding): """Reads the data from the specified file and stores it in the appropriate attributes. @@ -166,14 +164,14 @@ def __handle_dataset(self, filepath, separator, encoding): filepath : str The path to the file we are reading from. This should be either a .csv or .txt file. - separator : str - The separator used in the data file. + delimiter : str + The delimiter used in the data file. encoding : str The encoding of the data file. """ raw_data = np.genfromtxt( filepath, - delimiter=separator, + delimiter=delimiter, encoding=encoding, dtype=np.float64, names=True, @@ -321,7 +319,7 @@ def read_data( units=None, interpolation="linear", extrapolation="zero", - separator=",", + delimiter=",", encoding="utf-8", ): """Reads flight data from the specified paths. @@ -345,8 +343,8 @@ def read_data( The extrapolation method to use for data outside the range. Defaults to "zero", see rocketpy.mathutils.Function for more information. - separator : str, optional - The separator used in the data file. Defaults to ",". + delimiter : str, optional + The delimiter used in the data file. Defaults to ",". encoding : str, optional The encoding of the data file. Defaults to "utf-8". @@ -358,7 +356,7 @@ def read_data( ----- This method handles multiple files within the same path and processes each of them. It reads the data, applies the specified interpolation and - extrapolation methods, and sets the appropriate encoding and separator. + extrapolation methods, and sets the appropriate encoding and delimiter. """ # We need to handle multiple files within the same path if isinstance(paths, str): @@ -376,8 +374,8 @@ def read_data( self._units[filepath] = units self._columns_map[filepath] = columns_map self._encodings[filepath] = encoding - self._separators[filepath] = separator - self.__handle_dataset(filepath, separator, encoding) + self._delimiters[filepath] = delimiter + self.__handle_dataset(filepath, delimiter, encoding) self.__define_time_column(filepath) self.__create_attributes(filepath, interpolation, extrapolation) diff --git a/tests/test_flight_data_importer.py b/tests/test_flight_data_importer.py index 814d3bd56..9ce4e34ce 100644 --- a/tests/test_flight_data_importer.py +++ b/tests/test_flight_data_importer.py @@ -21,7 +21,7 @@ def test_flight_importer_bella_lui(): units=None, interpolation="linear", extrapolation="zero", - separator=",", + delimiter=",", encoding="utf-8", ) assert fd.name == "Bella Lui, EPFL Rocket Team, 2020"