Skip to content

Commit 25605c8

Browse files
committed
Adding functionality for split timing
1 parent ca65b40 commit 25605c8

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

basic_phenotyper_lib.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -633,16 +633,14 @@ def perform_spatialUMAP(spatial_umap, bc, umap_subset_per_fit, umap_subset_toggl
633633
spatial_umap.set_train_test(n_fit=n_fit, n_tra = n_tra, groupby_label = 'TMA_core_id', seed=54321, umap_subset_toggle = umap_subset_toggle)
634634

635635
# fit umap on training cells
636-
bc.startTimer()
637636
print('Fitting Model')
638637
spatial_umap.umap_fit = umap.UMAP().fit(spatial_umap.density[spatial_umap.cells['umap_train'].values].reshape((spatial_umap.cells['umap_train'].sum(), -1)))
639-
bc.printElapsedTime(f' Fitting {np.sum(spatial_umap.cells["umap_train"] == 1)} points to a model')
638+
bc.printElapsedTime(f' Fitting {np.sum(spatial_umap.cells["umap_train"] == 1)} points to a model', split = True)
640639

641640
# Transform test cells based on fitted model
642-
bc.startTimer()
643641
print('Transforming Data')
644642
spatial_umap.umap_test = spatial_umap.umap_fit.transform(spatial_umap.density[spatial_umap.cells['umap_test'].values].reshape((spatial_umap.cells['umap_test'].sum(), -1)))
645-
bc.printElapsedTime(f' Transforming {np.sum(spatial_umap.cells["umap_test"] == 1)} points with the model')
643+
bc.printElapsedTime(f' Transforming {np.sum(spatial_umap.cells["umap_test"] == 1)} points with the model', split = True)
646644

647645
spatial_umap.umap_completed = True
648646

benchmark_collector.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
Specifically to mark the time it takes for functions to run
44
and save their values in a spreadsheet (if wanted)
55
'''
6-
6+
from datetime import datetime
77
import os
88
import time
99
import numpy as np
1010
import pandas as pd
11-
from datetime import datetime
1211

1312
class benchmark_collector:
1413
'''
@@ -56,36 +55,42 @@ def __init__(self, fiol = None):
5655
self.benchmarkDF.loc[0, 'id'] = datetime.now()
5756
self.benchmarkDF.loc[0, 'on_NIDAP'] = self.on_nidap
5857
self.stTimer = None
58+
self.stTimer_split = None
5959
self.spTimer = None
6060

6161
def startTimer(self):
6262
'''
6363
Set the Start time to the current date-time
6464
'''
6565
self.stTimer = time.time()
66+
self.stTimer_split = self.stTimer
6667

6768
def stopTimer(self):
6869
'''
6970
Set the Stop time to the current date-time
7071
'''
7172
self.spTimer = time.time()
7273

73-
def elapsedTime(self):
74+
def elapsedTime(self, split = False):
7475
'''
7576
Calculate the elapsed time from the spTimer and the stTimer
7677
'''
77-
if self.stTimer is not None:
78+
if self.stTimer is not None and split is False:
79+
self.stopTimer()
80+
elapsed_time = np.round((self.spTimer - self.stTimer)/60, 2)
81+
elif self.stTimer is not None and split is True:
7882
self.stopTimer()
79-
elapsed_time = np.round(self.spTimer - self.stTimer, 3)
83+
elapsed_time = np.round((self.spTimer - self.stTimer_split)/60, 2)
84+
self.stTimer_split = self.spTimer
8085
else:
8186
elapsed_time = None
8287
return elapsed_time
8388

84-
def printElapsedTime(self, msg):
89+
def printElapsedTime(self, msg, split = False):
8590
'''
86-
Print the current value of elapsed time
91+
Print the current value of elapsed time
8792
'''
88-
print(f'{msg} took {self.elapsedTime()} s')
93+
print(f'{msg} took {self.elapsedTime(split)} min')
8994

9095
def check_df(self):
9196
'''

0 commit comments

Comments
 (0)