def process_data(conn,script_params,file_id,coords,sr_pix_size,nm_per_pixel): """ Calculates the neighbour distance in all the rectangular rois """ image_id = script_params['ImageID'] image = conn.getObject("Image",image_id) if not image: message = 'Could not find specified image' return message imageName = image.getName() name,ext = os.path.splitext(imageName) if 'ome' in name: name = name.split('.')[0] new_name = name + '_sr_histogram.ome' + ext else: new_name = name + '_sr_histogram' + ext parentDataset = image.getParent() parentProject = parentDataset.getParent() updateService = conn.getUpdateService() frame_width = image.getSizeX() print 'frame_width',frame_width frame_height = image.getSizeY() print 'frame_height',frame_height sizeT = 1 sizeZ = 1 if 'czi' in ext: num_frames = image.getSizeT() else: num_frames = image.getSizeZ() if 'zeiss2d2chan' in script_params['File_Type']: sizeC = 2 else: sizeC = 1 binsx = (frame_width * nm_per_pixel) / sr_pix_size binsy = (frame_height * nm_per_pixel) / sr_pix_size hist_data = np.zeros((sizeC,binsy,binsx)) for c in range(sizeC): hist = calc_hist('2d',coords[c,:,:],num_frames,binsy,binsx) hist_data[c,:,:] = hist def plane_gen(): for z in range(sizeZ): for c in range(sizeC): for t in range(sizeT): plane = hist_data[c,:,:] yield plane description = "Created from image:\n Name: %s\n File ID: %d" % (imageName, file_id) newImg = conn.createImageFromNumpySeq( plane_gen(), new_name, sizeZ=sizeZ, sizeC=sizeC, sizeT=sizeT, description=description) if newImg: iid = newImg.getId() print "New Image Id = %s" % iid # put new images in existing dataset dataset = None if parentDataset is not None and parentDataset.canLink(): parentDataset = parentDataset._obj else: parentDataset = None parentProject = None # don't add Dataset to parent. if parentDataset is None: link = None print "No dataset created or found for new images."\ " Images will be orphans." else: dsLink = omero.model.DatasetImageLinkI() dsLink.parent = omero.model.DatasetI( parentDataset.id.val, False) dsLink.child = omero.model.ImageI(iid, False) updateService.saveObject(dsLink) if parentProject and parentProject.canLink(): # and put it in the current project projectLink = omero.model.ProjectDatasetLinkI() projectLink.parent = omero.model.ProjectI( parentProject.getId(), False) projectLink.child = omero.model.DatasetI( dataset.id.val, False) updateService.saveAndReturnObject(projectLink) message = 'Super resolution histogram successfully created' else: message = 'Something went wrong, could not make super resolution histogram' return message