Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:

- run: pip install -e ".[dev]"

- run: ruff check src/
- run: ruff check .

- run: pytest -v tests/
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ spectroplot = "spectroplot:main"

[tool.setuptools.packages.find]
where = ["src"]

[tool.ruff]
line-length = 80

[tool.ruff.lint]
select = ["E", "F", "W", "I"]
1 change: 1 addition & 0 deletions src/spectroplot/_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import re

from spectroplot.global_constants import RE_SPECTRUM_ROOT_PATTERN

RE_SPECTRUM_ROOT = re.compile(RE_SPECTRUM_ROOT_PATTERN)
12 changes: 7 additions & 5 deletions src/spectroplot/data_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
"""

import logging
import re #regex

from pathlib import Path #path processing (replace os)
import re #regex
from pathlib import Path #path processing (replace os)
from typing import Iterator, Optional, Tuple

from spectroplot._patterns import RE_SPECTRUM_ROOT
from spectroplot.global_constants import (
SPECSTRING_START, SPECSTRING_END, IR_STRING, VPT2_STRING,
IR_STRING,
RAMAN_STRING,
SPECSTRING_END,
SPECSTRING_START,
VPT2_STRING,
)
from spectroplot._patterns import RE_SPECTRUM_ROOT

logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())
Expand Down
9 changes: 6 additions & 3 deletions src/spectroplot/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
"""

from typing import Optional
import numpy as np #element-wise tensor processing
import pandas as pd #dataframe processing
from spectroplot.global_constants import npt_nm, npt_wn, npt_ev, CONV_WNTOEV

import numpy as np #element-wise tensor processing
import pandas as pd #dataframe processing

from spectroplot._patterns import RE_SPECTRUM_ROOT
from spectroplot.global_constants import CONV_WNTOEV, npt_ev, npt_nm, npt_wn


def show_plots(ext: str, s: list[bool]) -> bool:
"""Check if the file type matches any requested plot type.
Expand Down
92 changes: 66 additions & 26 deletions src/spectroplot/spectroplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,77 @@
@author: Emmanuel Bourret
"""

import sys #sys files processing
import argparse #argument parser
import sys #sys files processing
from pathlib import Path #path processing
from typing import Optional
from pathlib import Path #path processing
import argparse #argument parser
import numpy as np #element-wise tensor processing
import pandas as pd #dataframes processing
import matplotlib.pyplot as plt #plots
import seaborn as sns #color palettes
from scipy.signal import find_peaks #peak detection

from spectroplot.global_constants import (
th_fac, esd_fac, ex_fac, color_palette,
label_tddft, label_sticks, label_expt, label_roots,
label_ir, label_raman, label_vpt2, label_vpt2_overt,
label_sticks_vib,
show_single_lineshape, show_single_lineshape_area,
show_conv_spectrum, show_sticks, show_exp_spectrum,
show_esd_spectrum, show_single_root_area,
show_label_peaks, show_label_roots,
show_minor_ticks, show_grid, show_legend, linear_locator,
y_label, y_label_PL, x_label_wn, x_label_ev, x_label_nm,
label_rotation_angle, figure_dpi, acs_w, acs_h, output_name,
CONV_WNTOEV, w_nm, w_wn, w_ev, w_ir, w_raman,
)
import matplotlib.pyplot as plt #plots
import numpy as np #element-wise tensor processing
import pandas as pd #dataframes processing
import seaborn as sns #color palettes
from scipy.signal import find_peaks #peak detection

