Repository: feder-observatory/stellarphot

Issue:
`PhotometryData` does not use column name mapping
It turns out that `PhotometryData` does not used the remapped column names in its `__init__`. I'll open a PR with a test that reproduces the issue and fixes it in a moment.

Discussion:

Patch:
diff --git a/stellarphot/core.py b/stellarphot/core.py
index c18e787..222b566 100644
--- a/stellarphot/core.py
+++ b/stellarphot/core.py
@@ -438,6 +438,9 @@ class PhotometryData(BaseEnhancedTable):
                 **kwargs,
             )
 
+            # 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
             if not isinstance(self.observatory, Observatory):
                 raise TypeError(
@@ -465,24 +468,24 @@ class PhotometryData(BaseEnhancedTable):
             ]
             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


Test patch:
diff --git a/stellarphot/tests/test_core.py b/stellarphot/tests/test_core.py
index 8e2b42d..4bbf4c2 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