Skip to content

Commit

Permalink
Be careful with isort
Browse files Browse the repository at this point in the history
  • Loading branch information
paddyroddy committed Sep 17, 2024
1 parent 431c12e commit dfb69e8
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 26 deletions.
10 changes: 6 additions & 4 deletions examples/1-basic/density.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@
"outputs": [],
"source": [
"# use the CAMB cosmology that generated the matter power spectra\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from matplotlib.colors import LogNorm\n",
"\n",
"import camb\n",
"from cosmology import Cosmology\n",
"\n",
"import glass.fields\n",
"import glass.galaxies\n",
"import glass.points\n",
"\n",
"# GLASS imports: matter, random fields, random points, galaxies\n",
"import glass.shells\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from cosmology import Cosmology\n",
"from matplotlib.colors import LogNorm\n",
"\n",
"# cosmology for the simulation\n",
"h = 0.7\n",
Expand Down
10 changes: 6 additions & 4 deletions examples/1-basic/lensing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,19 @@
"outputs": [],
"source": [
"# use the CAMB cosmology that generated the matter power spectra\n",
"import healpy as hp\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import camb\n",
"from cosmology import Cosmology\n",
"\n",
"import glass.fields\n",
"import glass.galaxies\n",
"import glass.lensing\n",
"\n",
"# GLASS imports\n",
"import glass.shells\n",
"import healpy as hp\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from cosmology import Cosmology\n",
"\n",
"# cosmology for the simulation\n",
"h = 0.7\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 @@ -35,15 +35,17 @@
"outputs": [],
"source": [
"# uses the CAMB cosmology which produced the cls\n",
"import healpy as hp\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import camb\n",
"from cosmology import Cosmology\n",
"\n",
"import glass.fields\n",
"\n",
"# these are the GLASS imports: matter and random fields\n",
"import glass.shells\n",
"import healpy as hp\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from cosmology import Cosmology\n",
"\n",
"# cosmology for the simulation\n",
"h = 0.7\n",
Expand Down
5 changes: 3 additions & 2 deletions examples/1-basic/photoz.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@
"outputs": [],
"source": [
"# GLASS imports: matter shells, galaxies, random points, and observational\n",
"import glass.galaxies\n",
"import glass.observations\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import glass.galaxies\n",
"import glass.observations\n",
"\n",
"# how many arcmin2 over the entire sphere\n",
"from glass.core.constants import ARCMIN2_SPHERE\n",
"\n",
Expand Down
8 changes: 5 additions & 3 deletions examples/1-basic/shells.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@
},
"outputs": [],
"source": [
"import camb\n",
"import glass.ext.camb\n",
"import glass.shells\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import camb\n",
"from cosmology import Cosmology\n",
"\n",
"import glass.ext.camb\n",
"import glass.shells\n",
"\n",
"# cosmology for the simulation\n",
"h = 0.7\n",
"Oc = 0.25\n",
Expand Down
10 changes: 6 additions & 4 deletions examples/2-advanced/cosmic_shear.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@
"outputs": [],
"source": [
"# use the CAMB cosmology that generated the matter power spectra\n",
"import healpy as hp\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import camb\n",
"from cosmology import Cosmology\n",
"\n",
"import glass.fields\n",
"import glass.galaxies\n",
"import glass.lensing\n",
Expand All @@ -43,10 +49,6 @@
"\n",
"# GLASS modules: cosmology and everything in the glass namespace\n",
"import glass.shells\n",
"import healpy as hp\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from cosmology import Cosmology\n",
"from glass.core.constants import ARCMIN2_SPHERE\n",
"\n",
"# cosmology for the simulation\n",
Expand Down
10 changes: 6 additions & 4 deletions examples/2-advanced/stage_4_galaxies.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@
"outputs": [],
"source": [
"# use the CAMB cosmology that generated the matter power spectra\n",
"import healpy as hp\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import camb\n",
"from cosmology import Cosmology\n",
"\n",
"import glass.ext.camb\n",
"import glass.fields\n",
"import glass.galaxies\n",
Expand All @@ -48,10 +54,6 @@
"\n",
"# GLASS modules: cosmology and everything in the glass namespace\n",
"import glass.shells\n",
"import healpy as hp\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from cosmology import Cosmology\n",
"\n",
"# cosmology for the simulation\n",
"h = 0.7\n",
Expand Down
14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ lint.ignore = [
"ISC001", # clashes with formatter
"NPY201", # TODO: remove after NumPy v2 support
]
lint.isort = {known-first-party = [
"glass",
], section-order = [
"future",
"standard-library",
"third-party",
"cosmo",
"first-party",
"local-folder",
], sections = {"cosmo" = [
"camb",
"cosmology",
]}}
lint.per-file-ignores = {"tests*" = [
"ANN001", # missing-type-function-argument
"ANN201", # missing-return-type-undocumented-public-function
Expand All @@ -114,3 +127,4 @@ lint.mccabe.max-complexity = 18

[tool.tomlsort]
overrides."project.classifiers".inline_arrays = false
overrides."tool.ruff.lint.isort.section-order".inline_arrays = false
3 changes: 2 additions & 1 deletion tests/core/test_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
@pytest.mark.skipif(not HAVE_SCIPY, reason="test requires SciPy")
def test_nnls():
import numpy as np
from glass.core.algorithm import nnls as nnls_glass
from scipy.optimize import nnls as nnls_scipy

from glass.core.algorithm import nnls as nnls_glass

a = np.random.randn(100, 20)
b = np.random.randn(100)

Expand Down
1 change: 1 addition & 0 deletions tests/test_fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
HAVE_FITSIO = False

import numpy as np

from glass import user


Expand Down
3 changes: 3 additions & 0 deletions tests/test_galaxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def test_redshifts():
from unittest.mock import Mock

import numpy as np

from glass.galaxies import redshifts

# create a mock radial window function
Expand All @@ -24,6 +25,7 @@ def test_redshifts():

def test_redshifts_from_nz():
import numpy as np

from glass.galaxies import redshifts_from_nz

# test sampling
Expand Down Expand Up @@ -95,6 +97,7 @@ def test_redshifts_from_nz():

def test_gaussian_phz():
import numpy as np

from glass.galaxies import gaussian_phz

# test sampling
Expand Down
1 change: 1 addition & 0 deletions tests/test_lensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def alpha(re, im):

def test_deflect_many():
import healpix

from glass.lensing import deflect

n = 1000
Expand Down
1 change: 1 addition & 0 deletions tests/test_shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def test_restrict():
@pytest.mark.parametrize("method", ["lstsq", "nnls", "restrict"])
def test_partition(method):
import numpy as np

from glass.shells import RadialWindow, partition

shells = [
Expand Down

0 comments on commit dfb69e8

Please sign in to comment.