def field1(): from lattice import FieldLattice # Create the data fl = FieldLattice( "2.5e-9, 97.5e-9, 20/2.5e-9, 47.5e-9, 10/2.5e-9, 7.5e-9, 1") def setter_function(position): return [1, 2, 3] fl.set(setter_function) return fl
def data2(): fl = FieldLattice([(2.5e-9, 97.5e-9, 20), (2.5e-9, 47.5e-9, 10), (2.5e-9, 22.5e-9, 5)], order="F") ctr = [50.0e-9, 25.0e-9, 12.5e-9] def fn(pos): d = [(ci - pi) for ci, pi in zip(ctr, pos)] dn = norm(d) return [0, 0, 0] if dn < 1e-15 else [di / dn for di in d] fl.set(fn) return fl
def get_field(self): root_node = self.content segment_node = root_node.a_segment h = segment_node.a_header ss = [h.a_xstepsize, h.a_ystepsize, h.a_zstepsize] dx, dy, dz = [0.5 * ssi.value for ssi in ss] min_max_ndim = \ [(h.a_xmin.value - dx, h.a_xmax.value + dx, h.a_xnodes.value), (h.a_ymin.value - dy, h.a_ymax.value + dy, h.a_ynodes.value), (h.a_zmin.value - dz, h.a_zmax.value + dz, h.a_znodes.value)] field_data = segment_node.a_data.field field_dim = root_node.field_dim return FieldLattice(min_max_ndim, dim=field_dim, data=field_data, order='F')
def read(self, stream): if not isinstance(stream, OVFStream): stream = OVFStream(stream) self.content.read(stream, root=self.content) self.content._end_section("main") def write(self, stream): if not isinstance(stream, OVFStream): stream = OVFStream(stream, mode="w") self.content.write(stream, root=self.content) if __name__ == "__main__no": import sys print("Reading") ovf = OVFFile(sys.argv[1]) print("Writing") # ovf.content.a_segment.a_databinary8.name = "Data Binary 4" ovf.write(sys.argv[2]) print("Done") elif __name__ == "__main__": # Here is how to create an OVF file from a FieldLattice object fl = FieldLattice("2.5e-9,97.5e-9,20/2.5e-9,47.5e-9,10/2.5e-9,7.5e-9,1", order="F") fl.set(lambda pos: [1, 0, 0]) ovf = OVFFile() ovf.new(fl, version=OVF20, data_type="binary8") ovf.content.a_segment.a_header.a_title = "MyFile" ovf.write("new-v1.ovf")