Skip to content

Commit

Permalink
Sort LFS, toml and tox (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
paddyroddy authored Feb 15, 2023
1 parent 4182b2c commit 29e06b2
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 84 deletions.
24 changes: 13 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v3

- name: Retrieve LFS files
run: |
git lfs ls-files -I \
bird_b697,\
EGM2008_Topography_flms_L2190.mat,\
theta30-60_phi30-60_L32.npy \
-l | cut -d' ' -f1 | sort > .lfs-assets-id
git lfs pull
- name: Checkout code
uses: nschloe/action-cached-lfs-checkout@v1
with:
include: |
bird_b697_N194,\
bird_b697,\
D_polar40_L16_N30,\
D_south_america_L16_N10,\
EGM2008_Topography_flms_L2190.mat,\
polar40_L32.npy,\
south_america_L16.npy,\
south_america_L32.npy,\
theta30-60_phi30-60_L32.npy
- name: Set up python
uses: actions/setup-python@v4
Expand Down
15 changes: 6 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ authors = [
{email = "patrickjamesroddy@gmail.com", name = "Patrick Roddy"},
]
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3 :: Only",
"Typing :: Typed",
]
dependencies = [
"cmocean==2.0.0",
Expand All @@ -24,13 +26,12 @@ dependencies = [
"numpy==1.23.5",
"pandas==1.5.3",
"plotly==5.13.0",
"psutil==5.9.4",
"pydantic==1.10.4",
"pys2let==2.2.4",
"pyssht==1.5.1",
"python-box[toml]==7.0.0",
"scipy==1.10.0",
"seaborn==0.12.2",
"tomli==2.0.1",
]
description = "Slepian Scale-Discretised Wavelets"
dynamic = [
Expand Down Expand Up @@ -60,12 +61,8 @@ urls.homepage = "https://github.com/astro-informatics/sleplet"
report = {skip_covered = true, sort = "cover"}
run = {branch = true, parallel = true, source = ["sleplet"]}
paths.source = [
"*/src",
"*\\src",
".tox*/*/lib/python*/site-packages",
".tox*/pypy*/site-packages",
".tox*\\*\\Lib\\site-packages",
"src",
".tox*/*/lib/python*/site-packages",
]

[tool.mypy]
Expand Down Expand Up @@ -113,7 +110,7 @@ mccabe.max-complexity = 18
[tool.setuptools_scm]

[tool.tomlsort]
all = true
sort_inline_arrays = false
spaces_indent_inline_array = 4
trailing_comma_inline_array = true

Expand Down
2 changes: 1 addition & 1 deletion src/sleplet/data/other/earth/create_africa_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def create_mask(L: int) -> None:
if __name__ == "__main__":
parser = ArgumentParser(description="create the Africa region mask")
parser.add_argument(
"--bandlimit", "-L", type=int, default=settings.L, help="bandlimit"
"--bandlimit", "-L", type=int, default=settings["L"], help="bandlimit"
)
args = parser.parse_args()
create_mask(args.bandlimit)
18 changes: 9 additions & 9 deletions src/sleplet/meshes/classes/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ class Mesh:
def __post_init_post_parse__(self) -> None:
mesh_config = extract_mesh_config(self.name)
self.camera_view = create_camera(
mesh_config.CAMERA_X,
mesh_config.CAMERA_Y,
mesh_config.CAMERA_Z,
mesh_config.REGION_ZOOM if self.zoom else mesh_config.DEFAULT_ZOOM,
x_center=mesh_config.CENTER_X if self.zoom else 0,
y_center=mesh_config.CENTER_Y if self.zoom else 0,
z_center=mesh_config.CENTER_Z if self.zoom else 0,
mesh_config["CAMERA_X"],
mesh_config["CAMERA_Y"],
mesh_config["CAMERA_Z"],
mesh_config["REGION_ZOOM"] if self.zoom else mesh_config["DEFAULT_ZOOM"],
x_center=mesh_config["CENTER_X"] if self.zoom else 0,
y_center=mesh_config["CENTER_Y"] if self.zoom else 0,
z_center=mesh_config["CENTER_Z"] if self.zoom else 0,
)
self.colourbar_pos = (
mesh_config.REGION_COLOURBAR_POS
mesh_config["REGION_COLOURBAR_POS"]
if self.zoom
else mesh_config.DEFAULT_COLOURBAR_POS
else mesh_config["DEFAULT_COLOURBAR_POS"]
)
self.vertices, self.faces = read_mesh(mesh_config)
self.region = create_mesh_region(mesh_config, self.vertices)
Expand Down
6 changes: 3 additions & 3 deletions src/sleplet/meshes/classes/mesh_slepian.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _compute_slepian_functions(self) -> None:
self.slepian_eigenvalues,
self.slepian_functions,
) = self._clean_evals_and_evecs(LA.eigh(D))
if settings.SAVE_MATRICES:
if settings["SAVE_MATRICES"]:
np.save(eval_loc, self.slepian_eigenvalues)
np.save(evec_loc, self.slepian_functions[: self.N])

Expand Down Expand Up @@ -97,11 +97,11 @@ def func(chunk: list[int]) -> None:

# split up L range to maximise effiency
chunks = split_arr_into_chunks(
self.mesh.mesh_eigenvalues.shape[0], settings.NCPU
self.mesh.mesh_eigenvalues.shape[0], settings["NCPU"]
)

# initialise pool and apply function
with ThreadPoolExecutor(max_workers=settings.NCPU) as e:
with ThreadPoolExecutor(max_workers=settings["NCPU"]) as e:
e.map(func, chunks)

# retrieve from parallel function
Expand Down
4 changes: 2 additions & 2 deletions src/sleplet/plotting/create_plot_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ def execute(self) -> None:
# create html and open if auto_open is true
html_filename = str(_fig_path / "html" / f"{self.filename}.html")

py.plot(fig, filename=html_filename, auto_open=settings.AUTO_OPEN)
py.plot(fig, filename=html_filename, auto_open=settings["AUTO_OPEN"])

# if save_fig is true then create png and pdf in their directories
if settings.SAVE_FIG:
if settings["SAVE_FIG"]:
for file_type in {"png", "pdf"}:
logger.info(f"saving {file_type}")
filename = str(_fig_path / file_type / f"{self.filename}.{file_type}")
Expand Down
4 changes: 2 additions & 2 deletions src/sleplet/plotting/create_plot_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ def execute(self) -> None:
# create html and open if auto_open is true
html_filename = str(_fig_path / "html" / f"{self.filename}.html")

py.plot(fig, filename=html_filename, auto_open=settings.AUTO_OPEN)
py.plot(fig, filename=html_filename, auto_open=settings["AUTO_OPEN"])

# if save_fig is true then create png and pdf in their directories
if settings.SAVE_FIG:
if settings["SAVE_FIG"]:
for file_type in {"png", "pdf"}:
logger.info(f"saving {file_type}")
filename = str(_fig_path / file_type / f"{self.filename}.{file_type}")
Expand Down
2 changes: 1 addition & 1 deletion src/sleplet/scripts/plotting_on_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def read_args() -> Namespace:
help=f"alpha/phi pi fraction - defaults to {ALPHA_DEFAULT}",
)
parser.add_argument(
"--bandlimit", "-L", type=int, default=settings.L, help="bandlimit"
"--bandlimit", "-L", type=int, default=settings["L"], help="bandlimit"
)
parser.add_argument(
"--beta",
Expand Down
18 changes: 9 additions & 9 deletions src/sleplet/slepian/slepian_region/slepian_arbitrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
class SlepianArbitrary(SlepianFunctions):
mask_name: str
_: KW_ONLY
L_max: int = settings.L_MAX
L_min: int = settings.L_MIN
L_max: int = settings["L_MAX"]
L_min: int = settings["L_MIN"]

def __post_init_post_parse__(self) -> None:
self.resolution = settings.SAMPLES * self.L
self.resolution = settings["SAMPLES"] * self.L
super().__post_init_post_parse__()

def _create_fn_name(self) -> str:
Expand Down Expand Up @@ -78,9 +78,9 @@ def _solve_D_matrix(self, eval_loc, evec_loc):
D = self._create_D_matrix()

# check whether the large job has been split up
if (
self.L_min != L_MIN_DEFAULT or self.L_max != self.L
) and settings.SAVE_MATRICES:
if (self.L_min != L_MIN_DEFAULT or self.L_max != self.L) and settings[
"SAVE_MATRICES"
]:
logger.info("large job has been used, saving intermediate matrix")
inter_loc = self.matrix_location / f"D_min{self.L_min}_max{self.L_max}.npy"
np.save(inter_loc, D)
Expand All @@ -91,7 +91,7 @@ def _solve_D_matrix(self, eval_loc, evec_loc):

# solve eigenproblem
eigenvalues, eigenvectors = clean_evals_and_evecs(LA.eigh(D))
if settings.SAVE_MATRICES:
if settings["SAVE_MATRICES"]:
np.save(eval_loc, eigenvalues)
np.save(evec_loc, eigenvectors[: self.N])
return eigenvalues, eigenvectors
Expand Down Expand Up @@ -126,11 +126,11 @@ def func(chunk: list[int]) -> None:

# split up L range to maximise effiency
chunks = split_arr_into_chunks(
self.L_max**2, settings.NCPU, arr_min=self.L_min**2
self.L_max**2, settings["NCPU"], arr_min=self.L_min**2
)

# initialise pool and apply function
with ThreadPoolExecutor(max_workers=settings.NCPU) as e:
with ThreadPoolExecutor(max_workers=settings["NCPU"]) as e:
e.map(func, chunks)

# retrieve from parallel function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _solve_eigenproblem(
else:
K = self._create_K_matrix()
eigenvalues, eigenvectors = self._clean_evals_and_evecs(LA.eigh(K))
if settings.SAVE_MATRICES:
if settings["SAVE_MATRICES"]:
np.save(eval_loc, eigenvalues)
np.save(evec_loc, eigenvectors[: self.N])
return eigenvalues, eigenvectors
Expand Down
6 changes: 3 additions & 3 deletions src/sleplet/slepian/slepian_region/slepian_polar_cap.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def _solve_eigenproblem_from_scratch(
eigenvectors,
self.order,
) = self._sort_all_evals_and_evecs(evals_all, evecs_all, emm)
if settings.SAVE_MATRICES:
if settings["SAVE_MATRICES"]:
limit = self.N if self.L > L_SAVE_ALL else None
np.save(eval_loc, eigenvalues)
np.save(evec_loc, eigenvectors[:limit])
Expand Down Expand Up @@ -181,10 +181,10 @@ def func(chunk: list[int]) -> None:
free_shared_memory(shm_int)

# split up L range to maximise effiency
chunks = split_arr_into_chunks(self.L - m, settings.NCPU)
chunks = split_arr_into_chunks(self.L - m, settings["NCPU"])

# initialise pool and apply function
with ThreadPoolExecutor(max_workers=settings.NCPU) as e:
with ThreadPoolExecutor(max_workers=settings["NCPU"]) as e:
e.map(func, chunks)

# retrieve from parallel function
Expand Down
5 changes: 3 additions & 2 deletions src/sleplet/utils/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from pathlib import Path

from box import Box
import tomli

_file_location = Path(__file__).resolve()
_settings_file = _file_location.parents[1] / "config" / "settings.toml"

settings = Box.from_toml(filename=_settings_file)
with open(_settings_file, "rb") as f:
settings = tomli.load(f)
29 changes: 14 additions & 15 deletions src/sleplet/utils/mask_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import numpy as np
import pyssht as ssht
from box import Box
from numpy import typing as npt

from sleplet.meshes.classes.mesh import Mesh
Expand Down Expand Up @@ -79,33 +78,33 @@ def ensure_masked_flm_bandlimited(
return ssht.forward(field, L, Reality=reality, Spin=spin, Method=SAMPLING_SCHEME)


def create_default_region(settings: Box) -> Region:
def create_default_region(settings: dict) -> Region:
"""
creates default region from settings object
"""
return Region(
gap=settings.POLAR_GAP,
mask_name=settings.SLEPIAN_MASK,
phi_max=np.deg2rad(settings.PHI_MAX),
phi_min=np.deg2rad(settings.PHI_MIN),
theta_max=np.deg2rad(settings.THETA_MAX),
theta_min=np.deg2rad(settings.THETA_MIN),
gap=settings["POLAR_GAP"],
mask_name=settings["SLEPIAN_MASK"],
phi_max=np.deg2rad(settings["PHI_MAX"]),
phi_min=np.deg2rad(settings["PHI_MIN"]),
theta_max=np.deg2rad(settings["THETA_MAX"]),
theta_min=np.deg2rad(settings["THETA_MIN"]),
)


def create_mesh_region(
mesh_config: Box, vertices: npt.NDArray[np.float_]
mesh_config: dict, vertices: npt.NDArray[np.float_]
) -> npt.NDArray[np.bool_]:
"""
creates the boolean region for the given mesh
"""
return (
(vertices[:, 0] >= mesh_config.XMIN)
& (vertices[:, 0] <= mesh_config.XMAX)
& (vertices[:, 1] >= mesh_config.YMIN)
& (vertices[:, 1] <= mesh_config.YMAX)
& (vertices[:, 2] >= mesh_config.ZMIN)
& (vertices[:, 2] <= mesh_config.ZMAX)
(vertices[:, 0] >= mesh_config["XMIN"])
& (vertices[:, 0] <= mesh_config["XMAX"])
& (vertices[:, 1] >= mesh_config["YMIN"])
& (vertices[:, 1] <= mesh_config["YMAX"])
& (vertices[:, 2] >= mesh_config["ZMIN"])
& (vertices[:, 2] <= mesh_config["ZMAX"])
)


Expand Down
29 changes: 15 additions & 14 deletions src/sleplet/utils/mesh_methods.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path

import numpy as np
from box import Box
import tomli
from igl import average_onto_faces, cotmatrix, read_triangle_mesh, upsample
from numpy import typing as npt
from scipy.sparse import linalg as LA_sparse
Expand Down Expand Up @@ -38,26 +38,27 @@ def average_functions_on_vertices_to_faces(


def create_mesh_region(
mesh_config: Box, vertices: npt.NDArray[np.float_]
mesh_config: dict, vertices: npt.NDArray[np.float_]
) -> npt.NDArray[np.bool_]:
"""
creates the boolean region for the given mesh
"""
return (
(vertices[:, 0] >= mesh_config.XMIN)
& (vertices[:, 0] <= mesh_config.XMAX)
& (vertices[:, 1] >= mesh_config.YMIN)
& (vertices[:, 1] <= mesh_config.YMAX)
& (vertices[:, 2] >= mesh_config.ZMIN)
& (vertices[:, 2] <= mesh_config.ZMAX)
(vertices[:, 0] >= mesh_config["XMIN"])
& (vertices[:, 0] <= mesh_config["XMAX"])
& (vertices[:, 1] >= mesh_config["YMIN"])
& (vertices[:, 1] <= mesh_config["YMAX"])
& (vertices[:, 2] >= mesh_config["ZMIN"])
& (vertices[:, 2] <= mesh_config["ZMAX"])
)


def extract_mesh_config(mesh_name: str) -> Box:
def extract_mesh_config(mesh_name: str) -> dict:
"""
reads in the given mesh region settings file
"""
return Box.from_toml(filename=_meshes_path / "regions" / f"{mesh_name}.toml")
with open(_meshes_path / "regions" / f"{mesh_name}.toml", "rb") as f:
return tomli.load(f)


def mesh_eigendecomposition(
Expand Down Expand Up @@ -99,21 +100,21 @@ def mesh_eigendecomposition(
laplacian, k=number_basis_functions, which="LM", sigma=0
)
eigenvectors = _orthonormalise_basis_functions(vertices, faces, eigenvectors.T)
if settings.SAVE_MATRICES:
if settings["SAVE_MATRICES"]:
logger.info("saving binaries...")
np.save(eval_loc, eigenvalues)
np.save(evec_loc, eigenvectors)
return eigenvalues, eigenvectors, number_basis_functions


def read_mesh(mesh_config: Box) -> tuple[npt.NDArray[np.float_], npt.NDArray[np.int_]]:
def read_mesh(mesh_config: dict) -> tuple[npt.NDArray[np.float_], npt.NDArray[np.int_]]:
"""
reads in the given mesh
"""
vertices, faces = read_triangle_mesh(
str(_meshes_path / "polygons" / mesh_config.FILENAME)
str(_meshes_path / "polygons" / mesh_config["FILENAME"])
)
return upsample(vertices, faces, number_of_subdivs=mesh_config.UPSAMPLE)
return upsample(vertices, faces, number_of_subdivs=mesh_config["UPSAMPLE"])


def _mesh_laplacian(
Expand Down
Loading

0 comments on commit 29e06b2

Please sign in to comment.