Skip to content

Commit

Permalink
Merge pull request #15 from JR-1991/main
Browse files Browse the repository at this point in the history
Added testing CI and compliance to Python >=3.7
  • Loading branch information
torogi94 authored Dec 30, 2022
2 parents b4e5719 + dcd075b commit 4a4b86a
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 155 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build and Test

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
pip3 install -e .
- name: Test with pytest
run: |
python3 -m pytest
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "SAS-tools"
version = "0.0"
description = "SAS-tools contains useful functions and classes for working with SAS data."
readme = "README.md"
requires-python = ">=3.10"
requires-python = ">=3.7"
license = {file = "LICENSE"}
authors = [
{name = "Torsten Giess", email = "[email protected]"},
Expand All @@ -32,9 +32,10 @@ dependencies = [
"matplotlib",
"numpy",
"pandas",
"pyaniml",
"pyAnIML==1.0.2",
"seaborn",
"scipy",
"pytest>=7.2.0"
]

[project.urls]
Expand Down
10 changes: 6 additions & 4 deletions sastools/analyzer/curvefitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import random

from pathlib import Path
from typing import Tuple, Dict, Optional

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -37,14 +38,15 @@ def __init__(
path_plots (Path): Path to where plots are to be saved.
path_fitting_data (Path): Path to where fitting data is to be saved.
"""

self.exp_data = experimental_data
self.x = self.exp_data.iloc[:, 0].values.tolist()
self.y = self.exp_data.iloc[:, 1].values.tolist()
self.file_name = file_name
self.path_plots = path_plots
self.path_fitting_data = path_fitting_data

def _pack_data_into_dict(self) -> dict:
def _pack_data_into_dict(self) -> Dict:
# Stores the data in a dictionary
data_dict = {"data": {"x": self.x, "y": self.y}}
return data_dict
Expand All @@ -63,7 +65,7 @@ def plot_raw_data(self) -> None:
)

def find_peaks_cwt(
self, peak_widths: tuple = (20,), cutoff_amplitude: float = None
self, peak_widths: Tuple = (20,), cutoff_amplitude: Optional[float] = None
) -> None:
"""Find peaks using the `find_peaks_cwt` method from signal.
Prints number of found peaks. Figure with positions of found
Expand Down Expand Up @@ -108,7 +110,7 @@ def plot_found_peak(self) -> None:
)

def set_specifications_manually(
self, number_of_models: int, model_specifications: dict
self, number_of_models: int, model_specifications: Dict
) -> None:
"""Manually sets the specifications for the individual model
used for the fitting procedure. Stores the generated
Expand Down Expand Up @@ -176,7 +178,7 @@ def set_specifications_automatically(
) as outfile:
outfile.write(json_models_dict)

def generate_model(self, speci: dict) -> tuple:
def generate_model(self, speci: Dict) -> tuple:
"""Generates a composite model and corresponding parameters
based on the provided specifications using the `model` class
of the python library `lmfit`.
Expand Down
9 changes: 5 additions & 4 deletions sastools/analyzer/llcphase.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""ABC defining properties of different LLC phases."""

from abc import ABC, abstractmethod
from typing import List, Tuple, Dict

from sastools.analyzer.enums import LLCPhases, LLCSpaceGroups

Expand All @@ -9,7 +10,7 @@ class LLCPhase(ABC):
"""ABC defining the properties of an LLC Phase."""

@abstractmethod
def calculate_lattice_parameters(self, d_meas: list[float]):
def calculate_lattice_parameters(self, d_meas: List[float]):
...

@property
Expand All @@ -24,15 +25,15 @@ def space_group(self) -> LLCSpaceGroups:

@property
@abstractmethod
def miller_indices(self) -> tuple[list[int], list[int], list[int]]:
def miller_indices(self) -> Tuple[List[int], List[int], List[int]]:
...

@property
@abstractmethod
def lattice_parameters(self) -> list[float]:
def lattice_parameters(self) -> List[float]:
...

@property
@abstractmethod
def phase_information(self) -> dict:
def phase_information(self) -> Dict:
...
46 changes: 24 additions & 22 deletions sastools/analyzer/llcphases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import numpy as np

from typing import List, Tuple, Dict

from sastools.analyzer.enums import LLCPhases, LLCSpaceGroups, LLCMillerIndices
from sastools.analyzer.llcphase import LLCPhase

Expand All @@ -26,13 +28,13 @@ def _calculate_a_H1(self, d: float, h: int, k: int) -> float:
return a_H1

def calculate_lattice_parameters(
self, d_meas: list[float], phase: LLCPhases = LLCPhases.H1
self, d_meas: List[float], phase: LLCPhases = LLCPhases.H1
) -> None:
"""Calculate lattice parameters of hexagonal phase using a list
of measured lattice plane distances `d_meas`.
Args:
d_meas (list[float]): Measured lattice plane distances.
d_meas (List[float]): Measured lattice plane distances.
phase (LLCPhases, optional): The hexagonal phase of the system. Defaults to LLCPhases.H1.
Raises:
Expand All @@ -43,7 +45,7 @@ def calculate_lattice_parameters(
f"Chosen LLC phase '{phase}' is not (yet) supported."
)
self._exact_phase = phase
for i, j in enumerate(d_meas):
for i, _ in enumerate(d_meas):
a_i = self._calculate_a_H1(
d_meas[i], self.miller_indices[0][i], self.miller_indices[1][i]
)
Expand All @@ -64,18 +66,18 @@ def space_group(self) -> LLCSpaceGroups:
return self._space_group

@property
def miller_indices(self) -> tuple[list[int], list[int], list[int]]:
def miller_indices(self) -> Tuple[List[int], List[int], List[int]]:
"""Get miller indices of hexagonal phase."""
self._miller_indices = LLCMillerIndices[self._space_group.name].value
return self._miller_indices

@property
def lattice_parameters(self) -> list[float]:
def lattice_parameters(self) -> List[float]:
"""Get lattice parameters of hexagonal phase."""
return self._lattice_parameters

@property
def phase_information(self) -> dict:
def phase_information(self) -> Dict:
"""Get full phase information of hexagonal phase."""
self._phase_information = dict(
phase=self.exact_phase.value,
Expand Down Expand Up @@ -107,15 +109,15 @@ def _calculate_a_V1(self, d: float, h: int, k: int, l: int) -> float:

def calculate_lattice_parameters(
self,
d_meas: list[float],
d_meas: List[float],
phase: LLCPhases = LLCPhases.V1,
space_group: LLCSpaceGroups = LLCSpaceGroups.IA3D,
) -> None:
"""Calculate lattice parameters of cubic phase using a list of
measured lattice plane distances `d_meas`.
Args:
d_meas (list[float]): Measured lattice plane distances.
d_meas (List[float]): Measured lattice plane distances.
phase (LLCPhases, optional): The cubic phase of the system. Defaults to LLCPhases.V1.
space_group (LLCSpaceGroups, optional): The space group corresponding to the cubic phase. Defaults to LLCSpaceGroups.IA3D.
Expand All @@ -137,13 +139,13 @@ def calculate_lattice_parameters(
)
self._lattice_parameters.append(a_i)

def calculate_d_reciprocal(self, peak_center: list[float]) -> None:
def calculate_d_reciprocal(self, peak_center: List[float]) -> None:
"""Calculate the reciprocal lattice plane distances
`d_reciprocal` from the `peak_centers` determined through
lorentzian fitting.
Args:
peak_center (list[float]): Peak centers determined by lorentzian fitting for the cubic phase.
peak_center (List[float]): Peak centers determined by lorentzian fitting for the cubic phase.
"""
self._d_reciprocal = [peak / (2 * np.pi) for peak in peak_center]

Expand Down Expand Up @@ -180,20 +182,20 @@ def space_group(self, space_group: LLCSpaceGroups) -> None:
self._space_group = space_group

@property
def miller_indices(self) -> tuple[list[int], list[int], list[int]]:
def miller_indices(self) -> Tuple[List[int], List[int], List[int]]:
"""Get miller indices of cubic phase."""
if self.space_group is None:
raise ValueError("space_group property has to be provided first.")
self._miller_indices = LLCMillerIndices[self._space_group.name].value
return self._miller_indices

@property
def lattice_parameters(self) -> list[float]:
def lattice_parameters(self) -> List[float]:
"""Get lattice parameters of cubic phase."""
return self._lattice_parameters

@property
def phase_information(self) -> dict:
def phase_information(self) -> Dict:
"""Get full phase information of cubic phase."""
self._phase_information = dict(
phase=self.exact_phase.value,
Expand All @@ -202,12 +204,12 @@ def phase_information(self) -> dict:
return self._phase_information

@property
def d_reciprocal(self) -> list[float]:
def d_reciprocal(self) -> List[float]:
"""Get reciprocal lattice plane distances of cubic phase."""
return self._d_reciprocal

@property
def sqrt_miller(self) -> list[int]:
def sqrt_miller(self) -> List[int]:
"""Get square roots of miller indices of cubic phase."""
return self._sqrt_miller

Expand All @@ -226,13 +228,13 @@ def __repr__(self) -> str:
return "Lamellar LLC Phase"

def calculate_lattice_parameters(
self, d_meas: list[float], phase: LLCPhases = LLCPhases.LA
self, d_meas: List[float], phase: LLCPhases = LLCPhases.LA
) -> None:
"""Calculate lattice parameters of lamellar phase using a list
of measured lattice plane distances `d_meas`.
Args:
d_meas (list[float]): Measured lattice plane distances.
d_meas (List[float]): Measured lattice plane distances.
phase (LLCPhases, optional): The lamellar phase of the system. Defaults to LLCPhases.LA.
Raises:
Expand Down Expand Up @@ -265,12 +267,12 @@ def miller_indices(self) -> None:
return self._miller_indices

@property
def lattice_parameters(self) -> list[float]:
def lattice_parameters(self) -> List[float]:
"""Get lattice parameters of lamellar phase."""
return self._lattice_parameters

@property
def phase_information(self) -> dict:
def phase_information(self) -> Dict:
"""Get full phase information of lamellar phase."""
self._phase_information = dict(
phase=self.exact_phase.value,
Expand All @@ -293,13 +295,13 @@ def __repr__(self) -> str:
return "Indeterminate LLC Phase"

def calculate_lattice_parameters(
self, d_meas: list[float], phase: LLCPhases = LLCPhases.INDETERMINATE
self, d_meas: List[float], phase: LLCPhases = LLCPhases.INDETERMINATE
) -> None:
"""Do not use this method! Indeterminate phases have no lattice
parameters.
Args:
d_meas (list[float]): Measured lattice plane distances.
d_meas (List[float]): Measured lattice plane distances.
phase (LLCPhases, optional): Indeterminate phase. Defaults to LLCPhases.INDETERMINATE.
Raises:
Expand Down Expand Up @@ -330,7 +332,7 @@ def lattice_parameters(self) -> None:
return self._lattice_parameters

@property
def phase_information(self) -> dict:
def phase_information(self) -> Dict:
"""Get full phase information of indeterminate phase."""
self._phase_information = dict(
phase=self.exact_phase.value,
Expand Down
Loading

0 comments on commit 4a4b86a

Please sign in to comment.