Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-231: add ruff linting to pre-commit #232

Merged
merged 34 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6bec081
Add `ruff` linting to `pre-commit`
paddyroddy Sep 17, 2024
6646a40
Removing the `classmethod` stuff
paddyroddy Sep 17, 2024
431c12e
Fix some `ruff` linting issues
paddyroddy Sep 17, 2024
dfb69e8
Be careful with `isort`
paddyroddy Sep 17, 2024
f41a589
Fix notebook imports
paddyroddy Sep 17, 2024
c880960
FIx import
paddyroddy Sep 17, 2024
bc26cde
Import
paddyroddy Sep 17, 2024
d9ced9d
Remove blank line
paddyroddy Sep 17, 2024
ff6f47d
Ignore more rules
paddyroddy Sep 18, 2024
8fc670d
Fix more `ruff` rules
paddyroddy Sep 18, 2024
a3f00f2
More `ruff` fixing
paddyroddy Sep 18, 2024
cdd99b6
More `ruff` fixes
paddyroddy Sep 18, 2024
1267516
More `ruff`
paddyroddy Sep 18, 2024
6c936e1
No warnings from `ruff`
paddyroddy Sep 18, 2024
9e6388e
SIlence `D205`
paddyroddy Sep 18, 2024
9162dbf
Remove duplicate `_`
paddyroddy Sep 18, 2024
2611eeb
Add equation
paddyroddy Sep 18, 2024
fb63a5a
Change to `NamedTuple`
paddyroddy Sep 18, 2024
8e6ba5e
Merge branch 'main' into paddy/ruff-lint
paddyroddy Sep 18, 2024
75e37aa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 18, 2024
d4ccd3a
Extend title `=`
paddyroddy Sep 18, 2024
d3241fd
Merge branch 'main' into paddy/ruff-lint
paddyroddy Sep 18, 2024
0c6e6ce
Add to git blame
paddyroddy Sep 18, 2024
14563b3
STY: pre-commit fixes
pre-commit-ci[bot] Sep 18, 2024
19d1a6c
Extend docs
paddyroddy Sep 18, 2024
4d36ab5
Update docstring
paddyroddy Sep 18, 2024
b83bc79
Fix docs
paddyroddy Sep 18, 2024
2236bd1
Add second underscore
paddyroddy Sep 18, 2024
f88ddf1
Fix all doc titles
paddyroddy Sep 18, 2024
dec1bae
Merge branch 'main' into paddy/ruff-lint
Saransh-cpp Sep 19, 2024
8fb20f3
cleanup from code review
Saransh-cpp Sep 19, 2024
cf2982f
headings without period
Saransh-cpp Sep 19, 2024
7a7e6e8
docs inside class, allow yoda conditions
Saransh-cpp Sep 19, 2024
1bdcc6b
avoid one-liner conditionals
Saransh-cpp Sep 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
b42067f6776dcd763827000d585a88e071b78af3
# applied prettier - https://github.com/glass-dev/glass/pull/227
f9bac62f497a7288aa71fd4dbd948945c37f854e
# applied ruff-linting - https://github.com/glass-dev/glass/pull/232
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Saransh-cpp when this is merged can you add the commit hash underneath?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🫡

1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.3
hooks:
- id: ruff
Saransh-cpp marked this conversation as resolved.
Show resolved Hide resolved
- id: ruff-format
- repo: https://github.com/pappasam/toml-sort
rev: v0.23.1
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

project = "GLASS"
author = "GLASS developers"
copyright = f"2022-{datetime.date.today().year} {author}"
copyright = f"2022-{datetime.date.today().year} {author}" # noqa: A001, DTZ011
version = metadata.version("glass")
release = version

