diff --git a/.gitignore b/.gitignore index df94531..259a2a7 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/notebooks/leakage_minimal.py b/notebooks/leakage_minimal.py index 4d4d732..712053b 100644 --- a/notebooks/leakage_minimal.py +++ b/notebooks/leakage_minimal.py @@ -1,5 +1,5 @@ # %% -# Plot binned quantites, see leakage_minima.py +# Compute binned quantities, see plot_binned_quantities.py # %% from IPython import get_ipython @@ -13,6 +13,7 @@ ipython.run_line_magic("load_ext", "log_cell_time") # %% +import os import numpy as np import pandas as pd @@ -28,7 +29,7 @@ from sp_validation import plots as sp_plots # %% -os.getcwd() +print("pwd:", os.getcwd()) # %% # Initialize calibration class instance @@ -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}$") diff --git a/notebooks/plot_binned_quantities.py b/notebooks/plot_binned_quantities.py index 5d22d63..69ada73 100644 --- a/notebooks/plot_binned_quantities.py +++ b/notebooks/plot_binned_quantities.py @@ -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 @@ -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 @@ -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" @@ -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 +# %% diff --git a/src/sp_validation/calibration.py b/src/sp_validation/calibration.py index 549c6f9..a4368f9 100644 --- a/src/sp_validation/calibration.py +++ b/src/sp_validation/calibration.py @@ -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 = {}