Skip to content

Commit

Permalink
Added documentation to other test cases in Tomomi's notebook. Still n…
Browse files Browse the repository at this point in the history
…eed to incorporate Caio's added functionality for sky vs. pixel coordinates in CLMM
  • Loading branch information
cavestruz committed Jul 16, 2024
1 parent 24a1470 commit b1245d5
Showing 1 changed file with 137 additions and 32 deletions.
169 changes: 137 additions & 32 deletions examples/test_coordinate.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"id": "2c4a9006-fb3e-4675-8dca-94c0ae1a88fe",
"metadata": {},
"source": [
"****Tests of coordinate system effects on shear profiles****\n",
"# Tests of coordinate system effects on shear profiles\n",
"\n",
"Author: Tomomi Sunayama, July 15, 2024\n",
"\n",
Expand All @@ -18,12 +18,41 @@
"We test:\n",
"- CosmoDC2 source galaxies with shears extracted from `TXPipe` for a single galaxy cluster (pixel coordinate system)\n",
"- Example source galaxies for galaxy clusters from a [Summer School](https://github.com/oguri/wlcluster_tutorial) taught by Masamune Oguri (pixel coordinate system)\n",
"- HSC Y3 source galaxies with shears post processed by Tomomi Sunayama (sky coordinate system)"
"- HSC Y3 source galaxies with shears post processed by Tomomi Sunayama (sky coordinate system)\n",
"\n",
"Before running this notebook, you will need to download some data. The data is available through a [dropbox link](https://www.dropbox.com/scl/fo/dwsccslr5iwb7lnkf8jvx/AJkjgFeemUEHpHaZaHHqpAg?rlkey=efbtsr15mdrs3y6xsm7l48o0r&st=xb58ap0g&dl=0)\n",
"\n",
"First, create a directory where you want to put the example data, e.g.\n",
"```\n",
"data_coords_dir=\"~/CLMM_test_data/data_coords\"\n",
"mkdir -p $data_coords_dir\n",
"cd $data_coords_dir\n",
"```\n",
"Download all files from [dropbox link](https://www.dropbox.com/scl/fo/dwsccslr5iwb7lnkf8jvx/AJkjgFeemUEHpHaZaHHqpAg?rlkey=efbtsr15mdrs3y6xsm7l48o0r&st=xb58ap0g&dl=0). This will be a zip file, `CLMM_data.zip` of size 242 Mb. scp or move this to `$data_coords_dir`.\n",
"\n",
"From the directory, you should be able to unzip:\n",
"```\n",
"unzip data_CLMM.zip -d .\n",
"```\n",
"You now have the necessary data files to run this notebook. Make sure to change the `data_coords_dir` variable in the cell below to the appropriate location where you unzipped these files.\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "f63b0937-4fb2-4ed4-8b70-4e1c4a2e24de",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# CHANGE THIS TO YOUR LOCATION\n",
"data_coords_dir=\"/pscratch/sd/a/avestruz/clmm-area/CLMM_test_data/data_coords/\""
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 4,
"id": "7e26eafb-4609-4c3a-a36b-4f7849d759db",
"metadata": {
"tags": []
Expand All @@ -43,7 +72,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 5,
"id": "e802529c-995e-4095-9e82-65f6a3a7f051",
"metadata": {
"tags": []
Expand All @@ -60,22 +89,24 @@
"id": "8f71fa8a-4c78-4033-a91c-3caf2b8a8078",
"metadata": {},
"source": [
"The cluster and source galaxy files are generated from the CosmoDC2 processed through TXPipe to test the coordinate system."
"## Example galaxy cluster from CosmoDC2\n",
"\n",
"Here, we plot an example galaxy cluster shear profile using `clmm`. The cluster and source galaxy files are generated from the CosmoDC2 processed through TXPipe. We test the coordinate system."
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"id": "6ff8236d-3cef-4990-a6b2-a089aa8318ea",
"metadata": {},
"outputs": [],
"source": [
"cluster = pandas.read_pickle('./data_coords/test_cluster.pkl')"
"cluster = pandas.read_pickle(data_coords_dir+'test_cluster.pkl')"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"id": "8a18381a-a8cf-47c0-85bd-b745a565b041",
"metadata": {},
"outputs": [],
Expand All @@ -87,17 +118,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"id": "00d69ca3-43ef-4533-9fa3-2ec2d0d8bfce",
"metadata": {},
"outputs": [],
"source": [
"source = np.genfromtxt('./data_coords/test_source.txt',names=True)"
"source = np.genfromtxt(data_coords_dir+'test_source.txt',names=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"id": "e79f1e35-2eb1-44c5-b8f4-12b6688a88d6",
"metadata": {},
"outputs": [],
Expand All @@ -112,7 +143,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"id": "4fe65c42-d695-43fb-b269-5a7513dd05ac",
"metadata": {},
"outputs": [],
Expand All @@ -127,12 +158,32 @@
")"
]
},
{
"cell_type": "markdown",
"id": "6fe3907e-bb9d-4565-a061-6189704fcc4c",
"metadata": {},
"source": [
"Here we create a `GalaxyCluster` object, specifying an *incorrect* coordinate system. For source galaxies from CosmoDC2, these are in the **pixel** coordinate system. We use the implemented kwarg when defining the galaxy cluster object to specify the **sky** coordinate system."
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 17,
"id": "b15c9144-ab4b-46cc-8f8e-5d2424b4028d",
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "TypeError",
"evalue": "GalaxyCluster.compute_tangential_and_cross_components() got an unexpected keyword argument 'coordinate_system'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[17], line 5\u001b[0m\n\u001b[1;32m 2\u001b[0m cluster \u001b[38;5;241m=\u001b[39m clmm\u001b[38;5;241m.\u001b[39mGalaxyCluster(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mName of cluster\u001b[39m\u001b[38;5;124m\"\u001b[39m, cluster_ra, cluster_dec, cluster_z, galaxies)\n\u001b[1;32m 4\u001b[0m \u001b[38;5;66;03m# Convert elipticities into shears for the members.\u001b[39;00m\n\u001b[0;32m----> 5\u001b[0m \u001b[43mcluster\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcompute_tangential_and_cross_components\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcoordinate_system\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43msky\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28mprint\u001b[39m(cluster\u001b[38;5;241m.\u001b[39mgalcat\u001b[38;5;241m.\u001b[39mcolnames)\n\u001b[1;32m 8\u001b[0m \u001b[38;5;66;03m# Measure profile and add profile table to the cluster.\u001b[39;00m\n",
"\u001b[0;31mTypeError\u001b[0m: GalaxyCluster.compute_tangential_and_cross_components() got an unexpected keyword argument 'coordinate_system'"
]
}
],
"source": [
"# Create a GalaxyCluster.\n",
"cluster = clmm.GalaxyCluster(\"Name of cluster\", cluster_ra, cluster_dec, cluster_z, galaxies)\n",
Expand All @@ -154,6 +205,14 @@
"print(cluster.profile.colnames)"
]
},
{
"cell_type": "markdown",
"id": "94723df5-971e-43cd-aeba-3cd9c49d8474",
"metadata": {},
"source": [
"Here, we plot the resulting profile when `clmm` uses assumes a coordinate system inconsistent with the catalogs provided. You will note that the signal is virtually zero at almost all radii."
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -179,6 +238,14 @@
"plt.show()"
]
},
{
"cell_type": "markdown",
"id": "f50c2431-e368-465c-9042-80f482951d81",
"metadata": {},
"source": [
"Here we create a `GalaxyCluster` object, specifying the *correct* coordinate system. For source galaxies from CosmoDC2, these are in the **pixel** coordinate system. We use the implemented kwarg when defining the galaxy cluster object to also specify the **pixel** coordinate system."
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -230,28 +297,36 @@
"id": "0c3d5d3d-0d6a-4c55-99f5-141e5ee9329a",
"metadata": {},
"source": [
"The cluster and source catalogs are available at https://github.com/oguri/wlcluster_tutorial (provided by Masamune Oguri). The coordinate system is pixel."
"## Example source galaxies from M. Oguri\n",
"\n",
"This dataset is a curated selection of cluster and source catalogs from Summer School lectures delivered by Masamune Oguri. There are eight galaxy clusters in this selection. \n",
"\n",
"More details on the corresponding tutorial can be found at this [GitHub link](https://github.com/oguri/wlcluster_tutorial). The coordinate system is pixel. These are also in the **pixel** coordinate system."
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"id": "493d1ce7-288e-4fe9-8e49-c01702f31614",
"metadata": {},
"outputs": [],
"source": [
"clusters = ['a1703', 'gho1320', 'sdss0851', 'sdss1050', 'sdss1138', 'sdss1226', 'sdss1329', 'sdss1531']\n",
"clusters = ['a1703', 'gho1320', 'sdss0851', 'sdss1050', \n",
" 'sdss1138', 'sdss1226', 'sdss1329', 'sdss1531']\n",
"\n",
"zl_all = {'a1703': 0.277, 'gho1320': 0.308, 'sdss0851': 0.370, 'sdss1050': 0.60, 'sdss1138': 0.451, 'sdss1226': 0.435, 'sdss1329': 0.443, 'sdss1531': 0.335}\n",
"zl_all = {'a1703': 0.277, 'gho1320': 0.308, 'sdss0851': 0.370, 'sdss1050': 0.60, \n",
" 'sdss1138': 0.451, 'sdss1226': 0.435, 'sdss1329': 0.443, 'sdss1531': 0.335}\n",
"\n",
"ra_cl_all = {'a1703': 198.771833, 'gho1320': 200.703208, 'sdss0851': 132.911917, 'sdss1050': 162.666250, 'sdss1138': 174.537292, 'sdss1226': 186.712958, 'sdss1329': 202.393708, 'sdss1531': 232.794167}\n",
"ra_cl_all = {'a1703': 198.771833, 'gho1320': 200.703208, 'sdss0851': 132.911917, 'sdss1050': 162.666250, \n",
" 'sdss1138': 174.537292, 'sdss1226': 186.712958, 'sdss1329': 202.393708, 'sdss1531': 232.794167}\n",
"\n",
"dec_cl_all = {'a1703': 51.817389, 'gho1320': 31.654944, 'sdss0851': 33.518361, 'sdss1050': 0.285306, 'sdss1138': 27.908528, 'sdss1226': 21.831194, 'sdss1329': 22.721167, 'sdss1531': 34.240278}"
"dec_cl_all = {'a1703': 51.817389, 'gho1320': 31.654944, 'sdss0851': 33.518361, 'sdss1050': 0.285306, \n",
" 'sdss1138': 27.908528, 'sdss1226': 21.831194, 'sdss1329': 22.721167, 'sdss1531': 34.240278}"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"id": "4c22f1f2-9ca5-4342-b18c-bb9e4e562040",
"metadata": {},
"outputs": [],
Expand All @@ -269,14 +344,22 @@
"zs = 1.0"
]
},
{
"cell_type": "markdown",
"id": "02037f9b-bbf1-46fd-a6a9-cbbda1dc0530",
"metadata": {},
"source": [
"We inspect the first galaxy cluster, Abell 1703."
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 21,
"id": "5a3a4fd5-0a9b-4dfc-a4f8-4f853174420a",
"metadata": {},
"outputs": [],
"source": [
"rfile = './data_coords/data_oguri/shear_' + cname + '.dat'\n",
"rfile = data_coords_dir+'data/shear_' + cname + '.dat'\n",
"data = np.loadtxt(rfile, comments = '#')\n",
"\n",
"ra = data[:, 0]\n",
Expand All @@ -291,12 +374,32 @@
")"
]
},
{
"cell_type": "markdown",
"id": "0275d3a6-4b95-4d98-8c1f-cec9c5db7534",
"metadata": {},
"source": [
"Here we create a GalaxyCluster object, specifying the correct coordinate system. For source galaxies from the Oguri curated dataset, these are in the pixel coordinate system. We use the implemented kwarg when defining the galaxy cluster object to also specify the pixel coordinate system."
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 22,
"id": "3cf8feb9-e4e2-4ab4-8fcd-498eb025d945",
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "TypeError",
"evalue": "GalaxyCluster.compute_tangential_and_cross_components() got an unexpected keyword argument 'coordinate_system'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[22], line 4\u001b[0m\n\u001b[1;32m 1\u001b[0m cluster \u001b[38;5;241m=\u001b[39m clmm\u001b[38;5;241m.\u001b[39mGalaxyCluster(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mName of cluster\u001b[39m\u001b[38;5;124m\"\u001b[39m, ra_cl, dec_cl, zl, galaxies)\n\u001b[1;32m 3\u001b[0m \u001b[38;5;66;03m# Convert elipticities into shears for the members.\u001b[39;00m\n\u001b[0;32m----> 4\u001b[0m \u001b[43mcluster\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcompute_tangential_and_cross_components\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcoordinate_system\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mpixel\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28mprint\u001b[39m(cluster\u001b[38;5;241m.\u001b[39mgalcat\u001b[38;5;241m.\u001b[39mcolnames)\n\u001b[1;32m 7\u001b[0m \u001b[38;5;66;03m# Measure profile and add profile table to the cluster.\u001b[39;00m\n",
"\u001b[0;31mTypeError\u001b[0m: GalaxyCluster.compute_tangential_and_cross_components() got an unexpected keyword argument 'coordinate_system'"
]
}
],
"source": [
"cluster = clmm.GalaxyCluster(\"Name of cluster\", ra_cl, dec_cl, zl, galaxies)\n",
"\n",
Expand Down Expand Up @@ -365,32 +468,34 @@
"id": "611ee615-05a0-49d1-a9a3-1820a136fa1b",
"metadata": {},
"source": [
"Simplified version of HSC Y3 data (GAMA15H)."
"## Example source galaxies from HSC Y3\n",
"\n",
"This dataset is a simplified version of HSC Y3 data (GAMA15H), post-processed by Tomomi Sunayama for testing purposes. The pre-processed data is already public. These catalogs assume a **sky** pixel coordinate system."
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"id": "d98e194a-5d49-4a03-9ecf-8b8e244222c2",
"metadata": {},
"outputs": [],
"source": [
"clust = np.genfromtxt('./data_coords/mini_GAMA15H/redmapper_dr8_GAMA15H.txt',dtype=np.dtype([('ra',np.float64),('dec',np.float64),('z',np.float64),('richness',np.float64)]))"
"clust = np.genfromtxt(data_coords_dir+'GAMA15H/redmapper_dr8_GAMA15H.txt',dtype=np.dtype([('ra',np.float64),('dec',np.float64),('z',np.float64),('richness',np.float64)]))"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 25,
"id": "f4b75a91-bdf7-48ce-83e6-38910b1c6ab6",
"metadata": {},
"outputs": [],
"source": [
"source = fits.getdata('./data_coords/mini_GAMA15H/GAMA15H_tutorial.fits')"
"source = fits.getdata(data_coords_dir+'GAMA15H/GAMA15H_tutorial.fits')"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 26,
"id": "3b6c7291-1c2d-4658-b5ac-e9d0cb8dea95",
"metadata": {},
"outputs": [],
Expand All @@ -400,7 +505,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 27,
"id": "6bb6d126-c1ce-496c-827e-fd5211763737",
"metadata": {},
"outputs": [],
Expand Down

0 comments on commit b1245d5

Please sign in to comment.