当前位置: 首页>>代码示例>>Python>>正文


Python io.savemat函数代码示例

本文整理汇总了Python中scipy.io.savemat函数的典型用法代码示例。如果您正苦于以下问题:Python savemat函数的具体用法?Python savemat怎么用?Python savemat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了savemat函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: store

    def store(self, filename=None, label=None, desc=None, date=None):
        """Store object to mat-file. TODO: determine format specification
        """
        date = date if date else datetime.now()
        date = date.replace(microsecond=0).isoformat()
        filename = filename if filename else date + '.mat'

        matfile = {
            'model': str(type(self)),
            'date': date,
            'dim': len(self.init_sol.shape),
            'dimlesses': self.coeffs,
            'init_solution': self.init_sol,
            'num_iters': self.num_iters,
            'num_nodes': self.num_nodes,
            'order': self.order,
            'originals': self.originals,
            'pumping': self.getPumping(),
            'spatial_step': self.dx,
            'time_step': self.dt,
        }

        if desc:
            matfile['desc'] = desc
        if label:
            matfile['label'] = label

        savemat(filename, matfile)
开发者ID:daskol,项目名称:nls,代码行数:28,代码来源:model.py

示例2: vti2mat

def vti2mat(fileIn, fileOut):
    """Convert voxel-array from VTI to MAT (MATLAB(R)) format.
    
    Parameters
    ----------
    fileIn : str
        Path for input VTI file.
        
    fileOut : str
        Path for output MAT file.
        
    """
    
    import numpy as np
    import vtk
    import scipy.io as sio
    from vtk.util import numpy_support as nps
    from math_utils import lcmm
    
    reader = vtk.vtkXMLImageDataReader()
    reader.SetFileName(fileIn)
    reader.Update()
    vtkImageData = reader.GetOutput()
    dim = vtkImageData.GetDimensions()
    flatV = nps.vtk_to_numpy(vtkImageData.GetPointData().GetScalars())
    V = flatV.reshape(dim[::-1])
    spacing = np.array(vtkImageData.GetSpacing())[::-1]
    estimatedFactors = lcmm(*spacing) / spacing
    estimatedVoxelSize = 1. / estimatedFactors
    sio.savemat(fileOut, {'volume':V, 'spacing': spacing, 'estimated_voxel_size': estimatedVoxelSize})
开发者ID:AlfiyaZi,项目名称:Py3DFreeHandUS,代码行数:30,代码来源:converters.py

示例3: diagrams2cellarray

def diagrams2cellarray( dia_list, outname, chop_inf=True, mat_type=np.float ):
    """dia_list : n-length list of k x 2 diagrams

    outname : name of output file. '.mat' will be automatically appended.

    Optional:
    --------

    chop_inf : Remove the row corresponding to the infinite generator.

    mat_type : some matlab programs expect a certain data type for
    diagrams (eg. Error using '+' will be thrown). defaults to
    double. Standard options should diverge far from np.int, np.float,
    np.int64, etc.

    Recipe from http://docs.scipy.org/doc/scipy/reference/tutorial/io.html#matlab-cell-arrays

    """
    n = len( dia_list )
    # object array to hold different length diagrams. Exclude the last
    # (inf) generator if chop_inf==True.
    C = np.zeros( (n,), dtype=np.object )
    
    for i,d in enumerate( dia_list ):
        # exclude last row
        if chop_inf:
            d = d[:-1]
        if d.dtype != mat_type:
            d = d.astype( mat_type )
        C[i] = d
    sio.savemat( outname+'.mat', { 'diagrams': C } )
开发者ID:caja-matematica,项目名称:pyTopTools,代码行数:31,代码来源:persistence_tools.py

示例4: RR_cv_estimate_alpha

