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

sqlite3 compatibility + note-scheduler_note fixes #444

Open
wants to merge 3 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
2 changes: 1 addition & 1 deletion rubin_sim/maf/batches/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def filter_list(all=True, extra_sql=None, extra_info_label=None):
sqls[f] = ""
info_labels[f] = md + "all bands"
else:
sqls[f] = 'filter = "%s"' % f
sqls[f] = "filter = '%s'" % f
info_labels[f] = md + "%s band" % f
if extra_sql is not None and len(extra_sql) > 0:
for s in sqls:
Expand Down
6 changes: 3 additions & 3 deletions rubin_sim/maf/batches/glance_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def glanceBatch(
else:
raise ValueError("Camera must be LSST or Comcam")

sql_per_filt = ['%s %s="%s"' % (sqlC, colmap["filter"], filtername) for filtername in filternames]
sql_per_filt = ["%s %s='%s'" % (sqlC, colmap["filter"], filtername) for filtername in filternames]
sql_per_and_all_filters = [sql_constraint] + sql_per_filt

standardStats = standard_summary()
Expand Down Expand Up @@ -349,7 +349,7 @@ def glanceBatch(
displayDict["caption"] = "Fraction of observations that are in pairs"
displayDict["subgroup"] = "Solar System"

sql = '%s (filter="g" or filter="r" or filter="i")' % sqlC
sql = "%s (filter='g' or filter='r' or filter='i')" % sqlC
pairSlicer = slicers.HealpixSlicer(
nside=pairnside,
lat_col=colmap["dec"],
Expand Down Expand Up @@ -402,7 +402,7 @@ def glanceBatch(
displayDict["subgroup"] = ""
for ddf in ddf_surveys:
label = ddf.replace("DD:", "")
sql = 'scheduler_note like "%s%%"' % ("DD:" + label)
sql = f"scheduler_note like 'DD:{label}%'"
slicer = slicers.UniSlicer()
metric = metrics.CumulativeMetric()
metricb = metric_bundles.MetricBundle(
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
14 changes: 7 additions & 7 deletions rubin_sim/maf/batches/radar_limited.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def radar_limited(
for filtername in "ugrizy":
displayDict["caption"] = "Surface brightness limit in %s, no extinction applied." % filtername
displayDict["order"] = filterorders[f]
sql = 'filter="%s"' % filtername
sql = "filter='%s'" % filtername
metric = metrics.SurfaceBrightLimitMetric()
bundle = mb.MetricBundle(
metric,
Expand Down Expand Up @@ -529,7 +529,7 @@ def radar_limited(
for yr_cut in yrs:
ptsrc_lim_mag_i_band = mag_cuts[yr_cut]
sqlconstraint = "night <= %s" % (yr_cut * 365.25 + 0.5)
sqlconstraint += ' and scheduler_note not like "DD%"'
sqlconstraint += " and scheduler_note not like 'DD%'"
info_label = f"{bandpass} band non-DD year {yr_cut}"
ThreebyTwoSummary_simple = metrics.StaticProbesFoMEmulatorMetricSimple(
nside=nside, year=yr_cut, metric_name="3x2ptFoM_simple"
Expand Down Expand Up @@ -581,7 +581,7 @@ def radar_limited(
subgroupCount += 1
displayDict["subgroup"] = f"{subgroupCount}: WL"
displayDict["order"] = 0
sqlconstraint = 'scheduler_note not like "DD%" and (filter="g" or filter="r" or filter="i")'
sqlconstraint = "scheduler_note not like 'DD%' and (filter='g' or filter='r' or filter='i')"
info_label = "gri band non-DD"
minExpTime = 15
m = metrics.WeakLensingNvisits(
Expand Down Expand Up @@ -612,8 +612,8 @@ def radar_limited(
# Do the weak lensing per year
for year in [10]:
sqlconstraint = (
'scheduler_note not like "DD%"'
+ ' and (filter="g" or filter="r" or filter="i") and night < %i' % (year * 365.25)
"scheduler_note not like 'DD%'"
+ " and (filter='g' or filter='r' or filter='i') and night < %i" % (year * 365.25)
)
m = metrics.WeakLensingNvisits(
lsst_filter=bandpass,
Expand Down Expand Up @@ -648,8 +648,8 @@ def radar_limited(
bundleList.append(bundle)

sqlconstraint = (
'scheduler_note not like "DD%"'
+ ' and (filter="r" or filter="i" or filter="z") and night < %i' % (year * 365.25)
"scheduler_note not like 'DD%'"
+ " and (filter='r' or filter='i' or filter='z') and night < %i" % (year * 365.25)
)
m = metrics.WeakLensingNvisits(
lsst_filter=bandpass,
Expand Down
26 changes: 13 additions & 13 deletions rubin_sim/maf/batches/science_radar_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def science_radar_batch(
for filtername in "ugrizy":
displayDict["caption"] = "Surface brightness limit in %s, no extinction applied." % filtername
displayDict["order"] = filterorders[f]
sql = 'filter="%s"' % filtername
sql = "filter='%s'" % filtername
metric = metrics.SurfaceBrightLimitMetric()
bundle = mb.MetricBundle(
metric,
Expand Down Expand Up @@ -568,7 +568,7 @@ def science_radar_batch(
for yr_cut in yrs:
ptsrc_lim_mag_i_band = mag_cuts[yr_cut]
sqlconstraint = "night <= %s" % (yr_cut * 365.25 + 0.5)
sqlconstraint += ' and scheduler_note not like "DD%"'
sqlconstraint += " and scheduler_note not like 'DD%'"
info_label = f"{bandpass} band non-DD year {yr_cut}"
ThreebyTwoSummary = maf.StaticProbesFoMEmulatorMetric(nside=nside, metric_name="3x2ptFoM")

Expand Down Expand Up @@ -612,7 +612,7 @@ def science_radar_batch(
plotDict = {"n_ticks": 5}
# Have to include all filters in query to check for filter coverage.
# Galaxy numbers calculated using 'bandpass' images only though.
sqlconstraint = 'scheduler_note not like "DD%"'
sqlconstraint = "scheduler_note not like 'DD%'"
info_label = f"{bandpass} band galaxies non-DD"
metric = maf.DepthLimitedNumGalMetric(
nside=nside,
Expand Down Expand Up @@ -652,7 +652,7 @@ def science_radar_batch(
subgroupCount += 1
displayDict["subgroup"] = f"{subgroupCount}: WL"
displayDict["order"] = 0
sqlconstraint = 'scheduler_note not like "DD%" and (filter="g" or filter="r" or filter="i")'
sqlconstraint = "scheduler_note not like 'DD%' and (filter='g' or filter='r' or filter='i')"
info_label = "gri band non-DD"
minExpTime = 15
m = metrics.WeakLensingNvisits(
Expand Down Expand Up @@ -684,8 +684,8 @@ def science_radar_batch(
for year in np.arange(1, 10):
displayDict["order"] = year
sqlconstraint = (
'scheduler_note not like "DD%"'
+ ' and (filter="g" or filter="r" or filter="i") and night < %i' % (year * 365.25)
"scheduler_note not like 'DD%'"
+ " and (filter='g' or filter='r' or filter='i') and night < %i" % (year * 365.25)
)
m = metrics.WeakLensingNvisits(
lsst_filter=bandpass,
Expand Down Expand Up @@ -720,8 +720,8 @@ def science_radar_batch(
bundleList.append(bundle)

sqlconstraint = (
'scheduler_note not like "DD%"'
+ ' and (filter="r" or filter="i" or filter="z") and night < %i' % (year * 365.25)
"scheduler_note not like 'DD%'"
+ " and (filter='r' or filter='i' or filter='z') and night < %i" % (year * 365.25)
)
m = metrics.WeakLensingNvisits(
lsst_filter=bandpass,
Expand Down Expand Up @@ -779,8 +779,8 @@ def science_radar_batch(
# Kuiper per year in gri and riz
for year in np.arange(1, 10):
sqlconstraint = (
'scheduler_note not like "DD%"'
+ ' and (filter="g" or filter="r" or filter="i") and night < %i' % (year * 365.25)
"scheduler_note not like 'DD%'"
+ " and (filter='g' or filter='r' or filter='i') and night < %i" % (year * 365.25)
)
metric1 = metrics.KuiperMetric("rotSkyPos", metric_name="Kuiper_rotSkyPos_gri_year%i" % year)
metric2 = metrics.KuiperMetric("rotTelPos", metric_name="Kuiper_rotTelPos_gri_year%i" % year)
Expand Down Expand Up @@ -1827,7 +1827,7 @@ def science_radar_batch(
i_starMap = maf.maps.StellarDensityMap(filtername="i")
lv_slicer = maf.maf_contrib.generate_known_lv_dwarf_slicer()
lv_metric = maf.maf_contrib.LVDwarfsMetric()
sqlconstraint = '(filter = "i" OR filter = "g")'
sqlconstraint = "(filter = 'i' OR filter = 'g')"
info_label = "gi"
cutoff = -6.4
summary_metrics = [
Expand Down Expand Up @@ -1874,7 +1874,7 @@ def science_radar_batch(
"star-galaxy separation), over the southern celestial pole,"
"to a distance of 0.1 Mpc."
)
sqlconstraint = '(filter = "i" OR filter = "g") and fieldDec < -60'
sqlconstraint = "(filter = 'i' OR filter = 'g') and fieldDec < -60"
info_label = "gi SCP"
lv_metric3 = maf.maf_contrib.LVDwarfsMetric(distlim=0.1 * u.Mpc) # for a distance limit, healpix map
summary_area = maf.metrics.AreaThresholdMetric(lower_threshold=0.0, metric_name="Area M_v>0.0")
Expand Down Expand Up @@ -1942,7 +1942,7 @@ def science_radar_batch(

displayDict = {"group": "Scaling Numbers", "subgroup": ""}
displayDict["subgroup"] = "N gals"
sql = 'filter="i"'
sql = "filter='i'"
metric = metrics.NgalScaleMetric()
# galaxy counting uses dustmap
slicer = slicers.HealpixSlicer(nside=nside, use_cache=False)
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
17 changes: 8 additions & 9 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 Expand Up @@ -74,9 +73,9 @@ def intraNight(
"order": 0,
}
if extraSql is not None and len(extraSql) > 0:
sql = '(%s) and (filter="g" or filter="r" or filter="i")' % extraSql
sql = "(%s) and (filter='g' or filter='r' or filter='i')" % extraSql
else:
sql = 'filter="g" or filter="r" or filter="i"'
sql = "filter='g' or filter='r' or filter='i'"
md = "gri"
if info_label is not None:
md += " " + info_label
Expand Down Expand Up @@ -215,11 +214,11 @@ def intraNight(
bundleList.append(bundle)
# subsets of adjacent filters
filtersubsets = {
"ug": '(filter = "u" or filter = "g")',
"gr": '(filter = "g" or filter = "r")',
"ri": '(filter = "r" or filter = "i")',
"iz": '(filter = "i" or filter = "z")',
"zy": '(filter = "z" or filter = "y")',
"ug": "(filter = 'u' or filter = 'g')",
"gr": "(filter = 'g' or filter = 'r')",
"ri": "(filter = 'r' or filter = 'i')",
"iz": "(filter = 'i' or filter = 'z')",
"zy": "(filter = 'z' or filter = 'y')",
}
sqls = [extraSql]
if extraSql is not None and len(extraSql) > 0:
Expand Down
9 changes: 4 additions & 5 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 Expand Up @@ -60,9 +59,9 @@ def phaseGap(
# largest phase gap for periods
periods = [0.1, 1.0, 10.0, 100.0]
sqls = [
'filter = "u"',
'filter="r"',
'filter="g" or filter="r" or filter="i" or filter="z"',
"filter='u'",
"filter='r'",
"filter='g' or filter='r' or filter='i' or filter='z'",
"",
]
filter_names = ["u", "r", "griz", "all"]
Expand Down
10 changes: 5 additions & 5 deletions rubin_sim/maf/maf_night_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def make_bundle_list(
azCol = "azimuth"
# Construct sql queries for each filter and all filters
filters = ["u", "g", "r", "i", "z", "y"]
sqls = ['night=%i and filter="%s"' % (night, f) for f in filters]
sqls = ["night=%i and filter='%s'" % (night, f) for f in filters]
sqls.append("night=%i" % night)

bundleList = []
Expand Down Expand Up @@ -107,12 +107,12 @@ def make_bundle_list(

# Make plots of the solar system pairs that were taken in the night
metric = metrics.PairMetric(mjd_col=mjdCol)
sql = 'night=%i and (filter ="r" or filter="g" or filter="i")' % night
sql = "night=%i and (filter ='r' or filter='g' or filter='i')" % night
bundle = metricBundles.MetricBundle(metric, reg_slicer, sql)
bundleList.append(bundle)

metric = metrics.PairMetric(mjd_col=mjdCol, metric_name="z Pairs")
sql = 'night=%i and filter="z"' % night
sql = "night=%i and filter='z'" % night
bundle = metricBundles.MetricBundle(metric, reg_slicer, sql)
bundleList.append(bundle)

Expand All @@ -127,11 +127,11 @@ def make_bundle_list(
# stats from the note column
if notes:
display_dict = {"group": "Basic Stats", "subgroup": "Percent stats"}
metric = metrics.StringCountMetric(col="note", percent=True, metric_name="Percents")
metric = metrics.StringCountMetric(col="scheduler_note", percent=True, metric_name="Percents")
bundle = metricBundles.MetricBundle(metric, unislicer, sql, display_dict=display_dict)
bundleList.append(bundle)
display_dict["subgroup"] = "Count Stats"
metric = metrics.StringCountMetric(col="note", metric_name="Counts")
metric = metrics.StringCountMetric(col="scheduler_note", metric_name="Counts")
bundle = metricBundles.MetricBundle(metric, unislicer, sql, display_dict=display_dict)
bundleList.append(bundle)

Expand Down
6 changes: 3 additions & 3 deletions rubin_sim/maf/metric_bundles/metric_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class MetricBundle:
Setting this provides an easy way to specify different
configurations of a metric, a slicer,
or just to rewrite your constraint into friendlier terms.
(i.e. a constraint like 'note not like "%DD%"' can become
(i.e. a constraint like 'scheduler_note not like "%DD%"' can become
"non-DD" in the file name and plot labels
by specifying info_label).
plot_dict : `dict` of plotting parameters, opt
Expand Down Expand Up @@ -90,7 +90,7 @@ class MetricBundle:
Together these define a unique combination of an opsim benchmark,
or "metric bundle".
An example would be:
a CountMetric, a HealpixSlicer, and a constraint of 'filter="r"'.
a CountMetric, a HealpixSlicer, and a constraint of "filter='r'".

After the metric is evaluated at each slice_point created by the
slicer, the resulting metric values are saved in the MetricBundle.
Expand Down Expand Up @@ -243,7 +243,7 @@ def _build_metadata(self, info_label, metadata=None):
"""If no info_label is provided, process the constraint
(by removing extra spaces, quotes, the word 'filter' and equal signs)
to make a info_label version.
e.g. 'filter = "r"' becomes 'r'
e.g. "filter = 'r'" becomes 'r'
"""
# Pass the deprecated version into info_label if info_label is not set
if metadata is not None and info_label is None:
Expand Down
2 changes: 1 addition & 1 deletion rubin_sim/maf/metric_bundles/mo_metric_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class MoMetricBundle(MetricBundle):
Setting this provides an easy way to specify different
configurations of a metric, a slicer,
or just to rewrite your constraint into friendlier terms.
(i.e. a constraint like 'note not like "%DD%"' can become
(i.e. a constraint like 'scheduler_note not like "%DD%"' can become
"non-DD" in the file name and plot labels
by specifying info_label).
plot_dict : `dict` of plotting parameters, opt
Expand Down
2 changes: 1 addition & 1 deletion rubin_sim/maf/metrics/sn_n_sn_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SNNSNMetric(BaseMetric):
seeing_col : `str`, opt
seeing column name (default: seeingFwhmEff)
note_col : `str`, opt
note column name (default: note)
note column name (default: scheduler_note)
season : `list`, opt
list of seasons to process (float)(default: -1 = all seasons)
coadd : `bool`, opt
Expand Down
2 changes: 1 addition & 1 deletion rubin_sim/maf/metrics/use_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def run(self, data_slice, slice_point=None): # pylint: disable=invalid-name
if band in note_elems[1]:
use_name = "wide with u, g, or r"

assert use_name is not None, f"Unrecognized note: {note}"
assert use_name is not None, f"Unrecognized scheduler_note: {note}"
return use_name


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: 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
Loading
Loading