from spectroplot._patterns import RE_SPECTRUM_ROOT
from spectroplot.data_reader import SpectrumData #spectrum data parser
from spectroplot.functions import (
atLeastTwo, plotType, show_plots, rootSum,
xdataPrep, xdatamin, xdatamax, plotxrange,
lineshape, normalization, rounddown, roundup,
atLeastTwo,
lineshape,
normalization,
plotType,
plotxrange,
rootSum,
rounddown,
roundup,
show_plots,
xdatamax,
xdatamin,
xdataPrep,
)
from spectroplot.global_constants import (
CONV_WNTOEV,
acs_h,
acs_w,
color_palette,
esd_fac,
ex_fac,
figure_dpi,
label_expt,
label_ir,
label_raman,
label_roots,
label_rotation_angle,
label_sticks,
label_sticks_vib,
label_tddft,
label_vpt2,
label_vpt2_overt,
linear_locator,
output_name,
show_conv_spectrum,
show_esd_spectrum,
show_exp_spectrum,
show_grid,
show_label_peaks,
show_label_roots,
show_legend,
show_minor_ticks,
show_single_lineshape,
show_single_lineshape_area,
show_single_root_area,
show_sticks,
th_fac,
w_ev,
w_ir,
w_nm,
w_raman,
w_wn,
x_label_ev,
x_label_nm,
x_label_wn,
y_label,
y_label_PL,
)
from spectroplot.data_reader import SpectrumData #spectrum data parser


