Skip to content

Commit

Permalink
MNT: Fix flake8 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
scottclowe committed Sep 13, 2024
1 parent dbfce02 commit f5e3b92
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ max-line-length = 99
extend-ignore = E203,E402,F401,D100,D101,D102,D103,D104,D105,D106,D107,D200
docstring-convention = numpy
# Ignore missing docstrings within unit testing functions.
per-file-ignores = **/tests/:D100,D101,D102,D103,D104,D105,D106,D107
# Ignore C420 Unnecessary dict comprehension
per-file-ignores = **/tests/:D100,D101,D102,D103,D104,D105,D106,D107,C420
2 changes: 1 addition & 1 deletion docs/examples/SIMA example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"sequences = [sima.Sequence.create(\"TIFF\", tiff) for tiff in tiffs[:1]]\n",
"try:\n",
" dataset = sima.ImagingDataset(sequences, \"example.sima\")\n",
"except BaseException:\n",
"except Exception:\n",
" dataset = sima.ImagingDataset.load(\"example.sima\")"
]
},
Expand Down
2 changes: 1 addition & 1 deletion examples/SIMA example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"sequences = [sima.Sequence.create(\"TIFF\", tiff) for tiff in tiffs[:1]]\n",
"try:\n",
" dataset = sima.ImagingDataset(sequences, \"example.sima\")\n",
"except BaseException:\n",
"except Exception:\n",
" dataset = sima.ImagingDataset.load(\"example.sima\")"
]
},
Expand Down
9 changes: 6 additions & 3 deletions fissa/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,9 @@ def separate_trials(
message_extra = " for ROI {}".format(label)
warnings.warn(
"{}Found values below zero in raw signal{}. Offsetting so minimum is 0."
"".format(header, message_extra)
"".format(header, message_extra),
UserWarning,
stacklevel=2,
)
X -= X.min()

Expand Down Expand Up @@ -1177,7 +1179,7 @@ def separation_prep(self, redo=False):
self.load(fname)
if self.raw is not None:
return
except BaseException as err:
except Exception as err:
print("An error occurred while loading {}".format(fname))
print(err)
print("Extraction will be redone and {} overwritten".format(fname))
Expand Down Expand Up @@ -1379,7 +1381,7 @@ def separate(self, redo_prep=False, redo_sep=False):
self.load(fname)
if self.result is not None:
return
except BaseException as err:
except Exception as err:
print("An error occurred while loading {}".format(fname))
print(err)
print(
Expand Down Expand Up @@ -1859,6 +1861,7 @@ def save_to_matlab(self, fname=None):
"The experiment.save_to_matlab() method is deprecated."
" Please use experiment.to_matfile() instead.",
DeprecationWarning,
stacklevel=2,
)
return self.to_matfile(fname=fname, legacy=True)

Expand Down
16 changes: 12 additions & 4 deletions fissa/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,19 @@ def image2array(image):
" with {} dimensions (page shaped {})."
" All dimensions before the final two (height and"
" width) will be treated as time-like and flattened."
"".format(image, n_pages, page.ndim, page.shape)
"".format(image, n_pages, page.ndim, page.shape),
UserWarning,
stacklevel=2,
)
elif page.ndim > 3 and (np.array(page.shape[:-2]) > 1).sum() > 1:
warnings.warn(
"TIFF {} has at least one page with {} dimensions"
" (page shaped {})."
" All dimensions before the final two (height and"
" width) will be treated as time-like and flattened."
"".format(image, page.ndim, page.shape)
"".format(image, page.ndim, page.shape),
UserWarning,
stacklevel=2,
)
shp = [-1] + list(page.shape[-2:])
frames.append(page.reshape(shp))
Expand Down Expand Up @@ -327,15 +331,19 @@ def getmean(data):
" with {} dimensions (page shaped {})."
" All dimensions before the final two (height and"
" width) will be treated as time-like and flattened."
"".format("", n_pages, page.ndim, page.shape)
"".format("", n_pages, page.ndim, page.shape),
UserWarning,
stacklevel=2,
)
elif page.ndim > 3 and (np.array(page.shape[:-2]) > 1).sum() > 1:
warnings.warn(
"TIFF {} has at least one page with {} dimensions"
" (page shaped {})."
" All dimensions before the final two (height and"
" width) will be treated as time-like and flattened."
"".format("", page.ndim, page.shape)
"".format("", page.ndim, page.shape),
UserWarning,
stacklevel=2,
)
shp = [-1] + list(page.shape[-2:])
page = page.reshape(shp)
Expand Down
2 changes: 1 addition & 1 deletion fissa/readimagejrois.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def _getcoords(z=0):
coords = _getcoords(z)
coords = coords.astype("float")
return {"polygons": coords}
except BaseException:
except Exception:
raise ValueError(
"read_imagej_roi: ROI type {} not supported".format(roi_type)
)
Expand Down
4 changes: 2 additions & 2 deletions fissa/tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def assert_starts_with(actual, desired):
"""
try:
assert len(actual) >= len(desired)
except BaseException:
except Exception:
print(
"Actual string too short ({} < {} characters)".format(
len(actual), len(desired)
Expand All @@ -89,7 +89,7 @@ def assert_starts_with(actual, desired):
raise
try:
return assert_equal(str(actual)[: len(desired)], desired)
except BaseException as err:
except Exception as err:
msg = "ACTUAL: {}".format(actual)
if isinstance(getattr(err, "args", None), str):
err.args += "\n" + msg
Expand Down
2 changes: 1 addition & 1 deletion fissa/tests/generate_downsampled_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def _writecoords(points):
_writecoords(coords)
coords = coords.astype("float")
# return {'polygons': coords}
except BaseException:
except Exception:
raise ValueError(
"read_imagej_roi: ROI type {} not supported".format(roi_type)
)
Expand Down
4 changes: 2 additions & 2 deletions fissa/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ def test_load_none_force(self):
# Make a save file which contains values set to `None`
fname = os.path.join(self.output_dir, "dummy.npz")
os.makedirs(self.output_dir)
np.savez_compressed(fname, **{field: None for field in fields})
np.savez_compressed(fname, **{field: None for field in fields}) # noqa: C420
# Load the file and check the data appears as None, not np.array(None)
exp.load(fname, force=True)
for field in fields:
Expand Down Expand Up @@ -1281,7 +1281,7 @@ def test_load_scalar_force(self):
# Make a save file which contains values set to a scalar
fname = os.path.join(self.output_dir, "dummy.npz")
os.makedirs(self.output_dir)
np.savez_compressed(fname, **{field: 1337 for field in fields})
np.savez_compressed(fname, **{field: 1337 for field in fields}) # noqa: C420
# Load the file and check the data appears correctly
exp.load(fname, force=True)
for field in fields:
Expand Down

0 comments on commit f5e3b92

Please sign in to comment.