Skip to content

Commit

Permalink
more docstrings, enforce tel_alt_limits name
Browse files Browse the repository at this point in the history
  • Loading branch information
yoachim committed Jan 19, 2024
1 parent 2a49a4b commit aa713c0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
37 changes: 28 additions & 9 deletions rubin_scheduler/scheduler/basis_functions/mask_basis_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"AltAzShadowMaskBasisFunction",
)

from warnings import warn

import healpy as hp
import matplotlib.pylab as plt
import numpy as np
Expand Down Expand Up @@ -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__(
Expand All @@ -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.
Expand All @@ -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)))
Expand All @@ -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)))
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions rubin_scheduler/scheduler/surveys/scripted_surveys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tests/scheduler/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit aa713c0

Please sign in to comment.