Skip to content

Commit a54acbf

Browse files
authored
Merge pull request #78 from tmesh/Meshkat_nb5_march25
Euclid notebooks: refactor the MER download and plot parts
2 parents 564dc73 + 1c8660c commit a54acbf

File tree

2 files changed

+31
-49
lines changed

2 files changed

+31
-49
lines changed

tutorials/euclid_access/1_Euclid_intro_MER_images.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Each MER image is approximately 1.47 GB. Downloading can take some time.
5050

5151
```{code-cell} ipython3
5252
# Uncomment the next line to install dependencies if needed.
53-
# !pip install numpy astropy matplotlib pyvo sep>=1.4 fsspec pandas
53+
# !pip install numpy astropy>=5.3 matplotlib pyvo sep>=1.4 fsspec pandas
5454
```
5555

5656
```{code-cell} ipython3
@@ -184,13 +184,21 @@ im_mer_irsa=hdu_mer_irsa[0].data
184184
print(im_mer_irsa.shape)
185185
```
186186

187-
Make a simple plot to show the large field of view of the full MER mosaic.
187+
Due to the large field of view of the MER mosaic, let's cut out a smaller section (2"x2")of the MER mosaic to inspect the image
188188

189189
```{code-cell} ipython3
190-
plt.imshow(im_mer_irsa, cmap='gray', origin='lower', norm=ImageNormalize(im_mer_irsa, interval=PercentileInterval(99.9), stretch=AsinhStretch()))
190+
plt.imshow(im_mer_irsa[0:1200,0:1200], cmap='gray', origin='lower', norm=ImageNormalize(im_mer_irsa[0:1200,0:1200], interval=PercentileInterval(99.9), stretch=AsinhStretch()))
191191
colorbar = plt.colorbar()
192192
```
193193

194+
Uncomment the code below to plot an image of the entire field of view of the MER mosaic.
195+
196+
```{code-cell} ipython3
197+
# # Full MER mosaic, may take a minute for python to create this image
198+
# plt.imshow(im_mer_irsa, cmap='gray', origin='lower', norm=ImageNormalize(im_mer_irsa, interval=PercentileInterval(99.9), stretch=AsinhStretch()))
199+
# colorbar = plt.colorbar()
200+
```
201+
194202
## 3. Create multiwavelength Euclid Q1 MER cutouts of a region of interest
195203

196204
+++

tutorials/euclid_access/5_Euclid_intro_SPE_catalog.md

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -118,34 +118,7 @@ tileID=re.search(r'TILE\s*(\d{9})', filename).group(1)
118118
print('The MER tile ID for this object is :',tileID)
119119
```
120120

121-
## 2. Read in the MER image from IRSA directly
122-
123-
### Download the MER image to this notebook
124-
Note this file is about 1.46 GB
125-
126-
```{code-cell} ipython3
127-
fname = download_file(filename, cache=True)
128-
hdu_mer_irsa = fits.open(fname)
129-
head_mer_irsa = hdu_mer_irsa[0].header
130-
131-
print(hdu_mer_irsa.info())
132-
```
133-
134-
#### Extract just the primary image
135-
136-
```{code-cell} ipython3
137-
im_mer_irsa=hdu_mer_irsa[0].data
138-
```
139-
140-
#### Make a quick and simple plot to show the full MER image, with its large FOV
141-
142-
```{code-cell} ipython3
143-
plt.imshow(im_mer_irsa, cmap='gray', origin='lower',
144-
norm=ImageNormalize(im_mer_irsa, interval=PercentileInterval(99.9), stretch=AsinhStretch()))
145-
colorbar = plt.colorbar()
146-
```
147-
148-
## 3. Download SPE catalog from IRSA directly to this notebook
121+
## 2. Download SPE catalog from IRSA directly to this notebook
149122

150123
Search for all tables in IRSA labeled as euclid
151124

@@ -162,15 +135,15 @@ for tablename in tables.keys():
162135
table_mer= 'euclid_q1_mer_catalogue'
163136
table_galaxy_candidates= 'euclid_q1_spectro_zcatalog_spe_galaxy_candidates'
164137
table_1dspectra= 'euclid.objectid_spectrafile_association_q1'
165-
table_spe= 'euclid_q1_spe_lines_line_features'
138+
table_lines= 'euclid_q1_spe_lines_line_features'
166139
```
167140

168141
### Learn some information about the table:
169142
- How many columns are there?
170143
- List the column names
171144

172145
```{code-cell} ipython3
173-
columns = tables[table_spe].columns
146+
columns = tables[table_lines].columns
174147
print(len(columns))
175148
```
176149

