Skip to content

Commit e3909b6

Browse files
[pre-commit.ci] pre-commit autoupdate (#148)
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/astral-sh/ruff-pre-commit: v0.5.6 → v0.6.3](astral-sh/ruff-pre-commit@v0.5.6...v0.6.3) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update lc_cat.ipynb --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Lehman Garrison <lgarrison@flatironinstitute.org>
1 parent c3ae3f5 commit e3909b6

8 files changed

Lines changed: 199 additions & 121 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ exclude: |
1313
1414
repos:
1515
- repo: https://github.com/astral-sh/ruff-pre-commit
16-
rev: "v0.5.6"
16+
rev: "v0.6.3"
1717
hooks:
1818
- id: ruff
1919
args: [--fix]

docs/tutorials/analysis/power_spectrum.ipynb

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
"metadata": {},
5050
"outputs": [],
5151
"source": [
52-
"power_test_data = dict(**np.load(\"../../../tests/data_power/test_pos.npz\"))\n",
53-
"Lbox = 1000.\n",
52+
"power_test_data = dict(**np.load('../../../tests/data_power/test_pos.npz'))\n",
53+
"Lbox = 1000.0\n",
5454
"pos = power_test_data['pos']"
5555
]
5656
},
@@ -73,8 +73,8 @@
7373
"nmesh = 72\n",
7474
"nbins_mu = 4\n",
7575
"logk = False\n",
76-
"k_hMpc_max = np.pi*nmesh/Lbox + 1.e-6\n",
77-
"nbins_k = nmesh//2\n",
76+
"k_hMpc_max = np.pi * nmesh / Lbox + 1.0e-6\n",
77+
"nbins_k = nmesh // 2\n",
7878
"poles = [0, 2, 4]"
7979
]
8080
},
@@ -91,8 +91,19 @@
9191
"metadata": {},
9292
"outputs": [],
9393
"source": [
94-
"power = calc_power(pos, Lbox, nbins_k, nbins_mu, k_hMpc_max, logk, \\\n",
95-
" paste, nmesh, compensated, interlaced, poles=poles)"
94+
"power = calc_power(\n",
95+
" pos,\n",
96+
" Lbox,\n",
97+
" nbins_k,\n",
98+
" nbins_mu,\n",
99+
" k_hMpc_max,\n",
100+
" logk,\n",
101+
" paste,\n",
102+
" nmesh,\n",
103+
" compensated,\n",
104+
" interlaced,\n",
105+
" poles=poles,\n",
106+
")"
96107
]
97108
},
98109
{
@@ -232,9 +243,9 @@
232243
"metadata": {},
233244
"outputs": [],
234245
"source": [
235-
"comp_str = \"_compensated\" if compensated else \"\"\n",
236-
"int_str = \"_interlaced\" if interlaced else \"\"\n",
237-
"fn = f\"../../../tests/data_power/nbody_{paste}{comp_str}{int_str}.npz\"\n",
246+
"comp_str = '_compensated' if compensated else ''\n",
247+
"int_str = '_interlaced' if interlaced else ''\n",
248+
"fn = f'../../../tests/data_power/nbody_{paste}{comp_str}{int_str}.npz'\n",
238249
"data = np.load(fn)\n",
239250
"k_nbody = data['k']\n",
240251
"Pkmu_nbody = data['power'].real\n",
@@ -274,9 +285,15 @@
274285
" else:\n",
275286
" label1 = label2 = None\n",
276287
" plt.plot(k_nbody, Pkmu_nbody[:, i] * k_nbody, c=colors[i], label=label1)\n",
277-
" plt.plot(power['k_mid'], power['power'][:, i] * power['k_mid'], c=colors[i], ls='--', label=label2)\n",
278-
"plt.ylabel(r\"$k P(k)$\")\n",
279-
"plt.xlabel(r\"$k \\ [h/{\\rm Mpc}]$\")\n",
288+
" plt.plot(\n",
289+
" power['k_mid'],\n",
290+
" power['power'][:, i] * power['k_mid'],\n",
291+
" c=colors[i],\n",
292+
" ls='--',\n",
293+
" label=label2,\n",
294+
" )\n",
295+
"plt.ylabel(r'$k P(k)$')\n",
296+
"plt.xlabel(r'$k \\ [h/{\\rm Mpc}]$')\n",
280297
"plt.legend();"
281298
]
282299
},
@@ -306,9 +323,15 @@
306323
" else:\n",
307324
" label1 = label2 = None\n",
308325
" plt.plot(k_nbody, Pell_nbody[i, :] * k_nbody, c=colors[i], label=label1)\n",
309-
" plt.plot(power['k_mid'], power['poles'][:,i] * power['k_mid'], c=colors[i], ls='--', label=label2)\n",
310-
"plt.ylabel(r\"$k P_\\ell(k)$\")\n",
311-
"plt.xlabel(r\"$k \\ [h/{\\rm Mpc}]$\")\n",
326+
" plt.plot(\n",
327+
" power['k_mid'],\n",
328+
" power['poles'][:, i] * power['k_mid'],\n",
329+
" c=colors[i],\n",
330+
" ls='--',\n",
331+
" label=label2,\n",
332+
" )\n",
333+
"plt.ylabel(r'$k P_\\ell(k)$')\n",
334+
"plt.xlabel(r'$k \\ [h/{\\rm Mpc}]$')\n",
312335
"plt.legend();"
313336
]
314337
}

