Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test and fix for PhotometryData initialization #470

Merged
merged 2 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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