Skip to content

Commit

Permalink
style: Perform full linting and fixes to the whole codebase (#124)
Browse files Browse the repository at this point in the history
* style: Add codespace whitelist and perform spell check (#34)

* style: Update line length config and fix E501 errors (#35)

* style: Fix eof line .codespell-whitelist

* style: Remove * imports, fixes F403 PEP violation (#36)

* style: Expand imports for data module

* style: Fix undefined variables (F821), etc. (#37)

* style: Update pre-commit hooks and last lintings (#38)

* style: Revert Doubt to Dout (#39)

* style: Lint fix _config.yml
  • Loading branch information
lsetiawan authored Dec 12, 2023
1 parent ffb5734 commit 40fee3e
Show file tree
Hide file tree
Showing 44 changed files with 458 additions and 239 deletions.
4 changes: 4 additions & 0 deletions .codespell-whitelist
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sie
childs
dout
din
39 changes: 17 additions & 22 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
exclude: |
(?x)^(
tests/utils.py |
.devcontainer/
tests/utils.py
)
ci:
autoupdate_commit_msg: "chore: update pre-commit hooks"
autofix_commit_msg: "style: pre-commit fixes"
autofix_prs: false

repos:
- repo: https://github.com/psf/black
rev: "23.7.0"
rev: "23.11.0"
hooks:
- id: black-jupyter

- repo: https://github.com/asottile/blacken-docs
rev: "1.15.0"
rev: "1.16.0"
hooks:
- id: blacken-docs
additional_dependencies: [black==23.7.0]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.4.0"
rev: "v4.5.0"
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -45,36 +43,33 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.0"
rev: "v4.0.0-alpha.4"
hooks:
- id: prettier
types_or: [yaml, markdown, html, css, scss, javascript, json]
args: [--prose-wrap=always]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.0.277"
rev: "v0.1.7"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.4.1"
hooks:
- id: mypy
files: src|tests
args: []
additional_dependencies:
- pytest
# 2023-12-11: Not use mypy for now.
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: "v1.7.1"
# hooks:
# - id: mypy
# files: src|tests
# args: []
# additional_dependencies:
# - pytest

- repo: https://github.com/codespell-project/codespell
rev: "v2.2.5"
rev: "v2.2.6"
hooks:
- id: codespell

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: "v0.9.0.5"
hooks:
- id: shellcheck
args: ["--write-changes", "--ignore-words", ".codespell-whitelist"]

- repo: https://github.com/kynan/nbstripout
rev: 0.6.1
Expand Down
4 changes: 2 additions & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ipywidgets
jupyter-book
matplotlib
sphinx
sphinx_rtd_theme
matplotlib
ipywidgets
4 changes: 2 additions & 2 deletions docs/source/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ sphinx:
- "sphinx.ext.ifconfig"
- "sphinx.ext.viewcode"
config:
html_theme_options:
html_theme_options:
logo:
image_light: ../../media/caustics_logo_white.png
image_dark: ../../media/caustics_logo.png
image_dark: ../../media/caustics_logo.png
4 changes: 2 additions & 2 deletions docs/source/tutorials/BasicIntroduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"source": [
"## Simulating an SIE lens\n",
"\n",
"Here we will demo the very basics of lensing with a classic `SIE` lens model. We will see what it takes to make an `SIE` model, lens a backgorund `Sersic` source, and sample some examples in a simulator. Caustic simulators can generalize to very complex scenarios. In these cases there can be a lot of parameters moving through the simulator, and the order/number of parameters may change depending on what lens or source is being used. To streamline this process, caustic impliments a class called `Parametrized` which has some knowledge of the parameters moving through it, this way it can keep track of everything for you. For this to work, you must put the parameters into a `Packed` object which it can recognize, each sub function can then unpack the parameters it needs. Below we will show some examples of what this looks like."
"Here we will demo the very basics of lensing with a classic `SIE` lens model. We will see what it takes to make an `SIE` model, lens a background `Sersic` source, and sample some examples in a simulator. Caustic simulators can generalize to very complex scenarios. In these cases there can be a lot of parameters moving through the simulator, and the order/number of parameters may change depending on what lens or source is being used. To streamline this process, caustic implements a class called `Parametrized` which has some knowledge of the parameters moving through it, this way it can keep track of everything for you. For this to work, you must put the parameters into a `Packed` object which it can recognize, each sub function can then unpack the parameters it needs. Below we will show some examples of what this looks like."
]
},
{
Expand Down Expand Up @@ -155,7 +155,7 @@
"source": [
"## Where to go next?\n",
"\n",
"The caustic tutorials are generally short and to the point, that way you can idenfity what you want and jump right to some useful code that demo's the particular problem you face. Below is a list of caustic tutorials and a quick description of what you will learn in each one::\n",
"The caustic tutorials are generally short and to the point, that way you can identify what you want and jump right to some useful code that demo's the particular problem you face. Below is a list of caustic tutorials and a quick description of what you will learn in each one::\n",
"\n",
"- `LensZoo`: here you can see all the built-in lens mass distributions in `caustic` and how they distort the same background Seric source.\n",
"- `Playground`: here we demo the main visualizations of a lensing system (deflection angles, convergence, potential, time delay, magnification) in an interactive display so you can change the parameters by hand and see how the visuals change!\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/tutorials/InvertLensEquation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"paths = CS.collections[0].get_paths()\n",
"caustic_paths = []\n",
"for path in paths:\n",
" # Collect the path into a descrete set of points\n",
" # Collect the path into a discrete set of points\n",
" vertices = path.interpolated(5).vertices\n",
" x1 = torch.tensor(list(float(vs[0]) for vs in vertices))\n",
" x2 = torch.tensor(list(float(vs[1]) for vs in vertices))\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/source/tutorials/MultiplaneDemo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"source": [
"# Multiplane Lensing\n",
"\n",
"The universe is three dimensional and filled with stuff. A light ray traveling to our telescope may encounter more than a single massive object on its way to our telescopes. This is handled by a multiplane lensing framework. Multiplane lensing involves tracing the path of a ray backwards from our telescope through each individual plane (which is treated similarly to typical single plane lensing, though extra factors account for the ray physically moving in 3D space) getting perturbed at each step until it finally lands on the source we'd like to image. For more mathmatical details see [Petkova et al. 2014](https://doi.org/10.1093/mnras/stu1860) for the formalism we use internally.\n",
"The universe is three dimensional and filled with stuff. A light ray traveling to our telescope may encounter more than a single massive object on its way to our telescopes. This is handled by a multiplane lensing framework. Multiplane lensing involves tracing the path of a ray backwards from our telescope through each individual plane (which is treated similarly to typical single plane lensing, though extra factors account for the ray physically moving in 3D space) getting perturbed at each step until it finally lands on the source we'd like to image. For more mathematical details see [Petkova et al. 2014](https://doi.org/10.1093/mnras/stu1860) for the formalism we use internally.\n",
"\n",
"The main concept to keep in mind is that a lot of quantities we are used to working with, such as \"reduced deflection angles\" don't really exist in multiplane lensing since these are normalized by the redshift of the source and lens, however there is no single \"lens redshift\" for multiplane! Instead we define everything with respect to results from full raytracing, once the raytracing is done we can define effective quantities (like effective reduced deflection angle) which behave similarly in intuition but are not quite the same in detail."
]
Expand Down Expand Up @@ -169,7 +169,7 @@
"paths = CS.collections[0].get_paths()\n",
"\n",
"for path in paths:\n",
" # Collect the path into a descrete set of points\n",
" # Collect the path into a discrete set of points\n",
" vertices = path.interpolated(5).vertices\n",
" x1 = torch.tensor(list(float(vs[0]) for vs in vertices))\n",
" x2 = torch.tensor(list(float(vs[1]) for vs in vertices))\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/source/tutorials/VisualizeCaustics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"source": [
"# Visualize Caustics\n",
"\n",
"Here we will demonstrate how to collect caustic lines using caustic! Since caustic (the code) uses autodiff and can get exact derivatives, it is actually very acurate at computing caustics. \n",
"Here we will demonstrate how to collect caustic lines using caustic! Since caustic (the code) uses autodiff and can get exact derivatives, it is actually very accurate at computing caustics. \n",
"\n",
"Conceptually a caustic occurs where the magnification of a lens diverges to infinity. A convenient way to measure the magnification in the image plane is by taking the determinant ($det$) of the jacobian of the lens equation ($A$), its reciprocal is the magnification. This means that anywhere that $det(A) = 0$ is a critical line in the image plane (magnification goes to infinity). If we take this line and raytrace it back to the source plane we can see the caustics which define boundaries for lensing phenomena."
]
Expand Down Expand Up @@ -125,7 +125,7 @@
"paths = CS.collections[0].get_paths()\n",
"\n",
"for path in paths:\n",
" # Collect the path into a descrete set of points\n",
" # Collect the path into a discrete set of points\n",
" vertices = path.interpolated(5).vertices\n",
" x1 = torch.tensor(list(float(vs[0]) for vs in vertices))\n",
" x2 = torch.tensor(list(float(vs[1]) for vs in vertices))\n",
Expand Down
6 changes: 3 additions & 3 deletions docs/source/tutorials/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Tutorials

Here you will find the jupyter notebook tutorials.
It is recommended that you go through the tutorials yourself,
but for quick reference a version of each tutorial is available here.
Here you will find the jupyter notebook tutorials. It is recommended that you go
through the tutorials yourself, but for quick reference a version of each
tutorial is available here.
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ version-file = "src/caustics/_version.py"

[tool.hatch.version.raw-options]
local_scheme = "no-local-version"

[tool.ruff]
# Same as Black.
line-length = 100
25 changes: 16 additions & 9 deletions src/caustics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
from ._version import version as VERSION # noqa

from .constants import *
from .lenses import *
from .cosmology import *
from .packed import *
from .parametrized import *
from .light import *
from .utils import *
from .sims import *
from .tests import *
from . import constants, lenses, cosmology, packed, parametrized, light, utils, sims
from .tests import test

# from .demo import *

__version__ = VERSION
__author__ = "Ciela"

__all__ = [
# Modules
"constants",
"lenses",
"cosmology",
"packed",
"parametrized",
"light",
"utils",
"sims",
# Functions
"test",
]
4 changes: 3 additions & 1 deletion src/caustics/cosmology.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .utils import interp1d
from .constants import G_over_c2, c_Mpc_s, km_to_Mpc
from .parametrized import Parametrized, unpack
from .packed import Packed

__all__ = (
"h0_default",
Expand Down Expand Up @@ -276,7 +277,8 @@ def critical_surface_density(

class FlatLambdaCDM(Cosmology):
"""
Subclass of Cosmology representing a Flat Lambda Cold Dark Matter (LCDM) cosmology with no radiation.
Subclass of Cosmology representing a Flat Lambda Cold Dark Matter (LCDM)
cosmology with no radiation.
"""

def __init__(
Expand Down
8 changes: 5 additions & 3 deletions src/caustics/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .hdf5dataset import *
from .illustris_kappa import *
from .probes import *
from .hdf5dataset import HDF5Dataset
from .illustris_kappa import IllustrisKappaDataset
from .probes import PROBESDataset

Check warning on line 3 in src/caustics/data/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/caustics/data/__init__.py#L1-L3

Added lines #L1 - L3 were not covered by tests

__all__ = ["HDF5Dataset", "IllustrisKappaDataset", "PROBESDataset"]

Check warning on line 5 in src/caustics/data/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/caustics/data/__init__.py#L5

Added line #L5 was not covered by tests
44 changes: 31 additions & 13 deletions src/caustics/lenses/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
from .base import *
from .epl import *
from .external_shear import *
from .pixelated_convergence import *
from .multiplane import *
from .nfw import *
from .point import *
from .pseudo_jaffe import *
from .sie import *
from .sis import *
from .singleplane import *
from .mass_sheet import *
from .tnfw import *
from .base import ThinLens, ThickLens
from .epl import EPL
from .external_shear import ExternalShear
from .pixelated_convergence import PixelatedConvergence
from .multiplane import Multiplane
from .nfw import NFW
from .point import Point
from .pseudo_jaffe import PseudoJaffe
from .sie import SIE
from .sis import SIS
from .singleplane import SinglePlane
from .mass_sheet import MassSheet
from .tnfw import TNFW


__all__ = [
"ThinLens",
"ThickLens",
"EPL",
"ExternalShear",
"PixelatedConvergence",
"Multiplane",
"NFW",
"Point",
"PseudoJaffe",
"SIE",
"SIS",
"SinglePlane",
"MassSheet",
"TNFW",
]
Loading

0 comments on commit 40fee3e

Please sign in to comment.