@@ -205,20 +178,20 @@ Finally we sort the data by descending spe_line_snr_gf to have the largest SNR H
205178

206179
```{code-cell} ipython3
207180
adql = f"SELECT DISTINCT mer.object_id,mer.ra, mer.dec, mer.tileid, mer.flux_y_templfit, \
208-
spe.spe_line_snr_gf,spe.spe_line_snr_di, spe.spe_line_name, spe.spe_line_central_wl_gf,\
209-
spe.spe_line_ew_gf, galaxy.spe_z_err, galaxy.spe_z,galaxy.spe_z_prob, spe.spe_line_flux_gf, spe.spe_line_flux_err_gf \
181+
lines.spe_line_snr_gf,lines.spe_line_snr_di, lines.spe_line_name, lines.spe_line_central_wl_gf,\
182+
lines.spe_line_ew_gf, galaxy.spe_z_err, galaxy.spe_z,galaxy.spe_z_prob, lines.spe_line_flux_gf, lines.spe_line_flux_err_gf \
210183
FROM {table_mer} AS mer \
211-
JOIN {table_spe} AS spe \
212-
ON mer.object_id = spe.object_id \
184+
JOIN {table_lines} AS lines \
185+
ON mer.object_id = lines.object_id \
213186
JOIN {table_galaxy_candidates} AS galaxy \
214-
ON spe.object_id = galaxy.object_id AND spe.spe_rank = galaxy.spe_rank \
215-
WHERE spe.spe_line_snr_gf >5 \
216-
AND spe.spe_line_name = 'Halpha' \
187+
ON lines.object_id = galaxy.object_id AND lines.spe_rank = galaxy.spe_rank \
188+
WHERE lines.spe_line_snr_gf >5 \
189+
AND lines.spe_line_name = 'Halpha' \
217190
AND mer.tileid = {tileID} \
218191
AND galaxy.spe_z_prob > 0.99 \
219192
AND galaxy.spe_z BETWEEN 1.4 AND 1.6 \
220-
AND spe.spe_line_flux_gf > 2E-16 \
221-
ORDER BY spe.spe_line_snr_gf DESC \
193+
AND lines.spe_line_flux_gf > 2E-16 \
194+
ORDER BY lines.spe_line_snr_gf DESC \
222195
"
223196
224197
# Use TAP with this ADQL string using pyvo
@@ -245,7 +218,7 @@ obj_tab
245218
### Pull the spectrum of this object
246219

247220
```{code-cell} ipython3
248-
adql_object = f"SELECT * FROM {table_1dspectra} WHERE objectid = {obj_id} AND uri IS NOT NULL "
221+
adql_object = f"SELECT * FROM {table_1dspectra} WHERE objectid = {obj_id}"
249222
250223
result2 = service.search(adql_object)
251224
df2 = result2.to_table().to_pandas()
@@ -275,19 +248,20 @@ with fits.open(BytesIO(response.content), memmap=True) as hdul:
275248
Divide by 10000 to convert from Angstrom to micron
276249

277250
```{code-cell} ipython3
278-
wavelengths = obj_2739401293646823742['spe_line_central_wl_gf']/10000.
279-
line_names = obj_2739401293646823742['spe_line_name']
280-
snr_gf = obj_2739401293646823742['spe_line_snr_gf']
251+
wavelengths = obj_tab['spe_line_central_wl_gf']/10000.
252+
line_names = obj_tab['spe_line_name']
253+
snr_gf = obj_tab['spe_line_snr_gf']
281254
282255
plt.plot(df_obj_irsa['WAVELENGTH']/10000., df_obj_irsa['SIGNAL'])
283256
284257
for wl, name, snr in zip(np.atleast_1d(wavelengths), np.atleast_1d(line_names), np.atleast_1d(snr_gf)):
285258
plt.axvline(wl, color='b', linestyle='--', alpha=0.3)
286-
plt.text(wl+0.02, .1, name+' SNR='+str(round(snr)), rotation=90, ha='center', va='bottom', fontsize=10)
259+
plt.text(wl+0.02, .2, name+' SNR='+str(round(snr)), rotation=90, ha='center', va='bottom', fontsize=10)
287260
288261
plt.xlabel('Wavelength (microns)')
289-
plt.ylabel('Flux (erg / (Angstrom s cm2))')
290-
plt.title(obj_id)
262+
plt.ylabel('Flux (erg / (s cm2))')
263+
plt.xlim(1.25, 1.85)
264+
plt.title('Object ID is '+str(obj_id))
291265
```
292266

293267
## About this Notebook

0 commit comments

Comments
 (0)