Skip to content

Commit

Permalink
move skyproj plotter tests into the same file as other plotter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ehneilsen committed Apr 5, 2024
1 parent b9f0a05 commit 6b26944
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 82 deletions.
70 changes: 69 additions & 1 deletion tests/maf/test_plotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

import numpy as np
from matplotlib.figure import Figure
from rubin_scheduler.scheduler.model_observatory import ModelObservatory

import rubin_sim.maf as maf


class TestPlotters(unittest.TestCase):
def setUp(self):
self.rng = np.random.default_rng()
# Set a seed to make the tests reproducible
self.rng = np.random.default_rng(seed=1234)

def test_healpix_plotters(self):
# Set up a metric bundle to send to plotters
Expand Down Expand Up @@ -63,6 +65,72 @@ def test_oned_plotter(self):
figs = bundle1.plot()
self.assertTrue(isinstance(figs["BinnedData"], Figure))

def test_hpxmap_plotter(self):
bundle = maf.create_empty_metric_bundle()
nside = 64
bundle.slicer = maf.HealpixSlicer(nside=nside)
bundle._setup_metric_values()
bundle.metric_values += self.rng.uniform(size=len(bundle.slicer))

plotter = maf.HpxmapPlotter()
bundle.set_plot_funcs([plotter])
_ = bundle.plot()

def test_visit_perimeter_plotter(self):
model_observatory = ModelObservatory(init_load_length=1)

num_points = 5
field_ra = np.arange(30, 30 + num_points, dtype=float)
field_dec = np.arange(-60, -60 + num_points, dtype=float)
rot_sky_pos = np.arange(num_points, dtype=float) % 360

unmasked_data = np.empty(dtype=object, shape=(1,))
unmasked_data[0] = np.core.records.fromarrays(
(field_ra, field_dec, rot_sky_pos),
dtype=np.dtype(
[
("fieldRA", field_ra.dtype),
("fieldDec", field_dec.dtype),
("rotSkyPos", rot_sky_pos.dtype),
]
),
)
masked_data = np.ma.MaskedArray(data=unmasked_data, mask=False, fill_value=-666, dtype=object)

bundle = maf.create_empty_metric_bundle()
bundle.slicer = maf.UniSlicer()
bundle._setup_metric_values()
bundle.metric_values = masked_data

def compute_camera_perimeter(ra, decl, rotation):
# just a quadrangle for this unit test.
# the math isn't quite right for an actual square,
# but good enough for a unit test.
size = 1.0
ras = [
ra - 0.5 * size * np.cos(np.radians(decl)) * np.sin(np.radians(rotation)),
ra - 0.5 * size * np.cos(np.radians(decl)) * np.cos(np.radians(rotation)),
ra + 0.5 * size * np.cos(np.radians(decl)) * np.sin(np.radians(rotation)),
ra + 0.5 * size * np.cos(np.radians(decl)) * np.cos(np.radians(rotation)),
]
decls = [
decl + 0.5 * size * np.cos(np.radians(rotation)),
decl - 0.5 * size * np.sin(np.radians(rotation)),
decl - 0.5 * size * np.cos(np.radians(rotation)),
decl + 0.5 * size * np.sin(np.radians(rotation)),
]
return ras, decls

plot_dict = {
"camera_perimeter_func": compute_camera_perimeter,
"model_observatory": model_observatory,
"decorations": ["ecliptic", "galactic_plane", "sun", "moon", "horizon"],
}
plotter = maf.VisitPerimeterPlotter()
bundle.set_plot_funcs([plotter])
bundle.set_plot_dict(plot_dict)
_ = bundle.plot()


if __name__ == "__main__":
unittest.main()
81 changes: 0 additions & 81 deletions tests/maf/test_skyproj_plotters.py

This file was deleted.

0 comments on commit 6b26944

Please sign in to comment.