예제 #1
0
파일: output.py 프로젝트: nullsub/maui-vs
def write_time(base, cycle, time):

	if cycle is not None:

		time_group = safe_create_group(base, "time")
		kv.set_attrs(time_group.name, "vsType", "time");
	#	time_group.attrs["vsType"] = np.string_("time")

		if cycle is not None:
			kv.set_attrs(time_group.name, "vsStep", cycle);
	#		time_group.attrs["vsStep"] = cycle
		if time is not None:
			kv.set_attrs(time_group.name, "vsTime", time);
	#		time_group.attrs["vsTime"] = time

		del time_group
예제 #2
0
파일: writer.py 프로젝트: nullsub/maui-vs
    def write(self, base, base_name=""):

        mesh_groups = dict()
        datasets = dict()

        if self.__local_only:
            keys = self.__data.keys()
        else:
            keys = self.__meta_data.keys()

        for key in keys:
            md = self.__meta_data[key]

            dom_string = ""
            for i in key:
                dom_string += "_"
                dom_string += str(i)

            base_name = self.__name+dom_string
            var_group = safe_create_group(base, base_name)
            mesh_group = safe_create_group(var_group, "mesh")

            # Add mesh attributes.
          #  mesh_group.attrs["vsType"] = np.string_("mesh")
            kv.set_attrs(mesh_group.name, "vsType", "mesh");

            #mesh_group.attrs["vsKind"] = np.string_("rectilinear")
            kv.set_attrs(mesh_group.name, "vsKind", "rectilinear");
            #mesh_group.attrs["vsMD"] = np.string_(self.__name + "mesh")
            kv.set_attrs(mesh_group.name, "vsMD", self.__name + "mesh");

            data_shape = []

            if self.__type > 0:
                for i in range(self.__type):
                    data_shape.append(len(md))

            for i in range(len(md)):
                #mesh_group.attrs["vsAxis"+str(i)] = np.string_("axis"+str(i))
                kv.set_attrs(mesh_group.name, "vsAxis"+str(i), "axis"+str(i));
                ds = safe_create_dataset(mesh_group, "axis"+str(i), shape=(md[i].stop-md[i].start,), dtype='float64')
                data_shape.append(md[i].stop-md[i].start)

            # Compute shape for mesh datasets
            mesh_groups[key] = mesh_group
            test = safe_create_dataset(var_group, self.__name, shape=tuple(data_shape), dtype='float64')

            #test.attrs["vsType"] = np.string_('variable')
            kv.set_attrs(test.name, "vsType", "variable");
            #test.attrs["vsMesh"] = np.string_('/'+base_name+'/mesh')
            kv.set_attrs(test.name, "vsMesh", '/'+base_name+'/mesh')
            if self.__var_unit is not None:
                #test.attrs["vsUnits"] = np.string_(self.__var_unit)
                kv.set_attrs(test.name, "vsUnits", self.__var_unit);

            if self.__type > 0:

                #test.attrs["vsIndexOrder"] = np.string_("compMajorC")
                kv.set_attrs(test.name, "vsIndexOrder", "compMajorC");

                if self.__type < 2:
                    derived_vars = safe_create_group(base, "derived_vars")
                    #derived_vars.attrs["vsType"] = np.string_("vsVars")
                    kv.set_attrs(derived_vars.name, "vsType", "vsVars");

                    tmp = "{"
                    for i in range(len(md)):
                        tmp += self.__name+"_"+str(i)
                        if i < len(md)**self.__type-1:
                            tmp += ", "
                    tmp += "}"
                    #derived_vars.attrs[self.__name] = np.string_(tmp)
                    kv.set_attrs(derived_vars.name, self.__name, tmp)

            if 'time' in base:
                #test.attrs["vsTimeGroup"] = np.string_("/time")
                kv.set_attrs(test.name, "vsTimeGroup", "/time");

            #test.attrs["vsMD"] = np.string_(self.__name)
            kv.set_attrs(test.name, "vsMD", self.__name);
            datasets[key] = test

        # Create Mesh Groups/Datasets
        # Create Variable Datasets

        # This is done from data and domain.mesh for the corresponding process:
        # Write mesh and data
        for key in self.__data.keys():
            data_shape = []
            for i in range(len(key)):

                if H5P_COLLECTIVE:
                    with mesh_groups[key]["axis"+str(i)].collective:
                        mesh_groups[key]["axis"+str(i)][:] = self.__domains[key].mesh.axes[i][:]
                else:
                    mesh_groups[key]["axis"+str(i)][:] = self.__domains[key].mesh.axes[i][:]

            if H5P_COLLECTIVE:
                with datasets[key].collective:
                    datasets[key][:] = self.__data[key][:]
            else:
                datasets[key][:] = self.__data[key][:]
        if hasattr(context, 'comm'):
            context.comm.Barrier()

        # delete groups and datasets before closing the file!
        for d in datasets.values():
            try:
                del d
            except UnboundLocalError:
                pass

        try:
            del datasets
        except UnboundLocalError:
            pass

        try:
            del var_group
        except UnboundLocalError:
            pass

        try:
            del mesh_group
        except UnboundLocalError:
            pass

        for g in mesh_groups.values():
            try:
                del g
            except UnboundLocalError:
                pass

        try:
            del mesh_groups
        except UnboundLocalError:
            pass
