def import_ThunderSTORM(filename, pixels_2_nm=115.): """ Load localisation data from ThunderSTORM. """ with open(filename, 'rb') as csvfile: localisations = csv.reader(csvfile, delimiter=',', quotechar='"') header = localisations.next() to_use = ('frame', 'x [nm]', 'y [nm]', 'z [nm]') cols = [i for i in xrange(len(header)) if header[i] in to_use] logger.info('Found: {0:s}'.format(', '.join([header[c] for c in cols]))) objects = [] #make a new object for data in localisations: obj = btypes.PyTrackObject() obj.t = int(float(data[cols[0]])) obj.x = float(data[cols[1]]) / pixels_2_nm obj.y = float(data[cols[2]]) / pixels_2_nm if 'z [nm]' in header: obj.z = float(data[cols[3]]) else: obj.z = 0. obj.dummy = False obj.label = 0 # obj.prob = np.zeros((5,),dtype='float') objects.append(obj) return objects
def new_PyTrackObject(self, ID, txyz, label=None, type=0): """ Set up a new PyTrackObject quickly using data from a file """ if label is not None: class_label = label[0] else: class_label = 0 new_object = btypes.PyTrackObject() new_object.ID = ID new_object.t = txyz[0] new_object.x = txyz[1] new_object.y = txyz[2] new_object.z = txyz[3] new_object.dummy = False new_object.label = class_label # DONE(arl): from the classifier new_object.probability = np.zeros((1, )) new_object.type = int(type) return new_object
def import_JSON_observations(filename, labeller=None): """ import_JSON_observations Open a JSON file containing PyTrackObject objects Basic format is: { "Object_203622": { "x": 554.29737483861709, "y": 1199.362071438818, "z": 0.0, "t": 862, "label": "interphase", "states": 5, "probability": [ 0.996992826461792, 0.0021888131741434336, 0.0006106126820668578, 0.000165432647918351, 4.232166247675195e-05 ], "dummy": false } } Args: filename: the filename of the JSON file labeller: an instance of the Labeller class Notes: None """ # set a labeller if not labeller: labeller = Labeller() trk_objects = [] with open(filename, 'r') as json_file: objects = json.load(json_file) itern = 0 object_IDs = objects.keys() while objects: ID = object_IDs.pop() obj = objects.pop(ID) trk_obj = btypes.PyTrackObject() trk_obj.ID = ID_from_name(ID) for param in obj.keys(): if param == 'probability': # TODO(arl): clean this up. prob need to change JSON # writer to prevent this outcome rather than fix here if isinstance(obj['probability'], list): trk_obj.probability = np.array(obj['probability'], dtype='float') else: trk_obj.probability = np.array((), dtype='float') # append the number of states trk_obj.states = len(obj['probability']) elif param == 'label': trk_obj.label = labeller(obj['label']) else: setattr(trk_obj, param, obj[param]) trk_objects.append(trk_obj) return trk_objects