Skip to content

Commit

Permalink
Merge pull request #169 from LSSTDESC/tqz/fix_blending_notebook
Browse files Browse the repository at this point in the history
specify ref_band and redshift_col after updates in unrec_blending
  • Loading branch information
ztq1996 authored Dec 7, 2024
2 parents 75f52e8 + b3f65d5 commit 41aa8b7
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions examples/creation_examples/blending_degrader_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@
"metadata": {},
"outputs": [],
"source": [
"data = np.random.normal(23, 3, size = (1000,12))\n",
"data = np.random.normal(24, 3, size = (1000,13))\n",
"data[:, 0] = np.random.uniform(low=0, high=0.03, size=1000)\n",
"data[:, 1] = np.random.uniform(low=0, high=0.03, size=1000)\n",
"data[:, 2] = np.random.uniform(low=0, high=2, size=1000)\n",
"\n",
"data_df = pd.DataFrame(data=data, # values\n",
" columns=['ra', 'dec', 'u', 'g', 'r', 'i', 'z', 'y', 'Y', 'J', 'H', 'F'])\n",
" columns=['ra', 'dec', 'z_true', 'u', 'g', 'r', 'i', 'z', 'y', 'Y', 'J', 'H', 'F'])\n",
"\n",
"data_truth_handle = DS.add_data('input', data_df, PqHandle)\n",
"data_truth = data_truth_handle.data"
Expand Down Expand Up @@ -105,8 +106,10 @@
"source": [
"## model configuration; linking length is in arcsecs\n",
"\n",
"lsst_zp_dict = {'u':12.65, 'g':14.69, 'r':14.56, 'i': 14.38, 'z':13.99, 'y': 13.02}\n",
"blModel = UnrecBlModel.make_stage(name='unrec_bl_model', ra_label='ra', dec_label='dec', linking_lengths=1.0, \\\n",
" bands='ugrizy')\n",
" bands='ugrizy', zp_dict=lsst_zp_dict, \n",
" ref_band = 'i', redshift_col = 'z_true')\n",
"blModel.get_config_dict()\n"
]
},
Expand Down Expand Up @@ -151,7 +154,7 @@
"metadata": {},
"outputs": [],
"source": [
"b = 'r'\n",
"b = 'i'\n",
"plt.hist(data_truth[b], bins=np.linspace(10, 30, 20), label='Original')\n",
"plt.hist(samples_w_bl[b], bins=np.linspace(10, 30, 20), fill=False, label='w. Unrec-BL')\n",
"\n",
Expand All @@ -163,18 +166,15 @@
{
"cell_type": "code",
"execution_count": null,
"id": "a1d51c15-1e04-4b22-9abb-9b267965dbeb",
"id": "51d759a6-2d27-42d6-896e-098059a25ffe",
"metadata": {},
"outputs": [],
"source": [
"flux = 10**(-(data_truth[b]-28.10)/2.5) # r band zp for lsst is 28.10\n",
"flux_bl = 10**(-(samples_w_bl[b]-28.10)/2.5)\n",
"\n",
"plt.hist(flux, bins=np.linspace(0, 10000, 40), label='Original')\n",
"plt.hist(flux_bl, bins=np.linspace(0, 10000, 40), fill=False, label='w. Unrec-BL')\n",
"plt.hist(data_truth['z_true'], bins=20, label='True Redshift')\n",
"plt.hist(samples_w_bl['z_weighted'], bins=20, fill=False, label='Weighted Mean')\n",
"\n",
"plt.xlabel(fr'Flux ${b}$', fontsize=14)\n",
"plt.yscale('log')\n",
"plt.xlabel(fr'Rdshift', fontsize=14)\n",
"plt.legend(fontsize=12)\n",
"plt.show()\n"
]
Expand Down Expand Up @@ -202,8 +202,9 @@
" rand_ind = np.random.randint(len(samples_w_bl))\n",
" this_bl = samples_w_bl.iloc[rand_ind]\n",
" group_id = this_bl['group_id']\n",
" \n",
" FoF_group = component_ind.query(f\"group_id == {group_id}\")\n",
"\n",
" mask = (component_ind['group_id'] == group_id)\n",
" FoF_group = component_ind[mask]\n",
" group_size = len(FoF_group)\n",
"\n",
"truth_comp = data_truth.iloc[FoF_group.index]\n",
Expand Down

0 comments on commit 41aa8b7

Please sign in to comment.