예제 #3
0
파일: output.py 프로젝트: nullsub/maui-vs
def write_provenance_data(h5file):

        run_info = safe_create_group(h5file, "runinfo")
        #run_info.attrs["vsType"] = np.string_("runInfo")
	kv.set_attrs(run_info.name, "vsType", "runInfo");
        #run_info.attrs["vsSoftware"] = np.string_("maui")
	kv.set_attrs(run_info.name, "vsSoftware", "maui");
        #run_info.attrs["vsSwVersion"] = np.string_(maui.__version__)
	kv.set_attrs(run_info.name, "vsSwVersion", maui.__version__);
	#run_info.attrs["vsVsVersion"] = np.string_("4.0.0")
	kv.set_attrs(run_info.name, "vsVsVersion", "4.0.0");
        #run_info.attrs["vsUser"] = np.string_(getpass.getuser())
	kv.set_attrs(run_info.name, "vsUser", getpass.getuser());
        #run_info.attrs["vsRunDate"] = np.string_(str(datetime.datetime.now()))
	kv.set_attrs(run_info.name, "vsRunDate", str(datetime.datetime.now()))

        tmp = str(sys.executable) + " "
        for arg in sys.argv:
            tmp = tmp + str(arg) + " "

        #run_info.attrs["vsCommandLine"] = np.string_(tmp.strip())
	kv.set_attrs(run_info.name, "vsCommandLine", tmp.strip())
        #run_info.attrs["vsRunHost"] = np.string_(socket.gethostname())
	kv.set_attrs(run_info.name, "vsRunHost", socket.gethostname())

        del run_info
예제 #4
0
파일: kv_test.py 프로젝트: nullsub/maui-vs
# -*- coding: utf-8 -*-

import kv
import h5py as h5

base = h5.File("file"+'.vsh5', 'w', driver='sec2')
a_group = h5.Group.create_group(base, "time")
kv.set_attrs(a_group.name, "aa", str.encode("utf8"))
kv.set_attrs(a_group.name, "vsType1", str.encode("utf8"))
a_group = h5.Group.create_group(base, "time1")
kv.set_attrs(a_group.name, "vsType", str.encode("utf8"))
kv.set_attrs(a_group.name, "vsType1", str.encode("utf8"))
a_group = h5.Group.create_group(base, "abc")
kv.set_attrs(a_group.name, "vsType1", str.encode("utf8"))
a_group = h5.Group.create_group(base, "qabc")
kv.set_attrs(a_group.name, "vsType1", str.encode("utf8"))
base.close
kv.finalize("file")