Skip to content

Commit b2b1a58

Browse files
committed
CONT: adding cosmoDC2 TAP access tutorial
1 parent 96fb1bb commit b2b1a58

File tree

1 file changed

+183
-0
lines changed

1 file changed

+183
-0
lines changed
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
---
2+
jupytext:
3+
formats: md:myst
4+
text_representation:
5+
extension: .md
6+
format_name: myst
7+
format_version: 0.13
8+
jupytext_version: 1.16.2
9+
kernelspec:
10+
display_name: Python 3 (ipykernel)
11+
language: python
12+
name: python3
13+
---
14+
15+
16+
17+
This tutorial demonstrates how to access the CosmoDC2 Mock V1 catalogs. More information about these catalogs can be found here: https://irsa.ipac.caltech.edu/Missions/cosmodc2.html
18+
19+
# Use IRSA's Virtual Observatory Table Access Protocol (TAP) Service to access these catalogs.
20+
21+
This catalog can be accessed through IRSA's Table Access Protocol (TAP) service. See https://www.ivoa.net/documents/TAP/ for details on the protocol. This service can be accessed through Python using the pvyo library.
22+
23+
```{code-cell} ipython3
24+
import pyvo as vo
25+
```
26+
27+
```{code-cell} ipython3
28+
service = vo.dal.TAPService("https://irsa.ipac.caltech.edu/TAP")
29+
```
30+
31+
## List the available DC2 tables
32+
33+
```{code-cell} ipython3
34+
tables = service.tables
35+
for tablename in tables.keys():
36+
if not "tap_schema" in tablename:
37+
if "dc2" in tablename:
38+
tables[tablename].describe()
39+
```
40+
41+
## Choose the DC2 catalog you want to work with.
42+
43+
IRSA currently offers 3 versions of the DC2 catalog.
44+
45+
* ``cosmodc2mockv1_new`` has been optimized to make searches with constraints on stellar mass and redshift fast.
46+
47+
* ``cosmodc2mockv1`` has been optimized to make searches with spatial constraints fast.
48+
49+
* ``cosmodc2mockv1_heavy`` is the same as ``cosmodc2mockv1_new``, except that it does not contain galaxies with stellar masses <= 10^7 solar masses.
50+
51+
If you are new to the DC2 catalog, we recommend that you start with ``cosmodc2mockv1_heavy``
52+
53+
```{code-cell} ipython3
54+
# Choose the abridged table to start with.
55+
# Queries should be faster on smaller tables.
56+
57+
tablename = 'cosmodc2mockv1_heavy'
58+
```
59+
60+
## How many rows are in the chosen table?
61+
62+
With TAP, you can query catalogs with constraints specified in IVOA Astronomical Data Query Language (ADQL; https://www.ivoa.net/documents/latest/ADQL.html), which is based on SQL.
63+
64+
```{code-cell} ipython3
65+
# For example, this snippet of ADQL counts the number of elements in
66+
# the redshift column of the table we chose.
67+
adql = f"SELECT count(redshift) FROM {tablename}"
68+
adql
69+
```
70+
71+
```{code-cell} ipython3
72+
# In order to use TAP with this ADQL string using pyvo, you can do the following:
73+
result = service.search(adql)
74+
result
75+
```
76+
77+
The above query shows that there are 597,488,849 redshifts in this table.
78+
79+
+++
80+
81+
## What is the default maximum number of rows returned by the service?
82+
83+
This service will return a maximum of 2 billion rows by default.
84+
85+
```{code-cell} ipython3
86+
service.maxrec
87+
```
88+
89+
This default maximum can be changed, and there is no hard upper limit to what it can be changed to.
90+
91+
```{code-cell} ipython3
92+
print(service.hardlimit)
93+
```
94+
95+
## List the columns in the chosen table
96+
97+
This table contains 301 columns.
98+
99+
```{code-cell} ipython3
100+
columns = tables[tablename].columns
101+
print(len(columns))
102+
```
103+
104+
Let's learn a bit more about them.
105+
106+
```{code-cell} ipython3
107+
for col in columns:
108+
print(f'{f"{col.name}":30s} {col.description}')
109+
```
110+
111+
## Create a histogram of redshifts
112+
113+
Let's figure out what redshift range these galaxies cover. Since we found out above that it's a large catalog, we can start with a spatial search over a small area of 0.1 deg. The ADQL that is needed for the spatial constraint is:
114+
115+
```{code-cell} ipython3
116+
adql = f"SELECT redshift FROM {tablename} WHERE CONTAINS(POINT('ICRS', RAMean, DecMean), CIRCLE('ICRS',54.218205903,-37.497959343,.1))=1"
117+
adql
118+
```
119+
120+
Now we can use the previously-defined service to execute the query with the spatial contraint.
121+
122+
```{code-cell} ipython3
123+
cone_results = service.search(adql)
124+
```
125+
126+
```{code-cell} ipython3
127+
# Plot a histogram
128+
import numpy as np
129+
import matplotlib.mlab as mlab
130+
import matplotlib.pyplot as plt
131+
132+
num_bins = 20
133+
# the histogram of the data
134+
n, bins, patches = plt.hist(cone_results['redshift'], num_bins,
135+
facecolor='blue', alpha = 0.5)
136+
plt.xlabel('Redshift')
137+
plt.ylabel('Number')
138+
plt.title('Redshift Histogram CosmoDC2 Mock Catalog V1 abridged')
139+
```
140+
141+
We can easily see form this plot that the simulated galaxies go out to z = 3.
142+
143+
+++
144+
145+
## Visualize galaxy colors at z ~ 0.5
146+
147+
Now let's visualize the galaxy main sequence at z = 2.0. First, we'll do a narrow redshift cut with no spatial constraint.
148+
149+
Let's do it as an asynchronous search since this might take awhile.
150+
151+
```{code-cell} ipython3
152+
service = vo.dal.TAPService("https://irsa.ipac.caltech.edu/TAP")
153+
adql = f"SELECT Mag_true_r_sdss_z0, Mag_true_g_sdss_z0, redshift FROM {tablename} WHERE redshift > 0.5 and redshift < 0.54"
154+
results = service.run_async(adql)
155+
```
156+
157+
```{code-cell} ipython3
158+
len(results['mag_true_r_sdss_z0'])
159+
```
160+
161+
```{code-cell} ipython3
162+
# Since this results in almost 4 million galaxies,
163+
# we will construct a 2D histogram rather than a scatter plot.
164+
plt.hist2d(results['mag_true_r_sdss_z0'], results['mag_true_g_sdss_z0']-results['mag_true_r_sdss_z0'],
165+
bins=200, cmap='plasma', cmax=500)
166+
167+
# Plot a colorbar with label.
168+
cb = plt.colorbar()
169+
cb.set_label('Number')
170+
171+
# Add title and labels to plot.
172+
plt.xlabel('SDSS Mag r')
173+
plt.ylabel('SDSS rest-frame g-r color')
174+
175+
# Show the plot.
176+
plt.show()
177+
```
178+
179+
## About this notebook
180+
181+
* Author: Vandana Desai (IRSA Science Lead)
182+
* Updated: 2024-07-24
183+
* Contact: https://irsa.ipac.caltech.edu/docs/help_desk.html

0 commit comments

Comments
 (0)