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

Use LSST transmission test data for passband unit tests #135

Merged
merged 14 commits into from
Oct 1, 2024

Conversation

OliviaLynn
Copy link
Member

@OliviaLynn OliviaLynn commented Sep 26, 2024

For the first part of #113 (updating unit tests to use LSST transmission tables stored in unit test data).

Should also cover #127 (LSST g band file is wrong).

Introduces a table_dir option to PassbandGroup, so you can specify a general transmission table directory to use, as in:

  • PassbandGroup(preset="LSST", table_dir="my/dir")
  • or to specify just a root dir when manually defining passbands with PassbandGroup(table_dir="my/dir", passband_parameters=[...]))

Copy link

github-actions bot commented Sep 27, 2024

Before [ffad7c4] After [de525ca] Ratio Benchmark (Parameter)
1.36±0.01s 1.36±0.01s 1 benchmarks.time_x1_from_hostmass
7.22±0.04ms 7.04±0.04ms 0.98 benchmarks.time_chained_evaluate

Click here to view all benchmarks.

@OliviaLynn OliviaLynn mentioned this pull request Sep 27, 2024
3 tasks
@OliviaLynn OliviaLynn marked this pull request as ready for review September 27, 2024 19:07
table_dir : str, optional
The path to the directory containing the passband tables. If a table_path has not been specified
in the passband_parameters dictionary, table paths will be set to
{table_dir}/{survey}/{filter_name}.dat. If None, the table path will be set to a default path.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change needed right now, but I had been thinking of this as "{table_dir}/{filter_name}.dat" so the user could effectively provide both the base directory and the survey name with the table_dir parameter.

This current approach better matches the presets below though.

self.passbands[f"LSST_{filter_name}"] = Passband(
"LSST",
filter_name,
**{**kwargs, "table_path": table_path},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be more readable to just do:

table_path=table_path,
**kwargs,
)

Copy link
Contributor

@hombit hombit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you.

from tdastro.sources.spline_model import SplineModel


def create_passband_group(path, delta_wave=5.0, trim_quantile=None):
"""Helper function to create a PassbandGroup object for testing."""
def create_lsst_passband_group(passbands_dir, delta_wave=5.0, trim_quantile=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a nice function for the library code!

assert "TOY_c" in toy_passband_group.passbands
assert np.allclose(
toy_passband_group.waves,
np.unique(np.concatenate([np.arange(100, 301, 5), np.arange(250, 351, 5), np.arange(400, 601, 5)])),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like the library code duplication.

# Make sure group.waves contains the union of all passband waves with no duplicates or other values
assert np.allclose(
lsst_passband_group.waves,
np.unique(np.concatenate([passband.waves for passband in lsst_passband_group.passbands.values()])),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also duplicates the library code


# Check the two dicts are the same
assert result_from_source_model.keys() == result_from_passband_group.keys()
for key in result_from_source_model:
np.testing.assert_allclose(result_from_source_model[key], result_from_passband_group[key])


def test_passband_group_calculate_in_band_wave_indices(passbands_dir, tmp_path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually a bit confused about the original function and different return formats for different cases. If a passband waves are represented by a range of catalog.waves it returns (lower_index, upper_index + 1) tuple, while for the opposite case it is an integer array of indexes. Than here it is used to index an array:

if isinstance(passband._in_band_wave_indices, tuple):
in_band_fluxes = flux_density_matrix[:, indices[0] : indices[1]]
else:
in_band_fluxes = flux_density_matrix[:, indices]

I'd suggest to return slice(lower_index, upper_index + 1) instead, than both types of the return indexes may be just used directly.

Should I make a separate issue for that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

@OliviaLynn OliviaLynn merged commit 4a0ba5f into main Oct 1, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants