Skip to content

Commit

Permalink
code cleanup / removing dupe loops
Browse files Browse the repository at this point in the history
  • Loading branch information
akumgill committed Jul 19, 2023
1 parent f1d118f commit 2b31613
Showing 1 changed file with 25 additions and 83 deletions.
108 changes: 25 additions & 83 deletions examples/triaxiality/delta_sigma_test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 136,
"execution_count": 1,
"id": "c176f9f7-534d-427d-b2e9-bf2661319118",
"metadata": {},
"outputs": [],
Expand All @@ -14,7 +14,7 @@
},
{
"cell_type": "code",
"execution_count": 137,
"execution_count": 2,
"id": "c136f015-0e5d-4ae4-b22f-c0add048d9a0",
"metadata": {},
"outputs": [],
Expand All @@ -26,7 +26,7 @@
},
{
"cell_type": "code",
"execution_count": 138,
"execution_count": 3,
"id": "6a05969e-2d03-4ff9-ada1-a82fef843623",
"metadata": {},
"outputs": [],
Expand All @@ -48,7 +48,7 @@
},
{
"cell_type": "code",
"execution_count": 139,
"execution_count": 4,
"id": "01bb66e5-b622-4ad1-97f6-ed82e13355ec",
"metadata": {},
"outputs": [],
Expand All @@ -65,7 +65,7 @@
},
{
"cell_type": "code",
"execution_count": 140,
"execution_count": 5,
"id": "65695a2d-30ea-42c0-93ea-8de8ba5cf000",
"metadata": {},
"outputs": [],
Expand All @@ -81,9 +81,6 @@
"r_bins = np.linspace(0, np.max(r), num_bins+1)\n",
"r_bins_mid = (r_bins[1:] + r_bins[:-1])/2\n",
"\n",
"# print(np.shape(r_bins))\n",
"# print(np.shape(r_bins_mid))\n",
"\n",
"r_inds = np.digitize(r, r_bins, right=True)\n",
"def delta_sigma(weight_1_ij, weight_2_ij, gamma_1_ij, gamma_2_ij, theta_ij, sigma_crit_ij=sigma_crit):\n",
" # TODO: summation over i\n",
Expand All @@ -92,7 +89,7 @@
},
{
"cell_type": "code",
"execution_count": 141,
"execution_count": 6,
"id": "bec47489-3f42-41fb-8237-5f403c862686",
"metadata": {},
"outputs": [],
Expand All @@ -110,12 +107,15 @@
},
{
"cell_type": "code",
"execution_count": 142,
"execution_count": 7,
"id": "2e90dc70-3178-4bd7-92ed-e2da79ee91ca",
"metadata": {},
"outputs": [],
"source": [
"delta_sigmas = []\n",
"delta_sigma_consts = []\n",
"delta_sigma_crosses = []\n",
"delta_sigma_cross_consts = []\n",
"for i in range(num_bins):\n",
" select = (r_inds-1) == i\n",
" theta_i = theta[select]\n",
Expand All @@ -124,13 +124,23 @@
" weight_i = weight_ij()\n",
" weight_1_i = weight_1_ij(theta_i)\n",
" weight_2_i = weight_2_ij(theta_i)\n",
" \n",
" delta_sigma_i = delta_sigma(weight_1_i, weight_2_i, gamma_1_i, gamma_2_i, theta_i)\n",
" delta_sigmas.append(np.mean(delta_sigma_i))"
" delta_sigmas.append(np.mean(delta_sigma_i))\n",
" \n",
" delta_sigma_const_i = delta_sigma_const(w_ij, gamma_1_i)\n",
" delta_sigma_consts.append(np.mean(delta_sigma_const_i))\n",
" \n",
" delta_sigma_cross_i = delta_sigma_cross(weight_1_i, weight_2_i, gamma_1_i, gamma_2_i, theta_i)\n",
" delta_sigma_crosses.append(np.mean(delta_sigma_cross_i))\n",
" \n",
" delta_sigma_cross_i = delta_sigma_cross_const(w_ij, gamma_2_i)\n",
" delta_sigma_cross_consts.append(np.mean(delta_sigma_cross_i))"
]
},
{
"cell_type": "code",
"execution_count": 158,
"execution_count": 8,
"id": "47299fb0-eb0d-49bf-9fe7-ba39b5b34d49",
"metadata": {},
"outputs": [
Expand All @@ -155,27 +165,7 @@
},
{
"cell_type": "code",
"execution_count": 144,
"id": "84b44e07-1975-4fe0-be25-88bfb0d6385d",
"metadata": {},
"outputs": [],
"source": [
"delta_sigma_consts = []\n",
"for i in range(num_bins):\n",
" select = (r_inds-1) == i\n",
" theta_i = theta[select]\n",
" gamma_1_i = gamma1[select]\n",
" gamma_2_i = gamma2[select]\n",
" weight_i = weight_ij()\n",
" weight_1_i = weight_1_ij(theta_i)\n",
" weight_2_i = weight_2_ij(theta_i)\n",
" delta_sigma_const_i = delta_sigma_const(w_ij, gamma_1_i)\n",
" delta_sigma_consts.append(np.mean(delta_sigma_const_i))"
]
},
{
"cell_type": "code",
"execution_count": 151,
"execution_count": 9,
"id": "b8b79c06-a93c-4543-9be2-ced9aaf3b43c",
"metadata": {},
"outputs": [
Expand All @@ -200,27 +190,7 @@
},
{
"cell_type": "code",
"execution_count": 146,
"id": "88616920-a344-4045-bf12-78981e5c3e47",
"metadata": {},
"outputs": [],
"source": [
"delta_sigma_crosses = []\n",
"for i in range(num_bins):\n",
" select = (r_inds-1) == i\n",
" theta_i = theta[select]\n",
" gamma_1_i = gamma1[select]\n",
" gamma_2_i = gamma2[select]\n",
" weight_i = weight_ij()\n",
" weight_1_i = weight_1_ij(theta_i)\n",
" weight_2_i = weight_2_ij(theta_i)\n",
" delta_sigma_cross_i = delta_sigma_cross(weight_1_i, weight_2_i, gamma_1_i, gamma_2_i, theta_i)\n",
" delta_sigma_crosses.append(np.mean(delta_sigma_cross_i))"
]
},
{
"cell_type": "code",
"execution_count": 159,
"execution_count": 10,
"id": "c977e706-e6d6-4f74-a3c1-20f9e0f041f5",
"metadata": {},
"outputs": [
Expand All @@ -245,27 +215,7 @@
},
{
"cell_type": "code",
"execution_count": 148,
"id": "2f4e8767-0b94-4caf-a717-b11a07131a27",
"metadata": {},
"outputs": [],
"source": [
"delta_sigma_cross_consts = []\n",
"for i in range(num_bins):\n",
" select = (r_inds-1) == i\n",
" theta_i = theta[select]\n",
" gamma_1_i = gamma1[select]\n",
" gamma_2_i = gamma2[select]\n",
" weight_i = weight_ij()\n",
" weight_1_i = weight_1_ij(theta_i)\n",
" weight_2_i = weight_2_ij(theta_i)\n",
" delta_sigma_cross_i = delta_sigma_cross_const(w_ij, gamma_2_i)\n",
" delta_sigma_cross_consts.append(np.mean(delta_sigma_cross_i))"
]
},
{
"cell_type": "code",
"execution_count": 153,
"execution_count": 11,
"id": "3a66e275-89f5-4b34-853c-50904f31ffb9",
"metadata": {},
"outputs": [
Expand All @@ -287,14 +237,6 @@
"plt.title('Excess Surface Density (Cross Const) as a function of Radius')\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "36ebf25d-2b80-4b95-b9a7-1693707cacb0",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit 2b31613

Please sign in to comment.