def print_groups(filename): """ Print the image set groups for this pipeline This function outputs a JSON string to the console composed of a list of the groups in the pipeline image set. Each element of the list is a two-tuple whose first element is a key/value dictionary of the group's key and the second is a tuple of the image numbers in the group. """ path = os.path.expanduser(filename) m = Measurements(filename=path, mode="r") metadata_tags = m.get_grouping_tags() groupings = m.get_groupings(metadata_tags) json.dump(groupings, sys.stdout)
def print_groups(filename): """ Print the image set groups for this pipeline This function outputs a JSON string to the console composed of a list of the groups in the pipeline image set. Each element of the list is a two-tuple whose first element is a key/value dictionary of the group's key and the second is a tuple of the image numbers in the group. """ path = os.path.expanduser(filename) m = Measurements(filename=path, mode="r") metadata_tags = m.get_grouping_tags() groupings = m.get_groupings(metadata_tags) # Groupings are np.int64 which cannot be dumped to json groupings_export = [] for g in groupings: groupings_export.append((g[0], [int(imgnr) for imgnr in g[1]])) json.dump(groupings_export, sys.stdout)
def get_batch_commands(filename, n_per_job=1): """Print the commands needed to run the given batch data file headless filename - the name of a Batch_data.h5 file. The file should group image sets. The output assumes that the executable, "CellProfiler", can be used to run the command from the shell. Alternatively, the output could be run through a utility such as "sed": CellProfiler --get-batch-commands Batch_data.h5 | sed s/CellProfiler/farm_job.sh/ """ path = os.path.expanduser(filename) m = Measurements(filename=path, mode="r") image_numbers = m.get_image_numbers() if m.has_feature(IMAGE, GROUP_NUMBER): group_numbers = m[IMAGE, GROUP_NUMBER, image_numbers, ] group_indexes = m[IMAGE, GROUP_INDEX, image_numbers, ] if numpy.any(group_numbers != 1) and numpy.all( (group_indexes[1:] == group_indexes[:-1] + 1) | ((group_indexes[1:] == 1) & (group_numbers[1:] == group_numbers[:-1] + 1))): # # Do -f and -l if more than one group and group numbers # and indices are properly constructed # bins = numpy.bincount(group_numbers) cumsums = numpy.cumsum(bins) prev = 0 for i, off in enumerate(cumsums): if off == prev: continue print("CellProfiler -c -r -p %s -f %d -l %d" % (filename, prev + 1, off)) prev = off else: metadata_tags = m.get_grouping_tags() if len(metadata_tags) == 1 and metadata_tags[0] == "ImageNumber": for i in range(0, len(image_numbers), n_per_job): first = image_numbers[i] last = image_numbers[min(i + n_per_job - 1, len(image_numbers) - 1)] print("CellProfiler -c -r -p %s -f %d -l %d" % (filename, first, last)) else: # LoadData w/ images grouped by metadata tags groupings = m.get_groupings(metadata_tags) for grouping in groupings: group_string = ",".join( ["%s=%s" % (k, v) for k, v in list(grouping[0].items())]) print("CellProfiler -c -r -p %s -g %s" % (filename, group_string)) return