Skip to content

Commit

Permalink
Added option to avoid recalculating features if they already exist
Browse files Browse the repository at this point in the history
  • Loading branch information
manics committed Jun 4, 2013
1 parent a66422c commit e919df3
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions scripts/Omero_Searcher_Feature_Calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@



def listExistingCZTS(conn, imageId, ftset):
"""
List the available CZT and scales for features associated with an image
feature table.
Returns a list of tuples (C, Z, T, scale)
"""
try:
ftnames, ftvalues = pyslid.features.get(
conn, 'vector', imageId, set=ftset)
return [r[1:5] for r in ftvalues]
except pyslid.utilities.PyslidException:
return []


def extractFeaturesOneChannel(conn, image, scale, ftset, scaleSet,
channels, zslice, timepoint):
"""
Expand Down Expand Up @@ -66,15 +80,18 @@ def extractFeaturesOneChannel(conn, image, scale, ftset, scaleSet,


def extractFeatures(conn, image, scale, ftset, scaleSet,
channels, zselect, tselect):
channels, zselect, tselect, recalc):
"""
Extract features for the requested channel(s)
"""

message = ''
imageId = image.getId()

# TODO: provide user option to only calculate if not already present
if recalc:
existing = []
else:
existing = listExistingCZTS(conn, imageId, ftset)

if zselect[0]:
zslice = image.getSizeZ() / 2
Expand Down Expand Up @@ -120,8 +137,13 @@ def extractFeatures(conn, image, scale, ftset, scaleSet,

for c in readoutCh:
chs = [c] + otherChs
message += extractFeaturesOneChannel(
conn, image, scale, ftset, scaleSet, chs, zslice, timepoint)

if (c, zslice, timepoint, scale) in existing:
message += 'Features already present for %d %d.%d.%d %e\n' % (
imageId, c, zslice, timepoint, scale)
else:
message += extractFeaturesOneChannel(
conn, image, scale, ftset, scaleSet, chs, zslice, timepoint)

return message

Expand All @@ -133,6 +155,7 @@ def processImages(client, scriptParams):
dataType = scriptParams['Data_Type']
ids = scriptParams['IDs']
ftset = scriptParams['Feature_set']
recalc = scriptParams['Recalculate_Existing_Features']
scale = float(scriptParams['Scale'])

channels = (scriptParams['Readout_All_Channels'],
Expand Down Expand Up @@ -163,7 +186,7 @@ def processImages(client, scriptParams):
message += 'Processing image id:%d\n' % image.getId()
msg = extractFeatures(
conn, image, scale, ftset, scaleSet,
channels, zselect, tselect)
channels, zselect, tselect, recalc)
message += msg + '\n'

else:
Expand All @@ -179,7 +202,7 @@ def processImages(client, scriptParams):
message += 'Processing image id:%d\n' % image.getId()
msg = extractFeatures(
conn, image, scale, ftset, scaleSet,
channels, zselect, tselect)
channels, zselect, tselect, recalc)
message += msg + '\n'

# Finally tidy up by removing duplicates
Expand Down Expand Up @@ -260,8 +283,14 @@ def runScript():
default=-1),


scripts.Bool(
'Recalculate_Existing_Features', optional=False, grouping='7',
description='Recalculate features if already present',
default=False),


scripts.String(
'Scale', optional=False, grouping='7',
'Scale', optional=False, grouping='8',
description='Scale',
default=rstring('1.0')),

Expand Down

0 comments on commit e919df3

Please sign in to comment.