<jupyter_start><jupyter_text>Time it all<jupyter_code>import galsim
from mdetsims import Sim
from mdetsims.metacal import MetacalTrueDetect, METACAL_TYPES
from mdetsims.defaults import TEST_METACAL_TRUEDETECT_CONFIG
# %%time

for i in range(2):
    rng = np.random.RandomState(seed=100)
    des_sim = Sim(
        rng=rng,
        g1=0.02 - i*0.04,
        gal_type='exp',
        scale=0.263,
        psf_type='gauss',
        n_coadd=30,
        n_coadd_psf=1,
        gal_grid=7)

    mbobs, tcat = des_sim.get_mbobs(return_truth_cat=True)
    mm = MetacalTrueDetect(TEST_METACAL_TRUEDETECT_CONFIG, mbobs, rng, tcat)
    mm.go()<jupyter_output>singular covariance
    pars at singular: -6.71e-10   3.6e-09  9.26e-08  -5.47e-08     0.304    0.0692 
     singular covariance
    pars at singular: -1.64e-09  -1.56e-08  2.46e-07  -2.76e-07     0.304    0.0692<jupyter_text>Look at the Parts<jupyter_code>import galsim
from mdetsims import Sim
des_sim = Sim(
    rng=np.random.RandomState(seed=100),
    g1=0.02,
    gal_type='exp',
    scale=0.263,
    psf_type='gauss',
    n_coadd=30,
    n_coadd_psf=1,
    gal_grid=7,
    gal_kws={'survey_name': 'DES'})
%%time

mbobs, tcat = des_sim.get_mbobs(return_truth_cat=True)
plt.figure(figsize=(10, 10))
sns.heatmap(mbobs[0][0].image)<jupyter_output><empty_output><jupyter_text>Run it all at once<jupyter_code>%%time
rng = np.random.RandomState(seed=100)

mbobs, tcat = des_sim.get_mbobs(return_truth_cat=True)
mm = MetacalTrueDetect(TEST_METACAL_TRUEDETECT_CONFIG, mbobs, rng, tcat)
mm.go()
res = mm.result
def _mask(cat, s2n_cut, size_cut):
    return (cat['mcal_s2n'] > s2n_cut) & (cat['mcal_T_ratio'] > size_cut)

msks = {}
for sh in METACAL_TYPES:
    msks[sh] = _mask(res[sh], 10, 0.5)
g1_1p = np.mean(res['1p']['mcal_g'][msks['noshear'], 0])
g1_1m = np.mean(res['1m']['mcal_g'][msks['noshear'], 0])
R11 = (g1_1p - g1_1m) / 2 / 0.01

g2_2p = np.mean(res['2p']['mcal_g'][msks['noshear'], 1])
g2_2m = np.mean(res['2m']['mcal_g'][msks['noshear'], 1])
R22 = (g2_2p - g2_2m) / 2 / 0.01

g1_1p = np.mean(res['noshear']['mcal_g'][msks['1p'], 0])
g1_1m = np.mean(res['noshear']['mcal_g'][msks['1m'], 0])
R11_sel = (g1_1p - g1_1m) / 2 / 0.01

g2_2p = np.mean(res['noshear']['mcal_g'][msks['2p'], 1])
g2_2m = np.mean(res['noshear']['mcal_g'][msks['2m'], 1])
R22_sel = (g2_2p - g2_2m) / 2 / 0.01

R11 += R11_sel
R22 += R22_sel
R11, R22
g1_1p = np.mean(res['1p']['mcal_g'][msks['1p'], 0])
g1_1m = np.mean(res['1m']['mcal_g'][msks['1m'], 0])
R11 = (g1_1p - g1_1m) / 2 / 0.01

g2_2p = np.mean(res['2p']['mcal_g'][msks['2p'], 1])
g2_2m = np.mean(res['2m']['mcal_g'][msks['2m'], 1])
R22 = (g2_2p - g2_2m) / 2 / 0.01

R11, R22<jupyter_output><empty_output><jupyter_text>Run Detection<jupyter_code>from mdetsims.metacal import TruthMEDSifier

tmbobs, tcat = des_sim.get_mbobs(return_truth_cat=True)
mfier = TruthMEDSifier(
    mbobs=tmbobs,
    meds_config=TEST_METACAL_TRUEDETECT_CONFIG['meds'],
    truth_cat=tcat)
mbmeds = mfier.get_multiband_meds()
mbobs = mbmeds.get_mbobs(3)

plt.figure()
plt.imshow(np.arcsinh(mbobs[0][0].noise))
plt.gca().grid(False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17905188981422165, 'fraction_numerical': 0.07623318385650224, 'mean_word_length': 4.547069271758437, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '577398', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1509, 'n_words': 220, 'path': 'plots_and_notebooks/run_metacal_truepos.ipynb', 'repo_name': 'vredwine/metadetect-sims', 'size': '3122'}