You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorials/spherex/spherex_sdt/sdt_irsa.md
+52-48Lines changed: 52 additions & 48 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,14 @@
1
1
---
2
-
jupyter:
3
-
jupytext:
4
-
text_representation:
5
-
extension: .md
6
-
format_name: markdown
7
-
format_version: '1.3'
8
-
jupytext_version: 1.19.1
9
-
kernelspec:
10
-
display_name: std_conda
11
-
language: python
12
-
name: std_conda
2
+
jupytext:
3
+
text_representation:
4
+
extension: .md
5
+
format_name: myst
6
+
format_version: 0.13
7
+
jupytext_version: 1.18.1
8
+
kernelspec:
9
+
display_name: std_conda
10
+
language: python
11
+
name: std_conda
13
12
---
14
13
15
14
# SPHEREx Source Discovery Tool IRSA Demo
@@ -27,6 +26,7 @@ This notebook demonstrates how to use it.
27
26
28
27
* Select sources interactively and extract their SPHEREx spectra
29
28
29
+
+++
30
30
31
31
## 2. SPHEREx Overview
32
32
@@ -42,9 +42,11 @@ The community will also mine SPHEREx data and combine it with synergistic data s
42
42
43
43
More information is available in the [SPHEREx Explanatory Supplement](https://irsa.ipac.caltech.edu/data/SPHEREx/docs/SPHEREx_Expsupp_QR.pdf).
44
44
45
+
+++
45
46
46
47
## 3. Requirements
47
48
49
+
+++
48
50
49
51
### 3.1 On local machines
50
52
@@ -84,10 +86,11 @@ Note that we use the `--user` option here, which will keep the environment avail
84
86
85
87
To use the environment in your Jupyter Lab notebooks on Fornax, directly select the environment `sdt_env` in your Jupyter Notebook using the dropdown on the upper left.
86
88
89
+
+++
87
90
88
91
## 4. Imports
89
92
90
-
```python
93
+
```{code-cell} ipython3
91
94
# Standard library imports
92
95
import concurrent.futures
93
96
import copy
@@ -125,7 +128,7 @@ from spx_sdt.sdt_utils import (
125
128
from spx_sdt.source_extraction import run_sextractor, get_sextractor_file
126
129
```
127
130
128
-
```python
131
+
```{code-cell} ipython3
129
132
# Suppress logging temporarily to prevent astropy
130
133
# from repeatedly printing out warning notices related to alternate WCSs
131
134
import logging
@@ -147,7 +150,7 @@ The query parameters below are valid as of **February 2026**, but will need to b
147
150
Specifically, the ephemeral query parameters _will_ change for future SPHEREx data releases.
148
151
```
149
152
150
-
```python
153
+
```{code-cell} ipython3
151
154
# General
152
155
data_release = "qr2"
153
156
@@ -165,20 +168,21 @@ sapm_s3 = [
165
168
166
169
## 6. Search for SPHEREx Spectral Images
167
170
171
+
+++
168
172
169
173
We search first search for all the available SPHEREx images around a given position on the sky.
170
174
171
175
Here, we choose the random position at R.A. = 150.7817877 degrees and Decl. = 3.3502204 degrees, which is close to the COSMOS field. We also choose a search radius of 50 arc-seconds.
We then search for the SPHEREx spectral images that overlap with the position in the search radius defined above.
179
183
For this we use the [IRSA module in astroquery](https://astroquery.readthedocs.io/en/latest/ipac/irsa/irsa.html) and the Simple Image Access (SIA) API.
with fits.open(f's3://{s3_fpath_d2}', fsspec_kwargs={"anon": True}) as hdul2:
@@ -290,6 +294,7 @@ If you want to download the SPHEREx spectral images from IPAC directly (not from
290
294
291
295
```
292
296
297
+
+++
293
298
294
299
## 8. Remove Local Background, Create Masks, and Reproject
295
300
@@ -307,8 +312,7 @@ You can find more calibration products for the SPHEREx spectral images on the S3
307
312
308
313
```
309
314
310
-
311
-
```python
315
+
```{code-cell} ipython3
312
316
s3_fpath_sapm2 = sapm_s3[1] # list idx 1 is value for D2 path
313
317
with fits.open(f's3://{s3_fpath_sapm2}', fsspec_kwargs={"anon": True}) as hdul_sapm2:
314
318
sapm_data2 = hdul_sapm2["IMAGE"].data
@@ -322,7 +326,7 @@ with fits.open(f"s3://{s3_fpath_sapm4}", fsspec_kwargs={"anon": True}) as hdul_s
322
326
323
327
After downloading the solid angle pixel map calibration products for each detector, we convert the images from brightness (MJy/sr) to spectral flux density ($\mu$Jy) and update the corresponding units in the headers of the imates.
@@ -479,7 +485,7 @@ A use case could be to search for red sources such as galaxies with an Active Ga
479
485
480
486
In the following, we run [<code>SExtractor</code>](https://sextractor.readthedocs.io/en/latest/Introduction.html) on all the images (reprojected D2, D4, and subtracted image) to identify sources. Before that, however, we have to save the subtracted image to disk (note that the D2 and D4 cutouts are already saved to disk).
481
487
482
-
```python
488
+
```{code-cell} ipython3
483
489
# Save subtracted image to fits file for source extraction
Now, we run <code>SExtractor</code>. This software needs a few parameter files such as a configuration and parameter files as well as some others (for example a convolution filter). These files are provided in the `spx_sdt` directory. For <code>SExtractor</code> to find them, we have to give it absolute path names to these files. We use `os.path.realpath()` in the following to translate relative paths to absolute paths.
491
497
Finally, we run <code>SExtractor</code> on the last lines.
@@ -511,7 +517,7 @@ In the following, we show two ways to visualize the extracted sources on the ima
511
517
512
518
First, we read in the <code>SExtractor</code> catalog. Note that we want to change `ALPHA_J2000` and `DELTA_J2000` to the more universal `ra` and `dec` column names. This is especially important for Firefly to be able to read the table out of the box and mark the source in the table on the images.
@@ -526,13 +532,13 @@ First, we demonstrate how we can use _bokeh_ to create an interactive dashboard
526
532
Currently, _bokeh_ tables cannot be displayed in Fornax. Therefore the example below will not work. The user is encouraged to use _Firefly_, which use is demonstrated in Section 10.2 below.
Alternatively, the sources can be easily selected in Python itself by defining a selection function.
534
540
535
-
```python
541
+
```{code-cell} ipython3
536
542
# Create custom selection function
537
543
def select_sources(sxt_tab):
538
544
"""Selects the 25 brightest sources from the SExtractor-generated catalog.
@@ -563,7 +569,7 @@ plot_apertures(subtracted_cut_path, source_tab=selected, label="25 Brightest Sou
563
569
Alternatively to _bokeh_, we can use the _Firefly_ application to show the image including the data table. First we reinitiate _Firefly_, which will again open a new tab called "Firefly Viewer".
564
570
As mentioned above, we give again two options for initiating _Firefly_; in a new browser tab or a new JupterLab tab.
@@ -590,8 +596,7 @@ You can align and lock the images by their WCS by adding
590
596
591
597
```
592
598
593
-
594
-
```python
599
+
```{code-cell} ipython3
595
600
# Load images
596
601
fc.show_fits_image(
597
602
file_input=cut_path2,
@@ -626,7 +631,7 @@ Finally, we compute the SPHEREx spectra for selected sources. This includes down
626
631
627
632
Here we select one source to proceed (multiple sources can be measured by looping over the code below). Note that we here directly give it the unique source ID that we defined in the catalog column `NUMBER`.
@@ -636,7 +641,7 @@ We then set up the TAP service as well as the cutout size to run a query for all
636
641
Note that the following procedure follows the one shown in the SPHEREx [Image Cutout tutorial notebook](https://caltech-ipac.github.io/irsa-tutorials/spherex-cutouts/).
637
642
```
638
643
639
-
```python
644
+
```{code-cell} ipython3
640
645
# Define the service endpoint for IRSA's Table Access Protocol (TAP)
641
646
# so that we can query SPHEREx metadata tables.
642
647
service = pyvo.dal.TAPService("https://irsa.ipac.caltech.edu/TAP")
@@ -667,7 +672,7 @@ print("Number of images found: {}".format(len(tap_results)))
667
672
668
673
We then define a handy function that downloads the images.
0 commit comments