Changeset 215 for canSAS2012
 Timestamp:
 Jul 31, 2012 9:04:26 AM (8 years ago)
 Location:
 canSAS2012/examples/hdf5
 Files:

 17 added
 2 deleted
 1 edited
Legend:
 Unmodified
 Added
 Removed

canSAS2012/examples/hdf5/fakecansas.py
r213 r215 3 3 import os 4 4 import sys 5 import inspect 5 6 import traceback 6 7 … … 31 32 self.nxdata.attrs["NX_class"] = "SASdata" 32 33 self.nxdata.attrs["Q_indices"] = qi 33 self.nxdata.attrs["I_ indices"] = ii34 self.nxdata.attrs["I_axes"] = ii 34 35 if mi != None: 35 36 self.nxdata.attrs["Mask_indices"] = mi … … 46 47 self.createFile() 47 48 self.createEntry("sasentry01") 48 self.createData("sasdata01", "*", "Q") 49 #data = np.genfromtxt("silver.txt", delimiter=" ", dtype=np.dtype("int16")) 49 self.createData("sasdata01", np.array([0]), "Q") 50 50 self.createDataSet("Q", np.random.rand(100,), {"units": "1/A"}) 51 51 self.createDataSet("I", np.random.rand(100,), {"units": "1/cm"}) 52 52 self.closeFile() 53 54 53 55 54 class Simple1DTimeSeries(ExampleFile): … … 57 56 self.createFile() 58 57 self.createEntry("sasentry01") 59 self.createData("sasdata01", ",*", "Time,Q") 60 #data = np.genfromtxt("silver.txt", delimiter=" ", dtype=np.dtype("int16")) 58 self.createData("sasdata01", np.array([1]), "Time,Q") 61 59 self.createDataSet("Q", np.random.rand(100,), {"units": "1/A"}) 62 60 self.createDataSet("I", np.random.rand(10,100,), {"units": "1/cm"}) … … 64 62 self.closeFile() 65 63 64 class Generic1DTimeSeries(ExampleFile): 65 def write(self): 66 self.createFile() 67 self.createEntry("sasentry01") 68 self.createData("sasdata01", np.array([0,1]), "Time,Q") 69 self.createDataSet("Q", np.random.rand(10,100,), {"units": "1/A"}) 70 self.createDataSet("I", np.random.rand(10,100,), {"units": "1/cm"}) 71 self.createDataSet("Time", np.random.rand(10,), {"units": "s"}) 72 self.closeFile() 73 74 class Simple2DCase(ExampleFile): 75 def write(self): 76 self.createFile() 77 self.createEntry("sasentry01") 78 self.createData("sasdata01", np.array([0,1]), "Q,Q") 79 self.createDataSet("Q", np.random.rand(256,100,), {"units": "1/A"}) 80 self.createDataSet("I", np.random.rand(256,100,), {"units": "1/cm"}) 81 self.closeFile() 82 83 84 class Simple2DMaskedCase(ExampleFile): 85 def write(self): 86 self.createFile() 87 self.createEntry("sasentry01") 88 self.createData("sasdata01", np.array([0,1]), "Q,Q", np.array([0,1])) 89 self.createDataSet("Q", np.random.rand(256,100,), {"units": "1/A"}) 90 self.createDataSet("I", np.random.rand(256,100,), {"units": "1/cm"}) 91 self.createDataSet("Mask", np.array(np.random.randint(0,1,256*100,).reshape(256,100), dtype=np.dtype("int8"))) 92 self.closeFile() 93 94 95 class Generic2DCase(ExampleFile): 96 def write(self): 97 self.createFile() 98 self.createEntry("sasentry01") 99 self.createData("sasdata01", np.array([0]), "Q") 100 self.createDataSet("Q", np.random.rand(256*100,), {"units": "1/A"}) 101 self.createDataSet("I", np.random.rand(256*100,), {"units": "1/cm"}) 102 self.closeFile() 103 104 105 class Generic2DTimeSeries(ExampleFile): 106 def write(self): 107 self.createFile() 108 self.createEntry("sasentry01") 109 self.createData("sasdata01", np.array([0,1]), "Time,Q") 110 self.createDataSet("Q", np.random.rand(33,256*100,), {"units": "1/A"}) 111 self.createDataSet("I", np.random.rand(33,256*100,), {"units": "1/cm"}) 112 self.createDataSet("Time", np.random.rand(33,), {"units": "ms"}) 113 self.closeFile() 114 115 116 class Generic2DTimeTPSeries(ExampleFile): 117 def write(self): 118 self.createFile() 119 self.createEntry("sasentry01") 120 self.createData("sasdata01", np.array([1,3,4]), "Temperature,Time,Pressure,Q,Q") 121 self.createDataSet("Q", np.random.rand(7,3,3), {"units": "1/A"}) 122 self.createDataSet("I", np.random.rand(3,7,2,3,3), {"units": "1/cm"}) 123 self.createDataSet("Time", np.random.rand(3,), {"units": "ms"}) 124 self.createDataSet("Temperature", np.random.rand(7,), {"units": "ms"}) 125 self.createDataSet("Pressure", np.random.rand(2,), {"units": "ms"}) 126 self.closeFile() 127 66 128 67 129 if __name__ == "__main__": 68 SimpleExampleFile("simple.h5").write() 69 Simple1DTimeSeries("simple1DTimeSeries.h5").write() 130 subclasses = [] 131 classType=ExampleFile 132 callers_module = sys._getframe(0).f_globals['__name__'] 133 classes = inspect.getmembers(sys.modules[callers_module], inspect.isclass) 134 for name, obj in classes: 135 if (obj is not classType) and (classType in inspect.getmro(obj)): 136 subclasses.append((obj, name)) 137 for file in subclasses: 138 filename = file[1]+".h5" 139 filename = filename.lower() 140 file[0](filename).write() 141 os.system("h5dump %s > %s.dump" % (filename, filename)) 70 142 143
Note: See TracChangeset
for help on using the changeset viewer.