diff --git a/README.md b/README.md index b661a47b0..9fbb7d2f1 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ import numpy as np psf = kb.PSF(1.5) # Create fake data with ten 512x512 pixel images and starting at MJD of 57130.2. -from kbmod.fake_data_creator import * +from kbmod.fake_data.fake_data_creator import * fake_times = create_fake_times(10, t0=57130.2) ds = FakeDataSet(512, 512, fake_times) imgs = ds.stack.get_images() diff --git a/notebooks/create_fake_data.ipynb b/notebooks/create_fake_data.ipynb index 6973c51e2..d64ea33ac 100644 --- a/notebooks/create_fake_data.ipynb +++ b/notebooks/create_fake_data.ipynb @@ -17,7 +17,7 @@ "source": [ "import os\n", "\n", - "from kbmod.fake_data_creator import *\n", + "from kbmod.fake_data.fake_data_creator import *\n", "from kbmod.search import *" ] }, diff --git a/src/kbmod/fake_orbits/__init__.py b/src/kbmod/fake_data/__init__.py similarity index 100% rename from src/kbmod/fake_orbits/__init__.py rename to src/kbmod/fake_data/__init__.py diff --git a/src/kbmod/fake_data_creator.py b/src/kbmod/fake_data/fake_data_creator.py similarity index 100% rename from src/kbmod/fake_data_creator.py rename to src/kbmod/fake_data/fake_data_creator.py diff --git a/src/kbmod/fake_orbits/insert_fake_orbit.py b/src/kbmod/fake_data/insert_fake_orbit.py similarity index 100% rename from src/kbmod/fake_orbits/insert_fake_orbit.py rename to src/kbmod/fake_data/insert_fake_orbit.py diff --git a/src/kbmod/fake_orbits/pyoorb_helper.py b/src/kbmod/fake_data/pyoorb_helper.py similarity index 100% rename from src/kbmod/fake_orbits/pyoorb_helper.py rename to src/kbmod/fake_data/pyoorb_helper.py diff --git a/tests/manual_test_fake_orbits.py b/tests/manual_test_fake_orbits.py index ff0678aec..9f0212cc1 100644 --- a/tests/manual_test_fake_orbits.py +++ b/tests/manual_test_fake_orbits.py @@ -10,8 +10,8 @@ import kbmod.search as kb from kbmod.configuration import SearchConfiguration -from kbmod.fake_orbits.insert_fake_orbit import insert_fake_orbit_into_work_unit -from kbmod.fake_orbits.pyoorb_helper import PyoorbOrbit +from kbmod.fake_data.insert_fake_orbit import insert_fake_orbit_into_work_unit +from kbmod.fake_data.pyoorb_helper import PyoorbOrbit from kbmod.work_unit import WorkUnit # Set the image parameters. diff --git a/tests/test_analysis_utils.py b/tests/test_analysis_utils.py index 506202de0..fcd1225ee 100644 --- a/tests/test_analysis_utils.py +++ b/tests/test_analysis_utils.py @@ -1,7 +1,7 @@ import unittest from kbmod.analysis_utils import * -from kbmod.fake_data_creator import add_fake_object +from kbmod.fake_data.fake_data_creator import FakeDataSet from kbmod.result_list import * from kbmod.search import * from kbmod.trajectory_utils import make_trajectory @@ -85,21 +85,20 @@ def setUp(self): # image properties self.img_count = 10 - self.dim_x = 15 - self.dim_y = 20 - self.noise_level = 1.0 - self.variance = self.noise_level**2 - self.p = PSF(0.5) - - # create image set with single moving object - self.imlist = [] - self.time_list = [] - for i in range(self.img_count): - time = i / self.img_count - self.time_list.append(time) - im = LayeredImage(self.dim_x, self.dim_y, self.noise_level, self.variance, time, self.p, i) - self.imlist.append(im) - self.stack = ImageStack(self.imlist) + self.dim_x = 100 + self.dim_y = 100 + + # Create fake images. + self.time_list = [i / self.img_count for i in range(self.img_count)] + self.fake_ds = FakeDataSet( + self.dim_x, + self.dim_y, + self.time_list, + noise_level=1.0, + psf_val=0.5, + use_seed=True, + ) + self.stack = self.fake_ds.stack # Set up old_results object for analysis_utils.PostProcess self.num_curves = 4 @@ -179,21 +178,12 @@ def test_load_and_filter_results_lh(self): make_trajectory(60, 60, 0, 0, 1.0, 1.0, self.img_count), ] - # Create fake images with the objects in them. - imlist = [] - for i in range(self.img_count): - t = self.time_list[i] - im = LayeredImage(100, 100, self.noise_level, self.variance, t, self.p, i) - - # Add the objects. - for j, trj in enumerate(trjs): - add_fake_object(im, trj.x, trj.y, trj.flux, self.p) - - # Append the image. - imlist.append(im) + # Add a fake object to the fake images. + for trj in trjs: + self.fake_ds.insert_object(trj) # Create the stack search and insert the fake results. - search = StackSearch(ImageStack(imlist)) + search = StackSearch(self.fake_ds.stack) search.set_results(trjs) # Do the filtering. diff --git a/tests/test_bilinear_interp.py b/tests/test_bilinear_interp.py index b2d02d338..cfe1f20f3 100644 --- a/tests/test_bilinear_interp.py +++ b/tests/test_bilinear_interp.py @@ -2,7 +2,7 @@ import numpy as np -from kbmod.fake_data_creator import add_fake_object +from kbmod.fake_data.fake_data_creator import add_fake_object import kbmod.search as kb diff --git a/tests/test_data_interface.py b/tests/test_data_interface.py index 200f573a8..cac15c8e4 100644 --- a/tests/test_data_interface.py +++ b/tests/test_data_interface.py @@ -10,7 +10,7 @@ load_input_from_file, load_input_from_individual_files, ) -from kbmod.fake_data_creator import create_fake_times, FakeDataSet +from kbmod.fake_data.fake_data_creator import create_fake_times, FakeDataSet from kbmod.search import * from kbmod.work_unit import WorkUnit from utils.utils_for_tests import get_absolute_data_path diff --git a/tests/test_end_to_end.py b/tests/test_end_to_end.py index 6b25b638b..5d8705b98 100644 --- a/tests/test_end_to_end.py +++ b/tests/test_end_to_end.py @@ -4,7 +4,7 @@ import tempfile import unittest -from kbmod.fake_data_creator import * +from kbmod.fake_data.fake_data_creator import * from kbmod.run_search import * from kbmod.search import * from kbmod.trajectory_utils import make_trajectory diff --git a/tests/test_fake_data_creator.py b/tests/test_fake_data_creator.py index 78a51b9b8..0ca5188fa 100644 --- a/tests/test_fake_data_creator.py +++ b/tests/test_fake_data_creator.py @@ -2,7 +2,7 @@ import tempfile import unittest -from kbmod.fake_data_creator import * +from kbmod.fake_data.fake_data_creator import * from kbmod.file_utils import * from kbmod.search import * from kbmod.work_unit import WorkUnit diff --git a/tests/test_image_stack.py b/tests/test_image_stack.py index 0f8991146..64706bf3d 100644 --- a/tests/test_image_stack.py +++ b/tests/test_image_stack.py @@ -1,7 +1,7 @@ import tempfile import unittest -from kbmod.fake_data_creator import add_fake_object +from kbmod.fake_data.fake_data_creator import add_fake_object from kbmod.search import * diff --git a/tests/test_layered_image.py b/tests/test_layered_image.py index e29f857f9..dbc1633dc 100644 --- a/tests/test_layered_image.py +++ b/tests/test_layered_image.py @@ -4,7 +4,7 @@ from astropy.io import fits -from kbmod.fake_data_creator import add_fake_object +from kbmod.fake_data.fake_data_creator import add_fake_object from kbmod.search import * diff --git a/tests/test_readme_example.py b/tests/test_readme_example.py index 4da0759bf..6c2614e5c 100644 --- a/tests/test_readme_example.py +++ b/tests/test_readme_example.py @@ -3,7 +3,7 @@ import numpy as np import kbmod.search as kb -from kbmod.fake_data_creator import * +from kbmod.fake_data.fake_data_creator import * class test_readme_example(unittest.TestCase): diff --git a/tests/test_regression_test.py b/tests/test_regression_test.py index 56c099a6e..ad9c614c1 100644 --- a/tests/test_regression_test.py +++ b/tests/test_regression_test.py @@ -13,7 +13,7 @@ import numpy as np from astropy.io import fits -from kbmod.fake_data_creator import add_fake_object +from kbmod.fake_data.fake_data_creator import add_fake_object from kbmod.file_utils import * from kbmod.result_list import ResultList from kbmod.run_search import SearchRunner diff --git a/tests/test_search.py b/tests/test_search.py index c9d2739f1..8e6985d39 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -2,7 +2,7 @@ import numpy as np -from kbmod.fake_data_creator import add_fake_object +from kbmod.fake_data.fake_data_creator import add_fake_object from kbmod.search import * from kbmod.trajectory_utils import make_trajectory @@ -15,7 +15,7 @@ def setUp(self): self.flux_error = 0.15 # image properties - self.imCount = 20 + self.img_count = 20 self.dim_y = 80 self.dim_x = 60 self.noise_level = 4.0 @@ -38,7 +38,7 @@ def setUp(self): ) # Add convenience array of all true bools for the stamp tests. - self.all_valid = [True] * self.imCount + self.all_valid = [True] * self.img_count # search parameters self.angle_steps = 150 @@ -54,8 +54,8 @@ def setUp(self): # create image set with single moving object self.imlist = [] - for i in range(self.imCount): - time = i / self.imCount + for i in range(self.img_count): + time = i / self.img_count im = LayeredImage(self.dim_x, self.dim_y, self.noise_level, self.variance, time, self.p, i) add_fake_object( im, @@ -127,7 +127,7 @@ def test_results(self): self.max_angle, self.min_vel, self.max_vel, - int(self.imCount / 2), + int(self.img_count / 2), ) results = self.search.get_results(0, 10) @@ -150,7 +150,7 @@ def test_results_extended_bounds(self): self.max_angle, self.min_vel, self.max_vel, - int(self.imCount / 2), + int(self.img_count / 2), ) results = self.search.get_results(0, 10) @@ -173,7 +173,7 @@ def test_results_reduced_bounds(self): self.max_angle, self.min_vel, self.max_vel, - int(self.imCount / 2), + int(self.img_count / 2), ) results = self.search.get_results(0, 10) @@ -198,16 +198,12 @@ def test_set_sigmag_config(self): @unittest.skipIf(not HAS_GPU, "Skipping test (no GPU detected)") def test_results_off_chip(self): - trj = Trajectory() - trj.x = -3 - trj.y = 12 - trj.vx = 25.0 - trj.vy = 10.0 + trj = make_trajectory(x=-3, y=12, vx=25.0, vy=10.0) # Create images with this fake object. imlist = [] - for i in range(self.imCount): - time = i / self.imCount + for i in range(self.img_count): + time = i / self.img_count im = LayeredImage(self.dim_x, self.dim_y, self.noise_level, self.variance, time, self.p, i) add_fake_object( im, @@ -230,7 +226,7 @@ def test_results_off_chip(self): self.max_angle, self.min_vel, self.max_vel, - int(self.imCount / 2), + int(self.img_count / 2), ) # Check the results. @@ -243,10 +239,10 @@ def test_results_off_chip(self): def test_sci_viz_stamps(self): sci_stamps = StampCreator.get_stamps(self.search.get_imagestack(), self.trj, 2) - self.assertEqual(len(sci_stamps), self.imCount) + self.assertEqual(len(sci_stamps), self.img_count) times = self.stack.build_zeroed_times() - for i in range(self.imCount): + for i in range(self.img_count): self.assertEqual(sci_stamps[i].width, 5) self.assertEqual(sci_stamps[i].height, 5) @@ -271,7 +267,7 @@ def test_stacked_sci(self): # Compute the true stacked pixel for the middle of the track. times = self.stack.build_zeroed_times() sum_middle = 0.0 - for i in range(self.imCount): + for i in range(self.img_count): t = times[i] x = int(self.trj.x + self.trj.vx * t) y = int(self.trj.y + self.trj.vy * t) @@ -286,7 +282,7 @@ def test_stacked_sci(self): def test_median_stamps_trj(self): # Compute the stacked science from two trajectories (one with bad points). - goodIdx = [[1] * self.imCount for _ in range(2)] + goodIdx = [[1] * self.img_count for _ in range(2)] goodIdx[1][1] = 0 goodIdx[1][5] = 0 goodIdx[1][9] = 0 @@ -303,7 +299,7 @@ def test_median_stamps_trj(self): times = self.stack.build_zeroed_times() pix_values0 = [] pix_values1 = [] - for i in range(self.imCount): + for i in range(self.img_count): t = times[i] x = int(self.trj.x + self.trj.vx * t) y = int(self.trj.y + self.trj.vy * t) @@ -312,8 +308,8 @@ def test_median_stamps_trj(self): pix_values0.append(pixVal) if pixVal != KB_NO_DATA and goodIdx[1][i] == 1: pix_values1.append(pixVal) - self.assertEqual(len(pix_values0), self.imCount) - self.assertEqual(len(pix_values1), self.imCount - 3) + self.assertEqual(len(pix_values0), self.img_count) + self.assertEqual(len(pix_values1), self.img_count - 3) # Check that we get the correct answer. self.assertAlmostEqual(np.median(pix_values0), medianStamps0.get_pixel(2, 2), delta=1e-5) @@ -321,11 +317,7 @@ def test_median_stamps_trj(self): def test_median_stamps_no_data(self): # Create a Trajectory that goes through the masked pixels. - trj = Trajectory() - trj.x = self.masked_x - trj.y = self.masked_y - trj.vx = 0 - trj.vy = 0 + trj = make_trajectory(x=self.masked_x, y=self.masked_y, vx=0.0, vy=0.0) # Compute the stacked science from a single Trajectory. medianStamp = StampCreator.get_median_stamp(self.search.get_imagestack(), trj, 2, self.all_valid) @@ -334,18 +326,18 @@ def test_median_stamps_no_data(self): # Compute the true median pixel for the middle of the track. pix_values = [] - for i in range(self.imCount): + for i in range(self.img_count): pixVal = self.imlist[i].get_science().get_pixel(self.masked_y, self.masked_x) if pixVal != KB_NO_DATA: pix_values.append(pixVal) - self.assertEqual(len(pix_values), self.imCount / 2) + self.assertEqual(len(pix_values), self.img_count / 2) # Check that we get the correct answer. self.assertAlmostEqual(np.median(pix_values), medianStamp.get_pixel(2, 2), delta=1e-5) def test_mean_stamps_trj(self): # Compute the stacked science from two trajectories (one with bad points). - goodIdx = [[1] * self.imCount for _ in range(2)] + goodIdx = [[1] * self.img_count for _ in range(2)] goodIdx[1][1] = 0 goodIdx[1][5] = 0 goodIdx[1][9] = 0 @@ -364,7 +356,7 @@ def test_mean_stamps_trj(self): pix_sum1 = 0.0 pix_count0 = 0.0 pix_count1 = 0.0 - for i in range(self.imCount): + for i in range(self.img_count): t = times[i] x = int(self.trj.x + self.trj.vx * t) y = int(self.trj.y + self.trj.vy * t) @@ -375,8 +367,8 @@ def test_mean_stamps_trj(self): if pixVal != KB_NO_DATA and goodIdx[1][i] == 1: pix_sum1 += pixVal pix_count1 += 1 - self.assertEqual(pix_count0, self.imCount) - self.assertEqual(pix_count1, self.imCount - 3) + self.assertEqual(pix_count0, self.img_count) + self.assertEqual(pix_count1, self.img_count - 3) # Check that we get the correct answer. self.assertAlmostEqual(pix_sum0 / pix_count0, meanStamp0.get_pixel(2, 2), delta=1e-5) @@ -394,12 +386,12 @@ def test_mean_stamps_no_data(self): # Compute the true median pixel for the middle of the track. pix_sum = 0.0 pix_count = 0.0 - for i in range(self.imCount): + for i in range(self.img_count): pixVal = self.imlist[i].get_science().get_pixel(self.masked_y, self.masked_x) if pixVal != KB_NO_DATA: pix_sum += pixVal pix_count += 1.0 - self.assertEqual(pix_count, self.imCount / 2.0) + self.assertEqual(pix_count, self.img_count / 2.0) # Check that we get the correct answer. self.assertAlmostEqual(pix_sum / pix_count, meanStamp.get_pixel(2, 2), delta=1e-5) @@ -478,11 +470,7 @@ def test_coadd_cpu_simple(self): all_valid = [True, True, True] # convenience array # One Trajectory right in the image's middle. - trj = Trajectory() - trj.x = 1 - trj.y = 1 - trj.vx = 0 - trj.vy = 0 + trj = make_trajectory(x=1, y=1, vx=0.0, vy=0.0) # Basic Stamp parameters. params = StampParameters() @@ -538,11 +526,7 @@ def test_coadd_gpu_simple(self): all_valid = [True, True, True] # convenience array # One Trajectory right in the image's middle. - trj = Trajectory() - trj.x = 1 - trj.y = 1 - trj.vx = 0 - trj.vy = 0 + trj = make_trajectory(x=1, y=1, vx=0.0, vy=0.0) # Basic Stamp parameters. params = StampParameters() @@ -607,7 +591,7 @@ def test_coadd_cpu(self): pix_sum = 0.0 pix_count = 0.0 pix_vals = [] - for i in range(self.imCount): + for i in range(self.img_count): t = times[i] x = int(self.trj.x + self.trj.vx * t) + x_offset y = int(self.trj.y + self.trj.vy * t) + y_offset @@ -664,7 +648,7 @@ def test_coadd_gpu(self): pix_sum = 0.0 pix_count = 0.0 pix_vals = [] - for i in range(self.imCount): + for i in range(self.img_count): t = times[i] x = int(self.trj.x + self.trj.vx * t) + x_offset y = int(self.trj.y + self.trj.vy * t) + y_offset @@ -690,7 +674,7 @@ def test_coadd_cpu_use_inds(self): params.stamp_type = StampType.STAMP_MEAN # Mark a few of the observations as "do not use" - inds = [[True] * self.imCount, [True] * self.imCount] + inds = [[True] * self.img_count, [True] * self.img_count] inds[0][5] = False inds[1][3] = False inds[1][6] = False @@ -713,7 +697,7 @@ def test_coadd_cpu_use_inds(self): sum_1 = 0.0 count_0 = 0.0 count_1 = 0.0 - for i in range(self.imCount): + for i in range(self.img_count): t = times[i] x = int(self.trj.x + self.trj.vx * t) + x_offset y = int(self.trj.y + self.trj.vy * t) + y_offset @@ -741,7 +725,7 @@ def test_coadd_gpu_use_inds(self): params.stamp_type = StampType.STAMP_MEAN # Mark a few of the observations as "do not use" - inds = [[True] * self.imCount, [True] * self.imCount] + inds = [[True] * self.img_count, [True] * self.img_count] inds[0][5] = False inds[1][3] = False inds[1][6] = False @@ -764,7 +748,7 @@ def test_coadd_gpu_use_inds(self): sum_1 = 0.0 count_0 = 0.0 count_1 = 0.0 - for i in range(self.imCount): + for i in range(self.img_count): t = times[i] x = int(self.trj.x + self.trj.vx * t) + x_offset y = int(self.trj.y + self.trj.vy * t) + y_offset diff --git a/tests/test_search_encode.py b/tests/test_search_encode.py index 168770d1a..c7456cef0 100644 --- a/tests/test_search_encode.py +++ b/tests/test_search_encode.py @@ -2,7 +2,7 @@ import numpy as np -from kbmod.fake_data_creator import FakeDataSet +from kbmod.fake_data.fake_data_creator import FakeDataSet from kbmod.search import * from kbmod.trajectory_utils import make_trajectory diff --git a/tests/test_search_filter.py b/tests/test_search_filter.py index 0ed248f9f..8de4c232a 100644 --- a/tests/test_search_filter.py +++ b/tests/test_search_filter.py @@ -2,7 +2,7 @@ import numpy as np -from kbmod.fake_data_creator import FakeDataSet +from kbmod.fake_data.fake_data_creator import FakeDataSet from kbmod.search import * from kbmod.trajectory_utils import make_trajectory diff --git a/tests/test_stamp_filters.py b/tests/test_stamp_filters.py index 829326251..174872a2e 100644 --- a/tests/test_stamp_filters.py +++ b/tests/test_stamp_filters.py @@ -2,7 +2,7 @@ import unittest from kbmod.configuration import SearchConfiguration -from kbmod.fake_data_creator import add_fake_object, create_fake_times, FakeDataSet +from kbmod.fake_data.fake_data_creator import add_fake_object, create_fake_times, FakeDataSet from kbmod.filters.stamp_filters import * from kbmod.result_list import * from kbmod.search import * diff --git a/tests/test_stamp_parity.py b/tests/test_stamp_parity.py index 2844af2e7..cfe709326 100644 --- a/tests/test_stamp_parity.py +++ b/tests/test_stamp_parity.py @@ -8,7 +8,7 @@ import numpy as np -from kbmod.fake_data_creator import FakeDataSet +from kbmod.fake_data.fake_data_creator import FakeDataSet from kbmod.search import * from kbmod.trajectory_utils import make_trajectory diff --git a/tests/test_work_unit.py b/tests/test_work_unit.py index 62e0716e8..e3583383e 100644 --- a/tests/test_work_unit.py +++ b/tests/test_work_unit.py @@ -9,7 +9,7 @@ import warnings from kbmod.configuration import SearchConfiguration -from kbmod.fake_data_creator import make_fake_wcs_info +from kbmod.fake_data.fake_data_creator import make_fake_wcs_info import kbmod.search as kb from kbmod.work_unit import hdu_to_raw_image, raw_image_to_hdu, WorkUnit