Expand Down
14 changes: 9 additions & 5 deletions examples/1-basic/density.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from matplotlib.colors import LogNorm\n",
"\n",
"# use the CAMB cosmology that generated the matter power spectra\n",
Expand All @@ -45,7 +45,6 @@
"# import GLASS for matter, random fields, random points, galaxies\n",
"import glass\n",
"\n",
"\n",
"# cosmology for the simulation\n",
"h = 0.7\n",
"Oc = 0.25\n",
Expand All @@ -56,7 +55,10 @@
"\n",
"# set up CAMB parameters for matter angular power spectrum\n",
"pars = camb.set_params(\n",
" H0=100 * h, omch2=Oc * h**2, ombh2=Ob * h**2, NonLinear=camb.model.NonLinear_both\n",
" H0=100 * h,\n",
" omch2=Oc * h**2,\n",
" ombh2=Ob * h**2,\n",
" NonLinear=camb.model.NonLinear_both,\n",
")\n",
"\n",
"# get the cosmology from CAMB\n",
Expand Down Expand Up @@ -169,8 +171,10 @@
" z1 = gal_z * np.cos(np.deg2rad(gal_lon)) * np.cos(np.deg2rad(gal_lat))\n",
" z2 = gal_z * np.sin(np.deg2rad(gal_lon)) * np.cos(np.deg2rad(gal_lat))\n",
" z3 = gal_z * np.sin(np.deg2rad(gal_lat))\n",
" (i, j, k), c = np.unique(\n",
" np.searchsorted(zcub[1:], [z1, z2, z3]), axis=1, return_counts=True\n",
" (i, j, k), c = np.unique( # noqa: PLW2901\n",
" np.searchsorted(zcub[1:], [z1, z2, z3]),\n",
" axis=1,\n",
" return_counts=True,\n",
" )\n",
" cube[i, j, k] += c"
]
Expand Down
17 changes: 11 additions & 6 deletions examples/1-basic/lensing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
},
"outputs": [],
"source": [
"import numpy as np\n",
"import healpy as hp\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"# use the CAMB cosmology that generated the matter power spectra\n",
"import camb\n",
Expand All @@ -49,7 +49,6 @@
"# import GLASS\n",
"import glass\n",
"\n",
"\n",
"# cosmology for the simulation\n",
"h = 0.7\n",
"Oc = 0.25\n",
Expand All @@ -60,7 +59,10 @@
"\n",
"# set up CAMB parameters for matter angular power spectrum\n",
"pars = camb.set_params(\n",
" H0=100 * h, omch2=Oc * h**2, ombh2=Ob * h**2, NonLinear=camb.model.NonLinear_both\n",
" H0=100 * h,\n",
" omch2=Oc * h**2,\n",
" ombh2=Ob * h**2,\n",
" NonLinear=camb.model.NonLinear_both,\n",
")\n",
"\n",
"# get the cosmology from CAMB\n",
Expand Down Expand Up @@ -253,22 +255,25 @@
"source": [
"# get the angular power spectra of the lensing maps\n",
"sim_cls = hp.anafast(\n",
" [kappa_bar, gamm1_bar, gamm2_bar], pol=True, lmax=lmax, use_pixel_weights=True\n",
" [kappa_bar, gamm1_bar, gamm2_bar],\n",
" pol=True,\n",
" lmax=lmax,\n",
" use_pixel_weights=True,\n",
")\n",
"\n",
"# get the expected cls from CAMB\n",
"pars.min_l = 1\n",
"pars.set_for_lmax(lmax)\n",
"pars.SourceWindows = [\n",
" camb.sources.SplinedSourceWindow(z=z, W=dndz, source_type=\"lensing\")\n",
" camb.sources.SplinedSourceWindow(z=z, W=dndz, source_type=\"lensing\"),\n",
"]\n",
"theory_cls = camb.get_results(pars).get_source_cls_dict(lmax=lmax, raw_cl=True)\n",
"\n",
"# get the HEALPix pixel window function, since the lensing fields have it\n",
"pw = hp.pixwin(nside, lmax=lmax)\n",
"\n",
"# plot the realised and expected cls\n",
"l = np.arange(lmax + 1)\n",
"l = np.arange(lmax + 1) # noqa: E741\n",
"plt.plot(l, sim_cls[0], \"-k\", lw=2, label=\"simulation\")\n",
"plt.plot(l, theory_cls[\"W1xW1\"] * pw**2, \"-r\", lw=2, label=\"expectation\")\n",
"plt.xscale(\"symlog\", linthresh=10, linscale=0.5, subs=[2, 3, 4, 5, 6, 7, 8, 9])\n",
Expand Down
10 changes: 6 additions & 4 deletions examples/1-basic/matter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
},
"outputs": [],
"source": [
"import numpy as np\n",
"import healpy as hp\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"# uses the CAMB cosmology which produced the cls\n",
"import camb\n",
Expand All @@ -45,7 +45,6 @@
"# import GLASS for matter and random fields\n",
"import glass\n",
"\n",
"\n",
"# cosmology for the simulation\n",
"h = 0.7\n",
"Oc = 0.25\n",
Expand All @@ -57,7 +56,10 @@
"\n",
"# set up CAMB parameters for matter angular power spectrum\n",
"pars = camb.set_params(\n",
" H0=100 * h, omch2=Oc * h**2, ombh2=Ob * h**2, NonLinear=camb.model.NonLinear_both\n",
" H0=100 * h,\n",
" omch2=Oc * h**2,\n",
" ombh2=Ob * h**2,\n",
" NonLinear=camb.model.NonLinear_both,\n",
")\n",
"\n",
"# get the cosmology from CAMB\n",
Expand Down Expand Up @@ -135,7 +137,7 @@
" theta, phi = hp.vec2ang(np.transpose([x[g] / zmax, y[g] / zmax, zg]))\n",
" grid[g] = hp.get_interp_val(delta_i, theta, phi)\n",
" ax.add_patch(\n",
" plt.Circle((0, 0), zmax / zend, fc=\"none\", ec=\"k\", lw=0.5, alpha=0.5, zorder=1)\n",
" plt.Circle((0, 0), zmax / zend, fc=\"none\", ec=\"k\", lw=0.5, alpha=0.5, zorder=1),\n",
" )\n",
"\n",
"# show the grid of shells\n",
Expand Down
3 changes: 1 addition & 2 deletions examples/1-basic/photoz.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"# import GLASS for matter shells, galaxies, random points, and observational\n",
"import glass\n",
"\n",
"# how many arcmin2 over the entire sphere\n",
"from glass.core.constants import ARCMIN2_SPHERE\n",
"\n",
"\n",
"# galaxy density\n",
"n_arcmin2 = 1e-4\n",
"\n",
Expand Down
9 changes: 6 additions & 3 deletions examples/1-basic/shells.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import camb\n",
"from cosmology import Cosmology\n",
"\n",
"import glass\n",
"import glass.ext.camb\n",
"\n",
"\n",
"# cosmology for the simulation\n",
"h = 0.7\n",
"Oc = 0.25\n",
Expand All @@ -57,7 +57,10 @@
"\n",
"# set up CAMB parameters for matter angular power spectrum\n",
"pars = camb.set_params(\n",
" H0=100 * h, omch2=Oc * h**2, ombh2=Ob * h**2, NonLinear=camb.model.NonLinear_both\n",
" H0=100 * h,\n",
" omch2=Oc * h**2,\n",
" ombh2=Ob * h**2,\n",
" NonLinear=camb.model.NonLinear_both,\n",
")\n",
"\n",
"# get the cosmology from CAMB\n",
Expand Down
13 changes: 8 additions & 5 deletions examples/2-advanced/cosmic_shear.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@
},
"outputs": [],
"source": [
"import numpy as np\n",
"import healpy as hp\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"# use the CAMB cosmology that generated the matter power spectra\n",
"import camb\n",
"from cosmology import Cosmology\n",
"\n",
"# GLASS modules: cosmology and everything in the glass namespace\n",
"import glass\n",
"from glass.core.constants import ARCMIN2_SPHERE\n",
"\n",
"\n",
"# cosmology for the simulation\n",
"h = 0.7\n",
"Oc = 0.25\n",
Expand All @@ -55,7 +55,10 @@
"\n",
"# set up CAMB parameters for matter angular power spectrum\n",
"pars = camb.set_params(\n",
" H0=100 * h, omch2=Oc * h**2, ombh2=Ob * h**2, NonLinear=camb.model.NonLinear_both\n",
" H0=100 * h,\n",
" omch2=Oc * h**2,\n",
" ombh2=Ob * h**2,\n",
" NonLinear=camb.model.NonLinear_both,\n",
")\n",
"\n",
"# get the cosmology from CAMB\n",
Expand Down Expand Up @@ -281,12 +284,12 @@
"pars.min_l = 1\n",
"pars.set_for_lmax(lmax)\n",
"pars.SourceWindows = [\n",
" camb.sources.SplinedSourceWindow(z=z, W=dndz, source_type=\"lensing\")\n",
" camb.sources.SplinedSourceWindow(z=z, W=dndz, source_type=\"lensing\"),\n",
"]\n",
"theory_cls = camb.get_results(pars).get_source_cls_dict(lmax=lmax, raw_cl=True)\n",
"\n",
"# factor transforming convergence to shear\n",
"l = np.arange(lmax + 1)\n",
"l = np.arange(lmax + 1) # noqa: E741\n",
"fl = (l + 2) * (l + 1) * l * (l - 1) / np.clip(l**2 * (l + 1) ** 2, 1, None)\n",
"\n",
"# the noise level from discrete observations with shape noise\n",
Expand Down
9 changes: 6 additions & 3 deletions examples/2-advanced/stage_4_galaxies.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@
},
"outputs": [],
"source": [
"import numpy as np\n",
"import healpy as hp\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"# use the CAMB cosmology that generated the matter power spectra\n",
"import camb\n",
"from cosmology import Cosmology\n",
"\n",
"# GLASS modules: cosmology and everything in the glass namespace\n",
"import glass\n",
"import glass.ext.camb\n",
"\n",
"\n",
"# cosmology for the simulation\n",
"h = 0.7\n",
"Oc = 0.25\n",
Expand All @@ -58,7 +58,10 @@
"\n",
"# set up CAMB parameters for matter angular power spectrum\n",
"pars = camb.set_params(\n",
" H0=100 * h, omch2=Oc * h**2, ombh2=Ob * h**2, NonLinear=camb.model.NonLinear_both\n",
" H0=100 * h,\n",
" omch2=Oc * h**2,\n",
" ombh2=Ob * h**2,\n",
" NonLinear=camb.model.NonLinear_both,\n",
")\n",
"\n",
"# get the cosmology from CAMB\n",
Expand Down
57 changes: 29 additions & 28 deletions glass/__init__.py
Original file line number Diff line number Diff line change
@@ -1,70 +1,71 @@
"""GLASS package."""

import contextlib
from importlib.metadata import PackageNotFoundError

try:
with contextlib.suppress(PackageNotFoundError):
from ._version import __version__, __version_tuple__
except PackageNotFoundError:
pass

from glass.fields import (
iternorm,
cls2cov,
multalm,
transform_cls,
effective_cls,
gaussian_gls,
lognormal_gls,
generate_gaussian,
generate_lognormal,
getcl,
effective_cls,
iternorm,
lognormal_gls,
multalm,
transform_cls,
)
from glass.galaxies import (
redshifts,
redshifts_from_nz,
galaxy_shear,
gaussian_phz,
redshifts,
redshifts_from_nz,
)
from glass.lensing import (
from_convergence,
shear_from_convergence,
MultiPlaneConvergence,
deflect,
from_convergence,
multi_plane_matrix,
multi_plane_weights,
deflect,
shear_from_convergence,
)
from glass.observations import (
vmap_galactic_ecliptic,
equal_dens_zbins,
fixed_zbins,
gaussian_nz,
smail_nz,
fixed_zbins,
equal_dens_zbins,
tomo_nz_gausserr,
vmap_galactic_ecliptic,
)
from glass.points import (
effective_bias,
linear_bias,
loglinear_bias,
position_weights,
positions_from_delta,
uniform_positions,
position_weights,
)
from glass.shapes import (
triaxial_axis_ratio,
ellipticity_ryden04,
ellipticity_gaussian,
ellipticity_intnorm,
ellipticity_ryden04,
triaxial_axis_ratio,
)
from glass.shells import (
distance_weight,
volume_weight,
RadialWindow,
combine,
cubic_windows,
density_weight,
tophat_windows,
distance_grid,
distance_weight,
linear_windows,
cubic_windows,
restrict,
partition,
redshift_grid,
distance_grid,
combine,
RadialWindow,
restrict,
tophat_windows,
volume_weight,
)
from glass.user import save_cls, load_cls, write_catalog
from glass.user import load_cls, save_cls, write_catalog
Loading