Skip to content

Commit

Permalink
Update DFL
Browse files Browse the repository at this point in the history
1. Changed edge removal after ComDet from 5% to 2%.
2. DFL result filename now includes the method and parameter used for the analysis.
3. Error handling when empty FoV were encountered, a place holder will be put on the summary table.
  • Loading branch information
zengjiexia committed Apr 3, 2023
1 parent b01eded commit 5ed8713
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
19 changes: 14 additions & 5 deletions logics.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@

class DiffractionLimitedAnalysis:

def __init__(self, data_path):
def __init__(self, data_path, parameters):

self.error = 1 # When this value is 1, no error was detected in the object.
self.path_program = os.path.dirname(__file__)
self.path_data_main = data_path
self.parameters = parameters

# Construct dirs for results
self.path_result_main = data_path + '_results'
self.path_result_main = data_path + '_results' + self.parameters
if os.path.isdir(self.path_result_main) != 1:
os.mkdir(self.path_result_main)
self.path_result_raw = os.path.join(self.path_result_main, 'raw')
Expand Down Expand Up @@ -144,8 +145,8 @@ def call_ComDet(self, size, threshold, progress_signal=None, IJ=None):
print('No spot found in FoV: ' + field)
else:
img_dimensions = Image.open(imgFile).size
df = df.loc[(df['X_(px)'] >= img_dimensions[0] * 0.05) & (df['X_(px)'] <= img_dimensions[0] * 0.95)]
df = df.loc[(df['Y_(px)'] >= img_dimensions[1] * 0.05) & (df['Y_(px)'] <= img_dimensions[1] * 0.95)]
df = df.loc[(df['X_(px)'] >= img_dimensions[0] * 0.02) & (df['X_(px)'] <= img_dimensions[0] * 0.98)]
df = df.loc[(df['Y_(px)'] >= img_dimensions[1] * 0.02) & (df['Y_(px)'] <= img_dimensions[1] * 0.98)]
# Remove particles detected in the 5% pixels from the edges
df = df.reset_index(drop=True)
df.to_csv(saveto + '_results.csv')
Expand Down Expand Up @@ -368,7 +369,15 @@ def generate_reports(self, progress_signal=None):
})
summary_report = pd.concat([summary_report, df_sum])
except pd.errors.EmptyDataError:
pass
df_sum = pd.DataFrame.from_dict({
'Well': [well],
'NoOfFoV': [len(self.wells[well])],
'ParticlePerFoV': [0],
'MeanSize': [0],
'MeanIntegrInt': [0],
'MeanIntPerArea': [0]
})
summary_report = pd.concat([summary_report, df_sum])
if progress_signal == None:
pass
else:
Expand Down
16 changes: 10 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ def clickDFLSPRun(self):

def clickDFLSPGenerateReports(self):
data_path = self.window.DFLSP_pathEntry.text()
self.data_path = data_path.replace('_results', '')
self.data_path = data_path.replace('_results' + self.parameters, '')
self.window.DFLSP_pathEntry.setText(self.data_path)
guard = self._checkDFLSPParameters()
if guard == 1:
if os.path.isdir(self.data_path + '_results') ==False:
if os.path.isdir(self.data_path + '_results' + self.parameters) ==False:
self.showMessage('w', 'This dataset has not been analysed. Please run analysis.')
else:

Expand All @@ -170,11 +170,11 @@ def clickDFLSPGenerateReports(self):

def clickDFLSPReadTaggedResults(self):
data_path = self.window.DFLSP_pathEntry.text()
self.data_path = data_path.replace('_results', '')
self.data_path = data_path.replace('_results' + self.parameters, '')
self.window.DFLSP_pathEntry.setText(self.data_path)
guard = self._checkDFLSPParameters()
if guard == 1:
if os.path.isdir(self.data_path + '_results') ==False:
if os.path.isdir(self.data_path + '_results' + self.parameters) ==False:
self.showMessage('w', 'This dataset has not been analysed. Please run analysis.')
else:
self.updateLog('Data path set to '+data_path)
Expand All @@ -194,6 +194,9 @@ def _checkDFLSPParameters(self):
self.window.DFLSP_pathEntry.setText(self.data_path)
self.updateLog('Data path set to '+data_path)

# Get the method for analysis
self.method = self.window.DFLSP_methodSelector.currentText()

# Check input: threshold
try:
self.threshold = int(self.window.DFLSP_thresholdEntry.text())
Expand All @@ -218,7 +221,8 @@ def _checkDFLSPParameters(self):
else:
self.updateLog('Estimated particle size set as '+str(self.size)+' pixels.')

self.project = DiffractionLimitedAnalysis(self.data_path) # Creat DiffractionLimitedAnalysis object
self.parameters = '_' + self.method + '_' + str(self.threshold) + '_' + str(self.size)
self.project = DiffractionLimitedAnalysis(self.data_path, self.parameters) # Creat DiffractionLimitedAnalysis object
if self.project.error == 1:
return 1
else:
Expand All @@ -231,7 +235,7 @@ def _runDFLSPAnalysis(self):
# Create a QThread object
self.PFThread = QThread()
# Create a worker object
self.particleFinder = toolbox.DFLParticleFinder(self.window.DFLSP_methodSelector.currentText(), self.project, self.size, self.threshold, self.IJ)
self.particleFinder = toolbox.DFLParticleFinder(self.method, self.project, self.size, self.threshold, self.IJ)

# Connect signals and slots
self.PFThread.started.connect(self.particleFinder.run)
Expand Down

0 comments on commit 5ed8713

Please sign in to comment.