@@ -45,7 +45,7 @@ The photometry of every source is processed through a photometric redshift fitti
4545
4646``` {code-cell} ipython3
4747# Uncomment the next line to install dependencies if needed.
48- # !pip install requests matplotlib pandas astropy pyvo fsspec firefly_client
48+ # !pip install requests matplotlib pandas astropy>5.2 pyvo fsspec firefly_client
4949```
5050
5151``` {code-cell} ipython3
@@ -69,8 +69,6 @@ from firefly_client import FireflyClient
6969import pyvo as vo
7070```
7171
72- +++
73-
7472## 1. Find the MER Tile ID that corresponds to a given RA and Dec
7573
7674In this case, choose random coordinates to show a different MER mosaic image. Search a radius around these coordinates.
@@ -179,23 +177,45 @@ We specify the following conditions on our search:
179177- phz_classification =2 means we select only galaxies
180178- Using the phz_90_int1 and phz_90_int2, we select just the galaxies where the error on the photometric redshift is less than 20%
181179- Select just the galaxies between a median redshift of 1.4 and 1.6
180+ - We search just a 3 arcminute box around an RA and Dec
182181
183182+++
184183
185184Search based on `` tileID `` :
186185
186+ ``` {code-cell} ipython3
187+ ######################## User defined section ############################
188+ ## How large do you want the image cutout to be?
189+ im_cutout= 5 * u.arcmin
190+
191+ ## What is the center of the cutout?
192+ ra_cutout = 267.8
193+ dec_cutout = 66
194+
195+ coords_cutout = SkyCoord(ra_cutout, dec_cutout, unit=(u.deg, u.deg), frame='icrs')
196+ ##########################################################################
197+ im_cutout_deg=im_cutout.to(u.deg).value
198+
199+ ## Create ra and dec bounds for the box
200+ ra0=ra_cutout-im_cutout_deg/2
201+ ra1=ra_cutout+im_cutout_deg/2
202+
203+ dec0=dec_cutout-im_cutout_deg/2
204+ dec1=dec_cutout+im_cutout_deg/2
205+ ```
206+
187207``` {code-cell} ipython3
188208adql = f"SELECT DISTINCT mer.object_id,mer.ra, mer.dec, phz.flux_vis_unif, phz.flux_y_unif, \
189209phz.flux_j_unif, phz.flux_h_unif, phz.phz_classification, phz.phz_median, phz.phz_90_int1, phz.phz_90_int2 \
190210FROM {table_mer} AS mer \
191211JOIN {table_phz} as phz \
192212ON mer.object_id = phz.object_id \
193- WHERE phz.flux_vis_unif> 0 \
213+ WHERE 1 = CONTAINS(POINT('ICRS', mer.ra, mer.dec), CIRCLE('ICRS', {ra_cutout}, {dec_cutout}, {im_cutout_deg/2})) \
214+ AND phz.flux_vis_unif> 0 \
194215AND phz.flux_y_unif > 0 \
195216AND phz.flux_j_unif > 0 \
196217AND phz.flux_h_unif > 0 \
197218AND phz.phz_classification = 2 \
198- AND mer.tileid = {tileID} \
199219AND ((phz.phz_90_int2 - phz.phz_90_int1) / (1 + phz.phz_median)) < 0.20 \
200220AND phz.phz_median BETWEEN 1.4 AND 1.6 \
201221"
@@ -213,40 +233,45 @@ df_g_irsa = result.to_table().to_pandas()
213233df_g_irsa.head()
214234```
215235
216- ## 3. Read in the MER image from IRSA directly
217-
218-
219236``` {code-cell} ipython3
220- print(filename )
237+ len(df_g_irsa )
221238```
222239
223- Download the MER image -- note this file is about 1.46 GB
240+ ## 3. Read in a cutout of the MER image from IRSA directly
224241
225242``` {code-cell} ipython3
226- fname = download_file(filename, cache=True)
227- hdu_mer_irsa = fits.open(fname)
228- head_mer_irsa = hdu_mer_irsa[0].header
243+ ## Use fsspec to interact with the fits file without downloading the full file
244+ hdu = fits.open(filename, use_fsspec=True)
229245
230- print(hdu_mer_irsa.info())
231- ```
246+ ## Store the header
247+ header = hdu[0].header
248+
249+ ## Read in the cutout of the image that you want
250+ cutout_data = Cutout2D(hdu[0].section, position=coords_cutout, size=im_cutout, wcs=WCS(hdu[0].header))
232251
233- ``` {tip}
234- Now you've downloaded this large file, if you would like to save it to disk, uncomment the following cell
252+ ## Define a new fits file based on this smaller cutout, with accurate WCS based on the cutout size
253+ new_hdu = fits.PrimaryHDU(data=cutout_data.data, header=header)
254+ new_hdu.header.update(cutout_data.wcs.to_header())
235255```
236256
237257``` {code-cell} ipython3
238- # download_path='/yourlocalpath/'
239- # hdu_mer_irsa.writeto(download_path+'./MER_image_VIS.fits', overwrite=True)
258+ im_mer_irsa = new_hdu.data
240259```
241260
242- ## 4. Overplot the catalog on the MER mosaic image
261+ ``` {code-cell} ipython3
262+ im_mer_irsa.shape
263+ ```
243264
244265``` {code-cell} ipython3
245- df_g_irsa.head()
266+ norm = ImageNormalize(im_mer_irsa, interval=PercentileInterval(99.9), stretch=AsinhStretch())
267+ plt.imshow(im_mer_irsa, cmap='gray', origin='lower', norm=norm)
246268```
247269
270+ ## 4. Overplot the catalog on the MER mosaic image
271+
248272``` {code-cell} ipython3
249273## Use the WCS package to extract the coordinates from the header of the image
274+ head_mer_irsa=new_hdu.header
250275wcs_irsa=WCS(head_mer_irsa) # VIS
251276```
252277
@@ -260,28 +285,39 @@ df_g_irsa['x_pix']=xy_irsa[0]
260285df_g_irsa['y_pix']=xy_irsa[1]
261286```
262287
288+ Due to the large field of view of the MER mosaic, let's cut out a smaller section (3'x3')of the MER mosaic to inspect the image
289+
290+ +++
291+
292+ Plot MER catalog sources on the Euclid VIS image 3'x3' cutout
293+
263294``` {code-cell} ipython3
264- df_g_irsa
295+ plt.imshow(im_mer_irsa, cmap='gray', origin='lower', norm=ImageNormalize(im_mer_irsa, interval=PercentileInterval(99.9), stretch=LogStretch()))
296+ colorbar = plt.colorbar()
297+ plt.scatter(df_g_irsa['x_pix'], df_g_irsa['y_pix'], s=36, facecolors='none', edgecolors='red')
298+
299+ plt.title('Galaxies between z = 1.4 and 1.6')
300+ plt.show()
265301```
266302
267303Pull the spectra on the top brightest source based on object ID
268304
269305``` {code-cell} ipython3
270- df_g_irsa_sort=df_g_irsa.sort_values(by='flux_vis_unif ',ascending=False)
306+ df_g_irsa_sort=df_g_irsa.sort_values(by='flux_h_unif ',ascending=False)
271307```
272308
273309``` {code-cell} ipython3
274- df_g_irsa_sort[0:3]
310+ df_g_irsa_sort.iloc [0:3]
275311```
276312
277313``` {code-cell} ipython3
278- obj_id=df_g_irsa_sort['object_id'].iloc[1]
314+ obj_id=df_g_irsa_sort['object_id'].iloc[2]
315+ redshift = df_g_irsa_sort['phz_median'].iloc[2]
279316
280317## Pull the data on these objects
281318adql_object = f"SELECT * \
282319FROM {table_1dspectra} \
283- WHERE objectid = {obj_id} \
284- AND uri IS NOT NULL "
320+ WHERE objectid = {obj_id}"
285321
286322## Pull the data on this particular galaxy
287323result2 = service.search(adql_object)
@@ -308,16 +344,18 @@ with fits.open(BytesIO(response.content), memmap=True) as hdul:
308344 df_obj_irsa = dat.to_pandas()
309345```
310346
311- ``` {code-cell} ipython3
347+ ### Now the data are read in, plot the spectrum
312348
313- ## Now the data are read in, show an image
349+ Divide by 10000 to convert from Angstrom to micron
314350
315- plt.plot(df_obj_irsa['WAVELENGTH'], df_obj_irsa['SIGNAL'])
351+ ``` {code-cell} ipython3
352+ plt.plot(df_obj_irsa['WAVELENGTH']/10000., df_obj_irsa['SIGNAL'])
316353
317- plt.xlabel('Wavelength ($\AA$)')
318- plt.ylabel('Flux (erg / (Angstrom s cm2))')
319- # plt.ylim(10,50)
320- plt.title('Object ID is '+str(obj_id))
354+ plt.xlabel('Wavelength (microns)')
355+ plt.ylabel('Flux (erg / (s cm2))')
356+ plt.xlim(1.25, 1.85)
357+ plt.ylim(-0.5,0.5)
358+ plt.title('Object ID is '+str(obj_id)+'with phz_median='+str(redshift))
321359```
322360
323361Let's cut out a very small patch of the MER image to see what this galaxy looks like
@@ -406,8 +444,8 @@ fc.show_table(uploaded_table)
406444
407445## About this Notebook
408446
409- ** Author** : Tiffany Meshkat (IPAC Scientist)
447+ ** Author** : Tiffany Meshkat, Anahita Alavi, Anastasia Laity, Andreas Faisst, Brigitta Sipőcz, Dan Masters, Harry Teplitz, Jaladh Singhal, Shoubaneh Hemmati.
410448
411- ** Updated** : 2025-03-19
449+ ** Updated** : 2025-03-26
412450
413451** Contact:** [ the IRSA Helpdesk] ( https://irsa.ipac.caltech.edu/docs/help_desk.html ) with questions or reporting problems.
0 commit comments