Skip to content

Commit

Permalink
HTML: updating to not execute notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
bsipocz committed Dec 6, 2023
1 parent 5b358a0 commit bb196ad
Show file tree
Hide file tree
Showing 21 changed files with 601 additions and 6,649 deletions.
1,469 changes: 97 additions & 1,372 deletions _sources/forced_photometry/multiband_photometry.ipynb

Large diffs are not rendered by default.

66 changes: 33 additions & 33 deletions _sources/forced_photometry/multiband_photometry.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jupytext:
kernelspec:
display_name: Python [conda env:tractor]
language: python
name: python3
name: conda-env-tractor-py
---

# Automated Multiband Forced Photometry on Large Datasets
Expand All @@ -17,7 +17,7 @@ kernelspec:
## Learning Goals:
By the end of this tutorial, you will be able to:
- get catalogs and images from NASA archives in the cloud where possible
- measure fluxes at any location by running forced photometry using "The Tractor"
- measure fluxes at any location by running forced photometry using "The Tractor"
- employ parallel processing to make this as fast as possible
- cross match large catalogs
- plot results
Expand Down Expand Up @@ -117,8 +117,8 @@ except ImportError:
```

## 1. Retrieve Initial Catalog from IRSA
- Automatically set up a catalog with ra, dec, photometric redshifts, fiducial band fluxes, & probability that it is a star
- Catalog we are using is COSMOS2015 (Laigle et al. 2016)
- Automatically set up a catalog with ra, dec, photometric redshifts, fiducial band fluxes, & probability that it is a star
- Catalog we are using is COSMOS2015 (Laigle et al. 2016)
- Data exploration

```{code-cell} ipython3
Expand All @@ -128,7 +128,7 @@ except ImportError:
coords = SkyCoord('150.01d 2.2d', frame='icrs') #COSMOS center acording to Simbad

#how large is the search radius, in arcmin
radius = 48.0 * u.arcmin
radius = 48.0 * u.arcmin

