Skip to content

Commit

Permalink
Merge pull request #470 from mwcraig/fix-photometry-data-issue
Browse files Browse the repository at this point in the history
Add test and fix for PhotometryData initialization
  • Loading branch information
mwcraig authored Oct 13, 2024
2 parents adc4858 + afc7267 commit eb6a7c1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
11 changes: 7 additions & 4 deletions stellarphot/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ def __init__(
**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(
Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions stellarphot/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eb6a7c1

Please sign in to comment.