Skip to content

Commit ff8368e

Browse files
committed
fix code smells
1 parent 062456c commit ff8368e

File tree

6 files changed

+26
-39
lines changed

6 files changed

+26
-39
lines changed

src/raman_fitting/deconvolution_models/base_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,14 @@ def add_substrate(self):
220220

221221
def validate_model_name_input(self, value):
222222
"""checks if given input name is valid"""
223-
if not type(value) == str:
223+
if type(value) != str:
224224
raise TypeError(
225225
f'Given name "{value}" for model_name should be a string insteady of type({type(value).__name__})'
226226
)
227227
elif not value:
228228
warn(f'\n\tThis name "{value}" is an empty string', BaseModelWarning)
229229
return value
230-
elif not "+" in value:
230+
elif "+" not in value:
231231
warn(
232232
f'\n\tThis name "{value}" does not contain the separator "+". (could be just 1 Peak)',
233233
BaseModelWarning,

src/raman_fitting/deconvolution_models/fit_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def run_fit(self, model, _data, method="leastsq", **kws):
131131
def get_int_label(self, value):
132132
_lbl = ""
133133
if isinstance(value, pd.DataFrame):
134-
cols = [i for i in value.columns if not "ramanshift" in i]
134+
cols = [i for i in value.columns if "ramanshift" not in i]
135135
if len(cols) == 0:
136136
_lbl = ""
137137
if len(cols) == 1:

src/raman_fitting/delegating/main_delegator.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -247,20 +247,6 @@ def simple_process_sample_wrapper(self, *sID_args, **kwargs):
247247
self._failed_samples.append((e, sID_args, kwargs))
248248
return exporter_sample
249249

250-
def _process_sample_wrapper(self, fn, *args, **kwargs):
251-
logger.warning(
252-
f"{self._cqnm} process_sample_wrapper args:\n\t - {fn}\n\t - {args}\n\t - {kwargs.keys()}"
253-
)
254-
exp_sample = None
255-
try:
256-
exp_sample = fn(self, *args, **kwargs)
257-
self.export_collect.append(exp_sample)
258-
except Exception as e:
259-
logger.warning(
260-
f"{self._cqnm} process_sample_wrapper exception on call {fn}: {e}"
261-
)
262-
self._failed_samples.append((e, args, kwargs))
263-
264250
def test_positions(
265251
self, sGrp_grp, sIDnm, grp_cols=["FileStem", "SamplePos", "FilePath"]
266252
):

src/raman_fitting/exporting/plotting.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def fit_spectrum_plot(
117117
plot_Residuals=True,
118118
): # pragma: no cover
119119

120+
modname_2 = peak2
120121
#%%
121122
sID = res1_peak_spec.extrainfo["SampleID"]
122123
SampleBgmean_col = res1_peak_spec.raw_data_col
@@ -178,14 +179,15 @@ def fit_spectrum_plot(
178179
c="grey",
179180
alpha=0.5,
180181
)
181-
ax2ndRes.plot(
182-
FitData_2nd["RamanShift"],
183-
FitData_2nd[res2_peak_spec.raw_data_col] - FitData_2nd[Model_data_col_2nd],
184-
label="Residual",
185-
lw=3,
186-
c="k",
187-
alpha=0.8,
188-
)
182+
if plot_Residuals:
183+
ax2ndRes.plot(
184+
FitData_2nd["RamanShift"],
185+
FitData_2nd[res2_peak_spec.raw_data_col] - FitData_2nd[Model_data_col_2nd],
186+
label="Residual",
187+
lw=3,
188+
c="k",
189+
alpha=0.8,
190+
)
189191

190192
for fit_comp_col_2nd in compscols_2nd: # automatic color cycle 'cyan' ...
191193
ax2nd.plot(
@@ -227,14 +229,16 @@ def fit_spectrum_plot(
227229
c="grey",
228230
alpha=0.8,
229231
)
230-
axRes.plot(
231-
FitData_1st["RamanShift"],
232-
FitData_1st[res1_peak_spec.raw_data_col] - FitData_1st[Model_data_col_1st],
233-
label="Residual",
234-
lw=3,
235-
c="k",
236-
alpha=0.8,
237-
)
232+
233+
if plot_Residuals:
234+
axRes.plot(
235+
FitData_1st["RamanShift"],
236+
FitData_1st[res1_peak_spec.raw_data_col] - FitData_1st[Model_data_col_1st],
237+
label="Residual",
238+
lw=3,
239+
c="k",
240+
alpha=0.8,
241+
)
238242

239243
for fit_comp_col_1st in compscols_1st: # automatic color cycle 'cyan' ...
240244
ax.plot(

src/raman_fitting/indexing/filedata_parser.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
import numpy as np
1212
import pandas as pd
13-
# from pandas.core.base import DataError
14-
# from pandas.core.frame import DataFrame
1513

16-
# from .. import __package_name__
1714

1815
logger = logging.getLogger(__name__)
1916

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

123120
try:
124-
loaded_array = np.loadtxt(filepath, usecols=(0, 1), **kwargs)
121+
loaded_array = np.loadtxt(filepath, usecols=usecols, **kwargs)
125122
except IndexError:
126123
logger.debug(f"IndexError called np genfromtxt for {filepath}")
127124
loaded_array = np.genfromtxt(filepath, invalid_raise=False)

src/raman_fitting/processing/spectrum_constructor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def load_data_delegator(self):
8989
if self.info:
9090
FP_from_info = self.info.get("FilePath", None)
9191
if FP_from_info:
92-
if not Path(FP_from_info) == self.file:
92+
if Path(FP_from_info) != self.file:
9393
raise ValueError(
9494
f"Mismatch in value for FilePath:\{self.file} != {FP_from_info}"
9595
)
@@ -307,7 +307,7 @@ def check_members(spectra: List[SpectrumDataLoader]):
307307
_false_spectra = [
308308
spec
309309
for spec in spectra
310-
if not type(spec) == SpectrumDataLoader or not hasattr(spec, "clean_data")
310+
if type(spec) != SpectrumDataLoader or not hasattr(spec, "clean_data")
311311
]
312312
if _false_spectra:
313313
logger.warning(

0 commit comments

Comments
 (0)