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

Helper function for auto-applying colmap #173

Merged
merged 1 commit into from
Oct 16, 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
3 changes: 3 additions & 0 deletions src/tdastro/astro_utils/opsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ def __len__(self):

def __getitem__(self, key):
"""Access the underlying opsim table."""
# Auto apply the colmap if possible.
if self.colmap is not None and key in self.colmap:
return self.table[self.colmap[key]]
return self.table[key]

@property
Expand Down
6 changes: 3 additions & 3 deletions src/tdastro/example_runs/simulate_snia.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def draw_single_random_sn(
obs_index = np.array(opsim.range_search(ra, dec, radius=1.75))

# Update obs_index to only include observations within SN lifespan
phase_obs = opsim[opsim.colmap["time"]][obs_index] - t0
phase_obs = opsim["time"][obs_index] - t0
obs_index = obs_index[(phase_obs > -20 * (1.0 + z)) & (phase_obs < 50 * (1.0 + z))]

times = opsim[opsim.colmap["time"]][obs_index].to_numpy()
filters = opsim[opsim.colmap["filter"]][obs_index].to_numpy(str)
times = opsim["time"][obs_index].to_numpy()
filters = opsim["filter"][obs_index].to_numpy(str)
# Change to match band names in passbands object
filters = np.char.add("LSST_", filters)

Expand Down
Loading