mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/SPATZ.git
synced 2025-06-10 01:55:59 +00:00
273 lines
7.9 KiB
Plaintext
273 lines
7.9 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Preprocess the data"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Next, we need to transform our simulation data into .csv files containing the data we need for our simulations. We can do that using the `preprocess_file` function in the file `preprocess.py`."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import os\n",
|
|
"import shutil\n",
|
|
"\n",
|
|
"from spatz.utils.preprocess import preprocess_file\n",
|
|
"\n",
|
|
"\n",
|
|
"PATH = 'data/simulations/'\n",
|
|
"\n",
|
|
"# Delete the old folder of preprocessed files.\n",
|
|
"if os.path.isdir(PATH + 'temp/'):\n",
|
|
" shutil.rmtree(PATH + 'temp/')\n",
|
|
"\n",
|
|
"# Create the folder again.\n",
|
|
"os.mkdir(PATH + 'temp/')\n",
|
|
"\n",
|
|
"# Preprocess the files.\n",
|
|
"for file in os.listdir(PATH):\n",
|
|
" if not os.path.isdir(PATH + file) and '.txt' in file:\n",
|
|
" df = preprocess_file(PATH + file)\n",
|
|
" df.to_csv(PATH + 'temp/' + file.replace('.txt', '.csv'))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Setup the simulation"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"First we have to create a simulation instance and specify how we want to iterate through the simulation. We choose to sample data every 0.1 seconds.\n",
|
|
"\n",
|
|
"In addition, there is the option to add delays in the sampling by adding Gaussian noise to the sampling rate. In this case data might be sampled after 0.1 + noise seconds."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from spatz.simulation import Simulation, UniformTimeSteps\n",
|
|
"\n",
|
|
"# Construct a time model.\n",
|
|
"timesteps = UniformTimeSteps(0.1, mu=0, sigma=0, delay_only=True)\n",
|
|
"\n",
|
|
"# Construct a simulation instance with the time model.\n",
|
|
"simulation = Simulation(timesteps)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Next, we need to specify the sensors we are using. For this demo we are using the sensors used by Aquila's CAPUT v4. We call `simulation.add_sensor` with the sensor class as an argument to register and create a sensor for the simulation. This allows the sensor to fetch the data."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from spatz.sensors.imu.wsen_isds import WSEN_ISDS_ACC, WSEN_ISDS_GYRO\n",
|
|
"from spatz.sensors.pressure.ms5611_01ba03 import MS5611_01BA03\n",
|
|
"\n",
|
|
"press_sensor = simulation.add_sensor(MS5611_01BA03)\n",
|
|
"\n",
|
|
"# Use the offset argument to change the position of the imu in relation to the rocket's center of gravity.\n",
|
|
"accelerometer = simulation.add_sensor(WSEN_ISDS_ACC, offset=0)\n",
|
|
"gyro = simulation.add_sensor(WSEN_ISDS_GYRO, offset=0)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Run the simulation"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"With everything set up, we can load the dataset we want to explore."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"<spatz.simulation.Simulation at 0x22239a355d0>"
|
|
]
|
|
},
|
|
"execution_count": 4,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"simulation.load(PATH + 'temp/' + '7km.csv')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"The simulation class has a function `run` which allows us to loop through every time step. The returned values are the index of the current step, the time of the current step and the change in time since the last time step.\n",
|
|
"\n",
|
|
"In each iteration we can call the sensors like functions to obtain the measurements at the current time steps. Please note that calling sensors multiple times at the same time steps may result in different measurements."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"ename": "ModuleNotFoundError",
|
|
"evalue": "No module named 'kalman'",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
|
"\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
|
|
"\u001b[1;32mc:\\Users\\Dario\\Documents\\Programmierung\\STA\\SPATZ\\demo.ipynb Cell 13\u001b[0m line \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> <a href='vscode-notebook-cell:/c%3A/Users/Dario/Documents/Programmierung/STA/SPATZ/demo.ipynb#X15sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mkalman\u001b[39;00m\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/Dario/Documents/Programmierung/STA/SPATZ/demo.ipynb#X15sZmlsZQ%3D%3D?line=3'>4</a>\u001b[0m logger \u001b[39m=\u001b[39m simulation\u001b[39m.\u001b[39mget_logger()\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/Dario/Documents/Programmierung/STA/SPATZ/demo.ipynb#X15sZmlsZQ%3D%3D?line=5'>6</a>\u001b[0m \u001b[39m# Set verbose to False to disable the progress bar\u001b[39;00m\n",
|
|
"\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'kalman'"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"logger = simulation.get_logger()\n",
|
|
"\n",
|
|
"# Set verbose to False to disable the progress bar\n",
|
|
"for step, t, dt in simulation.run(verbose=True):\n",
|
|
" # Get the sensor data for the current time\n",
|
|
" press = press_sensor()\n",
|
|
" acc = accelerometer()\n",
|
|
" rot_rate = gyro()\n",
|
|
"\n",
|
|
" # TODO: Add your computation here."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"df = logger.get_dataframe()\n",
|
|
"\n",
|
|
"df"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Do your research"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import matplotlib.pyplot as plt"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"plt.plot(df['time'][1:], df['mach/mach_no'][1:], label='mach number')\n",
|
|
"plt.plot(df['time'][1:], df['MS5611_01BA03/ts_effects'][1:], label='ts effects')\n",
|
|
"plt.show()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"plt.plot(df['mach/mach_no'][1:], df['MS5611_01BA03/ts_effects'][1:])\n",
|
|
"plt.show()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"plt.plot(df['time'][1:], df['MS5611_01BA03/pressure'][1:])\n",
|
|
"plt.show()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"plt.plot(df['time'], df['WSEN_ISDS/acc_x'], label='x')\n",
|
|
"plt.plot(df['time'], df['WSEN_ISDS/acc_y'], label='y')\n",
|
|
"plt.plot(df['time'], df['WSEN_ISDS/acc_z'], label='z')\n",
|
|
"plt.legend()\n",
|
|
"plt.show()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.10.4"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|