Skip to content

Commit

Permalink
fix: 🐛 Correct path to logo (#947)
Browse files Browse the repository at this point in the history
* fix: 🐛 Correct path to logo

* build: 🔖 v0.22.4

Add poetry.lock and pyproject.toml to git

* refactor: ♻️ Using reference class
  • Loading branch information
Anselmoo authored Aug 5, 2023
1 parent 959dda4 commit 6b2ba17
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 78 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ repos:
types-PyYAML==6.0.12.10,
types-tabulate==0.9.0.3,
types-mock==5.1.0.1,
types-setuptools==68.0.0.3,
numpy==1.23.4,
pydantic==2.1,
pytest==7.1.3,
Expand Down
118 changes: 63 additions & 55 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "SpectraFit"
version = "0.22.3"
version = "0.22.4"
description = "Fast fitting of 2D- and 3D-Spectra with established routines"
readme = "README.md"
authors = ["Anselm Hahn <[email protected]>"]
Expand Down Expand Up @@ -100,6 +100,7 @@ prospector = { extras = [
"pylint",
], version = "^1.10.2" }
bump-pydantic = "^0.6.0"
types-setuptools = "^68.0.0.3"

[tool.poetry.group.docs.dependencies]
mkdocstrings = { extras = ["python"], version = ">=0.19,<0.23" }
Expand Down
2 changes: 1 addition & 1 deletion spectrafit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""SpectraFit, fast command line tool for fitting data."""
__version__ = "0.22.3"
__version__ = "0.22.4"
6 changes: 5 additions & 1 deletion spectrafit/api/pptx_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import Union

import pandas as pd
import pkg_resources

from matplotlib import pyplot as plt
from pptx.util import Pt
Expand Down Expand Up @@ -336,7 +337,10 @@ class PPTXBasicTitleAPI(BaseModel):
table_2_description: str = "Table 2: Regression Metrics"
table_3_description: str = "Table 3: Variables"

credit_logo: Path = Path("spectrafit/plugins/img/SpectraFit.png")
credit_logo: Path = (
Path(pkg_resources.get_distribution("spectrafit").location)
/ "spectrafit/plugins/img/SpectraFit.png"
)
credit_description: str = f"SpectraFit: v{__version__}"


Expand Down
10 changes: 5 additions & 5 deletions spectrafit/api/test/test_cmd_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

def test_default_cmd() -> None:
"""Test for default settings of CMD Model."""
result = CMDModelAPI(infile="").dict()
result = CMDModelAPI(infile="").model_dump()
assert result["infile"] == ""
assert result["outfile"] == "spectrafit_results"
assert result["input"] == "fitting_input.toml"
Expand Down Expand Up @@ -51,7 +51,7 @@ def test_overwrite_cmd() -> None:
"width": [1],
"wlen": 1,
},
).dict()
).model_dump()
assert result["infile"] == ""
assert result["outfile"] == "test"
assert result["input"] == "fitting_input.toml"
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_sha256() -> None:

def test_default_description() -> None:
"""Test for default settings of Description Model."""
result = DescriptionAPI().dict()
result = DescriptionAPI().model_dump()
assert result["project_name"] == "FittingProject"
assert result["project_details"] == f"Fitting Project via SpectraFit v{__version__}"
assert result["keywords"] == ["spectra"]
Expand All @@ -103,7 +103,7 @@ def test_default_description() -> None:
@pytest.mark.parametrize("metadata", [{"test": "test"}, ["test"]])
def test_overwrite_description(metadata: Any) -> None:
"""Test for overwriting settings of Description Model."""
result = DescriptionAPI(metadata=metadata).dict()
result = DescriptionAPI(metadata=metadata).model_dump()
assert result["metadata"] == metadata


Expand All @@ -117,7 +117,7 @@ def test_overwrite_description(metadata: Any) -> None:
)
def test_overwrite_references(refs: Any) -> None:
"""Test for overwriting settings of Description Model."""
result = DescriptionAPI(refs=refs).dict()
result = DescriptionAPI(refs=refs).model_dump()
assert result["references"] == refs


Expand Down
6 changes: 3 additions & 3 deletions spectrafit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ def pearson4(
class ReferenceKeys:
"""Reference keys for model fitting and peak detection."""

__models__ = list(DistributionModelAPI.schema()["properties"].keys())
__models__ = list(DistributionModelAPI.model_json_schema()["properties"].keys())

__automodels__ = [
"gaussian",
Expand Down Expand Up @@ -1507,8 +1507,8 @@ def __init__(self, df: pd.DataFrame, args: Dict[str, Any]) -> None:
additional information beyond the command line arguments.
"""
super().__init__(df=df, args=args)
self.args_solver = SolverModelsAPI(**args).dict()
self.args_global = GlobalFittingAPI(**args).dict()
self.args_solver = SolverModelsAPI(**args).model_dump()
self.args_global = GlobalFittingAPI(**args).model_dump()
self.params = self.return_params

def __call__(self) -> Tuple[Minimizer, Any]:
Expand Down
4 changes: 2 additions & 2 deletions spectrafit/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def plot_global_spectra(self) -> None:
peaks = [
peak
for peak in self.df.columns
if not peak.startswith(tuple(ColumnNamesAPI().dict().values()))
if not peak.startswith(tuple(ColumnNamesAPI().model_dump().values()))
and peak.endswith(f"_{i+1}")
]
color_peaks = sns.color_palette("rocket", len(peaks))
Expand Down Expand Up @@ -154,7 +154,7 @@ def plot_local_spectra(self) -> None:
peaks = [
peak
for peak in self.df.columns
if peak not in list(ColumnNamesAPI().dict().values())
if peak not in list(ColumnNamesAPI().model_dump().values())
]
color_peaks = sns.color_palette("rocket", len(peaks))
for i, peak in enumerate(peaks):
Expand Down
4 changes: 3 additions & 1 deletion spectrafit/plugins/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,9 @@ def solver_model(
self.initial_model = initial_model

if isinstance(conf_interval, bool):
conf_interval = ConfIntervalAPI().dict() if conf_interval is True else False
conf_interval = (
ConfIntervalAPI().model_dump() if conf_interval is True else False
)
elif isinstance(conf_interval, dict):
conf_interval = ConfIntervalAPI(**conf_interval).dict(exclude_none=True)

Expand Down
2 changes: 1 addition & 1 deletion spectrafit/plugins/rixs_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def __call__(self) -> None:
emission_energy=args["emission_energy"],
rixs_map=args["rixs_map"],
mode=args["mode"],
).dict(),
).model_dump(),
fname=args["infile"],
export_format=args["export_format"],
)
Expand Down
2 changes: 1 addition & 1 deletion spectrafit/plugins/rixs_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ def load_data(infile: Path) -> RIXSModelAPI:

