Create Fake Data#
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.
[1]:
import os
from kbmod.fake_data_creator import *
from kbmod.search import *
Create a fake stack of images#
[2]:
# Set the characteristics of the fake data.
img_width = 256
img_height = 256
num_times = 20
# Create the fake images
ds = FakeDataSet(img_width, img_height, num_times)
Insert a fake moving object#
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.
[3]:
trj = ds.insert_random_object(500)
print(f"x={trj.x}, y={trj.y}, xv={trj.x_v}, yv={trj.y_v}")
x=145, y=133, xv=-12.479201316833496, yv=7.321131229400635
We can print the object’s location at each time step.
[4]:
# Check the object was inserted correctly.
t0 = ds.stack.get_single_image(0).get_time()
for i in range(ds.stack.img_count()):
ti = ds.stack.get_single_image(i).get_time()
dt = ti - t0
px = int(trj.x + dt * trj.x_v + 0.5)
py = int(trj.y + dt * trj.y_v + 0.5)
print(f"{i}: t={ti:.3f} at ({px}, {py})")
0: t=0.000 at (145, 133)
1: t=0.010 at (145, 133)
2: t=0.020 at (145, 133)
3: t=1.000 at (133, 140)
4: t=1.010 at (132, 140)
5: t=1.020 at (132, 140)
6: t=2.000 at (120, 148)
7: t=2.010 at (120, 148)
8: t=2.020 at (120, 148)
9: t=3.000 at (108, 155)
10: t=3.010 at (107, 155)
11: t=3.020 at (107, 155)
12: t=4.000 at (95, 162)
13: t=4.010 at (95, 162)
14: t=4.020 at (95, 162)
15: t=5.000 at (83, 170)
16: t=5.010 at (82, 170)
17: t=5.020 at (82, 170)
18: t=6.000 at (70, 177)
19: t=6.010 at (70, 177)
Save the fake image files#
We save the fake images to a given base directory.
[5]:
dir_path = "./fake_data"
ds.save_fake_data(dir_path)
print(os.listdir(dir_path))
['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']
Delete the fake data files.#
We can (optionally) delete the fake data files using the delete_fake_data() function.
[6]:
ds.delete_fake_data(dir_path)
print(os.listdir(dir_path))
[]
[ ]: