Skip to content

Commit 9c446a2

Browse files
authored
Merge pull request #137 from Caltech-IPAC/raen/IRSA-7280/euclid-uri-to-path
2 parents c1dc0bd + 4639fce commit 9c446a2

File tree

4 files changed

+33
-60
lines changed

4 files changed

+33
-60
lines changed

tutorials/cloud_access/euclid-cloud-access.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,10 @@ spec_association_tbl
277277
If you picked a target other than what this notebook uses, it's possible that there is no spectrum associated for your target's object ID. In that case, `spec_association_tbl` will contain 0 rows.
278278
```
279279

280-
In above table, we can see that the `uri` column gives us location of spectra file on IBE. We can map it to S3 bucket key to retrieve spectra file from the cloud. This is a very big FITS spectra file with multiple extensions where each extension contains spectrum of one object. The `hdu` column gives us the extension number for our object. So let's extract both of these.
280+
In above table, we can see that the `'path'` column gives us a url that can be used to call an IRSA service to get the spectrum of our object as SpectrumDM VOTable. We can map it to an S3 bucket key to retrieve a spectra file from the cloud. This is a very big FITS spectra file with multiple extensions where each extension contains spectrum of one object. The `'hdu'` column gives us the extension number for our object. So let's extract both of these.
281281

282282
```{code-cell} ipython3
283-
spec_fpath_key = spec_association_tbl['uri'][0].replace('ibe/data/euclid/', '')
283+
spec_fpath_key = spec_association_tbl['path'][0].replace('api/spectrumdm/convert/euclid/', '').split('?')[0]
284284
spec_fpath_key
285285
```
286286

@@ -295,14 +295,16 @@ Again, we use astropy's lazy-loading capability of FITS to only retrieve the spe
295295
with fits.open(f's3://{BUCKET_NAME}/{spec_fpath_key}', fsspec_kwargs={'anon': True}) as hdul:
296296
spec_hdu = hdul[object_hdu_idx]
297297
spec_tbl = Table.read(spec_hdu)
298+
spec_header = spec_hdu.header
298299
```
299300

300301
```{code-cell} ipython3
301302
spec_tbl
302303
```
303304

304305
```{code-cell} ipython3
305-
plt.plot(spec_tbl['WAVELENGTH'], spec_tbl['SIGNAL'])
306+
# The signal needs to be multiplied by the scale factor in the header.
307+
plt.plot(spec_tbl['WAVELENGTH'], spec_header['FSCALE'] * spec_tbl['SIGNAL'])
306308
plt.xlabel(spec_tbl['WAVELENGTH'].unit.to_string('latex_inline'))
307309
plt.ylabel(spec_tbl['SIGNAL'].unit.to_string('latex_inline'))
308310
@@ -311,8 +313,8 @@ plt.title(f'Spectrum of Target: {target_name}\n(Euclid Object ID: {object_id})')
311313

312314
## About this Notebook
313315

314-
**Author:** Jaladh Singhal (IRSA Developer) in conjunction with Vandana Desai, Brigitta Sipőcz, Tiffany Meshkat and the IPAC Science Platform team
316+
**Author:** Jaladh Singhal (IRSA Developer) in conjunction with Vandana Desai, Brigitta Sipőcz, Tiffany Meshkat, Troy Raen, and the IRSA Data Science Team
315317

316-
**Updated:** 2025-03-17
318+
**Updated:** 2025-09-23
317319

318320
**Contact:** the [IRSA Helpdesk](https://irsa.ipac.caltech.edu/docs/help_desk.html) with questions or reporting problems.

tutorials/euclid_access/3_Euclid_intro_1D_spectra.md

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ We rely on ``astroquery`` features that have been recently added, so please make
5555
```
5656

5757
```{code-cell} ipython3
58-
import urllib
59-
6058
import numpy as np
6159
import matplotlib.pyplot as plt
6260
@@ -100,40 +98,26 @@ result = Irsa.query_tap(adql_object).to_table()
10098
Pull out the file name from the ``result`` table:
10199

102100
```{code-cell} ipython3
103-
file_uri = urllib.parse.urljoin(Irsa.tap_url, result['uri'][0])
104-
file_uri
101+
spectrum_path = f"https://irsa.ipac.caltech.edu/{result['path'][0]}"
102+
spectrum_path
105103
```
106104

107105
## 3. Read in the spectrum for only our specific object
108106

109-
Currently IRSA has the spectra stored in very large files containing multiple (14220) extensions with spectra of many targets within one tile. You can choose to read in the big file below to see what it looks like (takes a few mins to load) or skip this step and just read in the specific extension we want for the 1D spectra (recommended).
110-
111-
```{code-cell} ipython3
112-
# hdul = fits.open(file_uri)
113-
# hdul.info()
114-
```
115-
116-
Open the large FITS file without loading it entirely into memory, pulling out just the extension we want for the 1D spectra of our object
107+
`spectrum_path` is a url that will return a VOTable containing the spectrum of our object.
117108

118109
```{code-cell} ipython3
119-
with fits.open(file_uri) as hdul:
120-
spectrum = QTable.read(hdul[result['hdu'][0]], format='fits')
121-
122-
spec_header = hdul[result['hdu'][0]].header
110+
spectrum = QTable.read(spectrum_path)
123111
```
124112

125113
```{code-cell} ipython3
126114
spectrum
127115
```
128116

129-
```{code-cell} ipython3
130-
spec_header
131-
```
132-
133117
## 4. Plot the image of the extracted spectrum
134118

135119
```{tip}
136-
As we use astropy.visualization's ``quantity_support``, matplotlib automatically picks up the axis units from the quantitites we plot.
120+
As we use astropy.visualization's ``quantity_support``, matplotlib automatically picks up the axis units from the quantities we plot.
137121
```
138122

139123
```{code-cell} ipython3
@@ -143,15 +127,11 @@ quantity_support()
143127
```{note}
144128
The 1D combined spectra table contains 6 columns, below are a few highlights:
145129
146-
- WAVELENGTH is in Angstroms by default
147-
- SIGNAL is the flux and should be multiplied by the FSCALE factor in the header
130+
- WAVELENGTH is in Angstroms by default.
131+
- SIGNAL is the flux. The values are scaled and the scaling factor is included in the column's units. This value corresponds to the `'FSCALE'` entry in the HDU header of the original FITS file.
148132
- MASK values can be used to determine which flux bins to discard. MASK = odd and MASK >=64 means the flux bins not be used.
149133
```
150134

151-
```{code-cell} ipython3
152-
signal_scaled = spectrum['SIGNAL'] * spec_header['FSCALE']
153-
```
154-
155135
We investigate the MASK column to see which flux bins are recommended to keep vs "Do Not Use"
156136

157137
```{code-cell} ipython3
@@ -165,19 +145,19 @@ We use the MASK column to create a boolean mask for values to ignore. We use the
165145
```{code-cell} ipython3
166146
bad_mask = (spectrum['MASK'].value % 2 == 1) | (spectrum['MASK'].value >= 64)
167147
168-
plt.plot(spectrum['WAVELENGTH'].to(u.micron), np.ma.masked_where(bad_mask, signal_scaled), color='black', label='Spectrum')
169-
plt.plot(spectrum['WAVELENGTH'], np.ma.masked_where(~bad_mask, signal_scaled), color='red', label='Do not use')
170-
plt.plot(spectrum['WAVELENGTH'], np.sqrt(spectrum['VAR']) * spec_header['FSCALE'], color='grey', label='Error')
148+
plt.plot(spectrum['WAVELENGTH'].to(u.micron), np.ma.masked_where(bad_mask, spectrum['SIGNAL']), color='black', label='Spectrum')
149+
plt.plot(spectrum['WAVELENGTH'], np.ma.masked_where(~bad_mask, spectrum['SIGNAL']), color='red', label='Do not use')
150+
plt.plot(spectrum['WAVELENGTH'], np.sqrt(spectrum['VAR']), color='grey', label='Error')
171151
172152
plt.legend(loc='upper right')
173-
plt.ylim(-0.15E-16, 0.25E-16)
153+
plt.ylim(-0.15, 0.25)
174154
plt.title(f'Object ID {obj_id}')
175155
```
176156

177157
## About this Notebook
178158

179-
**Author**: Tiffany Meshkat, Anahita Alavi, Anastasia Laity, Andreas Faisst, Brigitta Sipőcz, Dan Masters, Harry Teplitz, Jaladh Singhal, Shoubaneh Hemmati, Vandana Desai
159+
**Author**: Tiffany Meshkat, Anahita Alavi, Anastasia Laity, Andreas Faisst, Brigitta Sipőcz, Dan Masters, Harry Teplitz, Jaladh Singhal, Shoubaneh Hemmati, Vandana Desai, Troy Raen
180160

181-
**Updated**: 2025-03-31
161+
**Updated**: 2025-09-23
182162

183163
**Contact:** [the IRSA Helpdesk](https://irsa.ipac.caltech.edu/docs/help_desk.html) with questions or reporting problems.

tutorials/euclid_access/4_Euclid_intro_PHZ_catalog.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,20 +307,18 @@ result_spectra
307307
Pull out the file name from the ``result_spectra`` table:
308308

309309
```{code-cell} ipython3
310-
file_uri = urllib.parse.urljoin(Irsa.tap_url, result_spectra['uri'][0])
311-
file_uri
310+
spectrum_path = f"https://irsa.ipac.caltech.edu/{result_spectra['path'][0]}"
311+
spectrum_path
312312
```
313313

314314
```{code-cell} ipython3
315-
with fits.open(file_uri) as hdul:
316-
spectrum = QTable.read(hdul[result_spectra['hdu'][0]], format='fits')
317-
spectrum_header = hdul[result_spectra['hdu'][0]].header
315+
spectrum = QTable.read(spectrum_path)
318316
```
319317

320318
### Now the data are read in, plot the spectrum
321319

322320
```{tip}
323-
As we use astropy.visualization’s quantity_support, matplotlib automatically picks up the axis units from the quantitites we plot.
321+
As we use astropy.visualization’s quantity_support, matplotlib automatically picks up the axis units from the quantities we plot.
324322
```
325323

326324
```{code-cell} ipython3
@@ -418,8 +416,8 @@ fc.show_table(uploaded_table)
418416

