From e40dd19f840a4c8cbd61706a9e26a39fa6fcec2d Mon Sep 17 00:00:00 2001 From: Michael Baisch Date: Mon, 29 May 2023 17:17:07 +0200 Subject: [PATCH 1/2] AltitudeConstraint: Adjust max_best_rescale() to prevent unexpected output In previous versions, when setting the max parameter for altitude, max_best_rescale() would return 1.0 if the altitude exceeded the maximum limit. This behavior was unexpected. To rectify this, the greater_than_max argument in max_best_rescale() has been set to 0. This adjustment ensures that the output aligns with expectations when the altitude surpasses the specified maximum constraint. --- astroplan/constraints.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astroplan/constraints.py b/astroplan/constraints.py index f44f64d3..839633c0 100644 --- a/astroplan/constraints.py +++ b/astroplan/constraints.py @@ -354,7 +354,7 @@ def compute_constraint(self, times, observer, targets): uppermask = alt <= self.max return lowermask & uppermask else: - return max_best_rescale(alt, self.min, self.max) + return max_best_rescale(alt, self.min, self.max, greater_than_max=0) class AirmassConstraint(AltitudeConstraint): From e598f4403609e58ac876cacf48105489c0675399 Mon Sep 17 00:00:00 2001 From: Michael Baisch Date: Sat, 10 Jun 2023 09:18:28 +0200 Subject: [PATCH 2/2] AltitudeConstraint: add test --- astroplan/tests/test_constraints.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/astroplan/tests/test_constraints.py b/astroplan/tests/test_constraints.py index 800471fb..8d609753 100644 --- a/astroplan/tests/test_constraints.py +++ b/astroplan/tests/test_constraints.py @@ -98,6 +98,17 @@ def test_observability_table(): assert 'time observable' in stab.colnames +def test_altitude_constraint(): + subaru = Observer.at_site("Subaru") + time = Time('2001-02-03 15:35:00') + time_range = Time([time, time+3*u.hour]) + + constraint = AltitudeConstraint(min=40*u.deg, max=50*u.deg, boolean_constraint=False) + results = constraint(subaru, vega, times=time_grid_from_range(time_range)) + # Check if below min and above max values are 0 + assert np.all([results != 0][0] == [False, False, True, True, False, False]) + + def test_compare_altitude_constraint_and_observer(): time = Time('2001-02-03 04:05:06') time_ranges = [Time([time, time+1*u.hour]) + offset