Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,4 @@ notebooks/demo_check_footprint.ipynb
notebooks/demo_calibrate_minimal_cat.ipynb
notebooks/leakage_minimal.ipynb
notebooks/demo_add_bands.ipynb
notebooks/demo_add_bands_to_empty.ipynb
29 changes: 8 additions & 21 deletions notebooks/leakage_minimal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# %%
# Plot binned quantites, see leakage_minima.py
# Compute binned quantities, see plot_binned_quantities.py

# %%
from IPython import get_ipython
Expand All @@ -13,6 +13,7 @@
ipython.run_line_magic("load_ext", "log_cell_time")

# %%
import os
import numpy as np
import pandas as pd

Expand All @@ -28,7 +29,7 @@
from sp_validation import plots as sp_plots

# %%
os.getcwd()
print("pwd:", os.getcwd())

# %%
# Initialize calibration class instance
Expand Down Expand Up @@ -135,28 +136,14 @@

df = calibration.build_df(cat_gal)

# %

num_bins_x = 12
num_bins_y = 12
# %%
num_bins_x = 15
num_bins_y = 15

quantities, bin_edges = calibration.get_quantities_binned(cat_gal, num_bins_x, num_bins_y)
s
quantities, bin_edges = calibration.get_quantities_binned(cat_gal, num_bins_x, num_bins_y, which=which)

# Save binned matrices to files
for key in quantities:
io.write_binned_quantity(quantities[key], key, bin_edges)

# %%
vmin = {"diag": -0.2, "offdiag": -0.2}
vmax = {"diag": 1.2, "offdiag": 0.2}

sp_plots.plot_binned(quantities, "response", bin_edges["snr"], bin_edges["size_ratio"], "R", vmin=vmin, vmax=vmax, xlabel="SNR", ylabel=r"$r / r_{\rm psf}$")

# %%
sp_plots.plot_binned(quantities, "number", bin_edges["snr"], bin_edges["size_ratio"], "R", vmin=1, vmax=np.nanmax(quantities["number"]), xlabel="SNR", ylabel=r"$r / r_{\rm psf}$")

# %%
vmin = {"diag": -0.2, "offdiag": -0.2}
vmax = {"diag": 0.2, "offdiag": 0.2}

sp_plots.plot_binned(quantities, "leakage", bin_edges["snr"], bin_edges["size_ratio"], r"\alpha", vmin=vmin, vmax=vmax, xlabel="SNR", ylabel=r"$r / r_{\rm psf}$")
85 changes: 67 additions & 18 deletions notebooks/plot_binned_quantities.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# %%
# Plot binned quantites, which are the outputs of leakage_minima.py
# Plot binned quantities, which are the outputs of leakage_minimal.py

# %%
from IPython import get_ipython
Expand All @@ -11,7 +11,7 @@
ipython.run_line_magic("load_ext", "autoreload")
ipython.run_line_magic("autoreload", "2")

# %%
# %%
import matplotlib.pyplot as plt
import numpy as np
import numpy as np
Expand All @@ -28,19 +28,21 @@
from sp_validation import io
from sp_validation import plots


# %%
# enable inline plotting for interactive sessions
# (must be done *after* importing package that sets agg backend)
if ipython is not None:
ipython.run_line_magic("matplotlib", "inline")

## %%
## enable inline plotting for interactive sessions
## (must be done *after* importing package that sets agg backend)
#if ipython is not None:
# print("matplotlib inline")
# ipython.run_line_magic("matplotlib", "inline")

# %%
bin_edges = {}
quantities = {}

# %%
keys = ["number", "response", "leakage"]
keys = ["number", "response", "leakage", "w_iv", "mag", "NGMIX_Tpsf_NOSHEAR", "N_EPOCH", "e1_PSF", "e2_PSF", "fwhm_PSF"]


for key in keys:
fname = f"{key}_binned.npz"
Expand All @@ -49,21 +51,68 @@
if xy != "quantity":
bin_edges[xy] = result[xy]
quantities[key] = result["quantity"]

xlabel = "SNR"
ylabel = r"$r / r_{\rm psf}$"

# %%
vmin = {"diag": -0.2, "offdiag": -0.03}
vmax = {"diag": 1.2, "offdiag": 0.03}
lines = {
"x": [10, 500],
"y": [0.5, 3],
}

plots.plot_binned(quantities, "response", bin_edges["snr"], bin_edges["size_ratio"], "R", vmin=vmin, vmax=vmax, xlabel="SNR", ylabel=r"$r / r_{\rm psf}$")

# %%
plots.plot_binned(quantities, "number", bin_edges["snr"], bin_edges["size_ratio"], "R", vmin=1, vmax=np.nanmax(quantities["number"]), xlabel="SNR", ylabel=r"$r / r_{\rm psf}$")

# %%
vmin = {"diag": -0.2, "offdiag": -0.2}
vmax = {"diag": 0.1, "offdiag": 0.1}
vmin = {"diag": -0.2, "offdiag": -0.1}
vmax = {"diag": 1.2, "offdiag": 0.1}

plots.plot_binned(
quantities,
"response",
bin_edges["snr"],
bin_edges["size_ratio"],
title="R",
vmin=vmin,
vmax=vmax,
xlabel=xlabel,
ylabel=ylabel,
lines=lines,
close_fig=False,
)

plots.plot_binned(quantities, "leakage", bin_edges["snr"], bin_edges["size_ratio"], r"\alpha", vmin=vmin, vmax=vmax, xlabel="SNR", ylabel=r"$r / r_{\rm psf}$")
# %%
plots.plot_binned(
quantities,
"number",
bin_edges["snr"],
bin_edges["size_ratio"],
title="n",
vmin=1,
vmax=np.nanmax(quantities["number"]),
xlabel=xlabel,
ylabel=ylabel,
lines=lines,
close_fig=False,
)

# %%
vmin = {"diag": -0.2, "offdiag": -0.2}
vmax = {"diag": 0.2, "offdiag": 0.2}

plots.plot_binned(
quantities,
"leakage",
bin_edges["snr"],
bin_edges["size_ratio"],
title=r"\alpha",
vmin=vmin,
vmax=vmax,
xlabel=xlabel,
ylabel=ylabel,
lines=lines,
close_fig=False,
)

# %%
bin_edges
# %%
4 changes: 2 additions & 2 deletions src/sp_validation/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,8 @@ def get_quantities_binned(cat_gal, num_bins_x, num_bins_y=None, which=["response

# Create logarithmic bins in size and SNR
bin_edges = {}
bin_edges["snr"] = cut_to_bins(df_gal, "snr", num_bins_x, type="log", x_min=3, x_max=300)
bin_edges["size_ratio"] = cut_to_bins(df_gal, "size_ratio", num_bins_y, type="log", x_min=0.3, x_max=20)
bin_edges["snr"] = cut_to_bins(df_gal, "snr", num_bins_x, type="log", x_min=3, x_max=700)
bin_edges["size_ratio"] = cut_to_bins(df_gal, "size_ratio", num_bins_y, type="log", x_min=0.3, x_max=10)

# Initialize output dict
quantities = {}
Expand Down