ashirsch / spe2py

Loads Princeton Instruments LightField (SPE 3.0) files into a python environment.
16 stars 12 forks source link

metadata needs to be read alongside data #3

Open cameronsamuell opened 7 years ago

cameronsamuell commented 7 years ago

Hi, This is a fantastic utility.

Maybe i've missed an option someplace, but I don't think you're accounting for the possibility of metadata being present. In this case, the times and frame numbers will be present after the data and so become convoluted with the pixel values in your implementation. Easy enough fix, you just need to do a check for the values and dtypes in your MetaBlock and then read them in during _read_data. Alternatively compare the difference between the frame size and stride size to find the number of additional bytes to be read for each frame.

For example, the following would work for 3 pieces of metadata.

def _read_data(self, file):
        file.seek(4100)

        data = [[0 for _ in range(self.nroi)] for _ in range(self.nframes)]
        metadata = []
        for frame in range(0, self.nframes):
            for region in range(0, self.nroi):
                if self.nroi > 1:
                    data_xdim = len(self.xcoord[region])
                    data_ydim = len(self.ycoord[region])
                else:
                    data_xdim = np.asarray(self.xdim[region], np.uint32)
                    data_ydim = np.asarray(self.ydim[region], np.uint32)
                data[frame][region] = np.fromfile(file, self.dtype, data_xdim * data_ydim).reshape(data_ydim, data_xdim)
            metadata.append(np.fromfile(file, np.dtype('Int64'),3))

        return data, metadata

Cheers, Cam

ashirsch commented 7 years ago

Thanks for your interest in the project, and apologies for the delay! I've been away from the lab for the summer and don't have access to LightField, meaning that the above pull request is not currently tested on actual spe files. I'm working on getting my hands on some test files, but in the meantime please checkout the new branch and see what you think. Best!