def _plot_tddft(ax, row, i, plt_range_x, w, ls_gauss, palette, lw,
Expand Down
13 changes: 9 additions & 4 deletions tests/test_data_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"""

import sys

sys.path.insert(0, "src")

from spectroplot.data_reader import SpectrumData
from spectroplot.global_constants import SPECSTRING_START, SPECSTRING_END

from spectroplot.global_constants import SPECSTRING_END, SPECSTRING_START

DATA_DIR = "data"

Expand Down Expand Up @@ -296,7 +296,9 @@ def test_read_ir_lines(self):
assert abs(x[2] - 300.0) < 1e-6

def test_read_ir_early_exit(self):
x, y = self.sd.read_ir(lines=IR_LINES + ["extra\n", " 4: 400.00 0.200000\n"])
x, y = self.sd.read_ir(
lines=IR_LINES + ["extra\n", " 4: 400.00 0.200000\n"]
)
assert len(x) == 3, "should stop at blank line, not read extra"


Expand All @@ -311,7 +313,10 @@ def test_read_raman_lines(self):
assert abs(y[0] - 0.5) < 1e-6

def test_read_raman_early_exit(self):
x, y = self.sd.read_raman(lines=RAMAN_LINES + ["extra\n", " 4: 400.00 0.200000 0.500000\n"])
x, y = self.sd.read_raman(
lines=RAMAN_LINES
+ ["extra\n", " 4: 400.00 0.200000 0.500000\n"]
)
assert len(x) == 3, "should stop at blank line, not read extra"


Expand Down
94 changes: 70 additions & 24 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,43 @@
@author: Emmanuel Bourret
"""

import sys

import numpy as np
import pandas as pd
import sys

sys.path.insert(0, "src")

from hypothesis import given, strategies as st, settings
from hypothesis import given, settings
from hypothesis import strategies as st

from spectroplot.functions import (
wntonm, wntoev, nmtown, nmtoev,
lineshape, normalization, atLeastTwo,
plotType, roundup, rounddown, unitConverter,
show_plots, is_unique, rootSum,
xdataPrep, xdatamin, xdatamax, plotxrange,
atLeastTwo,
is_unique,
lineshape,
nmtoev,
nmtown,
normalization,
plotType,
plotxrange,
rootSum,
rounddown,
roundup,
show_plots,
unitConverter,
wntoev,
wntonm,
xdatamax,
xdatamin,
xdataPrep,
)
from spectroplot.global_constants import CONV_WNTOEV

# Strategies for property-based converter tests
positive_floats = st.floats(min_value=1, max_value=1e6, allow_infinity=False,
allow_nan=False)
positive_nparrays = st.lists(
st.floats(min_value=1, max_value=1e6, allow_infinity=False, allow_nan=False),
st.floats(min_value=1, max_value=1e6, allow_infinity=False,
allow_nan=False),
min_size=1, max_size=10,
).map(np.array)

Expand Down Expand Up @@ -221,32 +237,56 @@ def test_rounddown_nm(self):

class TestShowPlots:
def test_out_any_true(self):
assert show_plots(".out", [True, False, False, False, False, False, False]) is True
assert show_plots(".out", [False, True, False, False, False, False, False]) is True
assert show_plots(".out", [False, False, True, False, False, False, False]) is True
assert show_plots(".out", [False, False, False, True, False, False, False]) is True
assert show_plots(
".out", [True, False, False, False, False, False, False]
) is True
assert show_plots(
".out", [False, True, False, False, False, False, False]
) is True
assert show_plots(
".out", [False, False, True, False, False, False, False]
) is True
assert show_plots(
".out", [False, False, False, True, False, False, False]
) is True

def test_out_all_false(self):
assert show_plots(".out", [False, False, False, False, False, False, False]) is False
assert show_plots(
".out", [False, False, False, False, False, False, False]
) is False

def test_asc_true(self):
assert show_plots(".asc", [False, False, False, False, True, False, False]) is True
assert show_plots(
".asc", [False, False, False, False, True, False, False]
) is True

def test_asc_false(self):
assert show_plots(".asc", [False, False, False, False, False, False, False]) is False
assert show_plots(
".asc", [False, False, False, False, False, False, False]
) is False

def test_spectrum_true(self):
assert show_plots(".spectrum", [False, False, False, False, False, True, False]) is True
assert show_plots(".spectrum", [False, False, False, False, False, False, True]) is True
assert show_plots(
".spectrum", [False, False, False, False, False, True, False]
) is True
assert show_plots(
".spectrum", [False, False, False, False, False, False, True]
) is True

def test_spectrum_false(self):
assert show_plots(".spectrum", [False, False, False, False, False, False, False]) is False
assert show_plots(
".spectrum", [False, False, False, False, False, False, False]
) is False

def test_root_ext_true(self):
assert show_plots(".spectrum.root1", [False, False, False, False, False, True, False]) is True
assert show_plots(
".spectrum.root1", [False, False, False, False, False, True, False]
) is True

def test_unknown_ext(self):
assert show_plots(".xyz", [True, True, True, True, True, True, True]) is False
assert show_plots(
".xyz", [True, True, True, True, True, True, True]
) is False


class TestIsUnique:
Expand Down Expand Up @@ -275,7 +315,9 @@ def test_basic_sum(self):
result = rootSum(df)
assert len(result) == 1
np.testing.assert_array_equal(result.iloc[0]["xdata"], xdata)
np.testing.assert_array_equal(result.iloc[0]["ydata"], np.array([5.0, 7.0, 9.0]))
np.testing.assert_array_equal(
result.iloc[0]["ydata"], np.array([5.0, 7.0, 9.0])
)

def test_different_names_raises(self):
df = pd.DataFrame([
Expand Down Expand Up @@ -351,7 +393,9 @@ def test_asc(self):
assert xdatamin(row, 10.0) == 400.0 - 30.0

def test_out(self):
row = pd.Series({"ext": ".out", "xdata_plot": np.array([1000.0, 2000.0])})
row = pd.Series(
{"ext": ".out", "xdata_plot": np.array([1000.0, 2000.0])}
)
assert xdatamin(row, 10.0) == 1000.0


Expand All @@ -361,5 +405,7 @@ def test_asc(self):
assert xdatamax(row, 10.0) == 500.0 + 30.0

def test_out(self):
row = pd.Series({"ext": ".out", "xdata_plot": np.array([1000.0, 2000.0])})
row = pd.Series(
{"ext": ".out", "xdata_plot": np.array([1000.0, 2000.0])}
)
assert xdatamax(row, 10.0) == 2000.0
5 changes: 3 additions & 2 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"""

import sys
from pathlib import Path
from unittest.mock import MagicMock, patch

import pytest
Expand Down Expand Up @@ -95,7 +94,9 @@ def test_nonexistent_file_skipped(self):
assert exc_info.value.code == 1

def test_mixed_types(self):
mock_ax = self._run_main([TEST_FILES["tddft"], TEST_FILES["experimental"]])
mock_ax = self._run_main(
[TEST_FILES["tddft"], TEST_FILES["experimental"]]
)
assert mock_ax.plot.called

def test_multiple_esd_roots(self):
Expand Down
Loading