Skip to content

Commit

Permalink
many fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ARSadri committed Oct 10, 2024
1 parent 5673933 commit bbad732
Show file tree
Hide file tree
Showing 12 changed files with 710 additions and 359 deletions.
10 changes: 9 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,12 @@ History
* added contour_overlayed
* moved loopprocessor to multiprocessor
* added printv
* added plot_marker
* added plot_marker

0.12.16 (2024-09-10)
-------------------
* added plt_confusion_matrix
* changed the name of imshow_series and imshow_by_subplots and plot_marker
* plot_marker is plt_mark
* fixes for plt_utils
* all tests passed!
16 changes: 8 additions & 8 deletions lognflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
__version__ = '0.12.15'

from .lognflow import lognflow, getLogger
from .logviewer import logviewer
from .printprogress import printprogress
from .plt_utils import (
plt_colorbar, plt_imshow, plt_violinplot, plt_imhist, transform3D_viewer)
from .utils import (
select_directory, select_file, repr_raw, replace_all,
is_builtin_collection, text_to_collection, stack_to_frame,
stacks_to_frames, ssh_system, printv, Pyrunner)
from .multiprocessor import multiprocessor, loopprocessor
from .plt_utils import plt_imshow, plt_imhist, plt_hist2
from .utils import (select_directory,
select_file,
is_builtin_collection,
text_to_collection,
printv)

from .multiprocessor import multiprocessor

def basicConfig(*args, **kwargs):
...
75 changes: 25 additions & 50 deletions lognflow/lognflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,19 @@
from .utils import (repr_raw,
replace_all,
select_directory,
stack_to_frame,
name_from_file,
is_builtin_collection,
text_to_collection,
dummy_function)
from .plt_utils import (plt_colorbar,
stack_to_frame,
plt_hist,
plt_surface,
imshow_series,
imshow_by_subplots,
plt_imshow_series,
plt_imshow_subplots,
plt_imshow,
plt_scatter3)
plt_scatter3,
plt_confusion_matrix)
from typing import Union

@dataclass
Expand Down Expand Up @@ -1343,7 +1344,7 @@ def imshow_subplots(self,
if not self.enabled: return
time_tag = self.time_tag if (time_tag is None) else time_tag

fig, ax = imshow_by_subplots(images = images,
fig, ax = plt_imshow_subplots(images = images,
frame_shape = frame_shape,
grid_locations = grid_locations,
figsize = figsize,
Expand Down Expand Up @@ -1422,17 +1423,17 @@ def imshow_series(self,
if not self.enabled: return
time_tag = self.time_tag if (time_tag is None) else time_tag

fig, ax = imshow_series(list_of_stacks,
list_of_masks = list_of_masks,
figsize = figsize,
figsize_ratio = figsize_ratio,
text_as_colorbar = text_as_colorbar,
colorbar = colorbar,
cmap = cmap,
list_of_titles_columns = list_of_titles_columns,
list_of_titles_rows = list_of_titles_rows,
fontsize = fontsize,
transpose = transpose)
fig, ax = plt_imshow_series(list_of_stacks,
list_of_masks = list_of_masks,
figsize = figsize,
figsize_ratio = figsize_ratio,
text_as_colorbar = text_as_colorbar,
colorbar = colorbar,
cmap = cmap,
list_of_titles_columns = list_of_titles_columns,
list_of_titles_rows = list_of_titles_rows,
fontsize = fontsize,
transpose = transpose)

if not return_figure:
fpath = self.savefig(
Expand Down Expand Up @@ -1489,7 +1490,8 @@ def log_confusion_matrix(self,
figsize = None,
image_format = 'jpg',
dpi = 1200,
time_tag = False):
time_tag = False,
close_plt = True):
"""log a confusion matrix
given a sklearn confusion matrix (cm), make a nice plot
Expand Down Expand Up @@ -1529,43 +1531,16 @@ def log_confusion_matrix(self,
"""
if not self.enabled: return
accuracy = np.trace(cm) / np.sum(cm).astype('float')
misclass = 1 - accuracy

if figsize is None:
figsize = np.ceil(cm.shape[0]/3)

if target_names is None:
target_names = [chr(x + 65) for x in range(cm.shape[0])]

if cmap is None:
cmap = plt.get_cmap('Blues')

plt.figure(figsize=(4*figsize, 4*figsize))
im = plt.imshow(cm, interpolation='nearest', cmap=cmap)

if target_names is not None:
tick_marks = np.arange(len(target_names))
plt.xticks(tick_marks, target_names, rotation=45)
plt.yticks(tick_marks, target_names)

for i, j in itertools_product(range(cm.shape[0]), range(cm.shape[1])):
clr = np.array([1, 1, 1, 0]) \
* (cm[i, j] - cm.min()) \
/ (cm.max() - cm.min()) + np.array([0, 0, 0, 1])
plt.text(j, i, f"{cm[i, j]:2.02f}", horizontalalignment="center",
color=clr)

plt.ylabel('True label')
plt.xlabel('Predicted label\naccuracy={:0.4f}; ' \
+ 'misclass={:0.4f}'.format(accuracy, misclass))
plt.title(title)
plt.colorbar(im, fraction=0.046, pad=0.04)

plt_confusion_matrix(
cm, target_names=target_names, title=title,
cmap=cmap, figsize=figsize)

fpath = self.savefig(
parameter_name = parameter_name,
image_format=image_format, dpi=dpi,
time_tag = time_tag)
time_tag = time_tag,
close_plt = close_plt)
return fpath

def log_animation(
Expand Down
Loading

0 comments on commit bbad732

Please sign in to comment.