Skip to content

Commit

Permalink
fix code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
MyPyDavid committed Oct 4, 2022
1 parent 062456c commit ff8368e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/raman_fitting/deconvolution_models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,14 @@ def add_substrate(self):

def validate_model_name_input(self, value):
"""checks if given input name is valid"""
if not type(value) == str:
if type(value) != str:
raise TypeError(
f'Given name "{value}" for model_name should be a string insteady of type({type(value).__name__})'
)
elif not value:
warn(f'\n\tThis name "{value}" is an empty string', BaseModelWarning)
return value
elif not "+" in value:
elif "+" not in value:
warn(
f'\n\tThis name "{value}" does not contain the separator "+". (could be just 1 Peak)',
BaseModelWarning,
Expand Down
2 changes: 1 addition & 1 deletion src/raman_fitting/deconvolution_models/fit_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def run_fit(self, model, _data, method="leastsq", **kws):
def get_int_label(self, value):
_lbl = ""
if isinstance(value, pd.DataFrame):
cols = [i for i in value.columns if not "ramanshift" in i]
cols = [i for i in value.columns if "ramanshift" not in i]
if len(cols) == 0:
_lbl = ""
if len(cols) == 1:
Expand Down
14 changes: 0 additions & 14 deletions src/raman_fitting/delegating/main_delegator.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,20 +247,6 @@ def simple_process_sample_wrapper(self, *sID_args, **kwargs):
self._failed_samples.append((e, sID_args, kwargs))
return exporter_sample

def _process_sample_wrapper(self, fn, *args, **kwargs):
logger.warning(
f"{self._cqnm} process_sample_wrapper args:\n\t - {fn}\n\t - {args}\n\t - {kwargs.keys()}"
)
exp_sample = None
try:
exp_sample = fn(self, *args, **kwargs)
self.export_collect.append(exp_sample)
except Exception as e:
logger.warning(
f"{self._cqnm} process_sample_wrapper exception on call {fn}: {e}"
)
self._failed_samples.append((e, args, kwargs))

def test_positions(
self, sGrp_grp, sIDnm, grp_cols=["FileStem", "SamplePos", "FilePath"]
):
Expand Down
36 changes: 20 additions & 16 deletions src/raman_fitting/exporting/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def fit_spectrum_plot(
plot_Residuals=True,
): # pragma: no cover

modname_2 = peak2
#%%
sID = res1_peak_spec.extrainfo["SampleID"]
SampleBgmean_col = res1_peak_spec.raw_data_col
Expand Down Expand Up @@ -178,14 +179,15 @@ def fit_spectrum_plot(
c="grey",
alpha=0.5,
)
ax2ndRes.plot(
FitData_2nd["RamanShift"],
FitData_2nd[res2_peak_spec.raw_data_col] - FitData_2nd[Model_data_col_2nd],
label="Residual",
lw=3,
c="k",
alpha=0.8,
)
if plot_Residuals:
ax2ndRes.plot(
FitData_2nd["RamanShift"],
FitData_2nd[res2_peak_spec.raw_data_col] - FitData_2nd[Model_data_col_2nd],
label="Residual",
lw=3,
c="k",
alpha=0.8,
)

for fit_comp_col_2nd in compscols_2nd: # automatic color cycle 'cyan' ...
ax2nd.plot(
Expand Down Expand Up @@ -227,14 +229,16 @@ def fit_spectrum_plot(
c="grey",
alpha=0.8,
)
axRes.plot(
FitData_1st["RamanShift"],
FitData_1st[res1_peak_spec.raw_data_col] - FitData_1st[Model_data_col_1st],
label="Residual",
lw=3,
c="k",
alpha=0.8,
)

if plot_Residuals:
axRes.plot(
FitData_1st["RamanShift"],
FitData_1st[res1_peak_spec.raw_data_col] - FitData_1st[Model_data_col_1st],
label="Residual",
lw=3,
c="k",
alpha=0.8,
)

for fit_comp_col_1st in compscols_1st: # automatic color cycle 'cyan' ...
ax.plot(
Expand Down
5 changes: 1 addition & 4 deletions src/raman_fitting/indexing/filedata_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

import numpy as np
import pandas as pd
# from pandas.core.base import DataError
# from pandas.core.frame import DataFrame

# from .. import __package_name__

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -121,7 +118,7 @@ def spectrum_parser(self, filepath: Path):
def use_np_loadtxt(self, filepath, usecols=(0, 1), **kwargs):

try:
loaded_array = np.loadtxt(filepath, usecols=(0, 1), **kwargs)
loaded_array = np.loadtxt(filepath, usecols=usecols, **kwargs)
except IndexError:
logger.debug(f"IndexError called np genfromtxt for {filepath}")
loaded_array = np.genfromtxt(filepath, invalid_raise=False)
Expand Down
4 changes: 2 additions & 2 deletions src/raman_fitting/processing/spectrum_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def load_data_delegator(self):
if self.info:
FP_from_info = self.info.get("FilePath", None)
if FP_from_info:
if not Path(FP_from_info) == self.file:
if Path(FP_from_info) != self.file:
raise ValueError(
f"Mismatch in value for FilePath:\{self.file} != {FP_from_info}"
)
Expand Down Expand Up @@ -307,7 +307,7 @@ def check_members(spectra: List[SpectrumDataLoader]):
_false_spectra = [
spec
for spec in spectra
if not type(spec) == SpectrumDataLoader or not hasattr(spec, "clean_data")
if type(spec) != SpectrumDataLoader or not hasattr(spec, "clean_data")
]
if _false_spectra:
logger.warning(
Expand Down

0 comments on commit ff8368e

Please sign in to comment.