Skip to content

Commit 6e71b2a

Browse files
updating nb 9
1 parent f73e8ec commit 6e71b2a

1 file changed

Lines changed: 70 additions & 36 deletions

File tree

DP1/100_How_to_Use_RSP_Tools/103_Image_access_and_display/103_9_Image_stamps.ipynb

Lines changed: 70 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,6 @@
365365
" \"hspace\": 0})\n",
366366
"\n",
367367
" axes = axes.flatten()\n",
368-
" #fig, axes = plt.subplots(n_rows, n_cols, figsize=figsize)\n",
369-
" #axes = axes.flatten() if n_subplots > 1 else [axes]\n",
370368
"\n",
371369
" for ax in axes:\n",
372370
" ax.axis(\"off\")\n",
@@ -456,12 +454,44 @@
456454
"print(ra, dec)"
457455
]
458456
},
457+
{
458+
"cell_type": "markdown",
459+
"id": "823d68a9-210e-4201-99b0-b520be6fe80f",
460+
"metadata": {},
461+
"source": [
462+
"The cell below will perform a query to make sure the images retrieved span the time during which the DIAObject was changing and thus detectable as a DIASource. "
463+
]
464+
},
465+
{
466+
"cell_type": "code",
467+
"execution_count": null,
468+
"id": "15af811d-db19-4592-ad04-cde33486b11f",
469+
"metadata": {},
470+
"outputs": [],
471+
"source": [
472+
"dia_query = f\"\"\"\n",
473+
"SELECT MIN(midpointMjdTai) as first_detect_time,\n",
474+
" MAX(midpointMjdTai) as last_detect_time\n",
475+
"FROM dp1.DiaSource\n",
476+
"WHERE CONTAINS(POINT('ICRS', coord_ra, coord_dec), \n",
477+
" CIRCLE('ICRS', {ra}, {dec}, 0.001)) = 1\n",
478+
"\"\"\"\n",
479+
"\n",
480+
"dia_job = service.submit_job(dia_query)\n",
481+
"dia_job.run()\n",
482+
"dia_job.wait(phases=['COMPLETED', 'ERROR'])\n",
483+
"dia_results = dia_job.fetch_result().to_table()\n",
484+
"\n",
485+
"first_detect = dia_results['first_detect_time'][0]\n",
486+
"last_detect = dia_results['last_detect_time'][0]"
487+
]
488+
},
459489
{
460490
"cell_type": "markdown",
461491
"id": "e49e571a-c652-4e7b-9a06-81fd8a17e6d1",
462492
"metadata": {},
463493
"source": [
464-
"Use the SIA service to search for calibration level 2 images (`visit_images`) that overlap the search `circle`. Filter the results for r-band `visit_images` and sort them by observation time."
494+
"Use the SIA service to search for calibration level 2 images (`visit_images`) that overlap the search `circle`. "
465495
]
466496
},
467497
{
@@ -473,10 +503,40 @@
473503
"source": [
474504
"results_sci = sia_service.search(pos=circle, calib_level=2)\n",
475505
"\n",
476-
"lvl2_table = results_sci.to_table()\n",
506+
"lvl2_table = results_sci.to_table()\n"
507+
]
508+
},
509+
{
510+
"cell_type": "markdown",
511+
"id": "e95d41db-dc67-4d75-b1cd-911fef74c112",
512+
"metadata": {},
513+
"source": [
514+
"Filter the results for r-band `visit_images`, and to only return the visit images during which there was a DIA detection. The `if` statement ensures that a DIA detection was identified for that object. Lastly, sort the query results by observation time."
515+
]
516+
},
517+
{
518+
"cell_type": "code",
519+
"execution_count": null,
520+
"id": "47c923a8-8001-4ad6-9474-6dd31d2b683a",
521+
"metadata": {},
522+
"outputs": [],
523+
"source": [
524+
"if (not np.ma.is_masked(first_detect) and first_detect is not None and\n",
525+
" not np.ma.is_masked(last_detect) and last_detect is not None):\n",
526+
"\n",
527+
" tx = np.where(\n",
528+
" (lvl2_table['dataproduct_subtype'] == 'lsst.visit_image')\n",
529+
" & (lvl2_table['lsst_band'] == 'r')\n",
530+
" & (lvl2_table['t_min'] >= first_detect)\n",
531+
" & (lvl2_table['t_min'] <= last_detect)\n",
532+
" )[0]\n",
533+
"\n",
534+
" print(f\"Found {len(tx)} visits taken between MJD {first_detect: .2f} and {last_detect: .2f}.\")\n",
535+
"\n",
536+
"else:\n",
537+
" print(\"No DIA sources were ever detected in this region. Returning empty table.\")\n",
538+
" tx = []\n",
477539
"\n",
478-
"tx = np.where((lvl2_table['dataproduct_subtype'] == 'lsst.visit_image')\n",
479-
" & (lvl2_table['lsst_band'] == 'r'))[0]\n",
480540
"scitab = lvl2_table[tx]\n",
481541
"scitab.sort('t_max')"
482542
]
@@ -527,7 +587,7 @@
527587
"source": [
528588
"print('begin date:', scitab['t_max'][0], difftab['t_max'][0])\n",
529589
"print('end date:', scitab['t_max'][len(scitab['t_max'])-1])\n",
530-
"print('number of visits:', len(scitab['t_max']))"
590+
"print('number of visits:', len(scitab['t_max']))\n"
531591
]
532592
},
533593
{
@@ -724,7 +784,7 @@
724784
"source": [
725785
"## 3. Bulk image cutouts\n",
726786
"\n",
727-
"Bulk image cutouts will be a key visualization tool for DIA objects. Below, demonstrate how to retrieve many image cutouts (and save as png files)."
787+
"Bulk image cutouts will be a key visualization tool for DIA objects. Below, demonstrate how to retrieve many image cutouts (and save as png files). Since many visits span the time during which the target was a DIA source, limit the number to visualize to the first 20 (to save time). The full set of cutouts can be visualized by replacing the first line with `num_visits = len(scitab['t_max'])`"
728788
]
729789
},
730790
{
@@ -734,7 +794,7 @@
734794
"metadata": {},
735795
"outputs": [],
736796
"source": [
737-
"num_visits = 20 #len(scitab['t_max'])\n",
797+
"num_visits = 20\n",
738798
"print('number of visits:', num_visits)\n",
739799
"for i in range(num_visits):\n",
740800
" plt.title(f\"MJD {np.round(scitab['t_max'][i], 4)}\")\n",
@@ -803,7 +863,7 @@
803863
"source": [
804864
"print(tempdir)\n",
805865
"make_gif(tempdir)\n",
806-
"display(dimg(data=open(tempdir+'/animation.gif', 'rb').read()))"
866+
"dimg(data=open(tempdir+'/animation.gif', 'rb').read())"
807867
]
808868
},
809869
{
@@ -813,32 +873,6 @@
813873
"source": [
814874
"> **Figure 4**: A gif animation generated from the reproject visit images in Figure 3."
815875
]
816-
},
817-
{
818-
"cell_type": "markdown",
819-
"id": "172dc7bb-67ee-49f9-bee1-a6f50ad96c89",
820-
"metadata": {},
821-
"source": [
822-
"## 4. Future functionality\n",
823-
"\n",
824-
"when rotate, don't do grid in final version, then get to a releasable version if you explain that the wcs rotate and just produce a rotated image (png, no wcs info) rotated visit image stamp that you can make a png image out of. Say a few things about how we're working on how to overplot grid lines and wcs functionality. this gets us to a publishable thing "
825-
]
826-
},
827-
{
828-
"cell_type": "markdown",
829-
"id": "a8eb043b-5afe-4990-9050-bd059aaf5abf",
830-
"metadata": {},
831-
"source": [
832-
"\n",
833-
"\n",
834-
"\n",
835-
"only for epochs where it was detected in visit images. users can extrapolate to get all images. \n",
836-
"\n",
837-
"show how to do smaller more constrained part (i.e timeline over which visits are retrieved; where a dia ). \n",
838-
"\n",
839-
"\n",
840-
"start with an ra/dec and date range where you already know. don't even need to refer to the other notebook\n"
841-
]
842876
}
843877
],
844878
"metadata": {

0 commit comments

Comments
 (0)