{ "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": 13, "metadata": {}, "outputs": [], "source": [ "#Setup Sensors / observers\n", "\n", "from spatz.sensors.antenna.tx_gain import AntennaTxGain\n", "\n", "altitude = simulation.add_observer(['altitude'])\n", "latitude = simulation.add_observer(['latitude'])\n", "longitude = simulation.add_observer(['longitude'])\n", "\n", "x = simulation.add_observer(['x'])\n", "y = simulation.add_observer(['y'])\n", "z = simulation.add_observer(['z'])\n", "\n", "antenna_tx_gain_sensor = simulation.add_sensor(AntennaTxGain)\n", "\n", "simulation.load(PATH + 'temp/' + '13_5DrougeOnly.csv')\n", "logger = simulation.get_logger()\n", "\n" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|█████████▉| 299.9999999999997/300.0 [00:04<00:00, 70.82it/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", " latitude()\n", " longitude()\n", "\n", " x()\n", " y()\n", " z()" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | time | \n", "Generic Antenna TX/out | \n", "general/altitude | \n", "general/latitude | \n", "general/longitude | \n", "general/x | \n", "general/y | \n", "general/z | \n", "
---|---|---|---|---|---|---|---|---|
0 | \n", "0.0 | \n", "<NA> | \n", "<NA> | \n", "<NA> | \n", "<NA> | \n", "<NA> | \n", "<NA> | \n", "<NA> | \n", "
1 | \n", "0.1 | \n", "0 | \n", "319.189854 | \n", "1.184825 | \n", "0.367914 | \n", "0.0 | \n", "0.033017 | \n", "0.189854 | \n", "
2 | \n", "0.2 | \n", "0 | \n", "319.754649 | \n", "1.184825 | \n", "0.367914 | \n", "0.0 | \n", "0.131239 | \n", "0.754649 | \n", "
3 | \n", "0.3 | \n", "0 | \n", "320.689767 | \n", "1.184825 | \n", "0.367914 | \n", "0.0 | \n", "0.293862 | \n", "1.689767 | \n", "
4 | \n", "0.4 | \n", "0 | \n", "321.98961 | \n", "1.184825 | \n", "0.367914 | \n", "0.0 | \n", "0.519914 | \n", "2.98961 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
2996 | \n", "299.6 | \n", "0 | \n", "954.385196 | \n", "1.186267 | \n", "0.367917 | \n", "7.639079 | \n", "9218.178485 | \n", "628.737611 | \n", "
2997 | \n", "299.7 | \n", "0 | \n", "950.544731 | \n", "1.186267 | \n", "0.367917 | \n", "7.639903 | \n", "9218.177327 | \n", "624.897143 | \n", "
2998 | \n", "299.8 | \n", "0 | \n", "946.704266 | \n", "1.186267 | \n", "0.367917 | \n", "7.640726 | \n", "9218.176168 | \n", "621.056675 | \n", "
2999 | \n", "299.9 | \n", "0 | \n", "942.8638 | \n", "1.186267 | \n", "0.367917 | \n", "7.64155 | \n", "9218.175009 | \n", "617.216207 | \n", "
11999 | \n", "300.0 | \n", "0 | \n", "939.023335 | \n", "1.186267 | \n", "0.367917 | \n", "7.642373 | \n", "9218.17385 | \n", "613.37574 | \n", "
3001 rows × 8 columns
\n", "