def RR_cv_estimate_alpha(sspacing, tspacing, alphas):
    """
    Estimate the optimal regularization parameter using grid search from a list
    and via k-fold cross validation

    Parameters
    ----------
    sspacing : 2D subsampling ratio in space (in one direction)

    tspacing : 1D subsampling ratio in time

    alphas : list of regularization parameters to do grid search
    
    """
    #Load all training data
    (Xl_tr, mea_l, sig_l, Xh_tr,mea_h,sig_h) =  data_preprocess(sspacing, tspacing)  
    
    # RidgeCV
    from sklearn.linear_model import RidgeCV    
    ridge = RidgeCV(alphas = alphas, cv = 10, fit_intercept=False, normalize=False)
    ridge.fit(Xl_tr, Xh_tr)
    
    RR_alpha_opt = ridge.alpha_
    
    print('\n Optimal lambda:', RR_alpha_opt)
    
    # save to .mat file
    import scipy.io as io
    filename = "".join(['/data/PhDworks/isotropic/regerssion/RR_cv_alpha_sspacing',
                        str(sspacing),'_tspacing',str(tspacing),'.mat'])
    io.savemat(filename, dict(alphas=alphas, RR_alpha_opt=RR_alpha_opt))
    
    # return
    return RR_alpha_opt
开发者ID:linhvannguyen,项目名称:PhDworks,代码行数:34,代码来源:regressionUtils.py

示例5: run

 def run(self, y, x, initial_value, num_its, altered):
     """Run the model with the arguments: y_length, x_length, initial_value, number_of_iterations, altered"""
     self.initialise_grid(y, x, initial_value)
     
     self.write_file()
     
     self.initialise_shadow_map()
     
     self.num_iterations = num_its
     
     # Standard parameter values
     self.jump_length = 1
     self.pd_s = 0.6
     self.pd_ns = 0.4
     
     self.altered = altered
     
     if self.altered == True:
         # Create the depth grid
         self.depth = np.load("Gradual_Stepped_Full.npy")
     
     self.avcount = np.zeros(num_its + 1)
     
     # Run the model
     self.main_loop()
     
     print self.avcount
     io.savemat("Counts.mat", { "count":self.avcount})
     np.save("Counts.npy", self.avcount)
开发者ID:robintw,项目名称:WernerModel,代码行数:29,代码来源:werner.py

示例6: update_extra_mat

def update_extra_mat(matfile,to_remove):
    """ updates the time_frames, confounds and mask_suppressed arrays to
    reflect the removed volumes. However, does not change other items in
    _extra.mat file

    """

    mat = loadmat(matfile)
    # update time_frames
    ntf = np.delete(mat['time_frames'][0],to_remove)
    mat.update({'time_frames': ntf})

    # update confounds
    ncon = np.delete(mat['confounds'],to_remove,axis = 0)
    mat.update({'confounds': ncon})

    # update mask_suppressed
    ms = mat['mask_suppressed']
    for supp in to_remove:
        ms[supp][0] = 1
    mat.update({'mask_suppressed': ms})

    # save updated mat file
    jnk, flnme = os.path.split(matfile)
    savemat(os.path.join(output_dir,flnme),mat)
开发者ID:illdopejake,项目名称:ASL_TrT_project,代码行数:25,代码来源:harmonize_tag_control_frames.py

示例7: save_x

def save_x(tmpdir,x,i):
	# handle both vector and matrix inputs
	if x.ndim == 1:
		sio.savemat(tmpdir+"/x_"+`i`+".mat", {'x': x})	
	else:
		sio.savemat(tmpdir+"/x_"+`i`+".mat", {'x': x[:,i]})
	return 
开发者ID:sbordt,项目名称:markovmixing,代码行数:7,代码来源:iterate_distributions.py

示例8: write_file

 def write_file(self, ofile):
     '''
     Writes the file
     '''
     # Creates the Matlab dictionary
     mat_dict = {'longitude': self.longitude,
                 'latitude': self.latitude,
                 'imls': self.imls,
                 'imt': self.meta_info['imt'],
                 'period': None,
                 'damping': None,
                 'curves': self.curves,
                 'statistics': self.meta_info['statistics'],
                 'investigation_time': self.investigation_time}
     if self.meta_info['imt'] == 'SA':
         mat_dict['period'] = self.meta_info['period']
         mat_dict['damping'] = self.meta_info['damping']
     elif self.meta_info['imt'] == 'PGA':
         mat_dict['period'] = 0.
         
         mat_dict['damping'] = np.nan
     else:
         pass
     # Save to binary
     savemat(ofile, mat_dict, oned_as='row')
开发者ID:g-weatherill,项目名称:nrml_converters,代码行数:25,代码来源:hazard_curve_converter.py

