Skip to content

Commit

Permalink
Merge pull request #25 from arjunsavel/test_utils_more
Browse files Browse the repository at this point in the history
test PCA
  • Loading branch information
arjunsavel authored Aug 18, 2024
2 parents cb5a94b + 525add0 commit 42dc315
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
58 changes: 58 additions & 0 deletions src/scope/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,61 @@ def test_cube_normalized_max_still_max(self):
)
def test_calc_limb_darkening(values, output):
assert calc_limb_darkening(*values) == output


class TestPca(unittest.TestCase):
"""
These don't really test the fancy statistics of PCA. just assert that it's a
variance-reducing black box.
"""

n_exp = 10
n_pix = 10
cube = np.random.random((n_exp, n_pix))

def test_perform_pca_shapes(self):
"""
just make sure the output shapes are what we expect.
"""

n_princ_comp = 5
scaled_cube, pca = perform_pca(self.cube, n_princ_comp, return_noplanet=True)
assert scaled_cube.shape == self.cube.shape
assert pca.shape == self.cube.shape

def test_perform_pca_variance_removed(self):
"""
just make sure the output shapes are what we expect.
"""

n_princ_comp = 5
scaled_cube, pca = perform_pca(self.cube, n_princ_comp, return_noplanet=True)
assert np.std(scaled_cube) < np.std(
pca
) # the variance should be contained in the main components

def test_perform_pca_variance_removed_compared_input(self):
"""
just make sure the output shapes are what we expect.
"""

n_princ_comp = 5
scaled_cube, pca = perform_pca(self.cube, n_princ_comp, return_noplanet=True)
assert np.std(scaled_cube) < np.std(
self.cube
) # the variance should be contained in the main components

def test_perform_pca_variance_removed_compared_input_diffcompoents(self):
"""
just make sure the output shapes are what we expect.
"""

n_princ_comp = 5
scaled_cube5, pca5 = perform_pca(self.cube, n_princ_comp, return_noplanet=True)
n_princ_comp = 10
scaled_cube10, pca10 = perform_pca(
self.cube, n_princ_comp, return_noplanet=True
)
assert np.std(scaled_cube10) < np.std(
scaled_cube5
) # the variance should be contained in the main components
3 changes: 1 addition & 2 deletions src/scope/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def perform_pca(input_matrix, n_princ_comp, return_noplanet=False):
Inputs
------
:input_matrix:
:n_princ_comp: number of principle components to keep
:n_princ_comp: number of principal components to keep
"""
u, singular_values, vh = np.linalg.svd(
input_matrix, full_matrices=False
Expand Down Expand Up @@ -218,7 +218,6 @@ def calc_exposure_time(
plot=False,
):
"""
Todo: use the newer version of exoplanet, where the orbits are installed elsewhere.
todo: refactor this into separate functions, maybe?
Expand Down

0 comments on commit 42dc315

Please sign in to comment.