Skip to content

Commit

Permalink
Add main_filter to Observatory
Browse files Browse the repository at this point in the history
  • Loading branch information
moeyensj committed Aug 30, 2024
1 parent 536d1f8 commit 294bb5c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/adam_test_data/observatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Observatory:
bright_limit: list[float]
fov: FieldOfView
simulation: Simulation
main_filter: str


def observatory_to_sorcha_config(
Expand All @@ -92,6 +93,15 @@ def observatory_to_sorcha_config(
if time_range is not None:
sql_query += f" AND observationStartMJD >= {time_range[0]} AND observationStartMJD <= {time_range[1]}"

# The main filter needs to be first in the list of filters
if observatory.main_filter in observatory.filters:
observatory.filters.remove(observatory.main_filter)
observatory.filters.insert(0, observatory.main_filter)
else:
raise ValueError(
f"Main filter {observatory.main_filter} not in list of filters"
)

config = f"""
# Sorcha Configuration File - ADAM Test Data - {observatory.code}
Expand Down
19 changes: 18 additions & 1 deletion src/adam_test_data/tests/test_observatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def test_observatory_to_sorcha_config():
bright_limit=[16, 16, 16, 16, 16, 16],
fov=FieldOfView(camera_model="circle", fill_factor=0.9, circle_radius=3),
simulation=Simulation(ang_fov=1.0, fov_buffer=0.1),
main_filter="r",
)

assert (
Expand All @@ -130,7 +131,7 @@ def test_observatory_to_sorcha_config():
ar_healpix_order = 6
[FILTERS]
observing_filters = u,g,r,i,z,y
observing_filters = r,u,g,i,z,y
[BRIGHT_LIMITS]
bright_limit = 16,16,16,16,16,16
Expand Down Expand Up @@ -164,3 +165,19 @@ def test_observatory_to_sorcha_config():
trailing_losses_on = True
"""
)


def test_observatory_to_sorcha_config_raises():
# Test that observatory_to_sorcha_config raises the correct exceptions when invalid argument
# combinations are passed.

with pytest.raises(ValueError, match="Main filter r not in list of filters"):
obs = Observatory(
code="X05",
filters=["u", "g", "i", "z", "y"],
bright_limit=[16, 16, 16, 16, 16, 16],
fov=FieldOfView(camera_model="circle", fill_factor=0.9, circle_radius=3),
simulation=Simulation(ang_fov=1.0, fov_buffer=0.1),
main_filter="r",
)
observatory_to_sorcha_config(obs)

0 comments on commit 294bb5c

Please sign in to comment.