Пример #1
0
def save_text_file(text, filename=None):
    """save_text_file(text, filename=None)
        Save a string to a text file

        Parameters:
            filename (str): Text will be saved here
            text (str): Text to be saved

        Returns:
            Tuple with directory filename is stored in and filename's location

        """
    if filename is None or filename is False:
        filetypes = '*.txt'
        prompt = 'Save File As Txt'
        filename = save_file_gui(prompt, filetypes=filetypes)
        if filename is None:
            return None
    g.m.statusBar().showMessage('Saving Points in {}'.format(
        os.path.basename(filename)))
    file = open(filename, 'w')
    file.write(text)
    file.close()
    g.m.statusBar().showMessage('Successfully saved {}'.format(
        os.path.basename(filename)))
    directory = os.path.dirname(filename)
    return directory, filename
Пример #2
0
 def savetracksjson(self):
     tracks = self.points.tracks
     if isinstance(tracks[0][0], np.int64):
         tracks = [[np.asscalar(a) for a in b] for b in tracks]
     txy_pts = self.points.txy_pts.tolist()
     filename = save_file_gui("Save tracks as json", filetypes='*.json')
     pts = {'tracks': tracks, 'txy_pts': txy_pts}
     json.dump(pts,
               codecs.open(filename, 'w', encoding='utf-8'),
               separators=(',', ':'),
               sort_keys=True,
               indent=4)  ### this saves the array in .json format
 def savetracks(self):
     tracks = self.points.tracks
     if isinstance(tracks[0][0], np.int64):
         tracks = [[np.asscalar(a) for a in b] for b in tracks]
     txy_pts = self.points.txy_pts.tolist()
     txy_intensities = self.points.intensities
     filename = save_file_gui("Save all tracks as json  (also saves linked tracks as csv)", filetypes='*.json')
     base = os.path.splitext(filename)[0]
     filename_csv = base + '.csv'
     pts = {'tracks': tracks, 'txy_pts': txy_pts, 'txy_intensities': txy_intensities}
     json.dump(pts, codecs.open(filename, 'w', encoding='utf-8'), separators=(',', ':'), sort_keys=True, indent=4)  ### this saves the array in .json format
     self.savetrackscsv(filename_csv)
Пример #4
0
 def saveInsight(self):
     tracks = self.points.tracks
     kwargs = {'pts': self.pts_refined, 'tracks': tracks}
     save_file_gui(write_insight_bin, '.bin', 'Save File', kwargs)
Пример #5
0
    def savetracksCSV(self):
        self.exportIntensity = True
        #Intensity value export option
        if self.blurred_window_selector.window is None:
            g.alert(
                'If you wish to export intensity values (mean for 3x3 pixel around x,y position) first set a Blurred Window. Otherwise just x,y coordinates exported'
            )
            self.exportIntensity = False

        if self.exportIntensity:
            self.dataArray = self.blurred_window_selector.window.imageArray()
            #get intensities
            self.getIntensities()

        tracks = self.points.tracks
        if isinstance(tracks[0][0], np.int64):
            tracks = [[np.asscalar(a) for a in b] for b in tracks]
        txy_pts = self.points.txy_pts.tolist()

        if self.exportIntensity:
            txy_intensities = self.points.intensities

        filename = save_file_gui("Save tracks as CSV", filetypes='*.csv')

        #filter tracks list to only include linked tracks
        linkedTracks = [item for item in tracks if len(item) > 1]

        #get xy coordinates and intensities for linked tracks
        trackNumber = []

        txy_intensitiesByTrack = []

        # for i, indices in enumerate(linkedTracks):
        #     trackNumber.append( i )
        #     txy_ptsByTrack.append(list(txy_pts[j] for j in indices))
        #     #txy_intensitiesByTrack.append(list(txy_intensities[k] for k in indices))

        frameList = []
        xList = []
        yList = []

        for i, indices in enumerate(linkedTracks):
            ptsList = list(txy_pts[j] for j in indices)
            if self.exportIntensity:
                intensitiesList = list(txy_intensities[k] for k in indices)

            for pts in ptsList:
                trackNumber.append(i)
                frameList.append(pts[0])
                xList.append(pts[1])
                yList.append(pts[2])

            if self.exportIntensity:
                for intensity in intensitiesList:
                    txy_intensitiesByTrack.append(intensity)

        #make dataframe of tracks, xy coordianates and intensities for linked tracks

        if self.exportIntensity:
            dict = {
                'track_number': trackNumber,
                'frame': frameList,
                'x': xList,
                'y': yList,
                'intensities': txy_intensitiesByTrack
            }

        else:
            dict = {
                'track_number': trackNumber,
                'frame': frameList,
                'x': xList,
                'y': yList
            }

        self.linkedtrack_DF = pd.DataFrame(dict)

        #save df as csv
        self.linkedtrack_DF.to_csv(filename, index=False)

        print('CSV file {} saved'.format(filename))
Пример #6
0
 def saveLogData():
     f = save_file_gui("Save Logged Ploynomial Fit Data",
                       filetypes="*.txt")
     if f:
         self.saveLoggedData(f)