def __call__(self) -> None: # pragma: no cover
"""Run the RIXS Visualizer."""
app = RIXSApp(**self.load_data(self.get_args()["infile"]).dict())
app = RIXSApp(**self.load_data(self.get_args()["infile"]).model_dump())
app.app_run()


Expand Down
22 changes: 16 additions & 6 deletions spectrafit/plugins/test/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import gzip
import json
import pickle
import shutil

from pathlib import Path
from typing import Any
Expand All @@ -21,6 +22,7 @@
from nptyping import Float
from nptyping import NDArray
from nptyping import Shape
from spectrafit.api.pptx_model import PPTXBasicTitleAPI
from spectrafit.plugins.data_converter import DataConverter
from spectrafit.plugins.file_converter import FileConverter
from spectrafit.plugins.pkl_converter import ExportData
Expand Down Expand Up @@ -680,7 +682,6 @@ def test_cmd_pkl_converter(
"--export-format",
export_format,
)

assert ret.success
assert ret.stdout == ""
assert ret.stderr == ""
Expand Down Expand Up @@ -899,7 +900,7 @@ def test_create_rixs(
fname, keys = tmp_list_dict_rixs
converter = RIXSConverter()
data = converter.convert(fname, file_format="latin1")
rixs_map = converter.create_rixs(data, *keys, mode=mode).dict()
rixs_map = converter.create_rixs(data, *keys, mode=mode).model_dump()

assert isinstance(rixs_map["rixs_map"], np.ndarray)
if mode == "mean":
Expand Down Expand Up @@ -1070,13 +1071,22 @@ def test_cmd_pkl_converter(
script_runner (Any): Script runner.
tmp_toml_data (Path): Path to temporary file.
file_format (str): File format.
"""
source_path = Path("spectrafit/plugins/img/SpectraFit.png")
destination_path = PPTXBasicTitleAPI().credit_logo
destination_path.parent.mkdir(parents=True, exist_ok=True)
shutil.copy(source_path, destination_path)

ret = script_runner.run(
"spectrafit-pptx-converter",
str(tmp_toml_data),
"--file-format",
file_format,
[
"spectrafit-pptx-converter",
str(tmp_toml_data),
"--file-format",
file_format,
]
)
destination_path.unlink()
assert ret.success
assert ret.stderr == ""
assert ret.stdout == ""
Expand Down
2 changes: 1 addition & 1 deletion spectrafit/spectrafit.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def extracted_from_command_line_runner() -> Dict[str, Any]:
if "settings" in _args.keys():
for key in _args["settings"].keys():
result[key] = _args["settings"][key]
result = CMDModelAPI(**result).dict()
result = CMDModelAPI(**result).model_dump()
if "description" in _args["fitting"].keys():
result["description"] = _args["fitting"]["description"]
if "parameters" in _args["fitting"].keys():
Expand Down

0 comments on commit 6b2ba17

Please sign in to comment.