From aa713c047d2251687eab74616e46ded1626b29b9 Mon Sep 17 00:00:00 2001
From: Peter Yoachim <yoachim@uw.edu>
Date: Thu, 18 Jan 2024 14:11:43 -0800
Subject: [PATCH] more docstrings, enforce tel_alt_limits name

---
 .../basis_functions/mask_basis_funcs.py       | 37 ++++++++++++++-----
 .../model_observatory/model_observatory.py    |  4 +-
 .../scheduler/surveys/scripted_surveys.py     |  4 +-
 tests/scheduler/test_utils.py                 |  2 +-
 4 files changed, 33 insertions(+), 14 deletions(-)

diff --git a/rubin_scheduler/scheduler/basis_functions/mask_basis_funcs.py b/rubin_scheduler/scheduler/basis_functions/mask_basis_funcs.py
index 92a47bdb..daa3bb80 100644
--- a/rubin_scheduler/scheduler/basis_functions/mask_basis_funcs.py
+++ b/rubin_scheduler/scheduler/basis_functions/mask_basis_funcs.py
@@ -12,6 +12,8 @@
     "AltAzShadowMaskBasisFunction",
 )
 
+from warnings import warn
+
 import healpy as hp
 import matplotlib.pylab as plt
 import numpy as np
@@ -196,9 +198,24 @@ def _calc_value(self, conditions, indx=None):
 
 
 class AltAzShadowMaskBasisFunction(BaseBasisFunction):
-    """Mask any out of range altitudes and azimuths, then extend the
+    """Mask out range altitudes and azimuths, then extend the
     mask so if observations are taken in pairs, the second in the pair will
-    not have moved into a masked region.
+    not have moved into a masked region. 
+
+    Masks any alt/az regions as specified by the conditions object, then 
+    applies any additional altitude masking as suppied by the kwargs.
+    This mask is then extended using `shadow minutes`. 
+
+    Parameters
+    ----------
+    nside : `int`
+        HEALpix nside. Default None will look up the package-wide default.
+    min_alt : `float`
+        Minimum altitude to apply to the mask. Default 20 (degrees).
+    max_alt : `float`
+        Maximum altitude to allow. Default 82 (degrees).
+    shadow_minutes : `float`
+        How long to extend masked area in longitude. Default 40 (minutes).
     """
 
     def __init__(
@@ -212,15 +229,13 @@ def __init__(
         self.min_alt = np.radians(min_alt)
         self.max_alt = np.radians(max_alt)
         self.shadow_time = shadow_minutes / 60.0 / 24.0  # To days
-        self.result = np.zeros(hp.nside2npix(self.nside), dtype=float)
-        self.in_range = np.zeros(hp.nside2npix(self.nside), dtype=int)
 
     def _calc_value(self, conditions, indx=None):
         # Mask everything to start
-        result = self.result.copy() + np.nan
+        result = np.zeros(hp.nside2npix(self.nside), dtype=float) + np.nan
 
-        in_range_alt = self.in_range.copy()
-        in_range_az = self.in_range.copy()
+        in_range_alt = np.zeros(hp.nside2npix(self.nside), dtype=int)
+        in_range_az = np.zeros(hp.nside2npix(self.nside), dtype=int)
 
         # Compute the alt,az values in the future. Use the conditions object
         # so the results are cached and can be used by other surveys is needed.
@@ -229,7 +244,7 @@ def _calc_value(self, conditions, indx=None):
         future_alt, future_az = conditions.future_alt_az(np.max(conditions.mjd + self.shadow_time))
 
         # apply limits from the conditions object
-        for limits in conditions.alt_limits:
+        for limits in conditions.tel_alt_limits:
             good = np.where(
                 (IntRounded(conditions.alt) >= IntRounded(np.min(limits)))
                 & (IntRounded(conditions.alt) <= IntRounded(np.max(limits)))
@@ -241,7 +256,7 @@ def _calc_value(self, conditions, indx=None):
             )[0]
             in_range_alt[good] += 1
 
-        for limits in conditions.az_limits:
+        for limits in conditions.tel_az_limits:
             good = np.where(
                 (IntRounded(conditions.az) >= IntRounded(np.min(limits)))
                 & (IntRounded(conditions.az) <= IntRounded(np.max(limits)))
@@ -289,6 +304,10 @@ def __init__(
         penalty=np.nan,
         site="LSST",
     ):
+        warn.DeprecationWarning(
+            "Deprecating ZenithShadowMaskBasisFunction in favor of AltAzShadowMaskBasisFunction."
+        )
+
         super(ZenithShadowMaskBasisFunction, self).__init__(nside=nside)
         self.update_on_newobs = False
 
diff --git a/rubin_scheduler/scheduler/model_observatory/model_observatory.py b/rubin_scheduler/scheduler/model_observatory/model_observatory.py
index 0d2af188..9b5d1ff4 100644
--- a/rubin_scheduler/scheduler/model_observatory/model_observatory.py
+++ b/rubin_scheduler/scheduler/model_observatory/model_observatory.py
@@ -367,8 +367,8 @@ def return_conditions(self):
         self.conditions.mjd_start = self.mjd_start
 
         # Telescope limits
-        self.conditions.az_limits = self.observatory.az_limits
-        self.conditions.alt_limits = self.observatory.alt_limits
+        self.conditions.tel_az_limits = self.observatory.az_limits
+        self.conditions.tel_alt_limits = self.observatory.alt_limits
 
         # Planet positions from almanac
         self.conditions.planet_positions = self.almanac.get_planet_positions(self.mjd)
diff --git a/rubin_scheduler/scheduler/surveys/scripted_surveys.py b/rubin_scheduler/scheduler/surveys/scripted_surveys.py
index 829a9689..0180dff7 100644
--- a/rubin_scheduler/scheduler/surveys/scripted_surveys.py
+++ b/rubin_scheduler/scheduler/surveys/scripted_surveys.py
@@ -187,14 +187,14 @@ def _check_alts_ha(self, observation, conditions):
 
         # Also check the alt,az limits given by the conditions object
         count = in_range * 0
-        for limits in conditions.alt_limits:
+        for limits in conditions.tel_alt_limits:
             ir = np.where((alt[in_range] >= np.min(limits)) & (alt[in_range] <= np.max(limits)))[0]
             count[ir] += 1
         good = np.where(count > 0)[0]
         in_range = in_range[good]
 
         count = in_range * 0
-        for limits in conditions.az_limits:
+        for limits in conditions.tel_az_limits:
             ir = np.where((az[in_range] >= np.min(limits)) & (az[in_range] <= np.max(limits)))[0]
             count[ir] += 1
         good = np.where(count > 0)[0]
diff --git a/tests/scheduler/test_utils.py b/tests/scheduler/test_utils.py
index 0fb6d34e..2a83d6de 100644
--- a/tests/scheduler/test_utils.py
+++ b/tests/scheduler/test_utils.py
@@ -63,7 +63,7 @@ def test_example(self):
             "twilight_near_sun, 2",
             "twilight_near_sun, 3",
         ]
-        
+
         for note in notes_to_check:
             assert note in u_notes