419417
## About this Notebook
420418

421-
**Author**: Tiffany Meshkat, Anahita Alavi, Anastasia Laity, Andreas Faisst, Brigitta Sipőcz, Dan Masters, Harry Teplitz, Jaladh Singhal, Shoubaneh Hemmati, Vandana Desai
419+
**Author**: Tiffany Meshkat, Anahita Alavi, Anastasia Laity, Andreas Faisst, Brigitta Sipőcz, Dan Masters, Harry Teplitz, Jaladh Singhal, Shoubaneh Hemmati, Vandana Desai, Troy Raen
422420

423-
**Updated**: 2025-04-10
421+
**Updated**: 2025-09-24
424422

425423
**Contact:** [the IRSA Helpdesk](https://irsa.ipac.caltech.edu/docs/help_desk.html) with questions or reporting problems.

tutorials/euclid_access/5_Euclid_intro_SPE_catalog.md

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ We rely on ``astroquery`` features that have been recently added, so please make
5858
```
5959

6060
```{code-cell} ipython3
61-
import re
62-
import urllib
63-
6461
import matplotlib.pyplot as plt
6562
import numpy as np
6663
@@ -159,7 +156,7 @@ We specify the following conditions on our search:
159156
- Signal to noise ratio column (_gf = gaussian fit) should be greater than 5
160157
- We want to detect H-alpha.
161158
- We choose in which tileID to search, usign the tileID from the first notebook.
162-
- Choose spectroscopic redshift (spe_z) beween 1.4 and 1.6 and spe_z_prob greater than 0.999
159+
- Choose spectroscopic redshift (spe_z) between 1.4 and 1.6 and spe_z_prob greater than 0.999
163160
- H-alpha line flux should be more than 2x10^16 erg s^-1 cm^-2
164161
- Join the lines and galaxy candidates tables on object_id and spe_rank
165162

@@ -208,23 +205,19 @@ result_table2 = Irsa.query_tap(adql_object).to_qtable()
208205

209206
### The following steps to read in the spectrum follows the 3_Euclid_intro_1D_spectra notebook.
210207

211-
This involves reading in the spectrum without readin in the full FITS file, just pulling the extension we want.
212-
213208
```{code-cell} ipython3
214-
file_uri = urllib.parse.urljoin(Irsa.tap_url, result_table2['uri'][0])
215-
file_uri
209+
spectrum_path = f"https://irsa.ipac.caltech.edu/{result_table2['path'][0]}"
210+
spectrum_path
216211
```
217212

218213
```{code-cell} ipython3
219-
with fits.open(file_uri) as hdul:
220-
spectrum = QTable.read(hdul[result_table2['hdu'][0]], format='fits')
221-
spec_header = hdul[result_table2['hdu'][0]].header
214+
spectrum = QTable.read(spectrum_path)
222215
```
223216

224217
### Now the data are read in, plot the spectrum with the H-alpha line labeled
225218

226219
```{tip}
227-
As we use astropy.visualization's ``quantity_support``, matplotlib automatically picks up the axis units from the quantitites we plot.
220+
As we use astropy.visualization's ``quantity_support``, matplotlib automatically picks up the axis units from the quantities we plot.
228221
```
229222

230223
```{code-cell} ipython3
@@ -248,8 +241,8 @@ plt.title(f'Object ID {obj_id}')
248241

249242
## About this Notebook
250243

251-
**Author**: Tiffany Meshkat, Anahita Alavi, Anastasia Laity, Andreas Faisst, Brigitta Sipőcz, Dan Masters, Harry Teplitz, Jaladh Singhal, Shoubaneh Hemmati, Vandana Desai
244+
**Author**: Tiffany Meshkat, Anahita Alavi, Anastasia Laity, Andreas Faisst, Brigitta Sipőcz, Dan Masters, Harry Teplitz, Jaladh Singhal, Shoubaneh Hemmati, Vandana Desai, Troy Raen
252245

253-
**Updated**: 2025-03-31
246+
**Updated**: 2025-09-23
254247

255248
**Contact:** [the IRSA Helpdesk](https://irsa.ipac.caltech.edu/docs/help_desk.html) with questions or reporting problems.

0 commit comments

Comments
 (0)