Skip to content

Commit

Permalink
update selfcal
Browse files Browse the repository at this point in the history
  • Loading branch information
yoachim committed Oct 31, 2024
1 parent 3c307d3 commit 97d8f7f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
22 changes: 14 additions & 8 deletions rubin_sim/maf/maf_contrib/selfcal_uniformity_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ def _match(arr1, arr2):


class PhotometricSelfCalUniformityMetric(BaseMetric):
def __init__(self, nside_residual=128, highglat_cut=30.0, outlier_nsig=4.0):
def __init__(
self,
nside_residual=128,
highglat_cut=30.0,
outlier_nsig=4.0,
metric_name="PhotometricSelfCalUniformityMetric",
filter_name="r",
):
cols = [
"observationid",
"fieldra",
Expand All @@ -39,7 +46,7 @@ def __init__(self, nside_residual=128, highglat_cut=30.0, outlier_nsig=4.0):
"rotSkyPos",
"filter",
]
super().__init__(col=cols, metric_name="PhotometricSelfCalUniformityMetric")
super().__init__(col=cols, metric_name=metric_name)

filename = os.path.join(get_data_dir(), "maf", "monster_stars_uniformity_i15-18_sampled.parquet")
self.stars = Table.read(filename)
Expand All @@ -55,11 +62,10 @@ def __init__(self, nside_residual=128, highglat_cut=30.0, outlier_nsig=4.0):
self.outlier_nsig = outlier_nsig

self.units = "mmag"
self.filter_name = filter_name

def run(self, data_slice, slice_point=None):
filter_name = data_slice["filter"][0]

offsets = [OffsetSys(error_sys=0.03), OffsetSNR(lsst_filter=filter_name)]
offsets = [OffsetSys(error_sys=0.03), OffsetSNR(lsst_filter=self.filter_name)]

visits = np.zeros(
len(data_slice),
Expand All @@ -77,14 +83,14 @@ def run(self, data_slice, slice_point=None):
visits["fiveSigmaDepth"] = data_slice["fiveSigmaDepth"]
visits["rotSkyPos"] = data_slice["rotSkyPos"]

good_stars = np.isfinite(self.stars[f"{filter_name}mag"])
good_stars = np.isfinite(self.stars[f"{self.filter_name}mag"])
stars = self.stars[good_stars]

observed_stars = generate_catalog(
visits,
stars,
offsets=offsets,
lsst_filter=filter_name,
lsst_filter=self.filter_name,
n_patches=16,
verbose=False,
)
Expand All @@ -107,7 +113,7 @@ def run(self, data_slice, slice_point=None):
fit_stars_trimmed = fit_stars[b]

# Residuals after fit, removing floating zeropoint
resid = stars_trimmed[f"{filter_name}mag"] - fit_stars_trimmed["fit_mag"]
resid = stars_trimmed[f"{self.filter_name}mag"] - fit_stars_trimmed["fit_mag"]
resid = resid - np.median(resid)

resid_map = healbin(
Expand Down
19 changes: 15 additions & 4 deletions rubin_sim/maf/run_selfcal_metric.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def run_selfcal_metric():
action="store_true",
help="Do not remove existing directory outputs",
)
parser.add_argument("--filter", type=str, default="r")

args = parser.parse_args()

opsdb = args.db
Expand All @@ -43,13 +45,22 @@ def run_selfcal_metric():

# Set up the metric bundle.
map_nside = 128
selfcal_metric = PhotometricSelfCalUniformityMetric(nside_residual=map_nside)
selfcal_metric = PhotometricSelfCalUniformityMetric(
nside_residual=map_nside, filter_name=args.filter, metric_name="selfcal_uniformity-%s" % args.filter
)
slicer = UniSlicer()
# Exclude DDF visits
sql = "note not like '%DD%'"
sql = "scheduler_note not like '%DD%'"
# And run on only year 1 (?)
sql += " and night < 366"
bundle = MetricBundle(selfcal_metric, slicer, sql, run_name=sim_name, info_label="year 1 no-DD")
sql += " and filter='%s'" % args.filter
# Exclude strange exposure times
sql += " and visitExposureTime > 20"
sql += " and visitExposureTime < 40"

bundle = MetricBundle(
selfcal_metric, slicer, sql, run_name=sim_name, info_label="year 1 no-DD %s" % args.filter
)

# Set up the resultsDB
results_db = ResultsDb(out_dir=out_dir)
Expand All @@ -61,7 +72,7 @@ def run_selfcal_metric():

# Make plots of the residuals map
map_bundle = MetricBundle(
IdentityMetric(metric_name="PhotoCal Uniformity"),
IdentityMetric(metric_name="PhotoCal Uniformity, %s" % args.filter),
HealpixSlicer(map_nside),
sql,
run_name=sim_name,
Expand Down

0 comments on commit 97d8f7f

Please sign in to comment.