示例9: createDictionary

    def createDictionary(self):
        fileName = QtGui.QFileDialog.getSaveFileName(self , 'Save dictionary to a file' , expanduser('~')+'/dictionary' , 'Matlab file (*.mat);;Python pickle (*.p);;Comma sep. values (*.csv);;Excel file (*.xlsx)')
        if len(fileName) == 0:
            return
        self.displayInformation('Saving dictionary...' , flag='new')
        
        fileName = str(fileName)

        self.setDictionaryConfig()
        self.setAlgorithmConfig()

        config = generateFinalConfig(self.dictionaryConfig , self.dataMatrixes[self.filePath][1] , self.dataMatrixes[self.filePath][2])
        time   = np.arange(0,self.dataMatrixes[self.filePath][1]['numberOfSamples'])
        
        dictionary = generateDictionary(time , config)

        if fileName[-4:] == '.mat':
            dic = {col_name : dictionary[col_name].values for col_name in dictionary.columns.values}
            savemat(fileName , dic)
        elif fileName[-2:] == '.p':
            dictionary.to_pickle(fileName)
        elif fileName[-4:] == '.csv':
            dictionary.to_csv(fileName)
        elif fileName[-5:] == '.xlsx':
            dictionary.to_excel(fileName, sheet_name='dictionary')
        
        self.displayInformation('Dictionary saved.' , flag='new')
开发者ID:tspus,项目名称:python-matchingPursuit,代码行数:27,代码来源:settingsFunctions.py

示例10: __init__

 def __init__(self, userParameters):
     
     
     
     num = 7+8
     VV = np.linspace(-0.6, 0.6, num)
     RR = []
     
     
     for V in VV:
         
         print("Start V = ", V)
         tic = time.clock()
         
         lL = tb.Lead(1.2, 2.0, -0.4, -0.4, 300, 0, 0)
         T1 = "-0.4, 0.0; 0.0, -0.4"
         B1 = tb.Insulator(5.4, 5.4, -0.4, -0.4, 5, 0, 0, V)
         T2 = "-0.4, 0.0; 0.0, -0.4"
         lR = tb.Lead(1.2, 2.0, -0.4, -0.4, 300, pi/2, V)
         wire = tb.Chain(lL, T1, B1, T2, lR)
         
         RR.append(self.__func3__(wire, V))
         print("Result = ", RR[-1])
         toc = time.clock()
         print("Δt = ", toc-tic, "sec\n")
         sio.savemat("result.mat", {"VV": VV, "RR": RR})
     
     print("All calculation finish")
开发者ID:lise1020,项目名称:TBMTJ,代码行数:28,代码来源:TBApp.py

示例11: write

 def write(array, file, format, varname=None):
     if format == 'matlab':
         savemat(file+".mat", mdict={varname: array}, oned_as='column', do_compression='true')
     if format == 'npy':
         save(file, array)
     if format == 'text':
         savetxt(file+".txt", array, fmt="%.6f")
开发者ID:industrial-sloth,项目名称:thunder,代码行数:7,代码来源:export.py

示例12: saveFVs

def saveFVs(QuadDir,NumberofFrame,gmm,nbc,halfWindows):
    savefilename = "{}FVS/FVsnbc_{}_halfwin_{}.mat".format(QuadDir,str(nbc),str(halfWindows[-1])) 
#    if not os.path.isfile(savefilename):
    XX = []
    print "Saving Framwise FVS for ", QuadDir;
    for numFrame in range(1,NumberofFrame+1):
        filename = '{}desc{}.mat'.format(QuadDir,str(numFrame).zfill(5))
        Quads  = sio.loadmat(filename)['QuadDescriptors']
        XX.append(Quads)
    num = np.shape(XX)[0]
#    fvs = np.zeros((NumberofFrame,nbc*13))
    Allfvs = [np.zeros((NumberofFrame,nbc*13)) for k in range(len(halfWindows)) ]