docs/tutorials/analysis/tsc.ipynb

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@
5050
"source": [
5151
"# Generate some particles\n",
5252
"N = 10**7\n",
53-
"box = 123.\n",
53+
"box = 123.0\n",
5454
"nthread = 32\n",
5555
"\n",
5656
"rng = np.random.default_rng(123)\n",
57-
"pos = rng.random((N,3), dtype=np.float32) * box"
57+
"pos = rng.random((N, 3), dtype=np.float32) * box"
5858
]
5959
},
6060
{
@@ -98,7 +98,7 @@
9898
"metadata": {},
9999
"outputs": [],
100100
"source": [
101-
"dens = np.zeros((ngrid,ngrid,ngrid), dtype=np.float32)\n",
101+
"dens = np.zeros((ngrid, ngrid, ngrid), dtype=np.float32)\n",
102102
"dens = tsc_parallel(pos, dens, box, nthread=nthread)"
103103
]
104104
},
@@ -202,7 +202,7 @@
202202
"source": [
203203
"fig, ax = plt.subplots(dpi=144)\n",
204204
"ax.set_aspect('equal')\n",
205-
"ax.scatter(hpos[:,0], hpos[:,1])\n",
205+
"ax.scatter(hpos[:, 0], hpos[:, 1])\n",
206206
"ax.set_xlabel('$x$ [Mpc/$h$]')\n",
207207
"ax.set_ylabel('$y$ [Mpc/$h$]')\n",
208208
"ax.set_xlim(0, L)\n",
@@ -247,11 +247,12 @@
247247
"dens = tsc_parallel(hpos, 64, L, nthread=nthread)\n",
248248
"\n",
249249
"fig, ax = plt.subplots(dpi=144)\n",
250-
"ax.imshow(dens.sum(axis=2).T,\n",
250+
"ax.imshow(\n",
251+
" dens.sum(axis=2).T,\n",
251252
" origin='lower',\n",
252253
" interpolation='none',\n",
253-
" extent=(0,L,0,L),\n",
254-
" )\n",
254+
" extent=(0, L, 0, L),\n",
255+
")\n",
255256
"ax.set_xlabel('$x$ [Mpc/$h$]')\n",
256257
"ax.set_ylabel('$y$ [Mpc/$h$]')"
257258
]
@@ -323,10 +324,10 @@
323324
}
324325
],
325326
"source": [
326-
"dens = np.zeros((ngrid,ngrid,ngrid), dtype=np.float32)\n",
327+
"dens = np.zeros((ngrid, ngrid, ngrid), dtype=np.float32)\n",
327328
"%timeit tsc_parallel(pos, dens, box, nthread=nthread)\n",
328329
"\n",
329-
"dens64 = np.zeros((ngrid,ngrid,ngrid), dtype=np.float64)\n",
330+
"dens64 = np.zeros((ngrid, ngrid, ngrid), dtype=np.float64)\n",
330331
"pos64 = pos.astype(np.float64)\n",
331332
"%timeit tsc_parallel(pos64, dens64, box, nthread=nthread)"
332333
]
@@ -389,20 +390,25 @@
389390
],
390391
"source": [
391392
"def test_precision(N, ngrid):\n",
392-
" pos = rng.random((N,3), dtype=np.float32) * box\n",
393-
" dens = np.zeros((ngrid,ngrid,ngrid), dtype=np.float32)\n",
393+
" pos = rng.random((N, 3), dtype=np.float32) * box\n",
394+
" dens = np.zeros((ngrid, ngrid, ngrid), dtype=np.float32)\n",
394395
" tsc_parallel(pos, dens, box, nthread=nthread)\n",
395396
" print(f'Total dens, 32-bit computation, 32-bit summation type: {dens.sum()}')\n",
396-
" print(f'Total dens, 32-bit computation, 64-bit summation type: {dens.sum(dtype=np.float64)}')\n",
397+
" print(\n",
398+
" f'Total dens, 32-bit computation, 64-bit summation type: {dens.sum(dtype=np.float64)}'\n",
399+
" )\n",
397400
"\n",
398-
" dens = np.zeros((ngrid,ngrid,ngrid), dtype=np.float64)\n",
401+
" dens = np.zeros((ngrid, ngrid, ngrid), dtype=np.float64)\n",
399402
" tsc_parallel(pos, dens, box, nthread=nthread)\n",
400-
" print(f'Total dens, 64-bit computation, 64-bit summation type: {dens.sum(dtype=np.float64)}')\n",
403+
" print(\n",
404+
" f'Total dens, 64-bit computation, 64-bit summation type: {dens.sum(dtype=np.float64)}'\n",
405+
" )\n",
406+
"\n",
401407
"\n",
402408
"print('Case 1:')\n",
403409
"test_precision(10**7, 256)\n",
404410
"print('Case 2:')\n",
405-
"test_precision(5*10**9, 2048)"
411+
"test_precision(5 * 10**9, 2048)"
406412
]
407413
},
408414
{
@@ -429,7 +435,7 @@
429435
}
430436
],
431437
"source": [
432-
"pos = rng.random((5 * 10**9,3), dtype=np.float32) * box\n",
438+
"pos = rng.random((5 * 10**9, 3), dtype=np.float32) * box\n",
433439
"dens = tsc_parallel(pos, 2048, box, nthread=nthread)\n",
434440
"\n",
435441
"delta = dens / dens.mean(dtype=np.float64) - 1\n",

docs/tutorials/analysis/zcv.ipynb

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
"outputs": [],
6868
"source": [
6969
"# Load necessary packages\n",
70-
"import os\n",
7170
"\n",
7271
"import numpy as np\n",
7372
"import matplotlib.pyplot as plt\n",
@@ -93,7 +92,7 @@
9392
"outputs": [],
9493
"source": [
9594
"# Load the config file and parse in relevant parameters\n",
96-
"path2config = \"config/lrg_hod_base_z0.500_nmesh576.yaml\"\n",
95+
"path2config = 'config/lrg_hod_base_z0.500_nmesh576.yaml'\n",
9796
"\n",
9897
"# Read the parameters from the yaml file\n",
9998
"config = yaml.safe_load(open(path2config))\n",
@@ -163,7 +162,7 @@
163162
"newBall = AbacusHOD(sim_params, HOD_params, clustering_params)\n",
164163
"mock_dict = newBall.run_hod(newBall.tracers, want_rsd, write_to_disk, Nthread=16)\n",
165164
"nobj = mock_dict['LRG']['mass'].size\n",
166-
"print(\"number of galaxies\", nobj)"
165+
"print('number of galaxies', nobj)"
167166
]
168167
},
169168
{
@@ -311,9 +310,9 @@
311310
"zcv_dict = newBall.apply_zcv(mock_dict, config, load_presaved=load_presaved)\n",
312311
"print(zcv_dict.keys())\n",
313312
"for key in zcv_dict.keys():\n",
314-
" if \"Pk\" in key:\n",
313+
" if 'Pk' in key:\n",
315314
" print(key, zcv_dict[key][:, :10])\n",
316-
" print(\"-----------------\")"
315+
" print('-----------------')"
317316
]
318317
},
319318
{
@@ -385,9 +384,9 @@
385384
"zcv_dict_xi = newBall.apply_zcv_xi(mock_dict, config, load_presaved=load_presaved)\n",
386385
"print(zcv_dict_xi.keys())\n",
387386
"for key in zcv_dict_xi.keys():\n",
388-
" if \"Xi\" in key:\n",
387+
" if 'Xi' in key:\n",
389388
" print(key, zcv_dict_xi[key][:, :10])\n",
390-
" print(\"-----------------\")"
389+
" print('-----------------')"
391390
]
392391
},
393392
{
@@ -454,10 +453,9 @@
454453
"f, ax = plt.subplots(1, n_ell, sharex=True, sharey=True, figsize=figsize)\n",
455454
"if not want_rsd:\n",
456455
" ax = [ax]\n",
457-
" \n",
456+
"\n",
458457
"# Loop over all multipoles\n",
459458
"for ell in range(n_ell):\n",
460-
" \n",
461459
" if want_rsd:\n",
462460
" pk_zz_ell = pk_zz[ell, :].flatten()\n",
463461
" pk_zenbu_ell = pk_zenbu[ell, :].flatten()\n",
@@ -468,17 +466,21 @@
468466
" pk_zenbu_ell = pk_zenbu.flatten()\n",
469467
" pk_tt_poles_ell = pk_tt_poles.flatten()\n",
470468
" pk_nn_betasmooth_ell = pk_nn_betasmooth.flatten()\n",
471-
" \n",
472-
" ax[ell].plot(k_binc, k_binc * pk_tt_poles_ell, c=cs[0], label='Measured tracer power')\n",
469+
"\n",
470+
" ax[ell].plot(\n",
471+
" k_binc, k_binc * pk_tt_poles_ell, c=cs[0], label='Measured tracer power'\n",
472+
" )\n",
473473
" ax[ell].plot(k_binc, k_binc * pk_zz_ell, c=cs[1], label='IC rescaled power')\n",
474-
" ax[ell].plot(k_binc, k_binc * pk_nn_betasmooth_ell, c=cs[2], label='Reduced tracer power')\n",
474+
" ax[ell].plot(\n",
475+
" k_binc, k_binc * pk_nn_betasmooth_ell, c=cs[2], label='Reduced tracer power'\n",
476+
" )\n",
475477
" ax[ell].plot(k_binc, k_binc * pk_zenbu_ell, c=cs[3], label='ZeNBu fitted power')\n",
476-
" \n",
478+
"\n",
477479
" if ell == 0:\n",
478-
" ax[ell].set_ylabel(r\"$k P(k)$\")\n",
479-
" ax[ell].set_xlabel(r\"$k \\ [h/{\\rm Mpc}]$\")\n",
480+
" ax[ell].set_ylabel(r'$k P(k)$')\n",
481+
" ax[ell].set_xlabel(r'$k \\ [h/{\\rm Mpc}]$')\n",
480482
"plt.xscale('log')\n",
481-
"plt.legend()\n"
483+
"plt.legend()"
482484
]
483485
},
484486
{
@@ -520,11 +522,11 @@
520522
"figsize = (14, 6)\n",
521523
"f, ax = plt.subplots(1, n_ell, sharex=True, sharey=True, figsize=figsize)\n",
522524
"for ell in range(n_ell):\n",
523-
" ax[ell].plot(r_binc, xi[ell]*r_binc**2, cs[1], label='IFT[P(k)] CV')\n",
524-
" ax[ell].plot(r_binc, xi_raw[ell]*r_binc**2, cs[2], label='IFT[P(k)] Raw')\n",
525-
" ax[ell].set_xlabel(r\"$r \\ [{\\rm Mpc}/h]$\")\n",
525+
" ax[ell].plot(r_binc, xi[ell] * r_binc**2, cs[1], label='IFT[P(k)] CV')\n",
526+
" ax[ell].plot(r_binc, xi_raw[ell] * r_binc**2, cs[2], label='IFT[P(k)] Raw')\n",
527+
" ax[ell].set_xlabel(r'$r \\ [{\\rm Mpc}/h]$')\n",
526528
" if ell == 0:\n",
527-
" ax[ell].set_ylabel(r\"$\\xi_\\ell(r) \\ r^2 \\ [{\\rm Mpc}/h]$\")\n",
529+
" ax[ell].set_ylabel(r'$\\xi_\\ell(r) \\ r^2 \\ [{\\rm Mpc}/h]$')\n",
528530
"plt.legend(fontsize=16)\n",
529531
"plt.ylim([-100, 120])\n",
530532
"plt.xlim([1, 200])"
@@ -567,7 +569,7 @@
567569
],
568570
"source": [
569571
"# sqrt(1-rho_xc^2) gives the ratio between the ZCV and the Raw power spectrum uncertainty for each Legendre multipole\n",
570-
"print(np.sqrt(1.-r_zt[:, :30]**2))"
572+
"print(np.sqrt(1.0 - r_zt[:, :30] ** 2))"
571573
]
572574
},
573575
{

0 commit comments

Comments
 (0)