Skip to content

Commit

Permalink
OPSIM-1190: remove deprecated features and basis functions (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhiannonlynne authored Sep 16, 2024
2 parents c94814e + 2d075a2 commit ce6e319
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 1,666 deletions.
768 changes: 3 additions & 765 deletions rubin_scheduler/scheduler/basis_functions/basis_functions.py

Large diffs are not rendered by default.

43 changes: 7 additions & 36 deletions rubin_scheduler/scheduler/basis_functions/feasibility_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
"NightModuloBasisFunction",
"EndOfEveningBasisFunction",
"TimeToScheduledBasisFunction",
"LimitObsPnightBasisFunction",
"SunHighLimitBasisFunction",
"CloseToTwilightBasisFunction",
"MoonDistPointRangeBasisFunction",
"AirmassPointRangeBasisFunction",
Expand Down Expand Up @@ -203,17 +201,6 @@ def check_feasibility(self, conditions):
return result


class SunHighLimitBasisFunction(CloseToTwilightBasisFunction):

def __init__(self, sun_alt_limit=-14.8, time_to_12deg=21.0, time_remaining=15.0):
super().__init__(
max_sun_alt_limit=sun_alt_limit,
min_time_remaining=time_remaining,
max_time_to_12deg=time_to_12deg,
)
warnings.warn("Class has been renamed CloseToTwilightBasisFunction", DeprecationWarning, 2)


class OnceInNightBasisFunction(BaseBasisFunction):
"""Stop observing if something has been executed already in the night
Expand Down Expand Up @@ -254,22 +241,6 @@ def check_feasibility(self, conditions):
return result


class LimitObsPnightBasisFunction(BaseBasisFunction):
""""""

def __init__(self, survey_str="", nlimit=100.0):
super(LimitObsPnightBasisFunction, self).__init__()
self.nlimit = nlimit
self.survey_features["N_in_night"] = features.SurveyInNight(survey_str=survey_str)
send_unused_deprecation_warning(self.__class__.__name__)

def check_feasibility(self, conditions):
if self.survey_features["N_in_night"].feature >= self.nlimit:
return False
else:
return True


class NightModuloBasisFunction(BaseBasisFunction):
"""Only return true on certain nights"""

Expand Down Expand Up @@ -464,8 +435,8 @@ def __init__(
self.scheduler_note = scheduler_note
self.survey_features["last_obs_self"] = features.LastObservation(scheduler_note=self.scheduler_note)
self.fractions = fractions
self.survey_features["N_total"] = features.NObsSurvey(note=None)
self.survey_features["N_note"] = features.NObsSurvey(note=self.scheduler_note)
self.survey_features["N_total"] = features.NObsCount(note=None)
self.survey_features["N_note"] = features.NObsCount(note=self.scheduler_note)

def check_feasibility(self, conditions):
result = True
Expand Down Expand Up @@ -544,8 +515,8 @@ def __init__(self, frac_total, scheduler_note=None, survey_name=None):
else:
self.scheduler_note = scheduler_note
self.frac_total = frac_total
self.survey_features["N_total"] = features.NObsSurvey(note=None)
self.survey_features["N_note"] = features.NObsSurvey(note=self.scheduler_note)
self.survey_features["N_total"] = features.NObsCount(note=None)
self.survey_features["N_note"] = features.NObsCount(note=self.scheduler_note)

def check_feasibility(self, conditions):
# If nothing has been observed, fine to go
Expand Down Expand Up @@ -615,8 +586,8 @@ def __init__(
self.time_jump = time_jump / 60.0 / 24.0 # To days
self.time_needed = time_needed / 60.0 / 24.0 # To days
self.aggressive_fraction = aggressive_fraction
self.survey_features["N_total"] = features.NObsSurvey(note=None)
self.survey_features["N_note"] = features.NObsSurvey(note=self.scheduler_note)
self.survey_features["N_total"] = features.NObsCount(note=None)
self.survey_features["N_note"] = features.NObsCount(note=self.scheduler_note)

def check_feasibility(self, conditions):
result = True
Expand Down Expand Up @@ -710,6 +681,6 @@ def __init__(self, alt_limit=-12.1):

def check_feasibility(self, conditions):
result = True
if conditions.sunAlt > self.alt_limit:
if conditions.sun_alt > self.alt_limit:
result = False
return result
102 changes: 1 addition & 101 deletions rubin_scheduler/scheduler/basis_functions/mask_basis_funcs.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
__all__ = (
"SolarElongMaskBasisFunction",
"ZenithShadowMaskBasisFunction",
"HaMaskBasisFunction",
"MoonAvoidanceBasisFunction",
"MapCloudBasisFunction",
"PlanetMaskBasisFunction",
"MaskAzimuthBasisFunction",
"SolarElongationMaskBasisFunction",
"AreaCheckMaskBasisFunction",
"AltAzShadowMaskBasisFunction",
)

import warnings

import healpy as hp
import numpy as np

from rubin_scheduler.scheduler.basis_functions import BaseBasisFunction
from rubin_scheduler.scheduler.utils import HpInLsstFov, IntRounded
from rubin_scheduler.utils import Site, _angular_separation, _hpid2_ra_dec

from .basis_functions import send_unused_deprecation_warning
from rubin_scheduler.utils import _angular_separation


class SolarElongMaskBasisFunction(BaseBasisFunction):
Expand Down Expand Up @@ -312,76 +306,6 @@ def _calc_value(self, conditions, indx=None):
return result


class ZenithShadowMaskBasisFunction(BaseBasisFunction):
"""Mask the zenith, and things that will soon pass near zenith.
Useful for making sure observations will not be too close to zenith
when they need to be observed again (e.g. for a pair).
Parameters
----------
min_alt : float (20.)
The minimum alititude to alow. Everything lower is masked. (degrees)
max_alt : float (82.)
The maximum altitude to alow. Everything higher is masked. (degrees)
shadow_minutes : float (40.)
Mask anything that will pass through the max alt in the next
shadow_minutes time. (minutes)
"""

def __init__(
self,
nside=None,
min_alt=20.0,
max_alt=82.0,
shadow_minutes=40.0,
penalty=np.nan,
site="LSST",
):
warnings.warn(
"Deprecating ZenithShadowMaskBasisFunction in favor of AltAzShadowMaskBasisFunction.",
DeprecationWarning,
)

super(ZenithShadowMaskBasisFunction, self).__init__(nside=nside)
self.update_on_newobs = False

self.penalty = penalty

self.min_alt = np.radians(min_alt)
self.max_alt = np.radians(max_alt)
self.ra, self.dec = _hpid2_ra_dec(self.nside, np.arange(hp.nside2npix(self.nside)))
self.shadow_minutes = np.radians(shadow_minutes / 60.0 * 360.0 / 24.0)
# Compute the declination band where things could drift into zenith
self.decband = np.zeros(self.dec.size, dtype=float)
self.zenith_radius = np.radians(90.0 - max_alt) / 2.0
site = Site(name=site)
self.lat_rad = site.latitude_rad
self.lon_rad = site.longitude_rad
self.decband[
np.where(
(IntRounded(self.dec) < IntRounded(self.lat_rad + self.zenith_radius))
& (IntRounded(self.dec) > IntRounded(self.lat_rad - self.zenith_radius))
)
] = 1

self.result = np.empty(hp.nside2npix(self.nside), dtype=float)
self.result.fill(self.penalty)

def _calc_value(self, conditions, indx=None):
result = self.result.copy()
alt_limit = np.where(
(IntRounded(conditions.alt) > IntRounded(self.min_alt))
& (IntRounded(conditions.alt) < IntRounded(self.max_alt))
)[0]
result[alt_limit] = 1
to_mask = np.where(
(IntRounded(conditions.HA) > IntRounded(2.0 * np.pi - self.shadow_minutes - self.zenith_radius))
& (self.decband == 1)
)
result[to_mask] = np.nan
return result


class MoonAvoidanceBasisFunction(BaseBasisFunction):
"""Avoid observing within `moon_distance` of the moon.
Expand Down Expand Up @@ -515,27 +439,3 @@ def _calc_value(self, conditions, indx=None):
result[clouded] = self.out_of_bounds_val

return result


class MaskAzimuthBasisFunction(BaseBasisFunction):
"""Mask pixels based on azimuth.
Superseded by AltAzShadowMaskBasisFunction.
"""

def __init__(self, nside=None, out_of_bounds_val=np.nan, az_min=0.0, az_max=180.0):
super(MaskAzimuthBasisFunction, self).__init__(nside=nside)
self.az_min = IntRounded(np.radians(az_min))
self.az_max = IntRounded(np.radians(az_max))
self.out_of_bounds_val = out_of_bounds_val
self.result = np.ones(hp.nside2npix(self.nside))
send_unused_deprecation_warning(self.__class__.__name__)

def _calc_value(self, conditions, indx=None):
to_mask = np.where(
(IntRounded(conditions.az) > self.az_min) & (IntRounded(conditions.az) < self.az_max)
)[0]
result = self.result.copy()
result[to_mask] = self.out_of_bounds_val

return result
Loading

0 comments on commit ce6e319

Please sign in to comment.