{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Create Fake Data\n", "**Warning**: For the purposes this example we create (and possibly delete) a data directory at base_dir/fake_data. If that directory already exists, this notebook may overwrite the contents." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "from kbmod.fake_data_creator import *\n", "from kbmod.search import *" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Create a fake stack of images" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Set the characteristics of the fake data.\n", "img_width = 256\n", "img_height = 256\n", "num_times = 20\n", "\n", "# Create the fake images\n", "ds = FakeDataSet(img_width, img_height, num_times)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Insert a fake moving object\n", "\n", "This function creates a random moving object with a given flux that stays within the image for the entire time. The trajectory is defined by starting pixels (x, y) and velocities (x_v, y_v) of pixels per day." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "x=145, y=133, xv=-12.479201316833496, yv=7.321131229400635\n" ] } ], "source": [ "trj = ds.insert_random_object(500)\n", "print(f\"x={trj.x}, y={trj.y}, xv={trj.x_v}, yv={trj.y_v}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can print the object's location at each time step." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0: t=0.000 at (145, 133)\n", "1: t=0.010 at (145, 133)\n", "2: t=0.020 at (145, 133)\n", "3: t=1.000 at (133, 140)\n", "4: t=1.010 at (132, 140)\n", "5: t=1.020 at (132, 140)\n", "6: t=2.000 at (120, 148)\n", "7: t=2.010 at (120, 148)\n", "8: t=2.020 at (120, 148)\n", "9: t=3.000 at (108, 155)\n", "10: t=3.010 at (107, 155)\n", "11: t=3.020 at (107, 155)\n", "12: t=4.000 at (95, 162)\n", "13: t=4.010 at (95, 162)\n", "14: t=4.020 at (95, 162)\n", "15: t=5.000 at (83, 170)\n", "16: t=5.010 at (82, 170)\n", "17: t=5.020 at (82, 170)\n", "18: t=6.000 at (70, 177)\n", "19: t=6.010 at (70, 177)\n" ] } ], "source": [ "# Check the object was inserted correctly.\n", "t0 = ds.stack.get_single_image(0).get_time()\n", "for i in range(ds.stack.img_count()):\n", " ti = ds.stack.get_single_image(i).get_time()\n", " dt = ti - t0\n", " px = int(trj.x + dt * trj.x_v + 0.5)\n", " py = int(trj.y + dt * trj.y_v + 0.5)\n", "\n", " print(f\"{i}: t={ti:.3f} at ({px}, {py})\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Save the fake image files\n", "\n", "We save the fake images to a given base directory." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['000000.fits', '000001.fits', '000002.fits', '000003.fits', '000004.fits', '000005.fits', '000006.fits', '000007.fits', '000008.fits', '000009.fits', '000010.fits', '000011.fits', '000012.fits', '000013.fits', '000014.fits', '000015.fits', '000016.fits', '000017.fits', '000018.fits', '000019.fits']\n" ] } ], "source": [ "dir_path = \"./fake_data\"\n", "ds.save_fake_data(dir_path)\n", "print(os.listdir(dir_path))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Delete the fake data files.\n", "\n", "We can (optionally) delete the fake data files using the delete_fake_data() function." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[]\n" ] } ], "source": [ "ds.delete_fake_data(dir_path)\n", "print(os.listdir(dir_path))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python (.conda-kbmod)", "language": "python", "name": "conda-env-.conda-kbmod-py" }, "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.9.15" } }, "nbformat": 4, "nbformat_minor": 4 }