Example #1
0
def med_to_mat(medname):
    """Exports all stored measurement .pkl files to .mat files"""
    mypath = getcwd() + '/' + medname + '/'
    mymatpath = getcwd() + '/' + medname + '_mat/'
    if not exists(mymatpath):
        mkdir(mymatpath)
    mytakefilesprefix = medname + '_D_take-'
    myMSfile = medname + '_MS'
    if not exists(mypath):
        raise NameError(medname + ' not find in the current working directory')
    myfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
    #Load MS
    myMSpklfile = open(mypath + myMSfile + '.pkl', 'rb')
    myMSdict = pickle.load(myMSpklfile)
    myMSpklfile.close()
    myMSdict = _to_dict(myMSdict)
    io.savemat(mymatpath + myMSfile + '.mat', {'MeasurementSetup': myMSdict},
               format='5')
    for file in myfiles:
        filename = file.replace('.pkl', '')
        if mytakefilesprefix in file:
            pkl_file = open(mypath + file, 'rb')
            loadDict = pickle.load(pkl_file)
            for key in loadDict:
                if key == 'measuredData':
                    print('Exporting "' + filename + '" to .mat file.\n')
                    matDict = _to_dict(loadDict)
                    io.savemat(mymatpath + filename + '.mat',
                               matDict,
                               format='5')
Example #2
0
 def exportDict(self):
     expdic = vars(self)
     return _to_dict(expdic)