Skip to content

Commit

Permalink
tiickets/OPSIM-1193: add SURVEY_START_MJD and DEFAULT_NSIDE to replac…
Browse files Browse the repository at this point in the history
…e functions (#108)
  • Loading branch information
yoachim authored Sep 18, 2024
2 parents 14bd6b5 + a577316 commit afdabda
Show file tree
Hide file tree
Showing 41 changed files with 209 additions and 276 deletions.
54 changes: 27 additions & 27 deletions rubin_scheduler/scheduler/basis_functions/basis_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from rubin_scheduler.scheduler import features, utils
from rubin_scheduler.scheduler.utils import IntRounded, get_current_footprint
from rubin_scheduler.skybrightness_pre import dark_m5
from rubin_scheduler.utils import _hpid2_ra_dec, survey_start_mjd
from rubin_scheduler.utils import DEFAULT_NSIDE, SURVEY_START_MJD, _hpid2_ra_dec


def send_unused_deprecation_warning(name):
Expand All @@ -61,7 +61,7 @@ class BaseBasisFunction:
"""Class that takes features and computes a reward function when
called."""

def __init__(self, nside=None, filtername=None, **kwargs):
def __init__(self, nside=DEFAULT_NSIDE, filtername=None, **kwargs):
# Set if basis function needs to be recalculated if there is a new
# observation
self.update_on_newobs = True
Expand Down Expand Up @@ -318,7 +318,7 @@ class NObsPerYearBasisFunction(BaseBasisFunction):
def __init__(
self,
filtername="r",
nside=None,
nside=DEFAULT_NSIDE,
footprint=None,
n_obs=3,
season=300,
Expand Down Expand Up @@ -391,7 +391,7 @@ class NGoodSeeingBasisFunction(BaseBasisFunction):
Default 3.
mjd_start : `float`
The starting MJD of the survey.
Default None uses `rubin_scheduler.utils.survey_start_mjd()`.
Default None uses `rubin_scheduler.utils.SURVEY_START_MJD`.
footprint : `np.array`, (N,)
Only use area where footprint > 0. Should be a HEALpix map.
Default None calls `get_current_footprint()`.
Expand All @@ -400,7 +400,7 @@ class NGoodSeeingBasisFunction(BaseBasisFunction):
def __init__(
self,
filtername="r",
nside=None,
nside=DEFAULT_NSIDE,
seeing_fwhm_max=0.8,
m5_penalty_max=0.5,
n_obs_desired=3,
Expand All @@ -412,7 +412,7 @@ def __init__(
self.m5_penalty_max = m5_penalty_max
self.n_obs_desired = n_obs_desired
if mjd_start is None:
mjd_start = survey_start_mjd()
mjd_start = SURVEY_START_MJD
self.mjd_start = mjd_start
self.survey_features["N_good_seeing"] = features.NObservationsCurrentSeason(
filtername=self.filtername,
Expand Down Expand Up @@ -469,7 +469,7 @@ class NObsHighAmBasisFunction(BaseBasisFunction):

def __init__(
self,
nside=None,
nside=DEFAULT_NSIDE,
filtername="r",
footprint=None,
n_obs=3,
Expand Down Expand Up @@ -535,7 +535,7 @@ def _calc_value(self, conditions, indx=None):
class EclipticBasisFunction(BaseBasisFunction):
"""Mark the area around the ecliptic"""

def __init__(self, nside=None, distance_to_eclip=25.0):
def __init__(self, nside=DEFAULT_NSIDE, distance_to_eclip=25.0):
super(EclipticBasisFunction, self).__init__(nside=nside)
self.distance_to_eclip = np.radians(distance_to_eclip)
ra, dec = _hpid2_ra_dec(nside, np.arange(hp.nside2npix(self.nside)))
Expand Down Expand Up @@ -564,7 +564,7 @@ class CadenceInSeasonBasisFunction(BaseBasisFunction):
How long to wait before activating the basis function (days).
"""

def __init__(self, drive_map, filtername="griz", season_span=2.5, cadence=2.5, nside=None):
def __init__(self, drive_map, filtername="griz", season_span=2.5, cadence=2.5, nside=DEFAULT_NSIDE):
super(CadenceInSeasonBasisFunction, self).__init__(nside=nside, filtername=filtername)
self.drive_map = drive_map
self.season_span = season_span / 12.0 * np.pi # To radians
Expand Down Expand Up @@ -610,7 +610,7 @@ class SeasonCoverageBasisFunction(BaseBasisFunction):
Default of 3 is suitable for first year template building.
mjd_start : `float`, optional
The mjd of the start of the survey (days).
Default None uses `rubin_scheduler.utils.survey_start_mjd()`.
Default None uses `rubin_scheduler.utils.SURVEY_START_MJD`.
season_frac_start : `float`
Only start trying to gather observations after a season
is fractionally this far along.
Expand All @@ -623,7 +623,7 @@ class SeasonCoverageBasisFunction(BaseBasisFunction):
def __init__(
self,
filtername="r",
nside=None,
nside=DEFAULT_NSIDE,
footprint=None,
n_per_season=3,
mjd_start=None,
Expand All @@ -641,7 +641,7 @@ def __init__(

self.n_per_season = n_per_season
if mjd_start is None:
mjd_start = survey_start_mjd()
mjd_start = SURVEY_START_MJD
self.mjd_start = mjd_start
self.season_frac_start = season_frac_start
# Track how many observations have been taken at each RA/Dec
Expand Down Expand Up @@ -690,7 +690,7 @@ class AvoidFastRevisitsBasisFunction(BaseBasisFunction):
Will be masked if set to np.nan (default).
"""

def __init__(self, filtername="r", nside=None, gap_min=25.0, penalty_val=np.nan):
def __init__(self, filtername="r", nside=DEFAULT_NSIDE, gap_min=25.0, penalty_val=np.nan):
super().__init__(nside=nside, filtername=filtername)

self.filtername = filtername
Expand Down Expand Up @@ -729,7 +729,7 @@ class NearSunHighAirmassBasisFunction(BaseBasisFunction):
limit and more than 90 degrees azimuth toward the sun.
"""

def __init__(self, nside=None, max_airmass=2.5, penalty=np.nan):
def __init__(self, nside=DEFAULT_NSIDE, max_airmass=2.5, penalty=np.nan):
super().__init__(nside=nside)
self.max_airmass = IntRounded(max_airmass)
self.result = np.empty(hp.nside2npix(self.nside))
Expand Down Expand Up @@ -766,7 +766,7 @@ class VisitRepeatBasisFunction(BaseBasisFunction):
The number of pairs of observations to attempt to gather
"""

def __init__(self, gap_min=25.0, gap_max=45.0, filtername="r", nside=None, npairs=1):
def __init__(self, gap_min=25.0, gap_max=45.0, filtername="r", nside=DEFAULT_NSIDE, npairs=1):
super(VisitRepeatBasisFunction, self).__init__(nside=nside, filtername=filtername)

self.gap_min = IntRounded(gap_min / 60.0 / 24.0)
Expand Down Expand Up @@ -823,7 +823,7 @@ class M5DiffBasisFunction(BaseBasisFunction):
Default None uses `set_default_nside()`.
"""

def __init__(self, filtername="r", fiducial_FWHMEff=0.7, nside=None):
def __init__(self, filtername="r", fiducial_FWHMEff=0.7, nside=DEFAULT_NSIDE):
super().__init__(nside=nside, filtername=filtername)
# The dark sky surface brightness values
self.dark_map = None
Expand Down Expand Up @@ -940,7 +940,7 @@ class SlewtimeBasisFunction(BaseBasisFunction):
Default None will use `set_default_nside()`.
"""

def __init__(self, max_time=135.0, filtername="r", nside=None):
def __init__(self, max_time=135.0, filtername="r", nside=DEFAULT_NSIDE):
super(SlewtimeBasisFunction, self).__init__(nside=nside, filtername=filtername)

self.maxtime = max_time
Expand Down Expand Up @@ -996,7 +996,7 @@ class CadenceEnhanceBasisFunction(BaseBasisFunction):
def __init__(
self,
filtername="gri",
nside=None,
nside=DEFAULT_NSIDE,
supress_window=[0, 1.8],
supress_val=-0.5,
enhance_window=[2.1, 3.2],
Expand Down Expand Up @@ -1084,7 +1084,7 @@ class CadenceEnhanceTrapezoidBasisFunction(BaseBasisFunction):
def __init__(
self,
filtername="gri",
nside=None,
nside=DEFAULT_NSIDE,
delay_width=2,
delay_slope=2.0,
delay_peak=0,
Expand Down Expand Up @@ -1167,7 +1167,7 @@ class AzimuthBasisFunction(BaseBasisFunction):
large area of sky.
"""

def __init__(self, nside=None):
def __init__(self, nside=DEFAULT_NSIDE):
super(AzimuthBasisFunction, self).__init__(nside=nside)

def _calc_value(self, conditions, indx=None):
Expand All @@ -1190,7 +1190,7 @@ class AzModuloBasisFunction(BaseBasisFunction):
The azimuth limits (degrees) to use.
"""

def __init__(self, nside=None, az_limits=None, out_of_bounds_val=-1.0):
def __init__(self, nside=DEFAULT_NSIDE, az_limits=None, out_of_bounds_val=-1.0):
super(AzModuloBasisFunction, self).__init__(nside=nside)
self.result = np.ones(hp.nside2npix(self.nside))
if az_limits is None:
Expand Down Expand Up @@ -1234,7 +1234,7 @@ class DecModuloBasisFunction(BaseBasisFunction):
The azimuth limits (degrees) to use.
"""

def __init__(self, nside=None, dec_limits=None, out_of_bounds_val=-1.0):
def __init__(self, nside=DEFAULT_NSIDE, dec_limits=None, out_of_bounds_val=-1.0):
super(DecModuloBasisFunction, self).__init__(nside=nside)

npix = hp.nside2npix(nside)
Expand Down Expand Up @@ -1288,7 +1288,7 @@ class GoodSeeingBasisFunction(BaseBasisFunction):

def __init__(
self,
nside=None,
nside=DEFAULT_NSIDE,
filtername="r",
footprint=None,
fwhm_eff_limit=0.8,
Expand Down Expand Up @@ -1401,7 +1401,7 @@ class AvoidDirectWind(BaseBasisFunction):
`set_default_nside()`.
"""

def __init__(self, wind_speed_maximum=20.0, nside=None):
def __init__(self, wind_speed_maximum=20.0, nside=DEFAULT_NSIDE):
super().__init__(nside=nside)

self.wind_speed_maximum = wind_speed_maximum
Expand Down Expand Up @@ -1451,7 +1451,7 @@ class BalanceVisits(BaseBasisFunction):
to gain a reward boost in relative to it.
"""

def __init__(self, nobs_reference, note_survey, note_interest, nside=None):
def __init__(self, nobs_reference, note_survey, note_interest, nside=DEFAULT_NSIDE):
super().__init__(nside=nside)

self.nobs_reference = nobs_reference
Expand Down Expand Up @@ -1487,7 +1487,7 @@ class RewardNObsSequence(BaseBasisFunction):
they are all taken together.
"""

def __init__(self, n_obs_survey, note_survey, nside=None):
def __init__(self, n_obs_survey, note_survey, nside=DEFAULT_NSIDE):
super().__init__(nside=nside)

self.n_obs_survey = n_obs_survey
Expand Down Expand Up @@ -1523,7 +1523,7 @@ class RewardRisingBasisFunction(BaseBasisFunction):
Nside for the healpix map, default of None uses scheduler default.
"""

def __init__(self, slope=0.1, penalty_val=0, nside=None):
def __init__(self, slope=0.1, penalty_val=0, nside=DEFAULT_NSIDE):
super().__init__(nside=nside)
self.slope = slope
self.penalty_val = penalty_val
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from rubin_scheduler.scheduler import features
from rubin_scheduler.scheduler.basis_functions import BaseBasisFunction
from rubin_scheduler.scheduler.utils import IntRounded
from rubin_scheduler.utils import _angular_separation, ra_dec2_hpid
from rubin_scheduler.utils import DEFAULT_NSIDE, _angular_separation, ra_dec2_hpid


def send_unused_deprecation_warning(name):
Expand Down Expand Up @@ -110,7 +110,7 @@ class AirmassPointRangeBasisFunction(BaseBasisFunction):
The valid airmass range, default [1.05, 2.7].
"""

def __init__(self, ra, dec, airmass_range=[1.05, 2.7], nside=32):
def __init__(self, ra, dec, airmass_range=[1.05, 2.7], nside=DEFAULT_NSIDE):
super().__init__()
self.hpid = ra_dec2_hpid(nside, ra, dec)
self.airmass_range = airmass_range
Expand Down
20 changes: 10 additions & 10 deletions rubin_scheduler/scheduler/basis_functions/mask_basis_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

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


class SolarElongMaskBasisFunction(BaseBasisFunction):
Expand All @@ -26,7 +26,7 @@ class SolarElongMaskBasisFunction(BaseBasisFunction):
The limit beyond which to mask (degrees)
"""

def __init__(self, elong_limit=45.0, nside=32):
def __init__(self, elong_limit=45.0, nside=DEFAULT_NSIDE):
super(SolarElongMaskBasisFunction, self).__init__(nside=nside)
self.elong_limit = IntRounded(np.radians(elong_limit))
self.result = np.zeros(hp.nside2npix(self.nside), dtype=float)
Expand All @@ -49,7 +49,7 @@ class HaMaskBasisFunction(BaseBasisFunction):
The maximum hour angle to accept (hours)
"""

def __init__(self, ha_min=None, ha_max=None, nside=32):
def __init__(self, ha_min=None, ha_max=None, nside=DEFAULT_NSIDE):
super(HaMaskBasisFunction, self).__init__(nside=nside)
self.ha_max = ha_max
self.ha_min = ha_min
Expand All @@ -72,7 +72,7 @@ class AreaCheckMaskBasisFunction(BaseBasisFunction):
"""Take a list of other mask basis functions, and do an additional
check for area available"""

def __init__(self, bf_list, nside=32, min_area=1000.0):
def __init__(self, bf_list, nside=DEFAULT_NSIDE, min_area=1000.0):
super(AreaCheckMaskBasisFunction, self).__init__(nside=nside)
self.bf_list = bf_list
self.result = np.zeros(hp.nside2npix(self.nside), dtype=float)
Expand Down Expand Up @@ -111,7 +111,7 @@ class SolarElongationMaskBasisFunction(BaseBasisFunction):
The maximum solar elongation to consider (degrees).
"""

def __init__(self, min_elong=0.0, max_elong=60.0, nside=None, penalty=np.nan):
def __init__(self, min_elong=0.0, max_elong=60.0, nside=DEFAULT_NSIDE, penalty=np.nan):
super(SolarElongationMaskBasisFunction, self).__init__(nside=nside)
self.min_elong = np.radians(min_elong)
self.max_elong = np.radians(max_elong)
Expand Down Expand Up @@ -143,7 +143,7 @@ class PlanetMaskBasisFunction(BaseBasisFunction):
"""

def __init__(self, mask_radius=3.5, planets=None, nside=None, scale=1e5):
def __init__(self, mask_radius=3.5, planets=None, nside=DEFAULT_NSIDE, scale=1e5):
super(PlanetMaskBasisFunction, self).__init__(nside=nside)
if planets is None:
planets = ["venus", "mars", "jupiter"]
Expand Down Expand Up @@ -201,7 +201,7 @@ class AltAzShadowMaskBasisFunction(BaseBasisFunction):

def __init__(
self,
nside=None,
nside=DEFAULT_NSIDE,
min_alt=20.0,
max_alt=86.5,
min_az=0,
Expand Down Expand Up @@ -325,7 +325,7 @@ class MoonAvoidanceBasisFunction(BaseBasisFunction):
or below the horizon.
"""

def __init__(self, nside=None, moon_distance=30.0):
def __init__(self, nside=DEFAULT_NSIDE, moon_distance=30.0):
super(MoonAvoidanceBasisFunction, self).__init__(nside=nside)
self.update_on_newobs = False

Expand Down Expand Up @@ -360,7 +360,7 @@ class BulkCloudBasisFunction(BaseBasisFunction):
requested
"""

def __init__(self, nside=None, max_cloud_map=None, max_val=0.7, out_of_bounds_val=np.nan):
def __init__(self, nside=DEFAULT_NSIDE, max_cloud_map=None, max_val=0.7, out_of_bounds_val=np.nan):
super(BulkCloudBasisFunction, self).__init__(nside=nside)
self.update_on_newobs = False

Expand Down Expand Up @@ -409,7 +409,7 @@ class MapCloudBasisFunction(BaseBasisFunction):
requested
"""

def __init__(self, nside=None, max_cloud_map=None, max_val=0.7, out_of_bounds_val=np.nan):
def __init__(self, nside=DEFAULT_NSIDE, max_cloud_map=None, max_val=0.7, out_of_bounds_val=np.nan):
super(BulkCloudBasisFunction, self).__init__(nside=nside)
self.update_on_newobs = False

Expand Down
Loading

0 comments on commit afdabda

Please sign in to comment.