Skip to content

Commit

Permalink
Version 0.1.6
Browse files Browse the repository at this point in the history
Fixed various issues with numpy 2.0 as submitted by Maria Kisch. Provided more information on some errors. Set xslsx writer option to default to False.
  • Loading branch information
schwanbeck committed Nov 8, 2024
1 parent 28dee50 commit 7475515
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
EMAIL = '[email protected]'
AUTHOR = 'Julian Schwanbeck'
REQUIRES_PYTHON = '>=3.6.0'
VERSION = '0.1.5'
VERSION = '0.1.6'

# What packages are required for this module to be executed?
REQUIRED = [
Expand Down
2 changes: 1 addition & 1 deletion ysmr/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
# #### #### #### # ### # # # # ###### # # #### #### # # #####
or YoghurtYetis Software for Motility Recognition
"""
VERSION = (0, 1, 5)
VERSION = (0, 1, 6)

__version__ = '.'.join(map(str, VERSION))
11 changes: 9 additions & 2 deletions ysmr/helper_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ def collate_results_csv_to_xlsx(path=None, save_path=None, csv_extension='statis
try:
import xlsxwriter
except ImportError:
logger.warning('Could not import module \'xlsxwriter\', saving as .xlsx file is not possible.')
logger.warning(
'Could not import module \'xlsxwriter\', saving as .xlsx file is not possible.',
exc_info=True,
)
logger.warning('Please install xlsxwriter to save the file, or deactivate the option in tracking.ini:')
logger.warning('"collate results csv to xlsx = False"')
return
if save_path is None:
save_path = './'
Expand Down Expand Up @@ -527,7 +532,9 @@ def get_any_paths(prev_dir=None, rename=False, file_types=None, settings=None):
_config.read(settings['tracking_ini_filepath'])

try: # In case of headless or otherwise non-Tkinter cases
from tkinter import filedialog, Tk
# https://stackoverflow.com/questions/45533932/python-3-6-attributeerror-module-tkinter-has-no-attribute-filedialog/59624202#59624202
import tkinter.filedialog as filedialog
from tkinter import Tk
except ImportError:
logger.exception('Cannot import tkinter; files have to be specified manually.')
return None
Expand Down
6 changes: 5 additions & 1 deletion ysmr/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def ysmr(paths=None, settings=None, result_folder=None, multiprocess=False):
:return: list of (finished path, results)
:rtype paths_finished: list
"""

t_one = datetime.now() # to get rough time estimation
settings = get_configs(settings) # Get settings
if settings is None:
Expand Down Expand Up @@ -317,7 +318,10 @@ def ysmr(paths=None, settings=None, result_folder=None, multiprocess=False):
else:
logger.info('Finished with all files.')
if settings['collate results csv to xlsx']:
collate_results_csv_to_xlsx(path=result_folder, save_path=result_folder) # folder_path
try:
collate_results_csv_to_xlsx(path=result_folder, save_path=result_folder) # folder_path
finally:
pass

if settings['shut down after analysis']:
shutdown()
Expand Down
20 changes: 10 additions & 10 deletions ysmr/track_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,8 @@ def select_tracks(path_to_file=None, df=None, results_directory=None, fps=None,
initial_length, initial_size = (len(track_change), df.shape[0])

df['area'] = df['WIDTH'] * df['HEIGHT'] # calculate area of bacteria in px**2
# In general, area is set to np.NaN if anything is wrong, so we later only have
# to search for np.NaNs in one column in order to know which rows to remove
# In general, area is set to np.nan if anything is wrong, so we later only have
# to search for np.nans in one column in order to know which rows to remove
if settings['verbose']:
logger.debug('Starting to set NaNs')
# Remove rough outliers
Expand All @@ -634,19 +634,19 @@ def select_tracks(path_to_file=None, df=None, results_directory=None, fps=None,
(df['average_area'] >= settings['extreme area outliers lower end in px*px']) &
(df['average_area'] <= settings['extreme area outliers upper end in px*px']),
df['area'], # track is fine
np.NaN # delete otherwise
np.nan # delete otherwise
)
# Remove frames where bacterial area is x times average area
if settings['exclude measurement when above x times average area']:
df['area'] = np.where(
df['area'] <= (df['average_area'] * settings['exclude measurement when above x times average area']),
df['area'], # track is fine
np.NaN # delete otherwise
np.nan # delete otherwise
)
# set zeroes in area to NaN
# tracker.py sets width/height as 0 if it can't connect tracks,
# thus every data point with area == 0 is suspect
df.loc[df['area'] == 0, 'area'] = np.NaN
df.loc[df['area'] == 0, 'area'] = np.nan

# remove too short frames
df['length'] = (df.groupby('TRACK_ID')['POSITION_T'].transform('last') -
Expand All @@ -655,15 +655,15 @@ def select_tracks(path_to_file=None, df=None, results_directory=None, fps=None,
df['area'] = np.where(
df['length'] >= minimal_length_frames,
df['area'], # track is fine
np.NaN # delete otherwise
np.nan # delete otherwise
)

# Remove frames where GSFF predicted bacterium to be outside of frame
# df['area'] = np.where(
# (0 <= df['POSITION_X'] <= frame_width) &
# (0 <= df['POSITION_Y'] <= frame_height),
# df['area'], # track is fine
# np.NaN # delete otherwise
# np.nan # delete otherwise
# )
# -> moved to select_tracks()

Expand Down Expand Up @@ -1175,7 +1175,7 @@ def evaluate_tracks(path_to_file, results_directory, df=None, settings=None, fps
else:
cut_off_precursor = [(a, b, '{:.2f} - {:.2f}'.format(a, b)) for a, b in
zip(cut_off_list[:-1], cut_off_list[1:])]
cut_off_list = [(np.NINF, np.inf, name_all_categories)] # So one x contains all values
cut_off_list = [(-np.inf, np.inf, name_all_categories)] # So one x contains all values
cut_off_list.extend(cut_off_precursor)

# Calculate df_stats_seaborne for statistical plots
Expand All @@ -1184,7 +1184,7 @@ def evaluate_tracks(path_to_file, results_directory, df=None, settings=None, fps
df_stats_seaborne = df_stats.copy()

# To drop unassigned values later
df_stats_seaborne[cut_off_category] = np.NaN
df_stats_seaborne[cut_off_category] = np.nan
for index_cut_off, (low, high, category) in enumerate(cut_off_list):
# Since we'll concatenate df_stats to df_stats_seaborne, which already contains all
if category == name_all_categories:
Expand All @@ -1196,7 +1196,7 @@ def evaluate_tracks(path_to_file, results_directory, df=None, settings=None, fps
index_cut_off,
df_stats_seaborne[cut_off_category]
)
# All np.NaN in column get replaced with str when str values are set within column -> easier to exchange later
# All np.nan in column get replaced with str when str values are set within column -> easier to exchange later
df_stats_seaborne.dropna(subset=[cut_off_category], inplace=True)

# Exchange int values in 'Categories' for correct labels
Expand Down

0 comments on commit 7475515

Please sign in to comment.