From 095572a827268c7d614631fa1ad42ec182a5fa1a Mon Sep 17 00:00:00 2001 From: Lynne Jones Date: Tue, 5 Mar 2024 15:59:25 -0800 Subject: [PATCH] Update fO plot defaults, use 750 as min nvis for fO_area --- rubin_sim/maf/batches/glance_batch.py | 4 +- rubin_sim/maf/batches/info_batch.py | 6 +- rubin_sim/maf/batches/radar_limited.py | 4 +- rubin_sim/maf/batches/science_radar_batch.py | 4 +- rubin_sim/maf/batches/srd_batch.py | 124 ++++++++++--------- rubin_sim/maf/plots/special_plotters.py | 23 ++-- 6 files changed, 87 insertions(+), 78 deletions(-) diff --git a/rubin_sim/maf/batches/glance_batch.py b/rubin_sim/maf/batches/glance_batch.py index 13a3bd6ca..1c2d99d70 100644 --- a/rubin_sim/maf/batches/glance_batch.py +++ b/rubin_sim/maf/batches/glance_batch.py @@ -413,8 +413,8 @@ def glanceBatch( metric = metrics.CountExplimMetric(metric_name="fO") plotDict = { "xlabel": "Number of Visits", - "Asky": benchmarkArea, - "Nvisit": minNvisits, + "asky": benchmarkArea, + "n_visits": minNvisits, "x_min": 0, "x_max": 1500, } diff --git a/rubin_sim/maf/batches/info_batch.py b/rubin_sim/maf/batches/info_batch.py index 0ecaf0104..edcc51ca4 100644 --- a/rubin_sim/maf/batches/info_batch.py +++ b/rubin_sim/maf/batches/info_batch.py @@ -11,12 +11,12 @@ def info_bundle_dicts(allsky_slicer, wfd_slicer, opsim="opsim", colmap=batches.c bdict = {} for tag, slicer in zip(["All sky", "WFD"], [allsky_slicer, wfd_slicer]): - fO = batches.fOBatch(colmap=colmap, runName=opsim, slicer=slicer, extraInfoLabel=tag) + fO = batches.fOBatch(colmap=colmap, run_name=opsim, slicer=slicer, extra_info=tag) bdict.update(fO) - astrometry = batches.astrometryBatch(colmap=colmap, runName=opsim, slicer=slicer, extraInfoLabel=tag) + astrometry = batches.astrometryBatch(colmap=colmap, run_name=opsim, slicer=slicer, extra_info=tag) bdict.update(astrometry) rapidrevisit = batches.rapidRevisitBatch( - colmap=colmap, runName=opsim, slicer=slicer, extraInfoLabel=tag + colmap=colmap, run_name=opsim, slicer=slicer, extra_info=tag ) bdict.update(rapidrevisit) diff --git a/rubin_sim/maf/batches/radar_limited.py b/rubin_sim/maf/batches/radar_limited.py index 99eae4dd2..927ebd74e 100644 --- a/rubin_sim/maf/batches/radar_limited.py +++ b/rubin_sim/maf/batches/radar_limited.py @@ -80,8 +80,8 @@ def radar_limited( metric = metrics.CountExplimMetric(col="observationStartMJD", metric_name="fO") plotDict = { "xlabel": "Number of Visits", - "Asky": benchmarkArea, - "Nvisit": benchmarkNvisits, + "asky": benchmarkArea, + "n_visits": benchmarkNvisits, "x_min": 0, "x_max": 1500, } diff --git a/rubin_sim/maf/batches/science_radar_batch.py b/rubin_sim/maf/batches/science_radar_batch.py index 5ccfb1290..6865ae401 100644 --- a/rubin_sim/maf/batches/science_radar_batch.py +++ b/rubin_sim/maf/batches/science_radar_batch.py @@ -84,8 +84,8 @@ def science_radar_batch( metric = metrics.CountExplimMetric(metric_name="fO") plotDict = { "xlabel": "Number of Visits", - "Asky": benchmarkArea, - "Nvisit": minNvisits, + "asky": benchmarkArea, + "n_visits": minNvisits, "x_min": 0, "x_max": 1500, } diff --git a/rubin_sim/maf/batches/srd_batch.py b/rubin_sim/maf/batches/srd_batch.py index 9ee750700..7a94930d2 100644 --- a/rubin_sim/maf/batches/srd_batch.py +++ b/rubin_sim/maf/batches/srd_batch.py @@ -21,30 +21,36 @@ def fOBatch( colmap=None, - runName="run_name", - extraSql=None, - extraInfoLabel=None, + run_name="run_name", + extra_sql=None, + extra_info=None, slicer=None, - benchmarkArea=18000, - benchmarkn_visits=825, - minn_visits=750, + benchmark_area=18000, + benchmark_n_visits=825, + min_n_visits=750, ): """Metrics for calculating fO. Parameters ---------- - colmap : `dict` or None, optional + colmap : `dict` or None, opt A dictionary with a mapping of column names. - runName : `str`, optional + run_name : `str`, opt The name of the simulated survey. - extraSql : `str` or None, optional + extra_sql : `str` or None, opt Additional sql constraint to apply to all metrics. - extraInfoLabel : `str` or None, optional + extra_Info : `str` or None, opt Additional info_label to apply to all results. - slicer : `rubin_sim.maf.slicer.HealpixSlicer` or None, optional + slicer : `rubin_sim.maf.slicer.HealpixSlicer` or None, opt This must be a HealpixSlicer or some kind, although could be a HealpixSubsetSlicer. None will default to HealpixSlicer with nside=64. + benchmark_area : `float`, opt + Area to use when calculating fO_Nvis, for design. + benchmark_n_visits : `float`, opt + Nvisits minimum to use when calculating fO_Area, for design. + min_n_visits : `float`, opt + Nvisits minimum to use when calculating fO_Area, for minimum. Returns ------- @@ -58,13 +64,13 @@ def fOBatch( sql = "" info_label = "All visits" # Add additional sql constraint (such as wfdWhere) and info_label - if (extraSql is not None) and (len(extraSql) > 0): - sql = extraSql - if extraInfoLabel is None: - info_label = extraSql.replace("filter =", "").replace("filter=", "") + if (extra_sql is not None) and (len(extra_sql) > 0): + sql = extra_sql + if extra_info is None: + info_label = extra_sql.replace("filter =", "").replace("filter=", "") info_label = info_label.replace('"', "").replace("'", "") - if extraInfoLabel is not None: - info_label = extraInfoLabel + if extra_info is not None: + info_label = extra_info subgroup = info_label @@ -89,8 +95,8 @@ def fOBatch( metric = metrics.CountExplimMetric(metric_name="fO", exp_col=colmap["exptime"]) plotDict = { "xlabel": "Number of Visits", - "asky": benchmarkArea, - "n_visit": minn_visits, + "asky": benchmark_area, + "n_visits": min_n_visits, "x_min": 0, "x_max": 1500, } @@ -99,46 +105,46 @@ def fOBatch( nside=nside, norm=False, metric_name="fOArea", - asky=benchmarkArea, - n_visit=benchmarkn_visits, + asky=benchmark_area, + n_visit=benchmark_n_visits, ), metrics.FOArea( nside=nside, norm=True, metric_name="fOArea/benchmark", - asky=benchmarkArea, - n_visit=benchmarkn_visits, + asky=benchmark_area, + n_visit=benchmark_n_visits, ), metrics.FONv( nside=nside, norm=False, metric_name="fONv", - asky=benchmarkArea, - n_visit=benchmarkn_visits, + asky=benchmark_area, + n_visit=benchmark_n_visits, ), metrics.FONv( nside=nside, norm=True, metric_name="fONv/benchmark", - asky=benchmarkArea, - n_visit=benchmarkn_visits, + asky=benchmark_area, + n_visit=benchmark_n_visits, ), metrics.FOArea( nside=nside, norm=False, - metric_name=f"fOArea_{minn_visits}", - asky=benchmarkArea, - n_visit=minn_visits, + metric_name=f"fOArea_{min_n_visits}", + asky=benchmark_area, + n_visit=min_n_visits, ), ] caption = "The FO metric evaluates the overall efficiency of observing. " caption += ( "foNv: out of %.2f sq degrees, the area receives at least X and a median of Y visits " - "(out of %d, if compared to benchmark). " % (benchmarkArea, benchmarkn_visits) + "(out of %d, if compared to benchmark). " % (benchmark_area, benchmark_n_visits) ) caption += ( "fOArea: this many sq deg (out of %.2f sq deg if compared " - "to benchmark) receives at least %d visits. " % (benchmarkArea, benchmarkn_visits) + "to benchmark) receives at least %d visits. " % (benchmark_area, benchmark_n_visits) ) displayDict["caption"] = caption bundle = mb.MetricBundle( @@ -154,15 +160,15 @@ def fOBatch( bundleList.append(bundle) # Set the run_name for all bundles and return the bundleDict. for b in bundleList: - b.set_run_name(runName) + b.set_run_name(run_name) return mb.make_bundles_dict_from_list(bundleList) def astrometryBatch( colmap=None, - runName="opsim", - extraSql=None, - extraInfoLabel=None, + run_name="opsim", + extra_sql=None, + extra_info=None, slicer=None, ): """Metrics for evaluating proper motion and parallax. @@ -171,11 +177,11 @@ def astrometryBatch( ---------- colmap : `dict` or None, optional A dictionary with a mapping of column names. - runName : `str`, optional + run_name : `str`, optional The name of the simulated survey. - extraSql : `str` or None, optional + extra_sql : `str` or None, optional Additional sql constraint to apply to all metrics. - extraInfoLabel : `str` or None, optional + extra_info : `str` or None, optional Additional info_label to apply to all results. slicer : `rubin_sim.maf.slicer` or None, optional Optionally, specify something other than an nside=64 healpix slicer. @@ -191,13 +197,13 @@ def astrometryBatch( sql = "" info_label = "All visits" # Add additional sql constraint (such as wfdWhere) and info_label - if (extraSql is not None) and (len(extraSql) > 0): - sql = extraSql - if extraInfoLabel is None: - info_label = extraSql.replace("filter =", "").replace("filter=", "") + if (extra_sql is not None) and (len(extra_sql) > 0): + sql = extra_sql + if extra_info is None: + info_label = extra_sql.replace("filter =", "").replace("filter=", "") info_label = info_label.replace('"', "").replace("'", "") - if extraInfoLabel is not None: - info_label = extraInfoLabel + if extra_info is not None: + info_label = extra_info subgroup = info_label @@ -466,15 +472,15 @@ def astrometryBatch( # Set the run_name for all bundles and return the bundleDict. for b in bundleList: - b.set_run_name(runName) + b.set_run_name(run_name) return mb.make_bundles_dict_from_list(bundleList) def rapidRevisitBatch( colmap=None, - runName="opsim", - extraSql=None, - extraInfoLabel=None, + run_name="opsim", + extra_sql=None, + extra_info=None, slicer=None, ): """Metrics for evaluating proper motion and parallax. @@ -483,11 +489,11 @@ def rapidRevisitBatch( ---------- colmap : `dict` or None, optional A dictionary with a mapping of column names. - runName : `str`, optional + run_name : `str`, optional The name of the simulated survey. - extraSql : `str` or None, optional + extra_sql : `str` or None, optional Additional sql constraint to apply to all metrics. - extraInfoLabel : `str` or None, optional + extra_info : `str` or None, optional Additional info_label to apply to all results. slicer : `rubin_sim_maf.slicers.HealpixSlicer` or None, optional Optionally, specify something other than an nside=64 healpix slicer. @@ -504,13 +510,13 @@ def rapidRevisitBatch( sql = "" info_label = "All visits" # Add additional sql constraint (such as wfdWhere) and info_label. - if (extraSql is not None) and (len(extraSql) > 0): - sql = extraSql - if extraInfoLabel is None: - info_label = extraSql.replace("filter =", "").replace("filter=", "") + if (extra_sql is not None) and (len(extra_sql) > 0): + sql = extra_sql + if extra_info is None: + info_label = extra_sql.replace("filter =", "").replace("filter=", "") info_label = info_label.replace('"', "").replace("'", "") - if extraInfoLabel is not None: - info_label = extraInfoLabel + if extra_info is not None: + info_label = extra_info subgroup = info_label @@ -623,5 +629,5 @@ def rapidRevisitBatch( # Set the run_name for all bundles and return the bundleDict. for b in bundleList: - b.set_run_name(runName) + b.set_run_name(run_name) return mb.make_bundles_dict_from_list(bundleList) diff --git a/rubin_sim/maf/plots/special_plotters.py b/rubin_sim/maf/plots/special_plotters.py index ad7f4908c..b718d2ef1 100644 --- a/rubin_sim/maf/plots/special_plotters.py +++ b/rubin_sim/maf/plots/special_plotters.py @@ -75,34 +75,37 @@ def __call__(self, metric_value, slicer, user_plot_dict, fignum=None): ) # This results in calculating the summary stats in two places .. # not the ideal choice but easiest for most uses in this case. + asky = plot_dict["asky"] + n_visits = plot_dict["n_visits"] rarr = np.array(list(zip(metric_value.compressed())), dtype=[("fO", metric_value.dtype)]) f_o_area = metrics.FOArea( - col="fO", n_visit=plot_dict["n_visits"], norm=False, nside=slicer.nside + col="fO", n_visit=n_visits, norm=False, nside=slicer.nside ).run(rarr) - f_o_nv = metrics.FONv(col="fO", asky=plot_dict["asky"], norm=False, nside=slicer.nside).run(rarr) + f_o_nv = metrics.FONv(col="fO", asky=asky, norm=False, nside=slicer.nside).run(rarr) - plt.axvline(x=plot_dict["n_visits"], linewidth=plot_dict["reflinewidth"], color="b") - plt.axhline(y=plot_dict["asky"] / 1000.0, linewidth=plot_dict["reflinewidth"], color="r") + plt.axvline(x=n_visits, linewidth=plot_dict["reflinewidth"], color="b", linestyle=':') + plt.axhline(y=asky / 1000.0, linewidth=plot_dict["reflinewidth"], color="r", linestyle=':') # Add lines for nvis_median and f_o_area: # note if these are -666 (badval), they will 'disappear' - nvis_median = f_o_nv["value"][np.where(f_o_nv["name"] == "MedianNvis")] + nvis_median = f_o_nv["value"][np.where(f_o_nv["name"] == "MedianNvis")][0] + plt.axvline( x=nvis_median, linewidth=plot_dict["reflinewidth"], color="b", alpha=0.5, - linestyle=":", - label=r"f$_0$ Median n_visits=%.0f" % nvis_median, + linestyle="-", + label=f"f$_0$ Med. Nvis. (@ {asky/1000 :.0f}K sq deg) = {nvis_median :.0f} visits", ) plt.axhline( y=f_o_area / 1000.0, linewidth=plot_dict["reflinewidth"], color="r", alpha=0.5, - linestyle=":", - label="f$_0$ Area=%.0f" % f_o_area, + linestyle="-", + label=f"f$_0$ Area (@ {n_visits :.0f} visits) = {f_o_area/1000 :.01f}K sq deg", ) - plt.legend(loc="lower left", fontsize="small", numpoints=1) + plt.legend(loc="upper right", fontsize="small", numpoints=1, framealpha=1.0) plt.xlabel(plot_dict["xlabel"]) plt.ylabel(plot_dict["ylabel"])