################################################################################################### #Data Manipulation: Using the data access API to generate and retrieve data ################################################################################################### FormatTIFF.setParallelWriting(False) #Creating a 1D dataset from an array print "---- 1 -------" path="group/data1" data1d = [1.0, 2.0, 3.0, 4.0, 5.0] save_dataset(path, data1d) flush_data() #Reading ii back read =load_data(path) print read.tolist() assert data1d==read.tolist() plot(read) set_attribute(path, "AttrString", "Value") set_attribute(path, "AttrInteger", 1) set_attribute(path, "AttrDouble", 2.0) set_attribute(path, "AttrBoolean", True) #Creating a 2D dataset from an array with some attributes print "---- 2 -------" data2d = [ [1.0, 2.0, 3.0, 4.0, 5.0], [2.0, 3.0, 4.0, 5.0, 6.0, ], [3.0, 4.0, 5.0, 6.0, 7.0]] path="group/data2" save_dataset(path, data2d) set_attribute(path, "AttrString", "Value") set_attribute(path, "AttrInteger", 1) set_attribute(path, "AttrDouble", 2.0) set_attribute(path, "AttrBoolean", True) #Reading it back read =load_data(path) print read.tolist() plot(read) #Creating a 3D dataset from an array print "---- 3 -------" data3d = [ [ [1,2,3,4,5], [2,3,4,5,6], [3,4,5,6,7]], [ [3,2,3,4,5], [4,3,4,5,6], [5,4,5,6,7]]] path="group/data3" save_dataset(path, data3d) #Reading it back read =load_data(path,0) print read.tolist() read =load_data(path,1) print read.tolist() set_attribute(path, "AttrString", "Value") set_attribute(path, "AttrInteger", 1) set_attribute(path, "AttrDouble", 2.0) set_attribute(path, "AttrBoolean", True) #Creating a 2D dataset adding lines one by one print "---- 4 -------" path = "group/data4" create_dataset(path, 'd', False, (0,0)) for row in data2d: append_dataset(path, row) read =load_data(path) print read.tolist() plot(read) set_attribute(path, "AttrString", "Value") set_attribute(path, "AttrInteger", 1) set_attribute(path, "AttrDouble", 2.0) set_attribute(path, "AttrBoolean", True) #Creating a 3D dataset adding images one by one print "---- 5 -------" path = "group/data5" create_dataset(path, 'd', False, (0,0,0)) for i in range(len(data3d)): append_dataset(path,data3d[i]) read =load_data(path,0) print read.tolist() read =load_data(path,1) print read.tolist() set_attribute(path, "AttrString", "Value") set_attribute(path, "AttrInteger", 1) set_attribute(path, "AttrDouble", 2.0) set_attribute(path, "AttrBoolean", True)