#specify only select columns to limit the size of the catalog
cols = [
Expand Down Expand Up @@ -157,7 +157,7 @@ print("Number of objects: ", len(cosmos_table))
- if desired could filter the initial catalog to only include desired sources

```{code-cell} ipython3
#an example of how to filter the catalog to
#an example of how to filter the catalog to
#select those rows with either chandra fluxes or Galex NUV fluxes

#example_table = cosmos_table[(cosmos_table['flux_chandra_05_10']> 0) | (cosmos_table['flux_galex_fuv'] > 0)]
Expand All @@ -168,13 +168,13 @@ print("Number of objects: ", len(cosmos_table))

+++

#### Use the fornax cloud access API to obtain the IRAC data from the IRSA S3 bucket.
#### Use the fornax cloud access API to obtain the IRAC data from the IRSA S3 bucket.

Details here may change as the prototype code is being added to the appropriate libraries, as well as the data holding to the appropriate NGAP storage as opposed to IRSA resources.

```{code-cell} ipython3
# Temporary solution, remove when the fornax API is added to the image
# This relies on the assumption that https://github.com/fornax-navo/fornax-cloud-access-API is being cloned to this environment.
# This relies on the assumption that https://github.com/fornax-navo/fornax-cloud-access-API is being cloned to this environment.
# If it's not, then run a ``git clone https://github.com/fornax-navo/fornax-cloud-access-API --depth=1`` from a terminal at the highest directory root.
# You may need to update the fork if you forked it in the past

Expand Down Expand Up @@ -204,7 +204,7 @@ spitzer = cosmos_results[cosmos_results['dataset'] == 'IRAC']
```

```{code-cell} ipython3
# Temporarily add the cloud_access metadata to the Atlas response.
# Temporarily add the cloud_access metadata to the Atlas response.
# This dataset has limited acces, thus 'region' should be used instead of 'open'.
# S3 access should be available from the daskhub and those who has their IRSA token set up.

Expand All @@ -216,12 +216,12 @@ spitzer['cloud_access'] = [(f'{{"aws": {{ "bucket_name": "irsa-mast-tike-spitzer
```

```{code-cell} ipython3
# Adding function to download multiple files using the fornax API.
# Adding function to download multiple files using the fornax API.
# Requires https://github.com/fornax-navo/fornax-cloud-access-API/pull/4
def fornax_download(data_table, data_subdirectory, access_url_column='access_url',
fname_filter=None, verbose=False):
working_dir = os.getcwd()

data_directory = f"data/{data_subdirectory}"
os.chdir(data_directory)
for row in data_table:
Expand All @@ -232,12 +232,12 @@ def fornax_download(data_table, data_subdirectory, access_url_column='access_url
# on-prem download returns temp file path, s3 download downloads file
if temp_file:
os.rename(temp_file, os.path.basename(row['fname']))

os.chdir(working_dir)
```

```{code-cell} ipython3
fornax_download(spitzer, access_url_column='sia_url', fname_filter='go2_sci',
fornax_download(spitzer, access_url_column='sia_url', fname_filter='go2_sci',
data_subdirectory='IRAC', verbose=False)
```

Expand Down Expand Up @@ -445,13 +445,13 @@ sci_bkg_pairs = [
```{code-cell} ipython3
def calc_instrflux(band, ra, dec, stype, ks_flux_aper2, img_pair, df):
"""
Calculate single-band instrumental fluxes and uncertainties at the given ra, dec
Calculate single-band instrumental fluxes and uncertainties at the given ra, dec
using tractor.

Parameters:
-----------
band : `Band`
Collection of parameters for a single band.
Collection of parameters for a single band.
A `Band` is a named tuple with the following attributes:
idx : int
Identifier for the band/channel.
Expand Down Expand Up @@ -494,7 +494,7 @@ def calc_instrflux(band, ra, dec, stype, ks_flux_aper2, img_pair, df):
subimage, bkgsubimage, x1, y1, subimage_wcs = cutout.extract_pair(
ra, dec, img_pair=img_pair, cutout_width=band.cutout_width, mosaic_pix_scale=band.mosaic_pix_scale
)

# find nearby sources that are possible contaminants
objsrc, nconfsrcs = find_nconfsources(
ra, dec, stype, ks_flux_aper2, x1, y1, band.cutout_width, subimage_wcs, df
Expand Down Expand Up @@ -550,7 +550,7 @@ t1 = time.time()
```

### 3d. Calculate Forced Photometry - Parallelization
- Parallelization: we can either interate over the rows of the dataframe and run the four bands in parallel; or we could zip together the row index, band, ra, dec,
- Parallelization: we can either interate over the rows of the dataframe and run the four bands in parallel; or we could zip together the row index, band, ra, dec,

```{code-cell} ipython3
paramlist = []
Expand Down Expand Up @@ -625,7 +625,7 @@ df.rename(columns=cols, inplace = True)
```

```{code-cell} ipython3
#When doing a large run of a large area, save the dataframe with the forced photometry
#When doing a large run of a large area, save the dataframe with the forced photometry
# so we don't have to do the forced photometry every time

df.to_pickle(f'output/COSMOS_{radius.value}arcmin.pkl')
Expand All @@ -637,7 +637,7 @@ df.to_pickle(f'output/COSMOS_{radius.value}arcmin.pkl')
#df = pd.read_pickle('output/COSMOS_48.0arcmin.pkl')
```

### 3f. Plot to Confirm our Photometry Results
### 3f. Plot to Confirm our Photometry Results
- compare to published COSMOS 2015 catalog

```{code-cell} ipython3
Expand All @@ -650,8 +650,8 @@ fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)
fluxmax = 200
ymax = 100
xmax = 100
#ch1
#first shrink the dataframe to only those rows where I have tractor photometry
#ch1
#first shrink the dataframe to only those rows where I have tractor photometry
df_tractor = df[(df.splash_1_flux> 0) & (df.splash_1_flux < fluxmax)] #200
#sns.regplot(data = df_tractor, x = "splash_1_flux", y = "ch1flux", ax = ax1, robust = True)
sns.scatterplot(data = df_tractor, x = "splash_1_flux", y = "ch1flux", ax = ax1)
Expand All @@ -669,8 +669,8 @@ ax1.set_ylim([0, ymax])
ax1.set_xlim([0, xmax])


#ch2
#first shrink the dataframe to only those rows where I have tractor photometry
#ch2
#first shrink the dataframe to only those rows where I have tractor photometry
df_tractor = df[(df.splash_2_flux> 0) & (df.splash_2_flux < fluxmax)]
#sns.regplot(data = df_tractor, x = "splash_2_flux", y = "ch2flux", ax = ax2, robust = True)
sns.scatterplot(data = df_tractor, x = "splash_2_flux", y = "ch2flux", ax = ax2)
Expand All @@ -688,7 +688,7 @@ ax2.set_ylim([0, ymax])
ax2.set_xlim([0, xmax])


#ch3
#ch3
#first shrink the dataframe to only those rows where I have tractor photometry
df_tractor = df[(df.splash_3_flux> 0) & (df.splash_3_flux < fluxmax)]

Expand All @@ -708,8 +708,8 @@ ax3.set_ylim([0, ymax])
ax3.set_xlim([0, xmax])


#ch4
#first shrink the dataframe to only those rows where I have tractor photometry
#ch4
#first shrink the dataframe to only those rows where I have tractor photometry
df_tractor = df[(df.splash_4_flux> 0) & (df.splash_4_flux < fluxmax)]

#sns.regplot(data = df_tractor, x = "splash_4_flux", y = "ch4flux", ax = ax4, robust = True)
Expand Down Expand Up @@ -753,7 +753,7 @@ We are using `nway` as the tool to do the cross match (Salvato et al. 2017).
heasarc = Heasarc()
table = heasarc.query_mission_list()
mask = (table['Mission'] =="CHANDRA")
chandratable = table[mask]
chandratable = table[mask]

#find out which tables exist on Heasarc
#chandratable.pprint(max_lines = 200, max_width = 130)
Expand All @@ -773,7 +773,7 @@ ccosmoscat = heasarc.query_region(coords, mission=mission, radius='1 degree', re
#astropy doesn't recognize capitalized units
#so there might be some warnings here on writing out the file, but we can safely ignore those

#need to make the chandra catalog into a fits table
#need to make the chandra catalog into a fits table
#and needs to include area of the survey.
nway_write_header('data/Chandra/COSMOS_chandra.fits', 'CHANDRA', float(ccosmoscat_rad**2) )

Expand All @@ -791,7 +791,7 @@ nway_write_header('data/multiband_phot.fits', 'OPT', float((2*rad_in_arcmin/60)*
```{code-cell} ipython3
# call nway
!/home/jovyan/.local/bin/nway.py 'data/Chandra/COSMOS_chandra.fits' :ERROR_RADIUS 'data/multiband_phot.fits' 0.1 --out=data/Chandra/chandra_multiband.fits --radius 15 --prior-completeness 0.9

#!/opt/conda/bin/nway.py 'data/Chandra/COSMOS_chandra.fits' :ERROR_RADIUS 'data/multiband_phot.fits' 0.1 --out=data/Chandra/chandra_multiband.fits --radius 15 --prior-completeness 0.9
```

Expand All @@ -813,7 +813,7 @@ merged = pd.merge(df, matched, 'outer',left_on='ID', right_on = 'OPT_ID')
#remove all the rows which start with "OPT" because they are duplications of the original catalog
merged = merged.loc[:, ~merged.columns.str.startswith('OPT')]

#somehow the matching is giving negative fluxes in the band where there is no detection
#somehow the matching is giving negative fluxes in the band where there is no detection
#if there is a detection in the other band
#clean that up to make those negative fluxes = 0

Expand Down Expand Up @@ -850,8 +850,8 @@ print('number of Galex detections =',np.sum(merged.galex_detect > 0))
#overplot galex sources
#overplot xray sources

#first select on 24 micron
merged_24 = merged[(merged.flux_24 >= 0) ]
#first select on 24 micron
merged_24 = merged[(merged.flux_24 >= 0) ]

#negative Galex fluxes are causing problems, so set those to zero
merged_24.loc[merged_24.fuvflux < 0, 'fuvflux'] = 0
Expand Down Expand Up @@ -932,7 +932,7 @@ ax.set(xlabel = 'NUV - [3.6]', ylabel = 'FUV - NUV')
#plt.legend([],[], frameon=False)

#fig.savefig("output/color_color.png")
#mpld3.display(fig)
#mpld3.display(fig)
```

We extend the works of Bouquin et al. 2015 and Moutard et al. 2020 by showing a GALEX - Spitzer color color diagram over plotted with Chandra detections. Blue galaxies in these colors are generated by O and B stars and so must currently be forming stars. We find a tight blue cloud in this color space identifying those star forming galaxies. Galaxies off of the blue cloud have had their star formation quenched, quite possibly by the existence of an AGN through removal of the gas reservoir required for star formation. Chandra detected galaxies host AGN, and while those are more limited in number, can be shown here to be a hosted by all kinds of galaxies, including quiescent galaxies which would be in the upper right of this plot. This likely implies that AGN are indeed involved in quenching star formation. Additionally, we show the Chandra hardness ratio (HR) color coded according to the vertical color bar on the right side of the plot. Those AGN with higher hardness ratios have their soft x-ray bands heavily obscured and appear to reside preferentially toward the quiescent galaxies.
Expand Down
Loading

0 comments on commit bb196ad

Please sign in to comment.