Skip to content

Commit

Permalink
style: clean up precommit
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhi committed Jan 18, 2024
1 parent 503ccae commit d974fa7
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 113 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ default_install_hook_types: [pre-commit, commit-msg]

repos:
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v2.1.1
rev: v3.1.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-docstring-first
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.149
rev: v0.1.13
hooks:
- id: ruff
args: [--fix]
Expand All @@ -31,12 +31,12 @@ repos:
- id: black

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.10.1
rev: v0.15
hooks:
- id: validate-pyproject

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
rev: v1.8.0
hooks:
- id: mypy
files: "^src/"
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,4 @@ def linkcode_resolve(domain, info):

fn = os.path.relpath(fn, start=os.path.dirname("../raman_analysis"))

return f"https://github.com/ianhi/raman-analysis/blob/main/raman_analysis/{fn}{linespec}" # noqa
return f"https://github.com/ianhi/raman-analysis/blob/main/raman_analysis/{fn}{linespec}"
40 changes: 40 additions & 0 deletions src/raman_analysis/baseline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from typing import Any

import numpy as np
from pybaselines import Baseline

__all__ = [
"baseline",
]


def baseline(spectra: np.ndarray, method: str = "arpls", **params: Any) -> np.ndarray:
"""
Calculate the baseline of [many] spectra using pybaselines.
Parameters
----------
spectra : array-like ([N], wns)
The spectra to calculate the baseline of.
method : str, default: "arpls"
The pybaselines method name.
**params:
Passed to pybaselines
Returns
-------
baseline : np.ndarray ([N], wns)
The calculated baselines
"""
baseliner = Baseline(np.arange(1340))
baseline_func = getattr(baseliner, method)

spectra = np.atleast_2d(spectra)
if np.issubdtype(spectra.dtype, np.integer):
spectra = spectra.astype(np.float32)

baselines = np.zeros_like(spectra)

for i, spec in enumerate(spectra):
baselines[i], w = baseline_func(spec, **params)
return baselines.squeeze()
120 changes: 13 additions & 107 deletions src/raman_analysis/loading.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from typing import Iterable, Union
from __future__ import annotations

from typing import Iterable

import numpy as np
import pandas as pd
import xarray as xr


def ds2df(
ds: xr.Dataset, fov: int, cell_index_start: int = 0, filename=None
ds: xr.Dataset, fov: int, cell_index_start: int = 0, filename: str | None = None
) -> pd.DataFrame:
"""
Convert a single dataset into a dataframe.
Expand Down Expand Up @@ -39,11 +41,11 @@ def ds2df(
df["y"] = ds["cell_points"][:, 1]

cell_points = ds["cell_points"] * 2048
bkd_points = ds["bkd_points"] * 2048
cell_raman = ds["cell_raman"] - 608
bkd_raman = ds["bkd_raman"] - 608
# bkd_points = ds["bkd_points"] * 2048
# cell_raman = ds["cell_raman"] - 608
# bkd_raman = ds["bkd_raman"] - 608

thres = 140
# thres = 140

cell_com = cell_points.to_numpy().astype(int)
gfp_int = np.asarray([ds["img"][1, 0, x[0], x[1]].values for x in cell_com])
Expand All @@ -56,113 +58,15 @@ def ds2df(


def glob2df(
files: Union[Iterable[str], str],
conditions,
files: Iterable[str] | str,
conditions: tuple[str, str],
threshold: float,
well_number: int = 0,
cell_index_start: int = 0,
verbose: bool = True,
) -> pd.DataFrame:
"""
Convert a list of raman file names to a dataframe.
Parameters
----------
Expand All @@ -188,6 +92,8 @@ def glob2df(
images : xr.DataArray
"""
if isinstance(files, str):
from glob import glob

files = glob(files)
dfs = []
images = []
Expand Down

0 comments on commit d974fa7

Please sign in to comment.