{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2\n", "# Preprocess\n", "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": "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": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Processed 65160 lines in 0.3s.\n", "Used 65160 lines due to step size\n" ] } ], "source": [ "#Setup Sensors / observers\n", "\n", "from spatz.sensors.antenna.tx_gain import AntennaTxGain\n", "\n", "altitude = simulation.add_observer(['altitude'])\n", "pitch = simulation.add_observer(['pitch_l'])\n", "\n", "antenna_tx_gain_sensor = simulation.add_sensor(AntennaTxGain,gain_pattern_path=f\"data/gain_pattern/farfield_tx_aisler_v1.txt\")\n", "\n", "simulation.load(PATH + 'temp/' + '13.5.csv')\n", "logger = simulation.get_logger()\n", "\n" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|█████████▉| 521.40000000005/521.469806781021 [00:17<00:00, 30.61it/s] \n" ] } ], "source": [ "# Run simulation\n", "for step, t, dt in simulation.run(verbose=True):\n", " # Get the sensor data for the current time\n", " gain = antenna_tx_gain_sensor()\n", " \n", " \n", " # Get the correct altitude data.\n", " altitude()\n", " pitch()\n", "\n", "df = logger.get_dataframe()\n", " " ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | time | \n", "antenna/tx_gain/rocket_x | \n", "antenna/tx_gain/rocket_y | \n", "antenna/tx_gain/rocket_z | \n", "antenna/tx_gain/pos_x | \n", "antenna/tx_gain/pos_y | \n", "antenna/tx_gain/pos_z | \n", "antenna/tx_gain/theta | \n", "antenna/tx_gain/out | \n", "general/altitude | \n", "general/pitch_l | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "0.0 | \n", "<NA> | \n", "<NA> | \n", "<NA> | \n", "<NA> | \n", "<NA> | \n", "<NA> | \n", "<NA> | \n", "<NA> | \n", "<NA> | \n", "<NA> | \n", "
1 | \n", "0.1 | \n", "-0.000002 | \n", "0.171335 | \n", "0.985213 | \n", "0.769262 | \n", "0.637524 | \n", "-0.04242 | \n", "93.866758 | \n", "-6.808 | \n", "319.189854 | \n", "1.396263 | \n", "
2 | \n", "0.2 | \n", "-0.000002 | \n", "0.171335 | \n", "0.985213 | \n", "0.769249 | \n", "0.637555 | \n", "-0.042179 | \n", "93.880686 | \n", "-6.808 | \n", "319.754649 | \n", "1.396263 | \n", "
3 | \n", "0.3 | \n", "-0.000002 | \n", "0.171335 | \n", "0.985213 | \n", "0.769228 | \n", "0.637607 | \n", "-0.041781 | \n", "93.903746 | \n", "-6.808 | \n", "320.689767 | \n", "1.396263 | \n", "
4 | \n", "0.4 | \n", "-0.000002 | \n", "0.171335 | \n", "0.985213 | \n", "0.769199 | \n", "0.637678 | \n", "-0.041227 | \n", "93.935798 | \n", "-6.808 | \n", "321.98961 | \n", "1.396263 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
5210 | \n", "521.0 | \n", "0.00204 | \n", "0.999997 | \n", "0.000922 | \n", "0.167176 | \n", "0.98588 | \n", "-0.009586 | \n", "170.473891 | \n", "-5.719 | \n", "321.436986 | \n", "0.000023 | \n", "
5211 | \n", "521.1 | \n", "0.00204 | \n", "0.999997 | \n", "0.000922 | \n", "0.167176 | \n", "0.98588 | \n", "-0.009633 | \n", "170.473719 | \n", "-5.719 | \n", "320.918266 | \n", "0.000023 | \n", "
5212 | \n", "521.2 | \n", "0.00204 | \n", "0.999997 | \n", "0.000922 | \n", "0.167176 | \n", "0.98588 | \n", "-0.009681 | \n", "170.473546 | \n", "-5.719 | \n", "320.399547 | \n", "0.000023 | \n", "
5213 | \n", "521.3 | \n", "0.00204 | \n", "0.999997 | \n", "0.000922 | \n", "0.167176 | \n", "0.985879 | \n", "-0.009729 | \n", "170.473373 | \n", "-5.719 | \n", "319.880828 | \n", "0.000023 | \n", "
10427 | \n", "521.4 | \n", "0.00204 | \n", "0.999997 | \n", "0.000922 | \n", "0.167176 | \n", "0.985879 | \n", "-0.009777 | \n", "170.473198 | \n", "-5.719 | \n", "319.362108 | \n", "0.000023 | \n", "
5215 rows × 11 columns
\n", "