#    del fvs
    print np.shape(Allfvs),' one ',np.shape(Allfvs[0])
    for numFrame in xrange(1,NumberofFrame+1):
        wincount = -1
        for halfwin in halfWindows:
            wincount+=1
            XXtemp = []
            for fnum in np.arange(max(0,numFrame-halfwin-1),min(numFrame+halfwin,NumberofFrame),1):
                Quads = XX[fnum]
                if np.shape(Quads)[0]>1:
                    XXtemp.extend(Quads)
            num = np.shape(XXtemp)[0]
            if num>0:
                Allfvs[wincount][numFrame-1,:] = mytools.fisher_vector(XXtemp, gmm)
    
    wincount = -1    
    for halfwin in halfWindows:
        wincount+=1
        savefilename = "{}FVS/FVsnbc_{}_halfwin_{}.mat".format(QuadDir,str(nbc),str(halfwin))
        fvs = Allfvs[wincount]
        sio.savemat(savefilename,mdict = {'fvs':fvs})
开发者ID:gurkirt,项目名称:actNet-inAct,代码行数:33,代码来源:TaskII_SaveFVs4Testdata.py

示例13: debug_ana_speed

def debug_ana_speed(nnode=1000):
    # get the speed of the series solution for the calculation of the Stokeslets.
    node = np.random.sample(nnode * 3).reshape((-1, 3))
    b = 0.5

    from time import time

    cth_list = np.arange(10, 1000, 10)
    dt = np.zeros_like(cth_list, dtype=np.float)
    for i0, cth in enumerate(cth_list):
        greenFun = detail(threshold=cth, b=b)
        t0 = time()
        greenFun.solve_prepare()
        greenFun.solve_uxyz(node)
        t1 = time()
        dt[i0] = t1 - t0
        PETSc.Sys.Print('cth=%d: solve stokeslets analytically use: %fs' % (cth, dt[i0]))

    comm = PETSc.COMM_WORLD.tompi4py()
    rank = comm.Get_rank()
    if rank == 0:
        savemat('debug_ana_speed.mat',
                {'cth':    cth_list,
                 'dt_ana': dt,
                 'node':   node, },
                oned_as='column')
    return True
开发者ID:pcmagic,项目名称:stokes_flow,代码行数:27,代码来源:force_pipe.py

示例14: do_export_mat

def do_export_mat(fileHandle, b, f1_list, f2_list, f3_list, residualNorm, err, dp, ep, lp, rp, th, with_cover,
                  stokesletsInPipe_pipeFactor, vp_nodes, fp_nodes):
    comm = PETSc.COMM_WORLD.tompi4py()
    rank = comm.Get_rank()
    fileHandle = check_file_extension(fileHandle, extension='_force_pipe.mat')
    if rank == 0:
        savemat(fileHandle,
                {'b':                           b,
                 'f1_list':                     f1_list,
                 'f2_list':                     f2_list,
                 'f3_list':                     f3_list,
                 'residualNorm':                residualNorm,
                 'err':                         err,
                 'dp':                          dp,
                 'ep':                          ep,
                 'lp':                          lp,
                 'rp':                          rp,
                 'th':                          th,
                 'with_cover':                  with_cover,
                 'stokesletsInPipe_pipeFactor': stokesletsInPipe_pipeFactor,
                 'vp_nodes':                    vp_nodes,
                 'fp_nodes':                    fp_nodes},
                oned_as='column')
    PETSc.Sys().Print('export mat file to %s ' % fileHandle)
    pass
开发者ID:pcmagic,项目名称:stokes_flow,代码行数:25,代码来源:force_pipe.py

示例15: main

def main(argv):
	leveldb_name = sys.argv[1]
	print "%s" % sys.argv[1]
	print "%s" % sys.argv[2]
	print "%s" % sys.argv[3]
	print "%s" % sys.argv[4]
        # window_num = 1000;
        # window_num = 12736;
        window_num = int(sys.argv[2]);
        # window_num = 2845;

	start = time.time()
	if 'db' not in locals().keys():
		db = leveldb.LevelDB(leveldb_name)
		datum = feat_helper_pb2.Datum()

	ft = np.zeros((window_num, int(sys.argv[3])))

	for im_idx in range(window_num):
		datum.ParseFromString(db.Get(str(im_idx)))
		ft[im_idx, :] = datum.float_data

	print 'time 1: %f' %(time.time() - start)
	sio.savemat(sys.argv[4], {'feats':ft},oned_as='row')
	print 'time 2: %f' %(time.time() - start)
	print 'done!'
开发者ID:SophieZhou,项目名称:caffe-multilabel,代码行数:26,代码来源:leveldb2mat.py


注:本文中的scipy.io.savemat函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。