-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #376 from lsst/tickets/PREOPS-4124
tickets/PREOPS-4124 Support restricting the scheduler reward summary stats to a region of interest
- Loading branch information
Showing
5 changed files
with
203 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import unittest | ||
import healpy as hp | ||
import numpy as np | ||
from rubin_sim.scheduler.features import Conditions | ||
from rubin_sim.scheduler.utils import set_default_nside | ||
from rubin_sim.scheduler.basis_functions import HealpixLimitedBasisFunctionMixin | ||
from rubin_sim.scheduler.basis_functions import SimpleArrayBasisFunction | ||
|
||
|
||
class SimpleArrayAtHpixBasisFunction(HealpixLimitedBasisFunctionMixin, SimpleArrayBasisFunction): | ||
pass | ||
|
||
|
||
class TestHealpixLimitedBasisFunctionMixin(unittest.TestCase): | ||
def setUp(self): | ||
self.hpid = 2111 | ||
random_seed = 6563 | ||
self.nside = set_default_nside() | ||
self.npix = hp.nside2npix(self.nside) | ||
self.rng = np.random.default_rng(seed=random_seed) | ||
self.all_values = self.rng.random(self.npix) | ||
self.value = self.all_values[self.hpid] | ||
self.conditions = Conditions(nside=self.nside, mjd=60200.2) | ||
|
||
def test_array_data(self): | ||
basis_function = SimpleArrayBasisFunction(self.all_values) | ||
test_values = basis_function(self.conditions) | ||
self.assertTrue(np.array_equal(test_values, self.all_values)) | ||
|
||
def test_scalar_data(self): | ||
basis_function = SimpleArrayAtHpixBasisFunction(self.hpid, self.all_values) | ||
test_value = basis_function(self.conditions) | ||
self.assertEqual(test_value, self.value) | ||
|
||
feasible = basis_function(self.conditions) | ||
self.assertTrue(feasible) | ||
|
||
def test_infeasible_at_hpix(self): | ||
values_invalid_at_hpix = self.all_values.copy() | ||
values_invalid_at_hpix[self.hpid] = -np.inf | ||
basis_function = SimpleArrayAtHpixBasisFunction(self.hpid, values_invalid_at_hpix) | ||
feasible = basis_function.check_feasibility(self.conditions) | ||
self.assertFalse(feasible) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters