From 5eb4d686c5aed4b9634f58ebab0e2e7df8ee3dda Mon Sep 17 00:00:00 2001 From: Matt Craig Date: Sat, 12 Oct 2024 11:50:40 -0500 Subject: [PATCH 1/2] Add test and fix for PhotometryData initialization --- stellarphot/core.py | 11 +++++++---- stellarphot/tests/test_core.py | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/stellarphot/core.py b/stellarphot/core.py index c18e7874..29ced22b 100644 --- a/stellarphot/core.py +++ b/stellarphot/core.py @@ -438,6 +438,9 @@ def __init__( **kwargs, ) + # From this point forwarsd we should be using self to get at any data + # columns, because that is where BaseEnhancedTable has put the data. + # Perform input validation if not isinstance(self.observatory, Observatory): raise TypeError( @@ -465,24 +468,24 @@ def __init__( ] cnts_unit = self[counts_columns[0]].unit for this_col in counts_columns[1:]: - if input_data[this_col].unit != cnts_unit: + if self[this_col].unit != cnts_unit: raise ValueError( f"input_data['{this_col}'] has inconsistent units " f"with input_data['{counts_columns[0]}'] (should " f"be {cnts_unit} but it's " - f"{input_data[this_col].unit})." + f"{self[this_col].unit})." ) for this_col in counts_per_pixel_columns: if cnts_unit is None: perpixel = u.pixel**-1 else: perpixel = cnts_unit * u.pixel**-1 - if input_data[this_col].unit != perpixel: + if self[this_col].unit != perpixel: raise ValueError( f"input_data['{this_col}'] has inconsistent units " f"with input_data['{counts_columns[0]}'] (should " f"be {perpixel} but it's " - f"{input_data[this_col].unit})." + f"{self[this_col].unit})." ) # Compute additional columns diff --git a/stellarphot/tests/test_core.py b/stellarphot/tests/test_core.py index 8e2b42d5..4bbf4c23 100644 --- a/stellarphot/tests/test_core.py +++ b/stellarphot/tests/test_core.py @@ -491,6 +491,23 @@ def test_photometry_blank(): assert test_base.observatory is None +def test_photometry_with_colname_map(feder_cg_16m, feder_passbands, feder_obs): + # Rename one of the columns in the test data to something else + # and provide a colname_map that should fix it. + # Regression test for #469 + this_phot_data = testphot_clean.copy() + this_phot_data.rename_column("aperture_net_cnts", "bad_column") + colname_map = {"bad_column": "aperture_net_cnts"} + pd = PhotometryData( + input_data=this_phot_data, + colname_map=colname_map, + observatory=feder_obs, + camera=feder_cg_16m, + passband_map=feder_passbands, + ) + assert "bad_column" not in pd.columns + + @pytest.mark.parametrize("bjd_coordinates", [None, "custom"]) def test_photometry_data(feder_cg_16m, feder_passbands, feder_obs, bjd_coordinates): # Create photometry data instance From afc72677e4aa35b26d14bb1a521db952cbf220b4 Mon Sep 17 00:00:00 2001 From: Matt Craig Date: Sun, 13 Oct 2024 15:59:45 -0500 Subject: [PATCH 2/2] Update stellarphot/core.py Co-authored-by: Juan Cabanela --- stellarphot/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stellarphot/core.py b/stellarphot/core.py index 29ced22b..222b5664 100644 --- a/stellarphot/core.py +++ b/stellarphot/core.py @@ -438,7 +438,7 @@ def __init__( **kwargs, ) - # From this point forwarsd we should be using self to get at any data + # From this point forward we should be using self to get at any data # columns, because that is where BaseEnhancedTable has put the data. # Perform input validation