예제 #1
0
def write_csv(lat, data_path, mode='non-lin', source='silo'):
    "This reads curves from a silo file and writes the data to a csv file:"

    import os
    import pyvisfile.silo as silo
    import csv

    if source == 'silo':

        files = files_in_folder(path=data_path, filetype='silo')

        os.makedirs(data_path + '/csv')

        print 'Writing ' + str(len(files)) + ' cvs files.'

        i = 0
        for x in files:
            f = silo.SiloFile(x, create=False, mode=silo.DB_READ)
            curves = f.get_toc().curve_names

            if lat.spect and mode == 'non-lin':
                k_val = f.get_curve('field1' + '_S_k').x
            if lat.gws and mode == 'non-lin':
                k_val2 = f.get_curve('gw_spectrum').x
            if mode == 'non-lin':
                t_val = f.get_curve('a').x
            elif mode == 'homog':
                t_val = f.get_curve('a_hom').x

            f_name = data_path + '/csv/' + x.split('.')[-2] + '.csv'

            csv_file = open(f_name, 'w')
            writer = csv.writer(csv_file)
            if lat.gws:
                writer.writerow(['t_val', 'k_val', 'k_val2'] + curves)
            else:
                writer.writerow(['t_val', 'k_val'] + curves)
            writer.writerow(t_val)
            if lat.spect and mode == 'non-lin':
                writer.writerow(k_val)
            if lat.gws and mode == 'non-lin':
                writer.writerow(k_val2)
            for curve in curves:
                writer.writerow(f.get_curve(curve).y)

            csv_file.close()
            f.close()

            i += 1
예제 #2
0
    def write(self,filename):
        """write silo file with name `filename`"""

        # open the silo file
        self.f = silo.SiloFile(filename, mode = silo.DB_CLOBBER)

        # write the mesh
        self.f.put_quadmesh("mesh", self.mesh)

        # write the data
        for item in zip(self.keys,self.values):
            self.f.put_quadvar1(item[0], "mesh", item[1], item[1].shape,
                    centering = silo.DB_NODECENT)

        # close file
        self.f.close()
예제 #3
0
def main():
    p = argparse.ArgumentParser()
    p.add_argument('input_npz')
    p.add_argument('output_silo')
    args = p.parse_args()

    inp = np.load(args.input_npz)
    
    mesh = np.asarray(inp['coords'].T, order='C')
    v = np.asarray(inp['v'], order='C')
    v = np.clip(v, -5, 10)
    
    if os.path.exists(args.output_silo):
        p.error('File exists: %s' % args.output_silo)
    with silo.SiloFile(args.output_silo) as f:
        f.put_pointmesh('mesh', mesh)
        for i in range(20):
            f.put_pointvar1('var_%d' % i, 'mesh', np.ascontiguousarray(v[i, :]))
예제 #4
0
# modified from original code by Matthieu Haefele (IPP, Max-Planck-Gesellschaft)

import numpy
import pyvisfile.silo as silo

f = silo.SiloFile("qmesh.silo", mode=silo.DB_CLOBBER)
coord = [
        numpy.linspace(-1.0, 1.0, 50),
        numpy.linspace(-2.0, 2.0, 100)
        ]

f.put_quadmesh("meshxy", coord)

value = coord[0][:, numpy.newaxis] * coord[1][numpy.newaxis, :]

f.put_quadvar1("value", "meshxy", numpy.asarray(value, order="F"), value.shape,
        centering=silo.DB_NODECENT)

f.close()