Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

U/yoachim/futures #442

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions rubin_sim/maf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
"""Python interface to the metrics analysis framework.
"""
"""Python interface to the metrics analysis framework."""
from .batches import *
from .db import *
from .maf_contrib import *
Expand Down
3 changes: 1 addition & 2 deletions rubin_sim/maf/batches/hourglass_batch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Run the hourglass metric.
"""
"""Run the hourglass metric."""

__all__ = ("hourglassPlots",)

Expand Down
3 changes: 1 addition & 2 deletions rubin_sim/maf/batches/metadata_batch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Some basic physical quantity metrics.
"""
"""Some basic physical quantity metrics."""

__all__ = (
"metadataBasics",
Expand Down
3 changes: 1 addition & 2 deletions rubin_sim/maf/batches/openshutter_batch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Evaluate the open shutter fraction.
"""
"""Evaluate the open shutter fraction."""

__all__ = ("openshutterFractions",)

Expand Down
3 changes: 1 addition & 2 deletions rubin_sim/maf/batches/skycoverage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Evaluate some bulk properties of the sky coverage
"""
"""Evaluate some bulk properties of the sky coverage"""

__all__ = ("meanRADec", "eastWestBias")

Expand Down
3 changes: 1 addition & 2 deletions rubin_sim/maf/batches/slew_batch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Sets of slew metrics.
"""
"""Sets of slew metrics."""

__all__ = ("slewBasics",)

Expand Down
3 changes: 1 addition & 2 deletions rubin_sim/maf/batches/time_batch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Sets of metrics to look at time between visits/pairs, etc.
"""
"""Sets of metrics to look at time between visits/pairs, etc."""

__all__ = ("intraNight", "interNight", "timeGaps", "seasons")

Expand Down
3 changes: 1 addition & 2 deletions rubin_sim/maf/batches/time_sci_batch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Sets of metrics to look at impact of cadence on science
"""
"""Sets of metrics to look at impact of cadence on science"""

__all__ = ("phaseGap",)

Expand Down
2 changes: 1 addition & 1 deletion rubin_sim/maf/metrics/summary_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def __init__(
def run(self, data_slice, slice_point=None):
# Calculate the power spectrum.
if self.remove_dipole:
cl = hp.anafast(hp.remove_dipole(data_slice[self.colname], verbose=False))
cl = hp.anafast(hp.remove_dipole(data_slice[self.colname]))
else:
cl = hp.anafast(data_slice[self.colname])
ell = np.arange(np.size(cl))
Expand Down
3 changes: 1 addition & 2 deletions rubin_sim/maf/plots/hg_plotters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Second generation hourglass plotting classes.
"""
"""Second generation hourglass plotting classes."""

# pylint: disable=too-many-arguments
# pylint: disable=super-init-not-called
Expand Down
3 changes: 2 additions & 1 deletion rubin_sim/maf/plots/neo_distance_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import matplotlib.pyplot as plt
import numpy as np
from matplotlib import colormaps
from matplotlib.patches import Ellipse

from .plot_handler import BasePlotter
Expand Down Expand Up @@ -121,7 +122,7 @@ def __call__(self, metric_value, slicer, user_plot_dict, fig=None):
H[good] += 1

# Set the under value to white
my_cmap = copy.copy(plt.cm.get_cmap("jet"))
my_cmap = copy.copy(colormaps["jet"])
my_cmap.set_under("w")
blah = ax.pcolormesh(xgrid, ygrid + 1, H, cmap=my_cmap, vmin=0.001, shading="auto")
cb = plt.colorbar(blah, ax=ax)
Expand Down
4 changes: 0 additions & 4 deletions rubin_sim/maf/plots/spatial_plotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,10 +1016,6 @@ def __call__(self, metric_value_in, slicer, user_plot_dict, fig=None):
ax.set_xlim([-max_val, max_val])
ax.set_ylim([-max_val, max_val])

# Try to fix the ugly pdf contour problem
for c in tcf.collections:
c.set_edgecolor("face")

cb = plt.colorbar(tcf, format=plot_dict["cbar_format"])
cb.set_label(plot_dict["xlabel"])
if plot_dict["labelsize"] is not None:
Expand Down
3 changes: 1 addition & 2 deletions rubin_sim/maf/run_comparison/archive.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Tools for use of project-generated opsim simulations and analysis.
"""
"""Tools for use of project-generated opsim simulations and analysis."""

__all__ = (
"get_metric_subsets",
Expand Down
3 changes: 1 addition & 2 deletions rubin_sim/maf/run_comparison/summary_plots.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Summary metric plotting functions.
"""
"""Summary metric plotting functions."""

__all__ = (
"normalize_metric_summaries",
Expand Down
2 changes: 1 addition & 1 deletion rubin_sim/maf/slicers/time_interval_slicers.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def setup_slicer(self, sim_data, maps=None):
same_note = visits.note == visits.note.shift(-1)
adjacent_times = visits.end_mjd + self.gap_tolerance / 24.0 > visits.mjd.shift(-1)
visits["sid"] = np.logical_not(np.logical_and(same_note, adjacent_times)).cumsum().shift()
visits["sid"].fillna(0, inplace=True)
visits.fillna({"sid": 0}, inplace=True)
visits["sid"] = visits["sid"].astype(int)

blocks = visits.groupby("sid").agg(
Expand Down
2 changes: 1 addition & 1 deletion rubin_sim/maf/utils/stellar_mags.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def stellar_mags(stellar_type, rmag=19.0):
if not hasattr(stellar_mags, "data"):
names = ["stellar_type", "Model Name", "u-g", "g-r", "r-i", "i-z", "z-y"]
types = [("U", 20), ("U", 35), float, float, float, float, float]
data = np.core.records.fromrecords(
data = np._core.records.fromrecords(
[
(
"O",
Expand Down
8 changes: 4 additions & 4 deletions tests/maf/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def test_complex(self):
data = np.zeros(slicer.nslice, dtype="object")
for i, ack in enumerate(data):
n_el = rng.rand(1) * 4 # up to 4 elements
data[i] = np.arange(n_el)
data[i] = np.arange(n_el[0])
with TemporaryFile() as filename:
slicer.write_data(filename, data)
_ = filename.seek(0)
Expand All @@ -166,10 +166,10 @@ def test_complex(self):
def test_n_d_slicer(self):
rng = np.random.RandomState(621)
colnames = ["test1", "test2", "test3"]
data = []
n = 1000
dv = np.zeros(n, dtype=list(zip(colnames, [float] * 3)))
for c in colnames:
data.append(rng.rand(1000))
dv = np.core.records.fromarrays(data, names=colnames)
dv[c] = rng.rand(n)
slicer = slicers.NDSlicer(colnames, bins_list=10)
slicer.setup_slicer(dv)
with TemporaryFile() as filename:
Expand Down
18 changes: 8 additions & 10 deletions tests/maf/test_plotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,15 @@ def test_visit_perimeter_plotter(self):
field_dec = np.arange(-60, -60 + num_points, dtype=float)
rot_sky_pos = np.arange(num_points, dtype=float) % 360

names = ["fieldRA", "fieldDec", "rotSkyPos"]
dtypes = [float] * 3
data = np.empty(field_ra.size, dtype=list(zip(names, dtypes)))
data["fieldRA"] = field_ra
data["fieldDec"] = field_dec
data["rotSkyPos"] = rot_sky_pos

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),
]
),
)
unmasked_data[0] = data
masked_data = np.ma.MaskedArray(data=unmasked_data, mask=False, fill_value=-666, dtype=object)

bundle = maf.create_empty_metric_bundle()
Expand Down
17 changes: 6 additions & 11 deletions tests/maf/test_stackers.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,12 @@ def test_overhead_stacker(self):
observation_end_mjds = start_mjd + np.cumsum(visit_times) / (24 * 60 * 60)
mjds = observation_end_mjds - visit_times / (24 * 60 * 60)
mjds[num_first_night_visits:] += 1

data = np.core.records.fromarrays(
(mjds, exposure_times, visit_times),
dtype=np.dtype(
[
("observationStartMJD", mjds.dtype),
("visitExposureTime", exposure_times.dtype),
("visitTime", visit_times.dtype),
]
),
)
names = ["observationStartMJD", "visitExposureTime", "visitTime"]
types = [float] * 3
data = np.zeros(mjds.size, dtype=list(zip(names, types)))
data["observationStartMJD"] = mjds
data["visitExposureTime"] = exposure_times
data["visitTime"] = visit_times

overhead_stacker = stackers.OverheadStacker()
new_data = overhead_stacker.run(data)
Expand Down
87 changes: 59 additions & 28 deletions tests/maf/test_technicalmetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,16 @@ def test_n_changes_metric(self):
"""
filters = np.array(["u", "u", "g", "g", "r"])
visit_times = np.arange(0, filters.size, 1)
data = np.core.records.fromarrays([visit_times, filters], names=["observationStartMJD", "filter"])
names = ["observationStartMJD", "filter"]
types = [float, "U1"]
data = np.zeros(filters.size, dtype=list(zip(names, types)))
data["filter"] = filters
data["observationStartMJD"] = visit_times

metric = metrics.NChangesMetric()
result = metric.run(data)
self.assertEqual(result, 2)
filters = np.array(["u", "g", "u", "g", "r"])
data = np.core.records.fromarrays([visit_times, filters], names=["observationStartMJD", "filter"])
data["filter"] = np.array(["u", "g", "u", "g", "r"])
metric = metrics.NChangesMetric()
result = metric.run(data)
self.assertEqual(result, 4)
Expand All @@ -104,7 +108,11 @@ def test_min_time_between_states_metric(self):
"""
filters = np.array(["u", "g", "g", "r"])
visit_times = np.array([0, 5, 6, 7]) # days
data = np.core.records.fromarrays([visit_times, filters], names=["observationStartMJD", "filter"])
names = ["observationStartMJD", "filter"]
types = [float, "U1"]
data = np.zeros(filters.size, dtype=list(zip(names, types)))
data["filter"] = filters
data["observationStartMJD"] = visit_times
metric = metrics.MinTimeBetweenStatesMetric()
result = metric.run(data) # minutes
self.assertEqual(result, 2 * 24.0 * 60.0)
Expand All @@ -118,7 +126,11 @@ def test_n_state_changes_faster_than_metric(self):
"""
filters = np.array(["u", "g", "g", "r"])
visit_times = np.array([0, 5, 6, 7]) # days
data = np.core.records.fromarrays([visit_times, filters], names=["observationStartMJD", "filter"])
names = ["observationStartMJD", "filter"]
types = [float, "U1"]
data = np.zeros(filters.size, dtype=list(zip(names, types)))
data["filter"] = filters
data["observationStartMJD"] = visit_times
metric = metrics.NStateChangesFasterThanMetric(cutoff=3 * 24 * 60)
result = metric.run(data) # minutes
self.assertEqual(result, 1)
Expand All @@ -129,27 +141,37 @@ def test_max_state_changes_within_metric(self):
"""
filters = np.array(["u", "g", "r", "u", "g", "r"])
visit_times = np.array([0, 1, 1, 4, 6, 7]) # days
data = np.core.records.fromarrays([visit_times, filters], names=["observationStartMJD", "filter"])
names = ["observationStartMJD", "filter"]
types = [float, "U1"]
data = np.zeros(filters.size, dtype=list(zip(names, types)))
data["filter"] = filters
data["observationStartMJD"] = visit_times
metric = metrics.MaxStateChangesWithinMetric(timespan=1 * 24 * 60)
result = metric.run(data) # minutes
self.assertEqual(result, 2)
filters = np.array(["u", "g", "g", "u", "g", "r", "g", "r"])
visit_times = np.array([0, 1, 1, 4, 4, 7, 8, 8]) # days
data = np.core.records.fromarrays([visit_times, filters], names=["observationStartMJD", "filter"])
data = np.zeros(filters.size, dtype=list(zip(names, types)))
data["filter"] = filters
data["observationStartMJD"] = visit_times
metric = metrics.MaxStateChangesWithinMetric(timespan=1 * 24 * 60)
result = metric.run(data) # minutes
self.assertEqual(result, 3)

filters = np.array(["u", "g"])
visit_times = np.array([0, 1]) # days
data = np.core.records.fromarrays([visit_times, filters], names=["observationStartMJD", "filter"])
data = np.zeros(filters.size, dtype=list(zip(names, types)))
data["filter"] = filters
data["observationStartMJD"] = visit_times
metric = metrics.MaxStateChangesWithinMetric(timespan=1 * 24 * 60)
result = metric.run(data) # minutes
self.assertEqual(result, 1)

filters = np.array(["u", "u"])
visit_times = np.array([0, 1]) # days
data = np.core.records.fromarrays([visit_times, filters], names=["observationStartMJD", "filter"])
data = np.zeros(filters.size, dtype=list(zip(names, types)))
data["filter"] = filters
data["observationStartMJD"] = visit_times
metric = metrics.MaxStateChangesWithinMetric(timespan=1 * 24 * 60)
result = metric.run(data) # minutes
self.assertEqual(result, 0)
Expand All @@ -164,9 +186,12 @@ def test_teff_regression(self):
filters = rng.choice(bands, num_points)
fiducial_depth = {b: 24 + rng.random() for b in bands}
exposure_time = np.full(num_points, 30.0, dtype=float)
data = np.core.records.fromarrays(
[m5, filters, exposure_time], names=["fiveSigmaDepth", "filter", "visitExposureTime"]
)
names = ["fiveSigmaDepth", "filter", "visitExposureTime"]
types = [float, "U1", float]
data = np.zeros(filters.size, dtype=list(zip(names, types)))
data["filter"] = filters
data["fiveSigmaDepth"] = m5
data["visitExposureTime"] = exposure_time
teff_stacker = stackers.TeffStacker(fiducial_depth=fiducial_depth, teff_base=30.0)
data = teff_stacker.run(data)

Expand All @@ -176,9 +201,10 @@ def test_teff_regression(self):
old_result = old_metric.run(data)
self.assertEqual(result, old_result)

data = np.core.records.fromarrays(
[m5, filters, exposure_time], names=["fiveSigmaDepth", "filter", "visitExposureTime"]
)
data = np.zeros(filters.size, dtype=list(zip(names, types)))
data["filter"] = filters
data["fiveSigmaDepth"] = m5
data["visitExposureTime"] = exposure_time
teff_stacker = stackers.TeffStacker(fiducial_depth=fiducial_depth, teff_base=30.0, normed=True)
data = teff_stacker.run(data)
metric = metrics.MeanMetric(col="t_eff")
Expand All @@ -197,10 +223,12 @@ def test_open_shutter_fraction_metric(self):
visit_exp_time = np.ones(nvisit, dtype="float") * exptime
visit_time = np.ones(nvisit, dtype="float") * (exptime + 0.0)
slew_time = np.ones(nvisit, dtype="float") * slewtime
data = np.core.records.fromarrays(
[visit_exp_time, visit_time, slew_time],
names=["visitExposureTime", "visitTime", "slewTime"],
)
names = ["visitExposureTime", "visitTime", "slewTime"]
types = [float, float, float]
data = np.zeros(visit_exp_time.size, dtype=list(zip(names, types)))
data["visitExposureTime"] = visit_exp_time
data["visitTime"] = visit_time
data["slewTime"] = slew_time
metric = metrics.OpenShutterFractionMetric()
result = metric.run(data)
self.assertEqual(result, 0.5)
Expand All @@ -217,15 +245,18 @@ def test_brute_osf_metric(self):
slew_time = np.ones(nvisit, dtype="float") * slewtime
mjd = np.zeros(nvisit) + np.add.accumulate(visit_exp_time) + np.add.accumulate(slew_time)
mjd = mjd / 60.0 / 60.0 / 24.0
data = np.core.records.fromarrays(
[visit_exp_time, visit_time, slew_time, mjd],
names=[
"visitExposureTime",
"visit_time",
"slew_time",
"observationStartMJD",
],
)
names = [
"visitExposureTime",
"visit_time",
"slew_time",
"observationStartMJD",
]
types = [float] * 4
data = np.zeros(visit_exp_time.size, dtype=list(zip(names, types)))
data["visitExposureTime"] = visit_exp_time
data["visit_time"] = visit_time
data["slew_time"] = slew_time
data["observationStartMJD"] = mjd
metric = metrics.BruteOSFMetric()
result = metric.run(data)
self.assertGreater(result, 0.5)
Expand Down
Loading
Loading